Adds utility function and method to be able to enact a load of subscenes at a specific world position

Adds loadIf conditional logic to evaluate if a subscene is 'allowed' to load when tested
Adds isAlwaysActive to GameMode to be able to flag a gamemode as being defaulted to on and used automatically
Updated GetGameModesList function to return an arrayObject of the gamemodes found
Overhauled CallGameModeFunction to utilize the gamemodes list with active/alwaysActive modes being called against, rather than level-scanning
Updated ChooseLevelMenu to be able to toggle on/off multiple gamemodes with an image indicator if it's active or not
This commit is contained in:
JeffR 2024-10-04 00:10:26 -05:00
parent 20a01d9f02
commit e4d07c7e8d
14 changed files with 259 additions and 198 deletions

View file

@ -11,7 +11,6 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
canSaveDynamicFields = "1";
currentMenuIdx = "0";
launchInEditor = "0";
previewButtonSize = "445 120";
new GuiInputCtrl(ChooseLevelInputHandler) {
ignoreMouseEvents = "1";
@ -40,8 +39,8 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
new GuiStackControl(ChooseLevelMenuTabList) {
stackingType = "Horizontal";
padding = "10";
position = "405 61";
extent = "470 41";
position = "485 61";
extent = "310 41";
horizSizing = "center";
profile = "GuiDefaultProfile";
tooltipProfile = "GuiToolTipProfile";
@ -73,10 +72,12 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
position = "320 0";
extent = "150 41";
profile = "GuiMenuButtonProfile";
visible = "0";
command = "ChooseLevelMenu.openMenu(2);";
tooltipProfile = "GuiToolTipProfile";
internalName = "ConfigBtn";
class = "ChooseLevelMenuButton";
hidden = "1";
};
};
new GuiControl(ChooseLevelMenuNavButtonOverlay) {
@ -89,7 +90,7 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
new GuiBitmapCtrl(ChooseLevelMenuPrevNavIcon) {
BitmapAsset = "UI:Keyboard_Black_Q_image";
position = "405 24";
position = "485 24";
extent = "40 40";
vertSizing = "top";
profile = "GuiNonModalDefaultProfile";
@ -97,7 +98,7 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
};
new GuiBitmapCtrl(ChooseLevelMenuNextNavIcon) {
BitmapAsset = "UI:Keyboard_Black_E_image";
position = "515 24";
position = "595 24";
extent = "40 40";
vertSizing = "top";
profile = "GuiNonModalDefaultProfile";
@ -121,8 +122,8 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
new GuiStackControl(GameModePreviewArray) {
padding = "5";
position = "0 1";
extent = "445 120";
position = "1 1";
extent = "443 60";
horizSizing = "width";
vertSizing = "height";
profile = "GuiMenuDefaultProfile";
@ -130,15 +131,16 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
};
};
new GuiBitmapCtrl(GameModePreviewBitmap) {
BitmapAsset = "UI:no_preview_image";
position = "448 0";
extent = "440 440";
horizSizing = "left";
profile = "GuiNonModalDefaultProfile";
visible = "0";
tooltipProfile = "GuiToolTipProfile";
hidden = "1";
};
new GuiTextCtrl(GameModeNameText) {
text = "Example Level";
text = "DeathMatchGame";
position = "448 445";
extent = "440 20";
horizSizing = "left";
@ -175,7 +177,7 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
new GuiStackControl(LevelPreviewArray) {
padding = "5";
position = "0 1";
extent = "445 120";
extent = "445 60";
horizSizing = "width";
vertSizing = "height";
profile = "GuiMenuDefaultProfile";
@ -277,6 +279,7 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
tooltipProfile = "GuiToolTipProfile";
};
new GuiTextEditCtrl(serverNameCTRL) {
text = "Torque 3D Server";
position = "606 4";
extent = "295 22";
horizSizing = "left";
@ -374,8 +377,8 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
profile = "GuiMenuPanelProfile";
tooltipProfile = "GuiToolTipProfile";
new GuiIconButtonCtrl(ChooseLevelStartBtn) {
BitmapAsset = "UI:Keyboard_Black_Space_image";
new GuiIconButtonCtrl(ChooseLevelNextBtn) {
BitmapAsset = "UI:Keyboard_Black_Blank_image";
sizeIconToButton = "1";
makeIconSquare = "1";
textLocation = "Center";

View file

@ -25,7 +25,7 @@ function ChooseLevelMenu::onAdd( %this )
if(!isObject(ChooseLevelAssetQuery))
new AssetQuery(ChooseLevelAssetQuery);
%this.previewButtonSize = "445 120";
$LevelPreviewButtonSize = "445 60";
}
function ChooseLevelMenu::fillPrefEntries( %this )
@ -40,9 +40,9 @@ function ChooseLevelMenu::fillPrefEntries( %this )
function ChooseLevelMenu::onWake(%this)
{
%this.fillPrefEntries();
LevelPreviewArray.clear();
refreshGameModesList();
refreshLevelsList();
if(!$pref::HostMultiPlayer)
ChooseLevelTitleText.setText("SINGLE PLAYER");
@ -66,35 +66,48 @@ function refreshGameModesList()
//popilate the gamemodes list first
%gamemodeList = getGameModesList();
for(%i=0; %i < getTokenCount(%gamemodeList, ";"); %i++)
%gameModeCount = %gamemodeList.count();
for (%i=0; %i<%gameModeCount; %i++)
{
%gameModeObj = getToken(%gamemodeList, ";", %i);
%gameModeObj = %gamemodeList.getKey(%i);
if(isObject(%gameModeObj))
{
%gameModeName = %gameModeObj.gameModeName;
if(%gameModeName $= "")
%gameModeName = %gameModeObj.getName();
%preview = new GuiButtonCtrl() {
position = "0 0";
extent = ChooseLevelMenu.previewButtonSize;
buttonType = "PushButton";
profile = GuiMenuButtonLeftJustProfile;
horizSizing = "right";
vertSizing = "bottom";
internalName = "button";
class = "GameModePreviewButton";
//command = "ChooseGameModeBegin(" @ %i @ ");";
altCommand = "ChooseGameModeBegin(" @ %i @ ");"; //allow doubleclick to quick action it
text = %gameModeName;
gameModeObj = %gameModeObj;
gameModeDesc = %gameModeObj.description;
previewImage = %gameModeObj.previewImage;
textMargin = 120;
groupNum = 2;
cansave = false;
};
%preview = new GuiContainer() {
position = "0 0";
extent = $LevelPreviewButtonSize;
horizSizing = "right";
vertSizing = "bottom";
gameModeObj = %gameModeObj;
gameModeDesc = %gameModeObj.description;
previewImage = %gameModeObj.previewImage;
cansave = false;
new GuiToggleButtonCtrl() {
position = $LevelPreviewButtonSize.y SPC 0;
extent = $LevelPreviewButtonSize.x - $LevelPreviewButtonSize.y - 5 SPC $LevelPreviewButtonSize.y;
profile = GuiMenuButtonProfile;
horizSizing = "right";
vertSizing = "bottom";
internalName = "button";
class = "GameModePreviewButton";
text = %gameModeName;
command = "ToggleGameMode(" @ %i @ ");"; //allow doubleclick to quick action it
textMargin = 120;
};
new GuiBitmapCtrl() {
position = "0 0";
extent = $LevelPreviewButtonSize.y SPC $LevelPreviewButtonSize.y;
internalName = "checkbox";
bitmapAsset = "UI:toggleMarker_image";
};
};
GameModePreviewArray.add(%preview);
}
@ -122,6 +135,7 @@ function refreshLevelsList()
}
//filter the levelAssets by the gamemode selected
%filteredIndex = 0;
for(%i=0; %i < %count; %i++)
{
%assetId = ChooseLevelAssetQuery.getAsset(%i);
@ -142,21 +156,26 @@ function refreshLevelsList()
//filter for selected gamemode
%levelGameModes = %levelAsset.gameModesNames;
echo("LevelAsset gamemodes: " @ %levelGameModes);
%foundGameModeMatch = false;
for(%gm = 0; %gm < getTokenCount(%levelGameModes, ";"); %gm++)
{
%gameModeName = getToken(%levelGameModes, ";", %gm);
echo("testing gamemode: " @ %gameModeName);
echo("selected gamemode: " @ $pref::Server::GameMode.getName());
if(%gameModeName $= $pref::Server::GameMode.getName())
for(%g=0; %g < GameModePreviewArray.getCount(); %g++)
{
%foundGameModeMatch = true;
break;
%gmb = GameModePreviewArray.getObject(%g);
if(!isObject(%gmb.gameModeObj) || (!%gmb.gameModeObj.active && !%gmb.gameModeObj.alwaysActive))
continue;
if(%gameModeName $= %gmb.gameModeObj.getName())
{
%foundGameModeMatch = true;
break;
}
}
if(%foundGameModeMatch)
break;
}
if(!%foundGameModeMatch)
@ -169,7 +188,7 @@ function refreshLevelsList()
%preview = new GuiIconButtonCtrl() {
position = "0 0";
extent = ChooseLevelMenu.previewButtonSize;
extent = $LevelPreviewButtonSize;
buttonType = "PushButton";
profile = GuiMenuButtonLeftJustProfile;
horizSizing = "right";
@ -177,7 +196,7 @@ function refreshLevelsList()
internalName = "button";
class = "LevelPreviewButton";
//command = "$selectedLevelAsset = " @ %assetId @ ";";
altCommand = "ChooseLevelBegin(" @ %i @ ");"; //allow doubleclick to quick action it
altCommand = "ChooseLevelBegin(" @ %filteredIndex @ ");"; //allow doubleclick to quick action it
text = %levelAsset.levelName;
bitmapAsset = %levelPreviewImg;
levelAsset = %levelAsset;
@ -192,8 +211,11 @@ function refreshLevelsList()
};
LevelPreviewArray.add(%preview);
%filteredIndex++;
}
GameModePreviewArray.listPosition = 0;
LevelPreviewArray.listPosition = 0;
// Also add the new level mission as defined in the world editor settings
@ -236,10 +258,31 @@ function ChooseLevelMenu::syncGUI(%this)
ChooseLevelBackBtn.setBitmap(BaseUIActionMap.getCommandButtonBitmap(%device, "BaseUIBackOut"));
ChooseLevelStartBtn.setBitmap(ChooseLevelActionMap.getCommandButtonBitmap(%device, "ChooseLevelBegin"));
if(ChooseLevelMenu.currentMenuIdx == 0)
ChooseLevelNextBtn.text = "Toggle Mode";
else
ChooseLevelNextBtn.text = "Start Game";
ChooseLevelNextBtn.setBitmap(ChooseLevelActionMap.getCommandButtonBitmap(%device, "ChooseLevelMenuOption"));
ChooseLevelMenuPrevNavIcon.setBitmap(ChooseLevelActionMap.getCommandButtonBitmap(%device, "ChooseLevelMenuPrevMenu"));
ChooseLevelMenuNextNavIcon.setBitmap(ChooseLevelActionMap.getCommandButtonBitmap(%device, "ChooseLevelMenuNextMenu"));
%hasActiveGameMode = false;
for(%i=0; %i < GameModePreviewArray.getCount(); %i++)
{
%btn = GameModePreviewArray.getObject(%i);
if(!isObject(%btn.gameModeObj))
continue;
if((%btn.gameModeObj.isActive() || %btn.gameModeObj.isAlwaysActive()) == true)
{
%hasActiveGameMode = true;
break;
}
}
ChooseLevelMenuTabList-->LevelBtn.active = %hasActiveGameMode;
}
function LevelPreviewArray::syncGUI(%this)
@ -252,10 +295,19 @@ function LevelPreviewArray::syncGUI(%this)
function GameModePreviewArray::syncGUI(%this)
{
%btn = %this.getObject(%this.listPosition);
%btn.setHighlighted(true);
for(%i=0; %i < %this.getCount(); %i++)
{
%btn = %this.getObject(%i);
%btn-->button.setHighlighted(false);
%bitmapAst = (%btn.gameModeObj.active || %btn.gameModeObj.alwaysActive) ? "UI:toggleMarker_h_image" : "UI:toggleMarker_image";
%btn-->checkbox.setBitmap(%bitmapAst);
}
$pref::Server::GameMode = %btn.gameModeObject;
%btn = %this.getObject(%this.listPosition);
%btn-->button.setHighlighted(true);
//$pref::Server::GameMode = %btn.gameModeObject;
}
function ChooseLevelMenuPrevMenu(%val)
@ -270,6 +322,13 @@ function ChooseLevelMenuPrevMenu(%val)
%endIndex = 2;
ChooseLevelMenu.currentMenuIdx = mClamp(ChooseLevelMenu.currentMenuIdx, 0, %endIndex);
//bail if we're trying to step into a hidden or disabled menu
if(!ChooseLevelMenu.isMenuAvailable(ChooseLevelMenu.currentMenuIdx))
{
ChooseLevelMenu.currentMenuIdx = %currentIdx;
return;
}
if(%currentIdx == ChooseLevelMenu.currentMenuIdx)
return;
@ -290,6 +349,13 @@ function ChooseLevelMenuNextMenu(%val)
%endIndex = 2;
ChooseLevelMenu.currentMenuIdx = mClamp(ChooseLevelMenu.currentMenuIdx, 0, %endIndex);
//bail if we're trying to step into a hidden or disabled menu
if(!ChooseLevelMenu.isMenuAvailable(ChooseLevelMenu.currentMenuIdx))
{
ChooseLevelMenu.currentMenuIdx = %currentIdx;
return;
}
if(%currentIdx == ChooseLevelMenu.currentMenuIdx)
return;
@ -319,33 +385,48 @@ function ChooseLevelMenu::openMenu(%this, %menuIdx)
%this.syncGui();
}
function ChooseLevelMenu::isMenuAvailable(%this, %menuIdx)
{
if(%menuIdx == 0)
%btn = %this-->GameModeBtn;
else if(%menuIdx == 1)
%btn = %this-->LevelBtn;
else if(%menuIdx == 2)
%btn = %this-->ConfigBtn;
return %btn.isActive() && %btn.isVisible();
}
function ChooseLevelMenuOption(%val)
{
if(%val)
{
if(ChooseLevelMenu.currentMenuIdx == 0)
ChooseGameModeBegin(ChooseLevelMenu.listPosition);
ToggleGameMode(ChooseLevelMenu.listPosition);
else if(ChooseLevelMenu.currentMenuIdx == 1)
ChooseLevelBegin(ChooseLevelMenu.listPosition);
}
}
function ChooseGameModeBegin(%index)
function ToggleGameMode(%index)
{
if(%index $= "")
%index = $MenuList.listPosition;
%entry = GameModePreviewArray.getObject(%index);
if(!isObject(%entry) || !isObject(%entry.gameModeObj))
{
MessageBoxOK("Error", "Selected game mode does not have a valid mode");
return;
}
$pref::Server::GameMode = %entry.gameModeObj;
ChooseLevelMenuTabList-->LevelBtn.active = true;
%entry.gameModeObj.active = !%entry.gameModeObj.active;
refreshLevelsList();
ChooseLevelMenu.openMenu(1);
$MenuList.syncGui();
ChooseLevelMenu.syncGui();
}
function ChooseLevelBegin(%index)
@ -399,7 +480,7 @@ function GameModePreviewButton::onHighlighted(%this, %highlighted)
{
if(%highlighted)
{
$MenuList.listPosition = $MenuList.getObjectIndex(%this);
$MenuList.listPosition = $MenuList.getObjectIndex(%this.getParent());
GameModePreviewBitmap.bitmapAsset = %this.previewImage;