Sorting by Mission Type
by Ronald J Nelson · in Torque Game Engine · 08/28/2005 (1:10 am) · 6 replies
I am wanting to be able to sort my list of available missions by the type of mission they are (ie: Deathmatch, Capture the Flag,ect.).
I have already set up a popupmenmuctrl that lists the game types and assigns a number to designate it and have setup the missions to have a mission type with a number designator.
How do I modify the old startmission script that was in the startmissiongui file to allow this to sort and only display those missions that meet the chose mission type?
I have already set up a popupmenmuctrl that lists the game types and assigns a number to designate it and have setup the missions to have a mission type with a number designator.
How do I modify the old startmission script that was in the startmissiongui file to allow this to sort and only display those missions that meet the chose mission type?
#2
08/28/2005 (11:55 am)
Hey thanks that will be very useful.
#3
08/28/2005 (3:40 pm)
Well instead of going with rewriting source, I figured out a simple solution that works great.//----------------------------------------
function hostLanGui::onWake()
{
REN_MissionType.init();
SM_missionList.displayByType();
}
//----------------------------------------
function SM_missionList::displayByType()
{
SM_missionList.clear();
%i = 0;
for(%file = findFirstFile($Server::MissionFileSpec); %file !$= ""; %file = findNextFile($Server::MissionFileSpec))
if (strStr(%file, "/CVS/") == -1)
{
%mi = getMissionDisplayName(%file);
%desc = %mi.desc[0];
%mType = %mi.type[0];
for(%d = 1; %d < %mi.desclines; %d++)
%desc = %desc @ "" @ %mi.desc[%d];
SM_missionList.addRow(%i++, %mi.name @ "\t" @ %file @ "\t" @ %mi.preview @ "\t" @ %desc);
%mi.delete();
}
SM_missionList.sort(0);
SM_missionList.setSelectedRow(0);
SM_missionList.scrollVisible(0);
}
//----------------------------------------
function getMissionDisplayName( %missionFile )
{
%file = new FileObject();
%MissionInfoObject = "";
if ( %file.openForRead( %missionFile ) ) {
%inInfoBlock = false;
while ( !%file.isEOF() ) {
%line = %file.readLine();
%line = trim( %line );
if( %line $= "new ScriptObject(MissionInfo) {" )
%inInfoBlock = true;
else if( %inInfoBlock && %line $= "};" ) {
%inInfoBlock = false;
%MissionInfoObject = %MissionInfoObject @ %line;
break;
}
if( %inInfoBlock )
%MissionInfoObject = %MissionInfoObject @ %line @ " ";
}
%file.close();
}
%MissionInfoObject = "%MissionInfoObject = " @ %MissionInfoObject;
eval( %MissionInfoObject );
%file.delete();
if( %MissionInfoObject.name !$= "" )
{
if( %MissionInfoObject.desc0 $= "" )
%MissionInfoObject.desc0 = "This mission has no description.";
}
else
{
// there is no missioninfo object, so just return some
// generic data for this mission
%MissionInfoObject = new ScriptObject();
%MissionInfoObject.name = %missionFile;
%MissionInfoObject.desc0 = "This mission has no description.";
}
return %MissionInfoObject;
}
function REN_MissionType::init(%this)
{
//%this.clear();
%this.add("Racing", 1);
%this.add("Offroad Racing", 2);
%this.add("Capture the Flag", 3);
%this.add("Deathmatch", 4);
%this.add("Team Deathmatch", 5);
%this.add("Demolition Derby", 6);
%this.add("King of the Hill", 7);
}
function REN_MissionType::onSelect( %this, %id, %text )
{
switch ( %id )
{
case 1:$Server::MissionFileSpec = "*/missions/race/*.mis";
case 2:$Server::MissionFileSpec = "*/missions/orr/*.mis";
case 3:$Server::MissionFileSpec = "*/missions/ctf/*.mis";
case 4:$Server::MissionFileSpec = "*/missions/dm/*.mis";
case 5:$Server::MissionFileSpec = "*/missions/tdm/*.mis";
case 6:$Server::MissionFileSpec = "*/missions/dd/*.mis";
case 7:$Server::MissionFileSpec = "*/missions/koth/*.mis";
}
SM_missionList.displayByType();
}
#5
08/28/2005 (8:09 pm)
Well I would have if I hadn't already surpassed that. I thought it a bit limiting so I changed it up a bit to allow extra actions during the selections.function REN_MissionType::init(%this)
{
//%this.clear();
%this.add("Racing", 1);
%this.add("Offroad Racing", 2);
%this.add("Capture the Flag", 3);
%this.add("Deathmatch", 4);
%this.add("Team Deathmatch", 5);
%this.add("Demolition Derby", 6);
%this.add("King of the Hill", 7);
}
function REN_MissionType::onSelect( %this, %id, %text )
{
switch ( %id )
{
case 1:raceMission();
case 2:orrMission();
case 3:ctfMission();
case 4:dmMission();
case 5:tdmMission();
case 6:ddMission();
case 7:kothMission();
}
SM_missionList.displayByType();
}
//Individual Game-type functions
function raceMission()
{
%typePreview = "main/data/missions/Stronghold.png";
%typeText = "Testing 1, 2 , 3.....";
$Server::MissionFileSpec = "*/missions/race/*.mis";
gameTypeImage.setBitmap(%typePreview);
gameTypeDescription.setText(%typeText);
}
function orrMission()
{
$Server::MissionFileSpec = "*/missions/orr/*.mis";
}
function ctfMission()
{
$Server::MissionFileSpec = "*/missions/ctf/*.mis";
}
function dmMission()
{
$Server::MissionFileSpec = "*/missions/dm/*.mis";
}
function tdmMission()
{
$Server::MissionFileSpec = "*/missions/tdm/*.mis";
}
function ddMission()
{
$Server::MissionFileSpec = "*/missions/dd/*.mis";
}
function kothMission()
{
$Server::MissionFileSpec = "*/missions/koth/*.mis";
#6
08/28/2005 (8:10 pm)
I figured with this I could also execute the individual game type .cs files as well.
Torque 3D Owner Brandon Maness
function startMissionGui::onWake() { SM_missionList.clear(); %i = 0; for(%file = findFirstFile($Server::MissionFileSpec); %file !$= ""; %file = findNextFile($Server::MissionFileSpec)) if (strStr(%file, "/CVS/") == -1) SM_missionList.addRow(%i++, getMissionDisplayName(%file) @ "\t" @ %file ); SM_missionList.sort(0); SM_missionList.setSelectedRow(0); SM_missionList.scrollVisible(0); }The SM_missionList.sort(0) is how they sorted the original, just create your own function to sort this type of list.
If you want to create a new C++ sort for this GUI type, then go to ./engine/gui/guiTextCtrl.cc and around line 116 you will find the sort console method that the above script used in the .sort(0) call.
B--