Torque3D/Templates/BaseGame/game/data/UI/guis/chooseLevelDlg.tscript
JeffR c7763fe3ec Added cleanup of exec stack for module when it's finished to avoid duplicate executions
Added proper container bracketing for the main menu buttons and made that the main navigation target
Added logic to UINav to prevent needlessly re-setting the root page if it already is the root page, which would break the navigation stack
Added logic to UINav toprevent needlessly adding duplicate pages whicn would break the navigation stack
Added logic to close the chooseLevelDlg page when the level is loaded to avoid the page being left hanging on the nav stack
Fixed assetId for no preview image fallback on the chooseLevelDlg page
Fixed display of icons in the shape editor shape helper section
Fixed name lookup on terrain material editor dialogue which would break saving of terrain materials
Disables TORQUE_SFX_DirectX which is currently not in use and nonfunctional
2022-06-02 20:17:23 -05:00

211 lines
6.9 KiB
Plaintext

//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//----------------------------------------
function ChooseLevelDlg::onWake( %this )
{
if(!isObject(LevelListEntries))
new ArrayObject(LevelListEntries){};
if(!isObject(ChooseLevelAssetQuery))
new AssetQuery(ChooseLevelAssetQuery);
}
function ChooseLevelDlg::onOpen(%this)
{
LevelList.clearRows();
LevelListEntries.empty();
ChooseLevelWindow->CurrentPreview.setBitmap("UI:no_preview_image");
ChooseLevelWindow->LevelDescriptionLabel.visible = false;
ChooseLevelWindow->LevelDescription.visible = false;
ChooseLevelAssetQuery.clear();
AssetDatabase.findAssetType(ChooseLevelAssetQuery, "LevelAsset");
%count = ChooseLevelAssetQuery.getCount();
if(%count == 0 && !IsDirectory("tools"))
{
//We have no levels found. Prompt the user to open the editor to the default level if the tools are present
MessageBoxOK("Error", "No levels were found in any modules. Please ensure you have modules loaded that contain gameplay code and level files.",
"Canvas.popDialog(ChooseLevelDlg); if(isObject(ChooseLevelDlg.returnGui) && ChooseLevelDlg.returnGui.isMethod(\"onReturnTo\")) ChooseLevelDlg.returnGui.onReturnTo();");
ChooseLevelAssetQuery.delete();
return;
}
for(%i=0; %i < %count; %i++)
{
%assetId = ChooseLevelAssetQuery.getAsset(%i);
if(AssetDatabase.getAssetModule(%assetId).ModuleId $= "ToolsModule")
continue;
%levelAsset = AssetDatabase.acquireAsset(%assetId);
%file = %levelAsset.getLevelPath();
if ( !isFile(%file @ ".mis") && !isFile(%file @ ".mis.dso") &&!isFile(%file) )
continue;
// Skip our new level/mission if we arent choosing a level
// to launch in the editor.
if ( !%this.launchInEditor )
{
%fileName = fileName(%file);
if (strstr(%fileName, "newMission.mis") > -1 || strstr(%fileName, "newLevel.mis") > -1)
continue;
}
%this.addLevelAsset( %levelAsset );
}
// Also add the new level mission as defined in the world editor settings
// if we are choosing a level to launch in the editor.
if ( %this.launchInEditor )
{
%this.addMissionFile( "tools/levels/DefaultEditorLevel.mis" );
}
for(%i=0; %i < LevelListEntries.count(); %i++)
{
%levelAsset = LevelListEntries.getKey(%i);
LevelList.addRow(%levelAsset.LevelName, "", -1, -30);
}
LevelList.setSelected(0);
LevelList.onChange();
if(!$pref::HostMultiPlayer)
LevelSelectTitle.setText("SINGLE PLAYER");
else
LevelSelectTitle.setText("CREATE SERVER");
$activeMenuButtonContainer-->button1.disable();
$activeMenuButtonContainer-->button2.disable();
$activeMenuButtonContainer-->button3.disable();
$activeMenuButtonContainer-->button4.set("btn_a", "Return", "Start Level", "ChooseLevelDlg.beginLevel();");
$activeMenuButtonContainer-->button5.set("btn_b", "Escape", "Back", %this @ ".navigation.popPage();");
}
function ChooseLevelDlg::onSleep( %this )
{
// This is set from the outside, only stays true for a single wake/sleep
// cycle.
%this.launchInEditor = false;
}
function ChooseLevelDlg::addMissionFile( %this, %file )
{
%levelName = fileBase(%file);
%levelDesc = "A Torque level";
%LevelInfoObject = getLevelInfo(%file);
if (%LevelInfoObject != 0)
{
if(%LevelInfoObject.levelName !$= "")
%levelName = %LevelInfoObject.levelName;
else if(%LevelInfoObject.name !$= "")
%levelName = %LevelInfoObject.name;
if (%LevelInfoObject.desc0 !$= "")
%levelDesc = %LevelInfoObject.desc0;
if (%LevelInfoObject.preview !$= "")
%levelPreview = %LevelInfoObject.preview;
%LevelInfoObject.delete();
}
LevelListEntries.add( %levelName TAB %file TAB %levelDesc TAB %levelPreview );
}
function ChooseLevelDlg::addLevelAsset( %this, %levelAsset )
{
LevelListEntries.add( %levelAsset );
}
function LevelList::onChange(%this)
{
%index = %this.getSelectedRow();
%levelAsset = LevelListEntries.getKey(%index);
// Get the name
ChooseLevelWindow->LevelName.text = %levelAsset.LevelName;
// Get the level id
$selectedLevelAsset = %levelAsset.getAssetId();
// Find the preview image
%levelPreview = %levelAsset.getPreviewImagePath();
// Test against all of the different image formats
// This should probably be moved into an engine function
if (isFile(%levelPreview))
ChooseLevelWindow->CurrentPreview.setBitmap(%levelPreview);
else
ChooseLevelWindow->CurrentPreview.setBitmap("UI:no_preview_image");
// Get the description
%levelDesc = %levelAsset.description;
if(%levelDesc !$= "")
{
ChooseLevelWindow->LevelDescriptionLabel.setVisible(true);
ChooseLevelWindow->LevelDescription.setVisible(true);
ChooseLevelWindow->LevelDescription.setText(%levelDesc);
}
else
{
ChooseLevelWindow->LevelDescriptionLabel.setVisible(false);
ChooseLevelWindow->LevelDescription.setVisible(false);
}
}
// Do this onMouseUp not via Command which occurs onMouseDown so we do
// not have a lingering mouseUp event lingering in the ether.
function ChooseLevelDlg::beginLevel(%this)
{
// So we can't fire the button when loading is in progress.
if ( isObject( ServerGroup ) )
return;
%this.navigation.popPage();
// Launch the chosen level with the editor open?
if ( ChooseLevelDlg.launchInEditor )
{
activatePackage( "BootEditor" );
ChooseLevelDlg.launchInEditor = false;
StartGame("", "SinglePlayer");
}
else
{
StartGame();
}
}