Torque 2D/StandardTutorials/Basics/Options
From TDN
Contents |
Custom Options Dialog
Key-Bindings
Adding Bindings to the Game
To setup custom key-bindings for your game, all you have to do is add them to the gameMod/main.cs setupKeybinds() function, following the example provided in the function.
function setupKeybinds()
{
new ActionMap(moveMap);
moveMap.bind("keyboard", "a", "DoAction", "Description that shows up in Keybindings List");
}
Adding multiple moveMap.bind() calls to this function will add each of these to your Key-Bindings in the default TGB Options Dialog, it is probably suggested that you call "dumpKeybindings()" at some point -- usually good to call this in your shutdownProject() function, you can also attach it to the Options Dialog Close callback, which can be modified in the following:
Saving your Key-Bindings when they are Changed
Open common/gui/options.gui and at the top, you will see the creation of a new GuiButtonCtrl, this is your actual Options Dialog OK Button, with a default options.gui file, on line 380 you will see the following:
new GuiButtonCtrl() {
canSaveDynamicFields = "0";
Profile = "GuiButtonProfile";
HorizSizing = "left";
VertSizing = "top";
Position = "394 298";
Extent = "100 25";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "applyAVOptions(); Canvas.popDialog(OptionsDlg);";
hovertime = "1000";
text = "Ok";
groupNum = "-1";
buttonType = "PushButton";
Accelerator = "numpadenter";
};
You can change the highlighted line to the following:
Command = "applyAVOptions(); dumpKeybindings(); Canvas.popDialog(OptionsDlg);";
Making this change will force your game to save it's keybindings when the end-user presses "OK" -- reverting back to the defaults should be a 'factory default' functionality, but in the event you need to do it yourself, you can call the revertControlOptions(); function manually at any time which basically performs the functionality required to revert all your controls back to the defaults found in the common/preferences/bind.cs file.



