Relocates several game specific GUIs (with relevant art and scripts) out of the "core".

This commit is contained in:
thecelloman 2013-03-20 12:10:08 -04:00
parent 5094eb5930
commit c1831e4bd8
34 changed files with 26 additions and 32 deletions

View file

@ -72,10 +72,17 @@ function initClient()
// Load up the shell GUIs
exec("art/gui/mainMenuGui.gui");
exec("art/gui/StartupGui.gui");
exec("art/gui/chooseLevelDlg.gui");
exec("art/gui/loadingGui.gui");
exec("art/gui/optionsDlg.gui");
exec("art/gui/remapDlg.gui");
// Gui scripts
exec("scripts/gui/playGui.cs");
exec("scripts/gui/startupGui.cs");
exec("scripts/gui/chooseLevelDlg.cs");
exec("scripts/gui/loadingGui.cs");
exec("scripts/gui/optionsDlg.cs");
// Client scripts
exec("./missionDownload.cs");

View file

@ -0,0 +1,350 @@
//-----------------------------------------------------------------------------
// 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 StartLevel( %mission, %hostingType )
{
if( %mission $= "" )
{
%id = CL_levelList.getSelectedId();
%mission = getField(CL_levelList.getRowTextById(%id), 1);
}
if (%hostingType !$= "")
{
%serverType = %hostingType;
}
else
{
if ($pref::HostMultiPlayer)
%serverType = "MultiPlayer";
else
%serverType = "SinglePlayer";
}
// Show the loading screen immediately.
if ( isObject( LoadingGui ) )
{
Canvas.setContent("LoadingGui");
LoadingProgress.setValue(1);
LoadingProgressTxt.setValue("LOADING MISSION FILE");
Canvas.repaint();
}
createAndConnectToLocalServer( %serverType, %mission );
}
//----------------------------------------
function ChooseLevelDlg::onWake( %this )
{
CL_levelList.clear();
ChooseLevelWindow->SmallPreviews.clear();
%i = 0;
for(%file = findFirstFile($Server::MissionFileSpec); %file !$= ""; %file = findNextFile($Server::MissionFileSpec))
{
// Skip our new level/mission if we arent choosing a level
// to launch in the editor.
if ( !%this.launchInEditor )
{
if (strstr(%file, "newMission.mis") > -1)
continue;
if (strstr(%file, "newLevel.mis") > -1)
continue;
}
%this.addMissionFile( %file );
}
// 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 )
{
%file = EditorSettings.value( "WorldEditor/newLevelFile" );
if ( %file !$= "" )
%this.addMissionFile( %file );
}
// Sort our list
CL_levelList.sort(0);
// Set the first row as the selected row
CL_levelList.setSelectedRow(0);
for (%i = 0; %i < CL_levelList.rowCount(); %i++)
{
%preview = new GuiBitmapButtonCtrl() {
internalName = "SmallPreview" @ %i;
Extent = "108 81";
bitmap = "art/gui/no-preview";
command = "ChooseLevelWindow.previewSelected(ChooseLevelWindow->SmallPreviews->SmallPreview" @ %i @ ");";
};
ChooseLevelWindow->SmallPreviews.add(%preview);
// Set this small preview visible
if (%i >= 5)
%preview.setVisible(false);
// Set the level index
%preview.levelIndex = %i;
// Get the name
%name = getField(CL_levelList.getRowText(%i), 0);
%preview.levelName = %name;
%file = getField(CL_levelList.getRowText(%i), 1);
// Find the preview image
%levelPreview = filePath(%file) @ "/" @ fileBase(%file) @ "_preview";
// Test against all of the different image formats
// This should probably be moved into an engine function
if (isFile(%levelPreview @ ".png") ||
isFile(%levelPreview @ ".jpg") ||
isFile(%levelPreview @ ".bmp") ||
isFile(%levelPreview @ ".gif") ||
isFile(%levelPreview @ ".jng") ||
isFile(%levelPreview @ ".mng") ||
isFile(%levelPreview @ ".tga"))
{
%preview.setBitmap(%levelPreview);
}
// Get the description
%desc = getField(CL_levelList.getRowText(%i), 2);
%preview.levelDesc = %desc;
}
ChooseLevelWindow->SmallPreviews.firstVisible = -1;
ChooseLevelWindow->SmallPreviews.lastVisible = -1;
if (ChooseLevelWindow->SmallPreviews.getCount() > 0)
{
ChooseLevelWindow->SmallPreviews.firstVisible = 0;
if (ChooseLevelWindow->SmallPreviews.getCount() < 6)
ChooseLevelWindow->SmallPreviews.lastVisible = ChooseLevelWindow->SmallPreviews.getCount() - 1;
else
ChooseLevelWindow->SmallPreviews.lastVisible = 4;
}
if (ChooseLevelWindow->SmallPreviews.getCount() > 0)
ChooseLevelWindow.previewSelected(ChooseLevelWindow->SmallPreviews.getObject(0));
// If we have 5 or less previews then hide our next/previous buttons
// and resize to fill their positions
if (ChooseLevelWindow->SmallPreviews.getCount() < 6)
{
ChooseLevelWindow->PreviousSmallPreviews.setVisible(false);
ChooseLevelWindow->NextSmallPreviews.setVisible(false);
%previewPos = ChooseLevelWindow->SmallPreviews.getPosition();
%previousPos = ChooseLevelWindow->PreviousSmallPreviews.getPosition();
%previewPosX = getWord(%previousPos, 0);
%previewPosY = getWord(%previewPos, 1);
ChooseLevelWindow->SmallPreviews.setPosition(%previewPosX, %previewPosY);
ChooseLevelWindow->SmallPreviews.colSpacing = 10;//((getWord(NextSmallPreviews.getPosition(), 0)+11)-getWord(PreviousSmallPreviews.getPosition(), 0))/4;
ChooseLevelWindow->SmallPreviews.refresh();
}
if (ChooseLevelWindow->SmallPreviews.getCount() <= 1)
{
// Hide the small previews
ChooseLevelWindow->SmallPreviews.setVisible(false);
// Shrink the ChooseLevelWindow so that we don't have a large blank space
%extentX = getWord(ChooseLevelWindow.getExtent(), 0);
%extentY = getWord(ChooseLevelWindow->SmallPreviews.getPosition(), 1);
ChooseLevelWIndow.setExtent(%extentX, %extentY);
}
else
{
// Make sure the small previews are visible
ChooseLevelWindow->SmallPreviews.setVisible(true);
%extentX = getWord(ChooseLevelWindow.getExtent(), 0);
%extentY = getWord(ChooseLevelWindow->SmallPreviews.getPosition(), 1);
%extentY = %extentY + getWord(ChooseLevelWindow->SmallPreviews.getExtent(), 1);
%extentY = %extentY + 9;
ChooseLevelWIndow.setExtent(%extentX, %extentY);
}
}
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;
%LevelInfoObject.delete();
}
CL_levelList.addRow( CL_levelList.rowCount(), %levelName TAB %file TAB %levelDesc );
}
function ChooseLevelDlg::onSleep( %this )
{
// This is set from the outside, only stays true for a single wake/sleep
// cycle.
%this.launchInEditor = false;
}
function ChooseLevelWindow::previewSelected(%this, %preview)
{
// Set the selected level
if (isObject(%preview) && %preview.levelIndex !$= "")
CL_levelList.setSelectedRow(%preview.levelIndex);
else
CL_levelList.setSelectedRow(-1);
// Set the large preview image
if (isObject(%preview) && %preview.bitmap !$= "")
%this->CurrentPreview.setBitmap(%preview.bitmap);
else
%this->CurrentPreview.setBitmap("art/gui/no-preview");
// Set the current level name
if (isObject(%preview) && %preview.levelName !$= "")
%this->LevelName.setText(%preview.levelName);
else
%this->LevelName.setText("Level");
// Set the current level description
if (isObject(%preview) && %preview.levelDesc !$= "")
%this->LevelDescription.setText(%preview.levelDesc);
else
%this->LevelDescription.setText("A Torque Level");
}
function ChooseLevelWindow::previousPreviews(%this)
{
%prevHiddenIdx = %this->SmallPreviews.firstVisible - 1;
if (%prevHiddenIdx < 0)
return;
%lastVisibleIdx = %this->SmallPreviews.lastVisible;
if (%lastVisibleIdx >= %this->SmallPreviews.getCount())
return;
%prevHiddenObj = %this->SmallPreviews.getObject(%prevHiddenIdx);
%lastVisibleObj = %this->SmallPreviews.getObject(%lastVisibleIdx);
if (isObject(%prevHiddenObj) && isObject(%lastVisibleObj))
{
%this->SmallPreviews.firstVisible--;
%this->SmallPreviews.lastVisible--;
%prevHiddenObj.setVisible(true);
%lastVisibleObj.setVisible(false);
}
}
function ChooseLevelWindow::nextPreviews(%this)
{
%firstVisibleIdx = %this->SmallPreviews.firstVisible;
if (%firstVisibleIdx < 0)
return;
%firstHiddenIdx = %this->SmallPreviews.lastVisible + 1;
if (%firstHiddenIdx >= %this->SmallPreviews.getCount())
return;
%firstVisibleObj = %this->SmallPreviews.getObject(%firstVisibleIdx);
%firstHiddenObj = %this->SmallPreviews.getObject(%firstHiddenIdx);
if (isObject(%firstVisibleObj) && isObject(%firstHiddenObj))
{
%this->SmallPreviews.firstVisible++;
%this->SmallPreviews.lastVisible++;
%firstVisibleObj.setVisible(false);
%firstHiddenObj.setVisible(true);
}
}
//----------------------------------------
function getLevelInfo( %missionFile )
{
%file = new FileObject();
%LevelInfoObject = "";
if ( %file.openForRead( %missionFile ) ) {
%inInfoBlock = false;
while ( !%file.isEOF() ) {
%line = %file.readLine();
%line = trim( %line );
if( %line $= "new ScriptObject(LevelInfo) {" )
%inInfoBlock = true;
else if( %line $= "new LevelInfo(theLevelInfo) {" )
%inInfoBlock = true;
else if( %inInfoBlock && %line $= "};" ) {
%inInfoBlock = false;
%LevelInfoObject = %LevelInfoObject @ %line;
break;
}
if( %inInfoBlock )
%LevelInfoObject = %LevelInfoObject @ %line @ " ";
}
%file.close();
}
%file.delete();
if( %LevelInfoObject !$= "" )
{
%LevelInfoObject = "%LevelInfoObject = " @ %LevelInfoObject;
eval( %LevelInfoObject );
return %LevelInfoObject;
}
// Didn't find our LevelInfo
return 0;
}

View file

@ -0,0 +1,51 @@
//-----------------------------------------------------------------------------
// 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 LoadingGui::onAdd(%this)
{
%this.qLineCount = 0;
}
//------------------------------------------------------------------------------
function LoadingGui::onWake(%this)
{
// Play sound...
//CloseMessagePopup();
}
//------------------------------------------------------------------------------
function LoadingGui::onSleep(%this)
{
// Clear the load info:
if ( %this.qLineCount !$= "" )
{
for ( %line = 0; %line < %this.qLineCount; %line++ )
%this.qLine[%line] = "";
}
%this.qLineCount = 0;
LoadingProgress.setValue( 0 );
LoadingProgressTxt.setValue( "WAITING FOR SERVER" );
// Stop sound...
}

View file

@ -0,0 +1,844 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
/// Returns true if the current quality settings equal
/// this graphics quality level.
function GraphicsQualityLevel::isCurrent( %this )
{
// Test each pref to see if the current value
// equals our stored value.
for ( %i=0; %i < %this.count(); %i++ )
{
%pref = %this.getKey( %i );
%value = %this.getValue( %i );
if ( getVariable( %pref ) !$= %value )
return false;
}
return true;
}
/// Applies the graphics quality settings and calls
/// 'onApply' on itself or its parent group if its
/// been overloaded.
function GraphicsQualityLevel::apply( %this )
{
for ( %i=0; %i < %this.count(); %i++ )
{
%pref = %this.getKey( %i );
%value = %this.getValue( %i );
setVariable( %pref, %value );
}
// If we have an overloaded onApply method then
// call it now to finalize the changes.
if ( %this.isMethod( "onApply" ) )
%this.onApply();
else
{
%group = %this.getGroup();
if ( isObject( %group ) && %group.isMethod( "onApply" ) )
%group.onApply( %this );
}
}
function GraphicsQualityPopup::init( %this, %qualityGroup )
{
assert( isObject( %this ) );
assert( isObject( %qualityGroup ) );
// Clear the existing content first.
%this.clear();
// Fill it.
%select = -1;
for ( %i=0; %i < %qualityGroup.getCount(); %i++ )
{
%level = %qualityGroup.getObject( %i );
if ( %level.isCurrent() )
%select = %i;
%this.add( %level.getInternalName(), %i );
}
// Setup a default selection.
if ( %select == -1 )
%this.setText( "Custom" );
else
%this.setSelected( %select );
}
function GraphicsQualityPopup::apply( %this, %qualityGroup, %testNeedApply )
{
assert( isObject( %this ) );
assert( isObject( %qualityGroup ) );
%quality = %this.getText();
%index = %this.findText( %quality );
if ( %index == -1 )
return false;
%level = %qualityGroup.getObject( %index );
if ( isObject( %level ) && !%level.isCurrent() )
{
if ( %testNeedApply )
return true;
%level.apply();
}
return false;
}
function OptionsDlg::setPane(%this, %pane)
{
%this-->OptAudioPane.setVisible(false);
%this-->OptGraphicsPane.setVisible(false);
%this-->OptNetworkPane.setVisible(false);
%this-->OptControlsPane.setVisible(false);
%this.findObjectByInternalName( "Opt" @ %pane @ "Pane", true ).setVisible(true);
%this.fillRemapList();
// Update the state of the apply button.
%this._updateApplyState();
}
function OptionsDlg::onWake(%this)
{
if ( isFunction("getWebDeployment") && getWebDeployment() )
{
// Cannot enable full screen under web deployment
%this-->OptGraphicsFullscreenToggle.setStateOn( false );
%this-->OptGraphicsFullscreenToggle.setVisible( false );
}
else
{
%this-->OptGraphicsFullscreenToggle.setStateOn( Canvas.isFullScreen() );
}
%this-->OptGraphicsVSyncToggle.setStateOn( !$pref::Video::disableVerticalSync );
OptionsDlg.initResMenu();
%resSelId = OptionsDlg-->OptGraphicsResolutionMenu.findText( _makePrettyResString( $pref::Video::mode ) );
if( %resSelId != -1 )
OptionsDlg-->OptGraphicsResolutionMenu.setSelected( %resSelId );
OptGraphicsDriverMenu.clear();
%buffer = getDisplayDeviceList();
%count = getFieldCount( %buffer );
for(%i = 0; %i < %count; %i++)
OptGraphicsDriverMenu.add(getField(%buffer, %i), %i);
%selId = OptGraphicsDriverMenu.findText( getDisplayDeviceInformation() );
if ( %selId == -1 )
OptGraphicsDriverMenu.setFirstSelected();
else
OptGraphicsDriverMenu.setSelected( %selId );
// Setup the graphics quality dropdown menus.
%this-->OptMeshQualityPopup.init( MeshQualityGroup );
%this-->OptTextureQualityPopup.init( TextureQualityGroup );
%this-->OptLightingQualityPopup.init( LightingQualityGroup );
%this-->OptShaderQualityPopup.init( ShaderQualityGroup );
// Setup the anisotropic filtering menu.
%ansioCtrl = %this-->OptAnisotropicPopup;
%ansioCtrl.clear();
%ansioCtrl.add( "Off", 0 );
%ansioCtrl.add( "4X", 4 );
%ansioCtrl.add( "8X", 8 );
%ansioCtrl.add( "16X", 16 );
%ansioCtrl.setSelected( $pref::Video::defaultAnisotropy, false );
// set up the Refresh Rate menu.
%refreshMenu = %this-->OptRefreshSelectMenu;
%refreshMenu.clear();
// %refreshMenu.add("Auto", 60);
%refreshMenu.add("60", 60);
%refreshMenu.add("75", 75);
%refreshMenu.setSelected( getWord( $pref::Video::mode, $WORD::REFRESH ) );
// Audio
//OptAudioHardwareToggle.setStateOn($pref::SFX::useHardware);
//OptAudioHardwareToggle.setActive( true );
%this-->OptAudioVolumeMaster.setValue( $pref::SFX::masterVolume );
%this-->OptAudioVolumeShell.setValue( $pref::SFX::channelVolume[ $GuiAudioType] );
%this-->OptAudioVolumeSim.setValue( $pref::SFX::channelVolume[ $SimAudioType ] );
%this-->OptAudioVolumeMusic.setValue( $pref::SFX::channelVolume[ $MusicAudioType ] );
OptAudioProviderList.clear();
%buffer = sfxGetAvailableDevices();
%count = getRecordCount( %buffer );
for(%i = 0; %i < %count; %i++)
{
%record = getRecord(%buffer, %i);
%provider = getField(%record, 0);
if ( OptAudioProviderList.findText( %provider ) == -1 )
OptAudioProviderList.add( %provider, %i );
}
OptAudioProviderList.sort();
%selId = OptAudioProviderList.findText($pref::SFX::provider);
if ( %selId == -1 )
OptAudioProviderList.setFirstSelected();
else
OptAudioProviderList.setSelected( %selId );
// Populate the Anti-aliasing popup.
%aaMenu = %this-->OptAAQualityPopup;
%aaMenu.clear();
%aaMenu.Add( "Off", 0 );
%aaMenu.Add( "1x", 1 );
%aaMenu.Add( "2x", 2 );
%aaMenu.Add( "4x", 4 );
%aaMenu.setSelected( getWord( $pref::Video::mode, $WORD::AA ) );
OptMouseSensitivity.value = $pref::Input::LinkMouseSensitivity;
// Set the graphics pane to start.
%this-->OptGraphicsButton.performClick();
}
function OptionsDlg::onSleep(%this)
{
// write out the control config into the rw/config.cs file
moveMap.save( "scripts/client/config.cs" );
}
function OptGraphicsDriverMenu::onSelect( %this, %id, %text )
{
// Attempt to keep the same resolution settings:
%resMenu = OptionsDlg-->OptGraphicsResolutionMenu;
%currRes = %resMenu.getText();
// If its empty the use the current.
if ( %currRes $= "" )
%currRes = _makePrettyResString( Canvas.getVideoMode() );
// Fill the resolution list.
optionsDlg.initResMenu();
// Try to select the previous settings:
%selId = %resMenu.findText( %currRes );
if ( %selId == -1 )
%selId = 0;
%resMenu.setSelected( %selId );
OptionsDlg._updateApplyState();
}
function _makePrettyResString( %resString )
{
%width = getWord( %resString, $WORD::RES_X );
%height = getWord( %resString, $WORD::RES_Y );
%aspect = %width / %height;
%aspect = mRound( %aspect * 100 ) * 0.01;
switch$( %aspect )
{
case "1.33":
%aspect = "4:3";
case "1.78":
%aspect = "16:9";
default:
%aspect = "";
}
%outRes = %width @ " x " @ %height;
if ( %aspect !$= "" )
%outRes = %outRes @ " (" @ %aspect @ ")";
return %outRes;
}
function OptionsDlg::initResMenu( %this )
{
// Clear out previous values
%resMenu = %this-->OptGraphicsResolutionMenu;
%resMenu.clear();
// If we are in a browser then we can't change our resolution through
// the options dialog
if (getWebDeployment())
{
%count = 0;
%currRes = getWords(Canvas.getVideoMode(), $WORD::RES_X, $WORD::RES_Y);
%resMenu.add(%currRes, %count);
%count++;
return;
}
// Loop through all and add all valid resolutions
%count = 0;
%resCount = Canvas.getModeCount();
for (%i = 0; %i < %resCount; %i++)
{
%testResString = Canvas.getMode( %i );
%testRes = _makePrettyResString( %testResString );
// Only add to list if it isn't there already.
if (%resMenu.findText(%testRes) == -1)
{
%resMenu.add(%testRes, %i);
%count++;
}
}
%resMenu.sort();
}
function OptionsDlg::applyGraphics( %this, %testNeedApply )
{
%newAdapter = OptGraphicsDriverMenu.getText();
%numAdapters = GFXInit::getAdapterCount();
%newDevice = $pref::Video::displayDevice;
for( %i = 0; %i < %numAdapters; %i ++ )
if( GFXInit::getAdapterName( %i ) $= %newAdapter )
{
%newDevice = GFXInit::getAdapterType( %i );
break;
}
// Change the device.
if ( %newDevice !$= $pref::Video::displayDevice )
{
if ( %testNeedApply )
return true;
$pref::Video::displayDevice = %newDevice;
if( %newAdapter !$= getDisplayDeviceInformation() )
MessageBoxOK( "Change requires restart", "Please restart the game for a display device change to take effect." );
}
// Gather the new video mode.
if ( isFunction("getWebDeployment") && getWebDeployment() )
{
// Under web deployment, we use the custom resolution rather than a Canvas
// defined one.
%newRes = %this-->OptGraphicsResolutionMenu.getText();
}
else
{
%newRes = getWords( Canvas.getMode( %this-->OptGraphicsResolutionMenu.getSelected() ), $WORD::RES_X, $WORD::RES_Y );
}
%newBpp = 32; // ... its not 1997 anymore.
%newFullScreen = %this-->OptGraphicsFullscreenToggle.getValue() ? "true" : "false";
%newRefresh = %this-->OptRefreshSelectMenu.getSelected();
%newVsync = !%this-->OptGraphicsVSyncToggle.getValue();
%newFSAA = %this-->OptAAQualityPopup.getSelected();
// Under web deployment we can't be full screen.
if ( isFunction("getWebDeployment") && getWebDeployment() )
{
%newFullScreen = false;
}
else if ( %newFullScreen $= "false" )
{
// If we're in windowed mode switch the fullscreen check
// if the resolution is bigger than the desktop.
%deskRes = getDesktopResolution();
%deskResX = getWord(%deskRes, $WORD::RES_X);
%deskResY = getWord(%deskRes, $WORD::RES_Y);
if ( getWord( %newRes, $WORD::RES_X ) > %deskResX ||
getWord( %newRes, $WORD::RES_Y ) > %deskResY )
{
%newFullScreen = "true";
%this-->OptGraphicsFullscreenToggle.setStateOn( true );
}
}
// Build the final mode string.
%newMode = %newRes SPC %newFullScreen SPC %newBpp SPC %newRefresh SPC %newFSAA;
// Change the video mode.
if ( %newMode !$= $pref::Video::mode ||
%newVsync != $pref::Video::disableVerticalSync )
{
if ( %testNeedApply )
return true;
$pref::Video::mode = %newMode;
$pref::Video::disableVerticalSync = %newVsync;
configureCanvas();
}
// Test and apply the graphics settings.
if ( %this-->OptMeshQualityPopup.apply( MeshQualityGroup, %testNeedApply ) ) return true;
if ( %this-->OptTextureQualityPopup.apply( TextureQualityGroup, %testNeedApply ) ) return true;
if ( %this-->OptLightingQualityPopup.apply( LightingQualityGroup, %testNeedApply ) ) return true;
if ( %this-->OptShaderQualityPopup.apply( ShaderQualityGroup, %testNeedApply ) ) return true;
// Check the anisotropic filtering.
%level = %this-->OptAnisotropicPopup.getSelected();
if ( %level != $pref::Video::defaultAnisotropy )
{
if ( %testNeedApply )
return true;
$pref::Video::defaultAnisotropy = %level;
}
// If we're applying the state then recheck the
// state to update the apply button.
if ( !%testNeedApply )
%this._updateApplyState();
return false;
}
function OptionsDlg::_updateApplyState( %this )
{
%applyCtrl = %this-->Apply;
%graphicsPane = %this-->OptGraphicsPane;
assert( isObject( %applyCtrl ) );
assert( isObject( %graphicsPane ) );
%applyCtrl.active = %graphicsPane.isVisible() && %this.applyGraphics( true );
}
function OptionsDlg::_autoDetectQuality( %this )
{
%msg = GraphicsQualityAutodetect();
%this.onWake();
if ( %msg !$= "" )
{
MessageBoxOK( "Notice", %msg );
}
}
$RemapCount = 0;
$RemapName[$RemapCount] = "Forward";
$RemapCmd[$RemapCount] = "moveforward";
$RemapCount++;
$RemapName[$RemapCount] = "Backward";
$RemapCmd[$RemapCount] = "movebackward";
$RemapCount++;
$RemapName[$RemapCount] = "Strafe Left";
$RemapCmd[$RemapCount] = "moveleft";
$RemapCount++;
$RemapName[$RemapCount] = "Strafe Right";
$RemapCmd[$RemapCount] = "moveright";
$RemapCount++;
$RemapName[$RemapCount] = "Turn Left";
$RemapCmd[$RemapCount] = "turnLeft";
$RemapCount++;
$RemapName[$RemapCount] = "Turn Right";
$RemapCmd[$RemapCount] = "turnRight";
$RemapCount++;
$RemapName[$RemapCount] = "Look Up";
$RemapCmd[$RemapCount] = "panUp";
$RemapCount++;
$RemapName[$RemapCount] = "Look Down";
$RemapCmd[$RemapCount] = "panDown";
$RemapCount++;
$RemapName[$RemapCount] = "Jump";
$RemapCmd[$RemapCount] = "jump";
$RemapCount++;
$RemapName[$RemapCount] = "Fire Weapon";
$RemapCmd[$RemapCount] = "mouseFire";
$RemapCount++;
$RemapName[$RemapCount] = "Adjust Zoom";
$RemapCmd[$RemapCount] = "setZoomFov";
$RemapCount++;
$RemapName[$RemapCount] = "Toggle Zoom";
$RemapCmd[$RemapCount] = "toggleZoom";
$RemapCount++;
$RemapName[$RemapCount] = "Free Look";
$RemapCmd[$RemapCount] = "toggleFreeLook";
$RemapCount++;
$RemapName[$RemapCount] = "Switch 1st/3rd";
$RemapCmd[$RemapCount] = "toggleFirstPerson";
$RemapCount++;
$RemapName[$RemapCount] = "Chat to Everyone";
$RemapCmd[$RemapCount] = "toggleMessageHud";
$RemapCount++;
$RemapName[$RemapCount] = "Message Hud PageUp";
$RemapCmd[$RemapCount] = "pageMessageHudUp";
$RemapCount++;
$RemapName[$RemapCount] = "Message Hud PageDown";
$RemapCmd[$RemapCount] = "pageMessageHudDown";
$RemapCount++;
$RemapName[$RemapCount] = "Resize Message Hud";
$RemapCmd[$RemapCount] = "resizeMessageHud";
$RemapCount++;
$RemapName[$RemapCount] = "Show Scores";
$RemapCmd[$RemapCount] = "showPlayerList";
$RemapCount++;
$RemapName[$RemapCount] = "Animation - Wave";
$RemapCmd[$RemapCount] = "celebrationWave";
$RemapCount++;
$RemapName[$RemapCount] = "Animation - Salute";
$RemapCmd[$RemapCount] = "celebrationSalute";
$RemapCount++;
$RemapName[$RemapCount] = "Suicide";
$RemapCmd[$RemapCount] = "suicide";
$RemapCount++;
$RemapName[$RemapCount] = "Toggle Camera";
$RemapCmd[$RemapCount] = "toggleCamera";
$RemapCount++;
$RemapName[$RemapCount] = "Drop Camera at Player";
$RemapCmd[$RemapCount] = "dropCameraAtPlayer";
$RemapCount++;
$RemapName[$RemapCount] = "Drop Player at Camera";
$RemapCmd[$RemapCount] = "dropPlayerAtCamera";
$RemapCount++;
$RemapName[$RemapCount] = "Bring up Options Dialog";
$RemapCmd[$RemapCount] = "bringUpOptions";
$RemapCount++;
function restoreDefaultMappings()
{
moveMap.delete();
exec( "scripts/client/default.bind.cs" );
optionsDlg.fillRemapList();
}
function getMapDisplayName( %device, %action )
{
if ( %device $= "keyboard" )
return( %action );
else if ( strstr( %device, "mouse" ) != -1 )
{
// Substitute "mouse" for "button" in the action string:
%pos = strstr( %action, "button" );
if ( %pos != -1 )
{
%mods = getSubStr( %action, 0, %pos );
%object = getSubStr( %action, %pos, 1000 );
%instance = getSubStr( %object, strlen( "button" ), 1000 );
return( %mods @ "mouse" @ ( %instance + 1 ) );
}
else
error( "Mouse input object other than button passed to getDisplayMapName!" );
}
else if ( strstr( %device, "joystick" ) != -1 )
{
// Substitute "joystick" for "button" in the action string:
%pos = strstr( %action, "button" );
if ( %pos != -1 )
{
%mods = getSubStr( %action, 0, %pos );
%object = getSubStr( %action, %pos, 1000 );
%instance = getSubStr( %object, strlen( "button" ), 1000 );
return( %mods @ "joystick" @ ( %instance + 1 ) );
}
else
{
%pos = strstr( %action, "pov" );
if ( %pos != -1 )
{
%wordCount = getWordCount( %action );
%mods = %wordCount > 1 ? getWords( %action, 0, %wordCount - 2 ) @ " " : "";
%object = getWord( %action, %wordCount - 1 );
switch$ ( %object )
{
case "upov": %object = "POV1 up";
case "dpov": %object = "POV1 down";
case "lpov": %object = "POV1 left";
case "rpov": %object = "POV1 right";
case "upov2": %object = "POV2 up";
case "dpov2": %object = "POV2 down";
case "lpov2": %object = "POV2 left";
case "rpov2": %object = "POV2 right";
default: %object = "??";
}
return( %mods @ %object );
}
else
error( "Unsupported Joystick input object passed to getDisplayMapName!" );
}
}
return( "??" );
}
function buildFullMapString( %index )
{
%name = $RemapName[%index];
%cmd = $RemapCmd[%index];
%temp = moveMap.getBinding( %cmd );
if ( %temp $= "" )
return %name TAB "";
%mapString = "";
%count = getFieldCount( %temp );
for ( %i = 0; %i < %count; %i += 2 )
{
if ( %mapString !$= "" )
%mapString = %mapString @ ", ";
%device = getField( %temp, %i + 0 );
%object = getField( %temp, %i + 1 );
%mapString = %mapString @ getMapDisplayName( %device, %object );
}
return %name TAB %mapString;
}
function OptionsDlg::fillRemapList( %this )
{
%remapList = %this-->OptRemapList;
%remapList.clear();
for ( %i = 0; %i < $RemapCount; %i++ )
%remapList.addRow( %i, buildFullMapString( %i ) );
}
function OptionsDlg::doRemap( %this )
{
%remapList = %this-->OptRemapList;
%selId = %remapList.getSelectedId();
%name = $RemapName[%selId];
RemapDlg-->OptRemapText.setValue( "Re-bind \"" @ %name @ "\" to..." );
OptRemapInputCtrl.index = %selId;
Canvas.pushDialog( RemapDlg );
}
function redoMapping( %device, %action, %cmd, %oldIndex, %newIndex )
{
//%actionMap.bind( %device, %action, $RemapCmd[%newIndex] );
moveMap.bind( %device, %action, %cmd );
%remapList = %this-->OptRemapList;
%remapList.setRowById( %oldIndex, buildFullMapString( %oldIndex ) );
%remapList.setRowById( %newIndex, buildFullMapString( %newIndex ) );
}
function findRemapCmdIndex( %command )
{
for ( %i = 0; %i < $RemapCount; %i++ )
{
if ( %command $= $RemapCmd[%i] )
return( %i );
}
return( -1 );
}
/// This unbinds actions beyond %count associated to the
/// particular moveMap %commmand.
function unbindExtraActions( %command, %count )
{
%temp = moveMap.getBinding( %command );
if ( %temp $= "" )
return;
%count = getFieldCount( %temp ) - ( %count * 2 );
for ( %i = 0; %i < %count; %i += 2 )
{
%device = getField( %temp, %i + 0 );
%action = getField( %temp, %i + 1 );
moveMap.unbind( %device, %action );
}
}
function OptRemapInputCtrl::onInputEvent( %this, %device, %action )
{
//error( "** onInputEvent called - device = " @ %device @ ", action = " @ %action @ " **" );
Canvas.popDialog( RemapDlg );
// Test for the reserved keystrokes:
if ( %device $= "keyboard" )
{
// Cancel...
if ( %action $= "escape" )
{
// Do nothing...
return;
}
}
%cmd = $RemapCmd[%this.index];
%name = $RemapName[%this.index];
// Grab the friendly display name for this action
// which we'll use when prompting the user below.
%mapName = getMapDisplayName( %device, %action );
// Get the current command this action is mapped to.
%prevMap = moveMap.getCommand( %device, %action );
// If nothing was mapped to the previous command
// mapping then it's easy... just bind it.
if ( %prevMap $= "" )
{
unbindExtraActions( %cmd, 1 );
moveMap.bind( %device, %action, %cmd );
optionsDlg-->OptRemapList.setRowById( %this.index, buildFullMapString( %this.index ) );
return;
}
// If the previous command is the same as the
// current then they hit the same input as what
// was already assigned.
if ( %prevMap $= %cmd )
{
unbindExtraActions( %cmd, 0 );
moveMap.bind( %device, %action, %cmd );
optionsDlg-->OptRemapList.setRowById( %this.index, buildFullMapString( %this.index ) );
return;
}
// Look for the index of the previous mapping.
%prevMapIndex = findRemapCmdIndex( %prevMap );
// If we get a negative index then the previous
// mapping was to an item that isn't included in
// the mapping list... so we cannot unmap it.
if ( %prevMapIndex == -1 )
{
MessageBoxOK( "Remap Failed", "\"" @ %mapName @ "\" is already bound to a non-remappable command!" );
return;
}
// Setup the forced remapping callback command.
%callback = "redoMapping(" @ %device @ ", \"" @ %action @ "\", \"" @
%cmd @ "\", " @ %prevMapIndex @ ", " @ %this.index @ ");";
// Warn that we're about to remove the old mapping and
// replace it with another.
%prevCmdName = $RemapName[%prevMapIndex];
MessageBoxYesNo( "Warning",
"\"" @ %mapName @ "\" is already bound to \""
@ %prevCmdName @ "\"!\nDo you wish to replace this mapping?",
%callback, "" );
}
$AudioTestHandle = 0;
// Description to use for playing the volume test sound. This isn't
// played with the description of the channel that has its volume changed
// because we know nothing about the playback state of the channel. If it
// is paused or stopped, the test sound would not play then.
$AudioTestDescription = new SFXDescription()
{
sourceGroup = AudioChannelMaster;
};
function OptAudioUpdateMasterVolume( %volume )
{
if( %volume == $pref::SFX::masterVolume )
return;
sfxSetMasterVolume( %volume );
$pref::SFX::masterVolume = %volume;
if( !isObject( $AudioTestHandle ) )
$AudioTestHandle = sfxPlayOnce( AudioChannel, "core/art/sound/volumeTest.wav" );
}
function OptAudioUpdateChannelVolume( %description, %volume )
{
%channel = sfxGroupToOldChannel( %description.sourceGroup );
if( %volume == $pref::SFX::channelVolume[ %channel ] )
return;
sfxSetChannelVolume( %channel, %volume );
$pref::SFX::channelVolume[ %channel ] = %volume;
if( !isObject( $AudioTestHandle ) )
{
$AudioTestDescription.volume = %volume;
$AudioTestHandle = sfxPlayOnce( $AudioTestDescription, "core/art/sound/volumeTest.wav" );
}
}
function OptAudioProviderList::onSelect( %this, %id, %text )
{
// Skip empty provider selections.
if ( %text $= "" )
return;
$pref::SFX::provider = %text;
OptAudioDeviceList.clear();
%buffer = sfxGetAvailableDevices();
%count = getRecordCount( %buffer );
for(%i = 0; %i < %count; %i++)
{
%record = getRecord(%buffer, %i);
%provider = getField(%record, 0);
%device = getField(%record, 1);
if (%provider !$= %text)
continue;
if ( OptAudioDeviceList.findText( %device ) == -1 )
OptAudioDeviceList.add( %device, %i );
}
// Find the previous selected device.
%selId = OptAudioDeviceList.findText($pref::SFX::device);
if ( %selId == -1 )
OptAudioDeviceList.setFirstSelected();
else
OptAudioDeviceList.setSelected( %selId );
}
function OptAudioDeviceList::onSelect( %this, %id, %text )
{
// Skip empty selections.
if ( %text $= "" )
return;
$pref::SFX::device = %text;
if ( !sfxCreateDevice( $pref::SFX::provider,
$pref::SFX::device,
$pref::SFX::useHardware,
-1 ) )
error( "Unable to create SFX device: " @ $pref::SFX::provider
SPC $pref::SFX::device
SPC $pref::SFX::useHardware );
}
function OptMouseSetSensitivity(%value)
{
$pref::Input::LinkMouseSensitivity = %value;
}
/*
function OptAudioHardwareToggle::onClick(%this)
{
if (!sfxCreateDevice($pref::SFX::provider, $pref::SFX::device, $pref::SFX::useHardware, -1))
error("Unable to create SFX device: " @ $pref::SFX::provider SPC $pref::SFX::device SPC $pref::SFX::useHardware);
}
*/