Bladeren bron

Merge pull request #1624 from Sir-Skurpsalot/Skurpz/UI-Module-Fixes

Skurpz/UI module fixes
Brian Roberts 1 maand geleden
bovenliggende
commit
dd72a627a9

+ 9 - 5
Templates/BaseGame/game/core/clientServer/scripts/client/client.tscript

@@ -13,17 +13,21 @@ function initClient()
    exec( "./connectionToServer." @ $TorqueScriptFileExtension );
    exec( "./levelDownload." @ $TorqueScriptFileExtension );
    exec( "./levelLoad." @ $TorqueScriptFileExtension );
-   
-   //load prefs
    exec( "data/defaults." @ $TorqueScriptFileExtension );
+
+   moduleExec("initClient");
+
+   //load prefs
    %prefPath = getPrefpath();
    if ( isFile( %prefPath @ "/clientPrefs." @ $TorqueScriptFileExtension ) )
       exec( %prefPath @ "/clientPrefs." @ $TorqueScriptFileExtension );
-      
-   moduleExec("initClient");
+
+   //keybinds stores user custom keybinds generated by the UI module (if installed), this should be the only place this is executed
+   if(isScriptFile(%prefPath @ "/keybinds." @ $TorqueScriptFileExtension)) 
+      exec(%prefPath @ "/keybinds." @ $TorqueScriptFileExtension);
 
    // Copy saved script prefs into C++ code.
    setDefaultFov( $pref::Player::defaultFov );
    setZoomSpeed( $pref::Player::zoomSpeed );
    loadModuleMaterials();
-}
+}

+ 0 - 19
Templates/BaseGame/game/core/utility/scripts/input.tscript

@@ -9,22 +9,3 @@ function getMouseAdjustAmount(%val)
    // based on a default camera FOV of 90'
    return(%val * ($cameraFov / 90) * 0.01) * $pref::Input::LinkMouseSensitivity;
 }
-
-function addKeyRemap(%name, %actionMap, %device, %command, %description)
-{
-   if(%name $= "" ||
-      %actionMap $= "" ||
-      %device $= "" ||
-      %command $= "")
-   {
-      error("addKeybindRemap() - tried to add a remap entry, but didn't have all the keeded info!");
-      return;
-   }
-   
-   $RemapName[$RemapCount] = %name;
-   $RemapCmd[$RemapCount] = %command;
-   $RemapActionMap[$RemapCount] = %actionMap;
-   $RemapDevice[$RemapCount] = %device;
-   $RemapDescription[$RemapCount] = %description;
-   $RemapCount++;  
-}

+ 1 - 5
Templates/BaseGame/game/data/ExampleModule/ExampleModule.tscript

@@ -29,11 +29,7 @@ function ExampleModule::initClient(%this)
     
     //client scripts
    exec("./scripts/client/defaultkeybinds");
-   
-   %prefPath = getPrefpath();
-   if(isScriptFile(%prefPath @ "/keybinds"))
-      exec(%prefPath @ "/keybinds");
-      
+         
    %this.queueExec("./scripts/shared/ExampleGameMode");
 }
 

+ 3 - 2
Templates/BaseGame/game/data/UI/UI.tscript

@@ -21,7 +21,8 @@ function UI::onCreate( %this )
    // addLanguage("defaultTable","try","tr");
    createLangTable("defaultTable");
    setCoreLangTable("defaultTable");
-   exec("./langs/languageMap");
+   if(isFile("./langs/languageMap"))
+      exec("./langs/languageMap");
 }
 
 function UI::onDestroy( %this )
@@ -99,4 +100,4 @@ function UI::onDestroyClientConnection(%this)
 function UI::registerGameMenus(%this, %menusArrayObj)
 {
    %menusArrayObj.add("System", SystemMenu);
-}
+}

+ 1 - 1
Templates/BaseGame/game/data/UI/guis/ChooseLevelMenu.gui

@@ -388,7 +388,7 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
          horizSizing = "left";
          vertSizing = "center";
          profile = "GuiMenuButtonProfile";
-         command = "ChooseLevelBegin(1);";
+         command = "ChooseLevelMenuOption(1);";
          tooltipProfile = "GuiToolTipProfile";
       };
       new GuiIconButtonCtrl(ChooseLevelBackBtn) {

+ 3 - 3
Templates/BaseGame/game/data/UI/guis/ChooseLevelMenu.tscript

@@ -433,9 +433,9 @@ function ChooseLevelMenuOption(%val)
    if(%val)
    {
       if(ChooseLevelMenu.currentMenuIdx == 0)
-         ToggleGameMode(ChooseLevelMenu.listPosition);
+         ToggleGameMode($MenuList.listPosition);
       else if(ChooseLevelMenu.currentMenuIdx == 1)
-         ChooseLevelBegin(ChooseLevelMenu.listPosition);
+         ChooseLevelBegin($MenuList.listPosition);
    }
 }
 
@@ -536,4 +536,4 @@ function LevelPreviewButton::onHighlighted(%this, %highlighted)
       
       LevelPreviewScroll.scrollToObject(%this);
    }
-}
+}

File diff suppressed because it is too large
+ 197 - 443
Templates/BaseGame/game/data/UI/guis/optionsMenu.tscript


+ 0 - 125
Templates/BaseGame/game/data/UI/guis/remapConfirmDlg.gui

@@ -1,125 +0,0 @@
-//--- OBJECT WRITE BEGIN ---
-$guiContent = new GuiControl(RemapConfirmDlg) {
-   position = "0 0";
-   extent = "1024 768";
-   minExtent = "8 8";
-   horizSizing = "right";
-   vertSizing = "bottom";
-   profile = "GuiDefaultProfile";
-   visible = "1";
-   active = "1";
-   tooltipProfile = "GuiToolTipProfile";
-   hovertime = "1000";
-   isContainer = "1";
-   canSave = "1";
-   canSaveDynamicFields = "1";
-      helpTag = "0";
-
-   new GuiContainer(RemapConfirmationPanel) {
-      margin = "0 0 0 0";
-      padding = "0 0 0 0";
-      anchorTop = "1";
-      anchorBottom = "0";
-      anchorLeft = "1";
-      anchorRight = "0";
-      position = "168 352";
-      extent = "700 64";
-      minExtent = "8 2";
-      horizSizing = "center";
-      vertSizing = "center";
-      profile = "GuiDefaultProfile";
-      visible = "1";
-      active = "1";
-      tooltipProfile = "GuiToolTipProfile";
-      hovertime = "1000";
-      isContainer = "1";
-      canSave = "1";
-      canSaveDynamicFields = "0";
-
-      new GuiChunkedBitmapCtrl() {
-         bitmapAsset = "UI:hudfill_image";
-         useVariable = "0";
-         tile = "0";
-         position = "0 0";
-         extent = "700 64";
-         minExtent = "8 2";
-         horizSizing = "right";
-         vertSizing = "bottom";
-         profile = "GuiDefaultProfile";
-         visible = "1";
-         active = "1";
-         tooltipProfile = "GuiToolTipProfile";
-         hovertime = "1000";
-         isContainer = "0";
-         canSave = "1";
-         canSaveDynamicFields = "0";
-      };
-      new GuiTextCtrl(RemapConfirmationText) {
-         text = "\"m\" is already bound to \"Forward\"!\nDo you wish to replace this mapping?";
-         maxLength = "255";
-         margin = "0 0 0 0";
-         padding = "0 0 0 0";
-         anchorTop = "1";
-         anchorBottom = "0";
-         anchorLeft = "1";
-         anchorRight = "0";
-         position = "0 8";
-         extent = "700 20";
-         minExtent = "8 8";
-         horizSizing = "width";
-         vertSizing = "height";
-         profile = "GuiMenuButtonProfile";
-         visible = "1";
-         active = "1";
-         accelerator = "return";
-         tooltipProfile = "GuiToolTipProfile";
-         hovertime = "1000";
-         isContainer = "1";
-         canSave = "1";
-         canSaveDynamicFields = "0";
-      };
-      new GuiButtonCtrl(RemapConfirmationYesButton) {
-         text = "Yes";
-         groupNum = "-1";
-         buttonType = "PushButton";
-         useMouseEvents = "0";
-         position = "270 36";
-         extent = "80 22";
-         minExtent = "8 8";
-         horizSizing = "right";
-         vertSizing = "top";
-         profile = "GuiMenuButtonProfile";
-         visible = "1";
-         active = "1";
-         command = "ControlsMenu.redoMapping(keyboard, \"m\", \"jump\", 0, 4); Canvas.popDialog();";
-         accelerator = "return";
-         tooltipProfile = "GuiToolTipProfile";
-         hovertime = "1000";
-         isContainer = "0";
-         canSave = "1";
-         canSaveDynamicFields = "0";
-      };
-      new GuiButtonCtrl(RemapConfirmationNoButton) {
-         text = "No";
-         groupNum = "-1";
-         buttonType = "PushButton";
-         useMouseEvents = "0";
-         position = "367 36";
-         extent = "80 22";
-         minExtent = "8 8";
-         horizSizing = "right";
-         vertSizing = "top";
-         profile = "GuiMenuButtonProfile";
-         visible = "1";
-         active = "1";
-         command = "Canvas.popDialog();";
-         accelerator = "escape";
-         tooltipProfile = "GuiToolTipProfile";
-         hovertime = "1000";
-         isContainer = "0";
-         canSave = "1";
-         canSaveDynamicFields = "0";
-      };
-   };
-};
-//--- OBJECT WRITE END ---

+ 52 - 30
Templates/BaseGame/game/data/UI/guis/remapDlg.tscript

@@ -8,24 +8,27 @@ function OptRemapInputCtrl::onAxisEvent( %this, %device, %action, %axisVal)
       return;
 
    Canvas.popDialog( RemapDlg );
-   
+
    %this.doRemap(%device, %action, %axisVal);
 }
 
 function OptRemapInputCtrl::onInputEvent( %this, %device, %action )
 {
-   if(!startsWith(%device,$remapListDevice) && %action !$= "escape" && %action !$= "btn_start")
-   {
+   if(%action $= "escape" || %action $= "btn_start"){
+      Canvas.popDialog( RemapDlg );
       return;
    }
-   else 
-   {
+   // do nothing if gamepad is attempted to be used on the keyboard & mouse binds menu...
+   else if(%device $= "gamepad" && $remapListDevice $= "keyboard")
+      return;
+   // do nothing if keyboard or mouse is attempted to be used on the gamepad binds menu...
+   else if ((%device $= "mouse" || %device $= "keyboard") && $remapListDevice $= "gamePad")
+      return;
+   // procceed with remap if appropriate device used on binds menu...
+   else{
       Canvas.popDialog( RemapDlg );
-   
-      if(%action $= "escape" || %action $= "btn_start")
-         return;
-   
       %this.doRemap(%device, %action, 0);
+      $RemapDirty = true;
    }
 }
 
@@ -34,39 +37,40 @@ function OptRemapInputCtrl::doRemap(%this, %device, %action, %axisVal)
    %cmd  = $RemapCmd[%this.index];
    %name = $RemapName[%this.index];
    %actionMap = $RemapActionMap[%this.index];
-   
+
    echo("OptRemapInputCtrl::onInputEvent() - remapping details: " @ %cmd @ ", " @ %name @ ", " @ %actionMap @ " remapped to: " @ %device @ ", " @ %action);
 
    // 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 = %actionMap.getCommand( %device, %action );
-   
-   //TODO: clear all existant keybinds to a command and then bind it so we only have a single one at all times
+
+   // Make sure no other "action" (key / button press) is bound to this command
    unbindExtraActions( %cmd, %actionMap, %device, 0 );
    unbindExtraActions( %cmd, %actionMap, %device, 1 );
 
-   // If nothing was mapped to the previous command 
+   // If nothing was mapped to the previous command
    // mapping then it's easy... just bind it.
-   // If the previous command is the same as the 
+   // If the previous command is the same as the
    // current then they hit the same input as what
    // was already assigned.
    if ( %prevMap $= "" || %prevMap $= %cmd )
    {
-      //unbindExtraActions( %cmd, %actionMap, 1 );
       %actionMap.bind( %device, %action, %cmd );
-      
       OptionsMenu.populateKBMControls();
       OptionsMenu.populateGamepadControls();
       return;
    }
 
+   //------------------------------------------------------------------------------------------------------------------
+   // If this action (key / button press) was already bound to another command, undoing that is handled in this section
+   //------------------------------------------------------------------------------------------------------------------
    // Look for the index of the previous mapping.
    %prevMapIndex = findRemapCmdIndex( %prevMap );
-   
-   // If we get a negative index then the previous 
+
+   // 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 )
@@ -77,22 +81,23 @@ function OptRemapInputCtrl::doRemap(%this, %device, %action, %axisVal)
 
    // Setup the forced remapping callback command.
    %callback = "redoMapping(" @ %device @ ", " @ %actionMap @ ", \"" @ %action @ "\", \"" @
-                              %cmd @ "\", " @ %prevMapIndex @ ", " @ %this.index @ ");";
-   
+      %cmd @ "\");";
+
    // Warn that we're about to remove the old mapping and
    // replace it with another.
    %prevCmdName = $RemapName[%prevMapIndex];
-   //Canvas.pushDialog( RemapConfirmDlg );
-   
+
    %remapWarnText = "\"" @ %mapName @ "\" is already bound to \"" @ %prevCmdName @ "\"! Do you wish to replace this mapping?";
+
    %doRemapCommand = "redoMapping(" @ %device @ ", " @ %actionMap @ ", \"" @ %action @ "\", \"" @
-                              %cmd @ "\", " @ %prevMapIndex @ ", " @ %this.index @ ");";
+      %cmd @ "\");";
+
    %cancelCommand = "";
-   
-   MessageBoxYesNo( "Key already in use", %remapWarnText, %doRemapCommand, %cancelCommand );  
+
+   MessageBoxYesNo( "Key already in use", %remapWarnText, %doRemapCommand, %cancelCommand );
 }
 
-/// This unbinds actions beyond %count associated to the
+/// This unbinds actions (buttons / key presses) beyond %count associated to the
 /// particular actionMap %commmand.
 function unbindExtraActions( %command, %actionMap, %device, %count )
 {
@@ -105,8 +110,25 @@ function unbindExtraActions( %command, %actionMap, %device, %count )
    {
       %amDevice = getField( %temp, %i + 0 );
       %action = getField( %temp, %i + 1 );
-      
-      if(%device !$= "" || %device $= %amDevice)
-         %actionMap.unbind( %device, %action );
+
+      if(amDevice !$= "") {
+         %actionMap.unbind( %amDevice, %action ); //need to use %amDevice because could be changing from keyboard to mouse or vice versa
+      }
    }
 }
+
+function findRemapCmdIndex( %command ){
+   for ( %i = 0; %i < $RemapCount; %i++ )
+   {
+      if ( %command $= $RemapCmd[%i] )
+         return( %i );
+   }
+   return( -1 );
+}
+
+function redoMapping( %device, %actionMap, %action, %cmd)
+{
+   %actionMap.bind( %device, %action, %cmd );
+   OptionsMenu.populateKBMControls();
+   OptionsMenu.populateGamepadControls();
+}

+ 0 - 157
Templates/BaseGame/game/data/UI/scripts/controlsMenu.tscript

@@ -1,157 +0,0 @@
-// =============================================================================
-// KEYBINDS MENU
-// =============================================================================
-function ControlsMenuDefaultsButton::onClick(%this)
-{
-   //For this to work with module-style, we have to figure that somewhere, we'll set where our default keybind script is at.
-   //This can be hardcoded in your actual project.
-   //exec($KeybindPath);
-   //ControlsMenu.reload();
-}
-
-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!" );
-      }
-	}
-	else if ( strstr( %device, "gamepad" ) != -1 )
-	{
-	   return %action;
-	   
-	   %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, "thumb" );
-         if ( %pos != -1 )
-         {
-            //%instance = getSubStr( %action, strlen( "thumb" ), 1000 );
-            //return( "thumb" @ ( %instance + 1 ) );
-            return %action;
-         }
-         else
-            error( "Unsupported gamepad input object passed to getDisplayMapName!" );
-      }
-	}
-		
-	return( "" );		
-}
-
-function buildFullMapString( %index, %actionMap, %deviceType )
-{
-   %name       = $RemapName[%index];
-   %cmd        = $RemapCmd[%index];
-   
-   %temp = %actionMap.getBinding( %cmd );
-   if ( %temp $= "" )
-      return %name TAB "";
-
-   %mapString = "";
-
-   %count = getFieldCount( %temp );
-   for ( %i = 0; %i < %count; %i += 2 )
-   {
-      if ( %mapString !$= "" )
-         continue;
-         //%mapString = %mapString @ ", ";
-         
-      %device = getField( %temp, %i + 0 );
-      %object = getField( %temp, %i + 1 );
-      
-      if (startsWith(%device,"mouse"))
-          %deviceType = "mouse";
-      
-      if(%deviceType !$= "" && !startsWith(%device, %deviceType))
-         continue;
-         
-      %mapString = %mapString @ getMapDisplayName( %device, %object );
-   }
-
-   return %name TAB %mapString; 
-}
-
-function ControlsMenuRebindButton::onClick(%this)
-{
-   %name = $RemapName[%this.keybindIndex];
-   RemapDlg-->OptRemapText.text = "Re-bind \"" @ %name @ "\" to..." ;
-   
-   OptRemapInputCtrl.index = %this.keybindIndex;
-   OptRemapInputCtrl.optionIndex = %this.optionIndex;
-   Canvas.pushDialog( RemapDlg );
-}
-
-function findRemapCmdIndex( %command )
-{
-	for ( %i = 0; %i < $RemapCount; %i++ )
-	{
-		if ( %command $= $RemapCmd[%i] )
-			return( %i );			
-	}
-	return( -1 );	
-}
-
-
-function redoMapping( %device, %actionMap, %action, %cmd, %oldIndex, %newIndex )
-{
-	//%actionMap.bind( %device, %action, $RemapCmd[%newIndex] );
-	%actionMap.bind( %device, %action, %cmd );
-	
-	OptionsMenu.populateKBMControls();
-   OptionsMenu.populateGamepadControls();
-}

+ 28 - 5
Templates/BaseGame/game/data/UI/scripts/utility.tscript

@@ -182,11 +182,11 @@ function addLanguage(%langTable, %filename, %alias)
 {
     // generate an .lso file and if a languageMap file does not exist, it as well
     %needLangMap = true;
-    if(isFile("data/UI/langs/languageMap"))
-        %needLangMap = false;        
-        
-    CompileLanguage("data/UI/langs/"@ %filename @".txt", %needLangMap);    
-    %langTable.addLanguage("data/UI/langs/"@ %filename @".lso", %alias);
+    if(isFile("./langs/languageMap"))
+        %needLangMap = false;
+    
+    CompileLanguage("./langs/"@ %filename @".txt", %needLangMap);
+    %langTable.addLanguage("./langs/"@ %filename @".lso", %alias);
 }
 
 function switchLanguage(%language) //use here the #n as it's the order of inclusion
@@ -195,3 +195,26 @@ function switchLanguage(%language) //use here the #n as it's the order of inclus
 	getCoreLangTable().setCurrentLanguage(%language);
 	Canvas.setContent(Canvas.getContent());
 }
+
+function addKeyRemap(%name, %actionMap, %device, %command, %description)
+{
+   if(%name $= "" ||
+      %actionMap $= "" ||
+      %device $= "" ||
+      %command $= "")
+   {
+      error("addKeybindRemap() - tried to add a remap entry, but didn't have all the keeded info!");
+      return;
+   }
+
+   // "mouse" is accepted as a convenience, but the remappable actions related functions treat it same as "keyboard".
+   if(%device $= "mouse")
+      %device = "keyboard";
+
+   $RemapName[$RemapCount] = %name;
+   $RemapCmd[$RemapCount] = %command;
+   $RemapActionMap[$RemapCount] = %actionMap;
+   $RemapDevice[$RemapCount] = %device;
+   $RemapDescription[$RemapCount] = %description;
+   $RemapCount++;
+}

Some files were not shown because too many files changed in this diff