123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2013 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.
- //-----------------------------------------------------------------------------
- $toyAllCategoryIndex = 1;
- $defaultToySelected = false;
- //-----------------------------------------------------------------------------
- function ToyCategorySelectList::onSelect(%this)
- {
- // Fetch the index.
- %index = %this.currentToyCategory;
- $defaultToySelected = false;
- ToyListArray.initialize(%index);
- ToyListScroller.computeSizes();
- ToyListScroller.scrollToTop();
-
- // Unload the active toy.
- unloadToy();
- // Flag as the default toy selected.
- if ($defaultToySelected)
- {
- loadToy($defaultModuleID);
- }
- else
- {
- if ( ToyListArray.getCount() > 0 )
- {
- %firstToyButton = ToyListArray.getObject(0);
- if (isObject(%firstToyButton))
- %firstToyButton.performSelect();
- }
- }
- }
- //-----------------------------------------------------------------------------
- function ToyCategorySelectList::initialize(%this)
- {
- %this.toyCategories[$toyAllCategoryIndex] = "All";
- %this.toyCategories[$toyAllCategoryIndex+1] = "Physics";
- %this.toyCategories[$toyAllCategoryIndex+2] = "Features";
- %this.toyCategories[$toyAllCategoryIndex+3] = "Stress Testing";
- %this.toyCategories[$toyAllCategoryIndex+4] = "Fun and Games";
- %this.toyCategories[$toyAllCategoryIndex+5] = "Custom";
- %this.toyCategories[$toyAllCategoryIndex+6] = "Experiments";
- %this.maxToyCategories = $toyAllCategoryIndex + 7;
- // Set the "All" category as the default.
- // NOTE: This is important to use so that the user-configurable default toy
- // can be selected at start-up.
- %this.currentToyCategory = $toyAllCategoryIndex;
- %this.setText("All");
- %this.onSelect();
- }
- //-----------------------------------------------------------------------------
- function ToyCategorySelectList::nextCategory(%this)
- {
- if (%this.currentToyCategory >= %this.maxToyCategories)
- return;
- %this.currentToyCategory++;
- %text = %this.toyCategories[%this.currentToyCategory];
- %this.setText(%text);
- %this.onSelect();
- }
- //-----------------------------------------------------------------------------
- function ToyCategorySelectList::previousCategory(%this)
- {
- if (%this.currentToyCategory <= $toyAllCategoryIndex)
- return;
- %this.currentToyCategory--;
- %text = %this.toyCategories[%this.currentToyCategory];
- %this.setText(%text);
- %this.onSelect();
- }
- //-----------------------------------------------------------------------------
- function initializeToolbox()
- {
- // Populate the stock colors.
- %colorCount = getStockColorCount();
- for ( %i = 0; %i < %colorCount; %i++ )
- {
- // Fetch stock color name.
- %colorName = getStockColorName(%i);
-
- // Add to the list.
- BackgroundColorSelectList.add( getStockColorName(%i), %i );
-
- // Select the color if it's the default one.
- if ( %colorName $= $pref::Sandbox::defaultBackgroundColor )
- BackgroundColorSelectList.setSelected( %i );
- }
- BackgroundColorSelectList.sort();
- ToyCategorySelectList.initialize();
- // Is this on the desktop?
- if ( $platform $= "windows" || $platform $= "macos" )
- {
- // Yes, so make the controls screen controls visible.
- ResolutionSelectLabel.Visible = true;
- ResolutionSelectList.Visible = true;
- FullscreenOptionLabel.Visible = true;
- FullscreenOptionButton.Visible = true;
-
- // Fetch the active resolution.
- %activeResolution = getRes();
- %activeWidth = getWord(%activeResolution, 0);
- %activeHeight = getWord(%activeResolution, 1);
- %activeBpp = getWord(%activeResolution, 2);
-
- // Fetch the resolutions.
- %resolutionList = getResolutionList( $pref::Video::displayDevice );
- %resolutionCount = getWordCount( %resolutionList ) / 3;
- %inputIndex = 0;
- %outputIndex = 0;
- for( %i = 0; %i < %resolutionCount; %i++ )
- {
- // Fetch the resolution entry.
- %width = getWord( %resolutionList, %inputIndex );
- %height = getWord( %resolutionList, %inputIndex+1 );
- %bpp = getWord( %resolutionList, %inputIndex+2 );
- %inputIndex += 3;
-
- // Skip the 16-bit ones.
- if ( %bpp == 16 )
- continue;
-
- // Store the resolution.
- $sandboxResolutions[%outputIndex] = %width SPC %height SPC %bpp;
-
- // Add to the list.
- ResolutionSelectList.add( %width @ "x" @ %height SPC "(" @ %bpp @ ")", %outputIndex );
-
- // Select the resolution if it's the default one.
- if ( %width == %activeWidth && %height == %activeHeight && %bpp == %activeBpp )
- ResolutionSelectList.setSelected( %outputIndex );
-
- %outputIndex++;
- }
- }
-
- // Configure the main overlay.
- SandboxWindow.add(MainOverlay);
- %horizPosition = getWord(SandboxWindow.Extent, 0) - getWord(MainOverlay.Extent, 0);
- %verticalPosition = getWord(SandboxWindow.Extent, 1) - getWord(MainOverlay.Extent, 1);
- MainOverlay.position = %horizPosition SPC %verticalPosition;
- }
- //-----------------------------------------------------------------------------
- function toggleToolbox(%make)
- {
- // Finish if being released.
- if ( !%make )
- return;
-
- // Finish if the console is awake.
- if ( ConsoleDialog.isAwake() )
- return;
-
- // Is the toolbox awake?
- if ( ToolboxDialog.isAwake() )
- {
- // Yes, so deactivate it.
- if ( $enableDirectInput )
- activateKeyboard();
- Canvas.popDialog(ToolboxDialog);
- MainOverlay.setVisible(1);
- return;
- }
-
- // Activate it.
- if ( $enableDirectInput )
- deactivateKeyboard();
- MainOverlay.setVisible(0);
- Canvas.pushDialog(ToolboxDialog);
- }
- //-----------------------------------------------------------------------------
- function BackgroundColorSelectList::onSelect(%this)
- {
- // Fetch the index.
- $activeBackgroundColor = %this.getSelected();
-
- // Finish if the sandbox scene is not available.
- if ( !isObject(SandboxScene) )
- return;
-
- // Set the scene color.
- Canvas.BackgroundColor = getStockColorName($activeBackgroundColor);
- Canvas.UseBackgroundColor = true;
- }
- //-----------------------------------------------------------------------------
- function ResolutionSelectList::onSelect(%this)
- {
- // Finish if the sandbox scene is not available.
- if ( !isObject(SandboxScene) )
- return;
-
- // Fetch the index.
- %index = %this.getSelected();
- // Fetch resolution.
- %resolution = $sandboxResolutions[%index];
-
- // Set the screen mode.
- setScreenMode( GetWord( %resolution , 0 ), GetWord( %resolution, 1 ), GetWord( %resolution, 2 ), $pref::Video::fullScreen );
- }
- //-----------------------------------------------------------------------------
- function PauseSceneModeButton::onClick(%this)
- {
- // Sanity!
- if ( !isObject(SandboxScene) )
- {
- error( "Cannot pause/unpause the Sandbox scene as it does not exist." );
- return;
- }
-
- // Toggle the scene pause.
- SandboxScene.setScenePause( !SandboxScene.getScenePause() );
- }
- //-----------------------------------------------------------------------------
- function ReloadToyOverlayButton::onClick(%this)
- {
- // Finish if no toy is loaded.
- if ( !isObject(Sandbox.ActiveToy) )
- return;
- // Reset custom controls.
- resetCustomControls();
- // Reload the toy.
- loadToy( Sandbox.ActiveToy );
- }
- //-----------------------------------------------------------------------------
- function RestartToyOverlayButton::onClick(%this)
- {
- // Finish if no toy is loaded.
- if ( !isObject(Sandbox.ActiveToy) )
- return;
- // Reset the toy.
- if ( Sandbox.ActiveToy.ScopeSet.isMethod("reset") )
- Sandbox.ActiveToy.ScopeSet.reset();
- }
- //-----------------------------------------------------------------------------
- function updateToolboxOptions()
- {
- // Finish if the sandbox scene is not available.
- if ( !isObject(SandboxScene) )
- return;
-
- // Set the scene color.
- Canvas.BackgroundColor = getStockColorName($activeBackgroundColor);
- Canvas.UseBackgroundColor = true;
-
- // Set option.
- if ( $pref::Sandbox::metricsOption )
- SandboxScene.setDebugOn( "metrics" );
- else
- SandboxScene.setDebugOff( "metrics" );
- // Set option.
- if ( $pref::Sandbox::fpsmetricsOption )
- SandboxScene.setDebugOn( "fps" );
- else
- SandboxScene.setDebugOff( "fps" );
- // Set option.
- if ( $pref::Sandbox::controllersOption )
- SandboxScene.setDebugOn( "controllers" );
- else
- SandboxScene.setDebugOff( "controllers" );
-
- // Set option.
- if ( $pref::Sandbox::jointsOption )
- SandboxScene.setDebugOn( "joints" );
- else
- SandboxScene.setDebugOff( "joints" );
- // Set option.
- if ( $pref::Sandbox::wireframeOption )
- SandboxScene.setDebugOn( "wireframe" );
- else
- SandboxScene.setDebugOff( "wireframe" );
-
- // Set option.
- if ( $pref::Sandbox::aabbOption )
- SandboxScene.setDebugOn( "aabb" );
- else
- SandboxScene.setDebugOff( "aabb" );
- // Set option.
- if ( $pref::Sandbox::oobbOption )
- SandboxScene.setDebugOn( "oobb" );
- else
- SandboxScene.setDebugOff( "oobb" );
-
- // Set option.
- if ( $pref::Sandbox::sleepOption )
- SandboxScene.setDebugOn( "sleep" );
- else
- SandboxScene.setDebugOff( "sleep" );
- // Set option.
- if ( $pref::Sandbox::collisionOption )
- SandboxScene.setDebugOn( "collision" );
- else
- SandboxScene.setDebugOff( "collision" );
-
- // Set option.
- if ( $pref::Sandbox::positionOption )
- SandboxScene.setDebugOn( "position" );
- else
- SandboxScene.setDebugOff( "position" );
-
- // Set option.
- if ( $pref::Sandbox::sortOption )
- SandboxScene.setDebugOn( "sort" );
- else
- SandboxScene.setDebugOff( "sort" );
-
- // Set the options check-boxe.
- MetricsOptionCheckBox.setStateOn( $pref::Sandbox::metricsOption );
- FpsMetricsOptionCheckBox.setStateOn( $pref::Sandbox::fpsmetricsOption );
- ControllersOptionCheckBox.setStateOn( $pref::Sandbox::controllersOption );
- JointsOptionCheckBox.setStateOn( $pref::Sandbox::jointsOption );
- WireframeOptionCheckBox.setStateOn( $pref::Sandbox::wireframeOption );
- AABBOptionCheckBox.setStateOn( $pref::Sandbox::aabbOption );
- OOBBOptionCheckBox.setStateOn( $pref::Sandbox::oobbOption );
- SleepOptionCheckBox.setStateOn( $pref::Sandbox::sleepOption );
- CollisionOptionCheckBox.setStateOn( $pref::Sandbox::collisionOption );
- PositionOptionCheckBox.setStateOn( $pref::Sandbox::positionOption );
- SortOptionCheckBox.setStateOn( $pref::Sandbox::sortOption );
- BatchOptionCheckBox.setStateOn( SandboxScene.getBatchingEnabled() );
-
- // Is this on the desktop?
- //if ( $platform $= "windows" || $platform $= "macos" )
- if ( $platform !$= "iOS" )
- {
- // Set the fullscreen check-box.
- FullscreenOptionButton.setStateOn( $pref::Video::fullScreen );
-
- // Set the full-screen mode appropriately.
- if ( isFullScreen() != $pref::Video::fullScreen )
- toggleFullScreen();
- }
- }
- //-----------------------------------------------------------------------------
- function setFullscreenOption( %flag )
- {
- $pref::Video::fullScreen = %flag;
- updateToolboxOptions();
- }
- //-----------------------------------------------------------------------------
- function setMetricsOption( %flag )
- {
- $pref::Sandbox::metricsOption = %flag;
- updateToolboxOptions();
- }
- //-----------------------------------------------------------------------------
- function setFPSMetricsOption( %flag )
- {
- $pref::Sandbox::fpsmetricsOption = %flag;
- updateToolboxOptions();
- }
- //-----------------------------------------------------------------------------
- function setMetricsOption( %flag )
- {
- $pref::Sandbox::metricsOption = %flag;
- updateToolboxOptions();
- }
- //-----------------------------------------------------------------------------
- function setControllersOption( %flag )
- {
- $pref::Sandbox::controllersOption = %flag;
- updateToolboxOptions();
- }
- //-----------------------------------------------------------------------------
- function setJointsOption( %flag )
- {
- $pref::Sandbox::jointsOption = %flag;
- updateToolboxOptions();
- }
- //-----------------------------------------------------------------------------
- function setWireframeOption( %flag )
- {
- $pref::Sandbox::wireframeOption = %flag;
- updateToolboxOptions();
- }
- //-----------------------------------------------------------------------------
- function setAABBOption( %flag )
- {
- $pref::Sandbox::aabbOption = %flag;
- updateToolboxOptions();
- }
- //-----------------------------------------------------------------------------
- function setOOBBOption( %flag )
- {
- $pref::Sandbox::oobbOption = %flag;
- updateToolboxOptions();
- }
- //-----------------------------------------------------------------------------
- function setSleepOption( %flag )
- {
- $pref::Sandbox::sleepOption = %flag;
- updateToolboxOptions();
- }
- //-----------------------------------------------------------------------------
- function setCollisionOption( %flag )
- {
- $pref::Sandbox::collisionOption = %flag;
- updateToolboxOptions();
- }
- //-----------------------------------------------------------------------------
- function setPositionOption( %flag )
- {
- $pref::Sandbox::positionOption = %flag;
- updateToolboxOptions();
- }
- //-----------------------------------------------------------------------------
- function setSortOption( %flag )
- {
- $pref::Sandbox::sortOption = %flag;
- updateToolboxOptions();
- }
- //-----------------------------------------------------------------------------
- function ToyListScroller::scrollToNext(%this)
- {
- %currentScroll = %this.getScrollPositionY();
- %currentScroll += 85;
- %this.setScrollPosition(0, %currentScroll);
- }
- //-----------------------------------------------------------------------------
- function ToyListScroller::scrollToPrevious(%this)
- {
- %currentScroll = %this.getScrollPositionY();
- %currentScroll -= 85;
- %this.setScrollPosition(0, %currentScroll);
- }
- //-----------------------------------------------------------------------------
- function ToyListArray::initialize(%this, %index)
- {
- %this.clear();
- %currentExtent = %this.extent;
- %newExtent = getWord(%currentExtent, 0) SPC "20";
- %this.Extent = %newExtent;
-
- // Fetch the toy count.
- %toyCount = SandboxToys.getCount();
- // Populate toys in the selected category.
- for ( %toyIndex = 0; %toyIndex < %toyCount; %toyIndex++ )
- {
- // Fetch the toy module.
- %moduleDefinition = SandboxToys.getObject( %toyIndex );
-
- // Skip the toy module if the "all" category is not selected and if the toy is not in the selected category.
- if ( %index != $toyAllCategoryIndex && %moduleDefinition.ToyCategoryIndex != %index )
- continue;
- // Fetch the module version.
- %versionId = %moduleDefinition.versionId;
- // Format module title so that version#1 doesn't show version but all other versions do.
- if ( %versionId == 1 )
- %moduleTitle = %moduleDefinition.moduleId;
- else
- %moduleTitle = %moduleDefinition.moduleId SPC "(v" @ %moduleDefinition.versionId @ ")";
- // Add the toy GUI list.
- %this.addToyButton(%moduleTitle, %moduleDefinition);
-
- // Select the toy if it's the default and we've not selected a toy yet.
- if (!$defaultToySelected && %moduleDefinition.moduleId $= $pref::Sandbox::defaultToyId && %moduleDefinition.versionId == $pref::Sandbox::defaultToyVersionId )
- {
- $defaultToySelected = true;
- $defaultModuleID = %moduleDefinition.getId();
- }
- }
- }
- //-----------------------------------------------------------------------------
- function ToyListArray::addToyButton(%this, %moduleTitle, %moduleDefintion)
- {
- %button = new GuiButtonCtrl()
- {
- canSaveDynamicFields = "0";
- HorizSizing = "relative";
- class = "ToySelectButton";
- VertSizing = "relative";
- isContainer = "0";
- Profile = "BlueButtonProfile";
- toolTipProfile = "GuiToolTipProfile";
- toolTip = %moduleDefintion.Description;
- Position = "0 0";
- Extent = "160 80";
- Visible = "1";
- toy = %moduleDefintion.getId();
- isContainer = "0";
- Active = "1";
- text = %moduleTitle;
- groupNum = "-1";
- buttonType = "PushButton";
- useMouseEvents = "0";
- };
-
- %button.command = %button @ ".performSelect();";
-
- %this.add(%button);
- }
- //-----------------------------------------------------------------------------
- function ToySelectButton::performSelect(%this)
- {
- // Finish if already selected.
- if ( %this.toy == Sandbox.ActiveToy )
- return;
-
- // Load the selected toy.
- loadToy( %this.toy );
- }
|