Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

# TribesGUI.TribesOptionsControlsPanel

00001 00002 00003 00004 00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297

    // ====================================================================
    //  Class:  TribesGui.TribesOptionsControlsMenu
    //
    //  Menu to load map from entry screen.
    // ====================================================================

    class TribesOptionsControlsPanel extends TribesSettingsPanel
    	native;

    var(TribesGUI) private EditInline Config GUIMultiColumnListBox   MyKeyBindingsBox;
    var(TribesGUI) private EditInline Config GUIButton               MyKeyChoose;

    var(TribesGUI) private EditInline Config GUICheckBoxButton       InvertMouseButton;
    var(TribesGUI) private EditInline Config GUICheckBoxButton       TeamColorsButton;
    //var(TribesGUI) private EditInline Config GUIComboBox		     MyCategoryList;
    var(TribesGUI) private EditInline Config GUISlider			     MyMouseSensSlider;
    var(TribesGui) private EditInline Config GUIButton DefaultsButton "A component of this page which has its behavior defined in the code for this page's class.";
    var(TribesGUI) private string LastCategory;

    var() private config localized string KeyChangeMessage;
    var() private config localized string NoBindKeyChangeMessage;

    function InitComponent(GUIComponent MyOwner)
    {
        local int i;
    //	local int j;
    //	local bool bFound;

    	Super.InitComponent(MyOwner);
    	MyKeyChoose.OnClick=InternalOnClick;
    	MyMouseSensSlider.OnChange=OnSensitivityChange;
    	MyMouseSensSlider.UpdateFreq=0;
    	InvertMouseButton.OnClick=OnInvertMouseClick;
    	TeamColorsButton.OnClick=OnTeamColorsClick;

    	// discover categories
        /*for( i = 0; i < class'KeyBindings'.default.CommandCategory.Length; i++ )
        {
    		bFound = false;
    		for( j = 0; j < MyCategoryList.List.Elements.Length; j++)
    		{
    			if (MyCategoryList.List.Elements[j].ExtraStrData == class'KeyBindings'.default.CommandCategory[i])
    			{
    				bFound = true;
    				break;
    			}
    		}

    		if (!bFound)
    		{
    			MyCategoryList.List.Add(class'KeyBindings'.default.LocalizedCommandCategories[MyCategoryList.List.Elements.Length],,class'KeyBindings'.default.CommandCategory[i]);
    		}
        }
    	MyCategoryList.OnListIndexChanged = CategorySelectorOnClick;
    	MyCategoryList.ReadOnly(true);*/

    	LastCategory = class'KeyBindings'.default.CommandCategory[0];

    	for( i = 0; i < MyKeyBindingsBox.MultiColumnList.Length; i++ )
        {
            MyKeyBindingsBox.MultiColumnList[i].MCList.OnDblClick=InternalOnClick;
        }
    }

    function InternalOnActivate()
    {
    	DefaultsButton.bCanBeShown = true;
    	DefaultsButton.Show();

        GUIPage(MenuOwner.MenuOwner).OnPopupReturned=InternalOnPopupReturned;
    	DefaultsButton.OnClick=OnDefaults;
    	LoadSettings(false);
    }

    function InternalOnHide()
    {
    	EnsureConsistency();
    }

    function SaveSettings()
    {
        //no generic save needed for this panel
    	class'KeyBindings'.static.StaticSaveConfig();
    }

    function LoadSettings(bool bEnsureConsistency)
    {
        //no generic load needed for this panel
        LoadCategory( LastCategory );
    	MyMouseSensSlider.Value=float(PlayerOwner().ConsoleCommand("Get WinDrv.WindowsClient MouseXMultiplier"));
    	InvertMouseButton.bChecked=bool(PlayerOwner().ConsoleCommand("Get PlayerInput bInvertMouse"));
    	TeamColorsButton.bChecked=bool(PlayerOwner().ConsoleCommand("Get Gameplay.PlayerCharacterController bTeamMarkerColors"));

    	if (bEnsureConsistency)
    		EnsureConsistency();
    }

    private function LoadCategory( string Category )
    {
        local int i;
    	local string primaryMapping;
    	local string secondaryMapping;
    	local string currentSelection;

    	//MyCategoryList.Edit.SetText(Category);

        LastCategory=Category;
    	currentSelection=MyKeyBindingsBox.FindColumn("Functions").MCList.GetExtra();
        MyKeyBindingsBox.Clear();

        for( i = 0; i < class'KeyBindings'.default.CommandString.Length; i++ )
        {
            //only load ones in this category
            if( class'KeyBindings'.default.CommandCategory[i] != Category )
                continue;

            MyKeyBindingsBox.AddNewRowElement( "Functions",,class'KeyBindings'.default.LocalizedCommandString[i],i);

    		// add primary and secondary mappings
    		primaryMapping = PlayerOwner().ConsoleCommand("LOCALIZEDKEYNAME"@PlayerOwner().ConsoleCommand("KEYNUM"@class'KeyBindings'.default.PrimaryBinds[i]));
    		secondaryMapping = PlayerOwner().ConsoleCommand("LOCALIZEDKEYNAME"@PlayerOwner().ConsoleCommand("KEYNUM"@class'KeyBindings'.default.SecondaryBinds[i]));
    		//primaryMapping = class'KeyBindings'.default.PrimaryBinds[i];
    		//secondaryMapping = class'KeyBindings'.default.SecondaryBinds[i];

    		MyKeyBindingsBox.AddNewRowElement( "MappedKey",,primaryMapping,i);
            MyKeyBindingsBox.AddNewRowElement( "MappedKeySecondary",,secondaryMapping,i);

            MyKeyBindingsBox.PopulateRow( "Functions" );
        }

    	if (currentSelection == "")
    		MyKeyBindingsBox.SetIndex(0);
    	else
    		MyKeyBindingsBox.FindColumn("Functions").MCList.FindExtra(currentSelection);

        MyKeyBindingsBox.SetEnabled( Category != "Reserved" );
        MyKeyChoose.SetEnabled( Category != "Reserved" );
    }

    function InternalOnClick( GUIComponent Sender )
    {
        local string LocalizedFunc, Func, Bound;

    	LocalizedFunc = MyKeyBindingsBox.GetColumn( "Functions" ).GetExtra();
        Func = class'KeyBindings'.default.CommandString[MyKeyBindingsBox.GetColumn( "Functions" ).GetExtraIntData()];

    	if (MyKeyBindingsBox.LastClickedIndex <= 1)
    	{
    	    Bound = MyKeyBindingsBox.GetColumn( "MappedKey" ).GetExtra();
    	}
    	else
    	{
    	    Bound = MyKeyBindingsBox.GetColumn( "MappedKeySecondary" ).GetExtra();
    	}

    	if (Bound != "")
    	    Controller.OpenMenu( "TribesGui.TribesKeyMappingPopup", "TribesKeyMappingPopup", replaceStr(KeyChangeMessage, LocalizedFunc, Bound), Func );
    	else
    	    Controller.OpenMenu( "TribesGui.TribesKeyMappingPopup", "TribesKeyMappingPopup", replaceStr(NoBindKeyChangeMessage, LocalizedFunc), Func );
    }

    function InternalOnPopupReturned( GUIListElem returnObj, optional string Passback )
    {
    	local int i;
    	local string key;

    	key = returnObj.ExtraStrData;
    	log("Pressed"@returnObj.ExtraStrData);

    	// if we pressed escape, clear binding
    	if ( key ~= "Escape" )
    		key = "";

    	//remove the old binding
        for( i = 0; i < class'KeyBindings'.default.CommandString.Length; i++ )
        {
    		if (class'KeyBindings'.default.CommandString[i] == Passback)
    		{
    			if (MyKeyBindingsBox.LastClickedIndex <= 1)
    			{
    				PlayerOwner().ConsoleCommand("SET Input"@class'KeyBindings'.default.PrimaryBinds[i]);
    			}
    			else
    			{
    				PlayerOwner().ConsoleCommand("SET Input"@class'KeyBindings'.default.SecondaryBinds[i]);
    			}
    		}
    	}

        //map the new binding
        PlayerOwner().ConsoleCommand("SET Input"@key@Passback);

        for( i = 0; i < class'KeyBindings'.default.CommandString.Length; i++ )
        {
    		if (class'KeyBindings'.default.CommandString[i] == Passback)
    		{
    			if (MyKeyBindingsBox.LastClickedIndex <= 1)
    			{
    				class'KeyBindings'.default.PrimaryBinds[i] = key;
    				if (class'KeyBindings'.default.SecondaryBinds[i] == key)
    				{
    					PlayerOwner().ConsoleCommand("SET Input"@class'KeyBindings'.default.SecondaryBinds[i]);
    					class'KeyBindings'.default.SecondaryBinds[i] = "";
    				}
    			}
    			else
    			{
    				class'KeyBindings'.default.SecondaryBinds[i] = key;
    				if (class'KeyBindings'.default.PrimaryBinds[i] == key)
    				{
    					PlayerOwner().ConsoleCommand("SET Input"@class'KeyBindings'.default.PrimaryBinds[i]);
    					class'KeyBindings'.default.PrimaryBinds[i] = "";
    				}
    			}
    		}
    		else
    		{
    			if (class'KeyBindings'.default.PrimaryBinds[i] == key)
    			{
    				PlayerOwner().ConsoleCommand("SET Input"@class'KeyBindings'.default.PrimaryBinds[i]);
    				class'KeyBindings'.default.PrimaryBinds[i] = "";
    			}
    			if (class'KeyBindings'.default.SecondaryBinds[i] == key)
    			{
    				PlayerOwner().ConsoleCommand("SET Input"@class'KeyBindings'.default.SecondaryBinds[i]);
    				class'KeyBindings'.default.SecondaryBinds[i] = "";
    			}
    		}
    	}

        //Update the MCLB
        LoadCategory(LastCategory);

    	// force an update on the keybindings in the hud, because
    	// re-checking every frame is prohibitively expensive
    	if(PlayerCharacterController(PlayerOwner()) != None && PlayerCharacterController(PlayerOwner()).clientSideChar != None)
    		PlayerCharacterController(PlayerOwner()).clientSideChar.bHotKeysUpdated = false;

    	class'KeyBindings'.static.StaticSaveConfig();
    }

    private function CategorySelectorOnClick( GUIComponent Sender )
    {
        //LoadCategory(MyCategoryList.List.Elements[MyCategoryList.Index].ExtraStrData);
    }

    private function OnSensitivityChange( GUIComponent Sender )
    {
    	PlayerOwner().ConsoleCommand("Set WinDrv.WindowsClient MouseXMultiplier"@GUISlider(Sender).Value);
    	PlayerOwner().ConsoleCommand("Set WinDrv.WindowsClient MouseYMultiplier"@GUISlider(Sender).Value);
    }

    private function OnInvertMouseClick( GUIComponent Sender )
    {
    	PlayerOwner().ConsoleCommand("set PlayerInput bInvertMouse "$(InvertMouseButton.bChecked));
    }

    private function OnTeamColorsClick( GUIComponent Sender )
    {
    	PlayerOwner().ConsoleCommand("set Gameplay.PlayerCharacterController bTeamMarkerColors "$(TeamColorsButton.bChecked));
    }

    function OnDefaults(GUIComponent Sender)
    {
    	RestoreDefaults();
    	PlayerOwner().ConsoleCommand("set PlayerInput bInvertMouse 0");
    	PlayerOwner().ConsoleCommand("set Gameplay.PlayerCharacterController bTeamMarkerColors "$class'PlayerCharacterController'.default.bTeamMarkerColors);
    	LoadSettings(true);
    }

    native function RestoreDefaults();

    // ensure that user.ini corresponds with the primary/secondary binds list
    function EnsureConsistency()
    {
    	local int i;

        for( i = 0; i < class'KeyBindings'.default.CommandString.Length; i++ )
        {
    		if (class'KeyBindings'.default.PrimaryBinds[i] != "")
    			PlayerOwner().ConsoleCommand("SET Input"@class'KeyBindings'.default.PrimaryBinds[i]@class'KeyBindings'.default.CommandString[i]);
    		if (class'KeyBindings'.default.SecondaryBinds[i] != "")
    			PlayerOwner().ConsoleCommand("SET Input"@class'KeyBindings'.default.SecondaryBinds[i]@class'KeyBindings'.default.CommandString[i]);
    	}

    	PlayerOwner().ConsoleCommand("RELOADKEYBINDINGS");
    }

    defaultproperties
    {
    	KeyChangeMessage="The %1 function is already assigned to %2.  Press a new key to change it."
    	NoBindKeyChangeMessage="Press the key you want to assign to %1."

    	OnActivate=InternalOnActivate
    	OnHide=InternalOnHide
    }

Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

Class file time: st 16.4.2014 10:20:44.000 - Creation time: st 23.5.2018 00:10:48.723 - Created with UnCodeX