Game Development Community

Removing "Host Multi-Player" option in GUI

by Jules · in Torque Game Engine · 03/30/2007 (6:19 am) · 2 replies

How would I go about removing the "Host Multi-Player" checkbox option in the GUI based on the mission selected?

Example:
If mission (stronghold.mis) show checkbox option
If mission (singleplay.mis) do not show checkbox option

and another option to remove missions from the mission list:
If mission (singleplay.mis) do not show this mission on the list

Thanks in advance.

J

#1
03/30/2007 (6:50 am)
This is based on the starter.fps example:

In starter.fps\client\gui\startMissionGui.gui:
function SM_missionList::onSelect(%this, %id, %text)
{   
   %name = getMissionDisplayName(%text);
      
   if(%name $= "stronghold")
   {
      ML_isMultiplayer.setActive(false);   [b]// or you can call ML_isMultiplayer.setVisible(false);[/b]
   }
   if(%name $= "cpdemo1")
   {
      ML_isMultiplayer.setActive(true);    [b]// or you can call ML_isMultiplayer.setVisible(true);[/b]
   }
}

That takes care of displaying the checkbox (or disabling it).

The second part of your request can be tricky, depending on how you want to implement it. If you want to not display missions based on a variable inside the mission, you'd do something like the following:

DISPLAYING MISSION BASED ON IF IT IS A SINGLE PLAYER OR MULTIPLAYER MISSION:

Replace function getMissionDisplayName(%missionFile), with this:
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.";
 
     if(%MissionInfoObject.serverType $="")
         %MissionInfoObject.serverType = "singlePlayer";
   }
   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.";
      %MissionInfoObject.serverType = "singlePlayer";
   }
   
   
   return %MissionInfoObject;
}
Modify startMissionGui::onWake() in the same GUI file:
function startMissionGui::onWake()
{
   SM_missionList.clear();
   %i = 0;
   for(%file = findFirstFile($Server::MissionFileSpec); %file !$= ""; %file = findNextFile($Server::MissionFileSpec))  
      if (strStr(%file, "/CVS/") == -1)
      {
         %mi = getMissionDisplayName(%file);
         
         %serverType = %mi.serverType;
	 
         [b]// If it is single player, or whatver, don't add it[/b]
         if(%serverType !$= "singlePlayer")
                SM_missionList.addRow(%i++, getMissionDisplayName(%file).name @ "\t" @ %file );
	 %mi.delete();
      }
   SM_missionList.sort(0);
   SM_missionList.setSelectedRow(0);
   SM_missionList.scrollVisible(0);
}

That's a bit of work. You can always just check the mission name in startMissionGui::onWake() and not display it, but it requires more if checks:

function startMissionGui::onWake()
{
   SM_missionList.clear();
   %i = 0;
   for(%file = findFirstFile($Server::MissionFileSpec); %file !$= ""; %file = findNextFile($Server::MissionFileSpec))  
      if (strStr(%file, "/CVS/") == -1)
      {
         %mi = getMissionDisplayName(%file);
         
         [b]// If the mission has a specific name, don't add it[/b]
         if(%mi !$= "cpdemo1" || $mi !$= "cpdemo2")
                SM_missionList.addRow(%i++, getMissionDisplayName(%file).name @ "\t" @ %file );
	 %mi.delete();
      }
   SM_missionList.sort(0);
   SM_missionList.setSelectedRow(0);
   SM_missionList.scrollVisible(0);
}


*EDITS*- Fixed grammar and code mistakes. Just copied and pasted code using serverType method, ran without error and performed flawlessly.
#2
03/30/2007 (7:21 am)
Thanks Michael - you've been a great help.

J