UTMenu
Class SpeechBinderCW

source: e:\games\UnrealTournament\UTMenu\Classes\SpeechBinderCW.uc
Core.Object
   |
   +--UWindow.UWindowBase
      |
      +--UWindow.UWindowWindow
         |
         +--UWindow.UWindowClientWindow
            |
            +--UWindow.UWindowDialogClientWindow
               |
               +--UMenu.UMenuDialogClientWindow
                  |
                  +--UTMenu.SpeechBinderCW
Direct Known Subclasses:None

class SpeechBinderCW
extends UMenu.UMenuDialogClientWindow


Variables
 string AllString
 UMenuRaisedButton BinderButton[16]
 UMenuLabelControl BinderLabel[16]
 UWindowComboControl ChoiceCombo[16]
 UWindowSmallButton DefaultsButton
 string DefaultsHelp
 string DefaultsText
 string LabelText
 string LeaderString
 int MaxBindings
 string NotApplicable
 string NotBound
 string PlayerString
 UMenuRaisedButton SelectedButton
 int Selection
 UWindowComboControl TargetCombo[16]
 UWindowComboControl TypeCombo[16]
 class V
 bool bPolling
 bInitialized, bSetReady


Function Summary
 void BeforePaint(Canvas C, float X, float Y)
 void ChoiceChanged(int i)
 void Created()
 void KeyDown(int Key, float X, float Y)
 int LoadExistingKeys()
 void Notify(UWindowDialogControl C, byte E)
 void ProcessMenuKey(int KeyNo, string KeyName)
 void RemoveExistingKey(int KeyNo, string KeyName)
 void ResetAllKeys()
 void SetKey(int KeyNo, string KeyName)
 void TargetChanged(int i)
 void TypeChanged(int i)



Source Code


00001	class SpeechBinderCW expands UMenuDialogClientWindow;
00002	
00003	var UWindowComboControl TypeCombo[16];
00004	var UWindowComboControl ChoiceCombo[16];
00005	var UWindowComboControl TargetCombo[16];
00006	var UMenuRaisedButton BinderButton[16];
00007	var UMenuLabelControl BinderLabel[16];
00008	
00009	var class<ChallengeVoicePack> V;
00010	
00011	var bool bInitialized, bSetReady;
00012	
00013	var localized string LabelText;
00014	var localized string NotApplicable;
00015	var localized string AllString;
00016	var localized string LeaderString;
00017	var localized string PlayerString;
00018	var localized string NotBound;
00019	
00020	var UMenuRaisedButton SelectedButton;
00021	var int Selection;
00022	var bool bPolling;
00023	
00024	var UWindowSmallButton DefaultsButton;
00025	var localized string DefaultsText;
00026	var localized string DefaultsHelp;
00027	
00028	var int MaxBindings;
00029	
00030	function Created()
00031	{
00032		local int ButtonWidth, ButtonLeft, ButtonTop;
00033		local int LabelWidth, LabelLeft;
00034		local int i, j;
00035		local int TypeLeft, ChoiceLeft, TargetLeft;
00036		local int ChoiceWidth;
00037	
00038		MaxBindings = 16;
00039	
00040		V = class<ChallengeVoicePack>(GetPlayerOwner().PlayerReplicationInfo.VoiceType);
00041		if (V == None)
00042		{
00043			Log("SpeechBinder: Critical Error, V is None.");
00044		}
00045	
00046		bIgnoreLDoubleClick = True;
00047		bIgnoreMDoubleClick = True;
00048		bIgnoreRDoubleClick = True;
00049	
00050		Super.Created();
00051	
00052		SetAcceptsFocus();
00053	
00054		ChoiceWidth = WinWidth / 4;
00055		TypeLeft = (WinWidth - (ChoiceWidth*3 + 20))/2;
00056		ChoiceLeft = TypeLeft + ChoiceWidth + 10;
00057		TargetLeft = ChoiceLeft + ChoiceWidth + 10;
00058	
00059		LabelWidth = 60;
00060		LabelLeft = TypeLeft;
00061	
00062		ButtonWidth = WinWidth/5;
00063		ButtonLeft = LabelLeft + LabelWidth + 20;
00064	
00065		// Defaults Button
00066		DefaultsButton = UWindowSmallButton(CreateControl(class'UWindowSmallButton', 30, 10, 48, 16));
00067		DefaultsButton.SetText(DefaultsText);
00068		DefaultsButton.SetFont(F_Normal);
00069		DefaultsButton.SetHelpText(DefaultsHelp);
00070	
00071		ButtonTop = 35;
00072		for (i=0; i<MaxBindings; i++)
00073		{
00074			TypeCombo[i] = UWindowComboControl(CreateControl(class'UWindowComboControl', TypeLeft, ButtonTop, ChoiceWidth, 1));
00075			TypeCombo[i].bAcceptsFocus = False;
00076			TypeCombo[i].EditBoxWidth = ChoiceWidth;
00077			for (j=0; j<class'SpeechWindow'.Default.NumOptions-2; j++)
00078			{
00079				TypeCombo[i].AddItem(class'SpeechWindow'.Default.Options[j]);
00080			}
00081			TypeCombo[i].SetSelectedIndex(0);
00082	
00083			ChoiceCombo[i] = UWindowComboControl(CreateControl(class'UWindowComboControl', ChoiceLeft, ButtonTop, ChoiceWidth, 1));
00084			ChoiceCombo[i].bAcceptsFocus = False;
00085			ChoiceCombo[i].EditBoxWidth = ChoiceWidth;
00086	
00087			TargetCombo[i] = UWindowComboControl(CreateControl(class'UWindowComboControl', TargetLeft, ButtonTop, ChoiceWidth, 1));
00088			TargetCombo[i].bAcceptsFocus = False;
00089			TargetCombo[i].EditBoxWidth = ChoiceWidth;
00090	
00091			ButtonTop += 22;
00092	
00093			BinderLabel[i] = UMenuLabelControl(CreateControl(class'UMenuLabelControl', LabelLeft, ButtonTop+3, LabelWidth, 1));
00094			BinderLabel[i].SetText(LabelText);
00095			BinderLabel[i].SetFont(F_Normal);
00096	
00097			BinderButton[i] = UMenuRaisedButton(CreateControl(class'UMenuRaisedButton', ButtonLeft, ButtonTop, ButtonWidth, 1));
00098			BinderButton[i].bAcceptsFocus = False;
00099			BinderButton[i].bIgnoreLDoubleClick = True;
00100			BinderButton[i].bIgnoreMDoubleClick = True;
00101			BinderButton[i].bIgnoreRDoubleClick = True;
00102			BinderButton[i].Text = NotBound;
00103			BinderButton[i].Index = i;
00104			ButtonTop += 35;
00105		}
00106	
00107		bInitialized = True;
00108	
00109		j = LoadExistingKeys();
00110	
00111		for (i=j; i<MaxBindings; i++)
00112			TypeChanged(i);
00113	
00114		bSetReady = True;
00115	
00116		DesiredHeight = ButtonTop + 45;
00117	}
00118	
00119	function BeforePaint(Canvas C, float X, float Y)
00120	{
00121		local int ButtonWidth, ButtonLeft, ButtonTop;
00122		local int LabelWidth, LabelLeft;
00123		local int i;
00124		local int TypeLeft, ChoiceLeft, TargetLeft;
00125		local int TypeLeft2, ChoiceLeft2;
00126		local int ChoiceWidth;
00127		local int ChoiceWidth2;
00128	
00129		Super.BeforePaint(C, X, Y);
00130	
00131		ChoiceWidth = WinWidth / 4;
00132		TypeLeft = (WinWidth - (ChoiceWidth*3 + 20))/2;
00133		ChoiceLeft = TypeLeft + ChoiceWidth + 10;
00134		TargetLeft = ChoiceLeft + ChoiceWidth + 10;
00135	
00136		ChoiceWidth2 = WinWidth / 3;
00137		TypeLeft2 = (WinWidth - (ChoiceWidth2*2 + 10))/2;
00138		ChoiceLeft2 = TypeLeft2 + ChoiceWidth2 + 10;
00139	
00140		LabelWidth = 60;
00141		LabelLeft = TypeLeft;
00142	
00143		ButtonWidth = WinWidth/5;
00144		ButtonLeft = LabelLeft + LabelWidth + 20;
00145	
00146		DefaultsButton.AutoWidth(C);
00147		DefaultsButton.WinLeft = 30;
00148		DefaultsButton.WinTop = 10;
00149	
00150		ButtonTop = 35;
00151		for (i=0; i<MaxBindings; i++)
00152		{
00153			if (TargetCombo[i].WindowIsVisible())
00154			{
00155				TypeCombo[i].WinLeft = TypeLeft;
00156				TypeCombo[i].WinTop = ButtonTop;
00157				TypeCombo[i].SetSize(ChoiceWidth, 1);
00158				TypeCombo[i].EditBoxWidth = ChoiceWidth;
00159	
00160				ChoiceCombo[i].WinLeft = ChoiceLeft;
00161				ChoiceCombo[i].WinTop = ButtonTop;
00162				ChoiceCombo[i].SetSize(ChoiceWidth, 1);
00163				ChoiceCombo[i].EditBoxWidth = ChoiceWidth;
00164	
00165				TargetCombo[i].WinLeft = TargetLeft;
00166				TargetCombo[i].WinTop = ButtonTop;
00167				TargetCombo[i].SetSize(ChoiceWidth, 1);
00168				TargetCombo[i].EditBoxWidth = ChoiceWidth;
00169			} else {
00170				TypeCombo[i].WinLeft = TypeLeft2;
00171				TypeCombo[i].WinTop = ButtonTop;
00172				TypeCombo[i].SetSize(ChoiceWidth2, 1);
00173				TypeCombo[i].EditBoxWidth = ChoiceWidth2;
00174	
00175				ChoiceCombo[i].WinLeft = ChoiceLeft2;
00176				ChoiceCombo[i].WinTop = ButtonTop;
00177				ChoiceCombo[i].SetSize(ChoiceWidth2, 1);
00178				ChoiceCombo[i].EditBoxWidth = ChoiceWidth2;
00179			}
00180	
00181			ButtonTop += 22;
00182	
00183			BinderLabel[i].WinLeft = LabelLeft;
00184			BinderLabel[i].WinTop = ButtonTop+3;
00185			BinderLabel[i].SetSize(LabelWidth, 1);
00186	
00187			BinderButton[i].WinLeft = ButtonLeft;
00188			BinderButton[i].WinTop = ButtonTop;
00189			BinderButton[i].SetSize(ButtonWidth, 1);
00190			ButtonTop += 35;
00191		}
00192	}
00193	
00194	function int LoadExistingKeys()
00195	{
00196		local int i, j, pos;
00197		local int Type, Choice, Target;
00198		local string KeyName;
00199		local string Alias;
00200		local string Rest;
00201	
00202		for (i=0; i<255; I++)
00203		{
00204			KeyName = GetPlayerOwner().ConsoleCommand( "KEYNAME "$i );
00205			if ( KeyName != "" )
00206			{
00207				Alias = GetPlayerOwner().ConsoleCommand( "KEYBINDING "$KeyName );
00208				if ( Alias != "" )
00209				{
00210					pos = InStr(Alias, "speech ");
00211					if (pos != -1)
00212					{
00213						BinderButton[j].Text = class'UMenuCustomizeClientWindow'.default.LocalizedKeyName[i];
00214	
00215						Rest = Right(Alias, Len(Alias) - 7);
00216						pos = InStr(Rest, " ");
00217						Type = int(Left(Rest, pos));
00218						TypeCombo[j].SetSelectedIndex(Type);
00219	
00220						Rest = Right(Rest, Len(Rest) - pos - 1);
00221						pos = InStr(Rest, " ");
00222						Choice = int(Left(Rest, pos));
00223						ChoiceCombo[j].SetSelectedIndex(Choice);
00224	
00225						Rest = Right(Rest, Len(Rest) - pos - 1);
00226						Target = int(Rest);
00227						TargetCombo[j].SetSelectedIndex(Target+1);
00228	
00229						j++;
00230						if (j > 7)
00231							return j;
00232					}
00233				}
00234			}
00235		}
00236		return j;
00237	}
00238	
00239	function KeyDown( int Key, float X, float Y )
00240	{
00241		if (bPolling)
00242		{
00243			ProcessMenuKey( Key, mid(string(GetEnum(enum'EInputKey',Key)),3) );
00244			bPolling = False;
00245			SelectedButton.bDisabled = False;
00246		}
00247	}
00248	
00249	function ResetAllKeys()
00250	{
00251		local int i;
00252	
00253		for (i=0; i<MaxBindings; i++)
00254		{
00255			if (BinderButton[i].Text != NotBound)
00256			{
00257				GetPlayerOwner().ConsoleCommand("SET Input"@BinderButton[i].Text);
00258				BinderButton[i].Text = NotBound;
00259				bSetReady = False;
00260				TypeCombo[i].SetSelectedIndex(0);
00261				ChoiceCombo[i].SetSelectedIndex(0);
00262				TargetCombo[i].SetSelectedIndex(0);
00263				bSetReady = True;
00264			}
00265		}
00266		GetPlayerOwner().SaveConfig();
00267	}
00268	
00269	function RemoveExistingKey(int KeyNo, string KeyName)
00270	{
00271		local int i;
00272		local int Type, Choice, Target;
00273		local string KeyName2, Alias, Binding;
00274	
00275		// Unbind this key.
00276		for (i=0; i<MaxBindings; i++)
00277		{
00278			if (BinderButton[i].Text == KeyName)
00279			{
00280				GetPlayerOwner().ConsoleCommand("SET Input"@BinderButton[i].Text);
00281				BinderButton[i].Text = "";
00282			}
00283		}
00284	
00285		// Find what we are binding and remove all others of that type.
00286		Type = TypeCombo[SelectedButton.Index].GetSelectedIndex();
00287		Choice = ChoiceCombo[SelectedButton.Index].GetSelectedIndex();
00288		if (Type == 2) // Orders
00289			Target = TargetCombo[SelectedButton.Index].GetSelectedIndex() - 1;
00290		else
00291			Target = 0;
00292		Binding = "speech"@Type@Choice@Target;
00293		for (i=0; i<255; i++)
00294		{
00295			KeyName2 = GetPlayerOwner().ConsoleCommand( "KEYNAME "$i );
00296			if ( KeyName2 != "" )
00297			{
00298				Alias = GetPlayerOwner().ConsoleCommand( "KEYBINDING "$KeyName2 );
00299				if ( Alias ~= Binding )
00300					GetPlayerOwner().ConsoleCommand("SET Input"@KeyName2);
00301			}
00302		}			
00303	}
00304	
00305	function SetKey(int KeyNo, string KeyName)
00306	{
00307		local int Type, Choice, Target;
00308	
00309		Type = TypeCombo[SelectedButton.Index].GetSelectedIndex();
00310		Choice = ChoiceCombo[SelectedButton.Index].GetSelectedIndex();
00311		if (Type == 2) // Orders
00312			Target = TargetCombo[SelectedButton.Index].GetSelectedIndex() - 1;
00313		else
00314			Target = 0;
00315	
00316		GetPlayerOwner().ConsoleCommand("SET Input"@KeyName@"speech"@Type@Choice@Target);
00317		SelectedButton.Text = class'UMenuCustomizeClientWindow'.default.LocalizedKeyName[KeyNo];
00318		GetPlayerOwner().SaveConfig();
00319	}
00320	
00321	function ProcessMenuKey( int KeyNo, string KeyName )
00322	{
00323		if ( (KeyName == "") || (KeyName == "Escape")
00324			|| ((KeyNo >= 0x70 ) && (KeyNo <= 0x79)) // function keys
00325			|| ((KeyNo >= 0x30 ) && (KeyNo <= 0x39))) // number keys
00326			return;
00327	
00328		RemoveExistingKey(KeyNo, KeyName);
00329		SetKey(KeyNo, KeyName);
00330	}
00331	
00332	function Notify(UWindowDialogControl C, byte E)
00333	{
00334		local int i;
00335	
00336		Super.Notify(C, E);
00337	
00338		switch(E)
00339		{
00340		case DE_Change:
00341			for (i=0; i<MaxBindings; i++)
00342			{
00343				if (C == TypeCombo[i])
00344					TypeChanged(i);
00345				if (C == ChoiceCombo[i])
00346					ChoiceChanged(i);
00347				if (C == TargetCombo[i])
00348					TargetChanged(i);
00349			}
00350		case DE_Click:
00351			if (C == DefaultsButton)
00352				ResetAllKeys();
00353			for (i=0; i<MaxBindings; i++)
00354			{
00355				if (C == BinderButton[i])
00356				{
00357					SelectedButton = UMenuRaisedButton(C);
00358					Selection = i;
00359					bPolling = True;
00360					SelectedButton.bDisabled = True;
00361				}
00362			}
00363		}
00364	}
00365	
00366	function TypeChanged(int i)
00367	{
00368		local int j;
00369		local class<ChallengeVoicePack> V;
00370	
00371		if (!bInitialized)
00372			return;
00373	
00374		V = class<ChallengeVoicePack>(GetPlayerOwner().PlayerReplicationInfo.VoiceType);
00375	
00376		// Update the choices.
00377		ChoiceCombo[i].Clear();
00378		switch (TypeCombo[i].GetSelectedIndex())
00379		{
00380			case 0: // Acks
00381				for (j=0; j<V.Default.NumAcks; j++)
00382				{
00383					ChoiceCombo[i].AddItem(V.Static.GetAckString(j));
00384				}
00385				break;
00386			case 1: // Friendly Fire
00387				for (j=0; j<V.Default.NumFFires; j++)
00388				{
00389					ChoiceCombo[i].AddItem(V.Static.GetFFireString(j));
00390				}
00391				break;
00392			case 2: // Orders
00393				for (j=0; j<5; j++)
00394				{
00395					ChoiceCombo[i].AddItem(V.Static.GetOrderString(j, ""));
00396				}
00397				break;
00398			case 3: // Taunts
00399				for (j=0; j<V.Default.NumTaunts; j++)
00400				{
00401					ChoiceCombo[i].AddItem(V.Static.GetTauntString(j));
00402				}
00403				break;
00404			case 4: // Other
00405				for (j=0; j<32; j++)
00406				{
00407					if (V.Static.GetOtherString(j) != "")
00408						ChoiceCombo[i].AddItem(V.Static.GetOtherString(j));
00409				}
00410				break;
00411		}
00412		ChoiceCombo[i].SetSelectedIndex(0);
00413		ChoiceChanged(i);
00414	}
00415	
00416	function ChoiceChanged(int i)
00417	{
00418		local int j;
00419	
00420		if (!bInitialized)
00421			return;
00422	
00423		TargetCombo[i].Clear();
00424		switch (TypeCombo[i].GetSelectedIndex())
00425		{
00426			case 0: // Acks
00427				TargetCombo[i].AddItem(NotApplicable);
00428				TargetCombo[i].HideWindow();
00429				break;
00430			case 1: // Friendly Fire
00431				TargetCombo[i].AddItem(NotApplicable);
00432				TargetCombo[i].HideWindow();
00433				break;
00434			case 2: // Orders
00435				TargetCombo[i].AddItem(AllString);
00436				TargetCombo[i].AddItem(LeaderString);
00437				TargetCombo[i].ShowWindow();
00438				for (j=2; j<16; j++)
00439					TargetCombo[i].AddItem(PlayerString@j);
00440				break;
00441			case 3: // Taunts
00442				TargetCombo[i].AddItem(NotApplicable);
00443				TargetCombo[i].HideWindow();
00444				break;
00445			case 4: // Other
00446				TargetCombo[i].AddItem(NotApplicable);
00447				TargetCombo[i].HideWindow();
00448				break;
00449		}
00450		TargetCombo[i].SetSelectedIndex(0);
00451		TargetChanged(i);
00452	}
00453	
00454	function TargetChanged(int i)
00455	{
00456		if (!bInitialized)
00457			return;
00458	
00459		if (BinderButton[i].Text != NotBound)
00460		{
00461			SelectedButton = BinderButton[i];
00462			if (bSetReady)
00463				SetKey(0, BinderButton[i].Text);
00464		}
00465	}
00466	
00467	defaultproperties
00468	{
00469	     LabelText="Bind to Key:"
00470	     NotApplicable="N/A"
00471	     AllString="All"
00472	     LeaderString="Team Leader"
00473	     PlayerString="Team Mate"
00474	     NotBound="Unbound"
00475	     DefaultsText="Reset"
00476	     DefaultsHelp="Unbind all speech keys."
00477	}

End Source Code