diff --git a/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs index f3552f2987..5846ddd6ce 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs @@ -129,72 +129,50 @@ namespace OpenRA.Mods.RA.Widgets.Logic var specialHotkeyTemplate = specialHotkeyList.Get("SPECIALHOTKEY_TEMPLATE"); var pauseKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); - pauseKey.Get("FUNCTION").GetText = () => "Pause the game:"; - SetupKeyBinding(pauseKey.Get("HOTKEY"), - () => keyConfig.PauseKey, k => keyConfig.PauseKey = k); + SetupKeyBinding(pauseKey, "Pause the game:", () => keyConfig.PauseKey, k => keyConfig.PauseKey = k); specialHotkeyList.AddChild(pauseKey); var viewportToBase = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); - viewportToBase.Get("FUNCTION").GetText = () => "Move Viewport to Base:"; - SetupKeyBinding(viewportToBase.Get("HOTKEY"), - () => keyConfig.CycleBaseKey, k => keyConfig.CycleBaseKey = k); + SetupKeyBinding(viewportToBase, "Move Viewport to Base:", () => keyConfig.CycleBaseKey, k => keyConfig.CycleBaseKey = k); specialHotkeyList.AddChild(viewportToBase); var lastEventKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); - lastEventKey.Get("FUNCTION").GetText = () => "Move Viewport to Last Event:"; - SetupKeyBinding(lastEventKey.Get("HOTKEY"), - () => keyConfig.GotoLastEventKey, k => keyConfig.GotoLastEventKey = k); + SetupKeyBinding(lastEventKey, "Move Viewport to Last Event:", () => keyConfig.GotoLastEventKey, k => keyConfig.GotoLastEventKey = k); specialHotkeyList.AddChild(lastEventKey); var sellKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); - sellKey.Get("FUNCTION").GetText = () => "Switch to Sell-Cursor:"; - SetupKeyBinding(sellKey.Get("HOTKEY"), - () => keyConfig.SellKey, k => keyConfig.SellKey = k); + SetupKeyBinding(sellKey, "Switch to Sell-Cursor:", () => keyConfig.SellKey, k => keyConfig.SellKey = k); specialHotkeyList.AddChild(sellKey); var powerDownKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); - powerDownKey.Get("FUNCTION").GetText = () => "Switch to Power-Down-Cursor:"; - SetupKeyBinding(powerDownKey.Get("HOTKEY"), - () => keyConfig.PowerDownKey, k => keyConfig.PowerDownKey = k); + SetupKeyBinding(powerDownKey, "Switch to Power-Down-Cursor:", () => keyConfig.PowerDownKey, k => keyConfig.PowerDownKey = k); specialHotkeyList.AddChild(powerDownKey); var repairKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); - repairKey.Get("FUNCTION").GetText = () => "Switch to Repair-Cursor:"; - SetupKeyBinding(repairKey.Get("HOTKEY"), - () => keyConfig.RepairKey, k => keyConfig.RepairKey = k); + SetupKeyBinding(repairKey, "Switch to Repair-Cursor:", () => keyConfig.RepairKey, k => keyConfig.RepairKey = k); specialHotkeyList.AddChild(repairKey); var unitCommandHotkeyList = keys.Get("UNITCOMMANDHOTKEY_LIST"); var unitCommandHotkeyTemplate = unitCommandHotkeyList.Get("UNITCOMMANDHOTKEY_TEMPLATE"); var attackKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); - attackKey.Get("FUNCTION").GetText = () => "Attack Move:"; - SetupKeyBinding(attackKey.Get("HOTKEY"), - () => keyConfig.AttackMoveKey, k => keyConfig.AttackMoveKey = k); + SetupKeyBinding(attackKey, "Attack Move:", () => keyConfig.AttackMoveKey, k => keyConfig.AttackMoveKey = k); unitCommandHotkeyList.AddChild(attackKey); var stopKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); - stopKey.Get("FUNCTION").GetText = () => "Stop:"; - SetupKeyBinding(stopKey.Get("HOTKEY"), - () => keyConfig.StopKey, k => keyConfig.StopKey = k); + SetupKeyBinding(stopKey, "Stop:", () => keyConfig.StopKey, k => keyConfig.StopKey = k); unitCommandHotkeyList.AddChild(stopKey); var scatterKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); - scatterKey.Get("FUNCTION").GetText = () => "Scatter:"; - SetupKeyBinding(scatterKey.Get("HOTKEY"), - () => keyConfig.ScatterKey, k => keyConfig.ScatterKey = k); + SetupKeyBinding(scatterKey, "Scatter:", () => keyConfig.ScatterKey, k => keyConfig.ScatterKey = k); unitCommandHotkeyList.AddChild(scatterKey); var stanceCycleKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); - stanceCycleKey.Get("FUNCTION").GetText = () => "Cycle Stance:"; - SetupKeyBinding(stanceCycleKey.Get("HOTKEY"), - () => keyConfig.StanceCycleKey, k => keyConfig.StanceCycleKey = k); + SetupKeyBinding(stanceCycleKey, "Cycle Stance:", () => keyConfig.StanceCycleKey, k => keyConfig.StanceCycleKey = k); unitCommandHotkeyList.AddChild(stanceCycleKey); var deployKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); - deployKey.Get("FUNCTION").GetText = () => "Deploy:"; - SetupKeyBinding(deployKey.Get("HOTKEY"), - () => keyConfig.DeployKey, k => keyConfig.DeployKey = k); + SetupKeyBinding(deployKey, "Deploy:", () => keyConfig.DeployKey, k => keyConfig.DeployKey = k); unitCommandHotkeyList.AddChild(deployKey); // Debug @@ -276,17 +254,21 @@ namespace OpenRA.Mods.RA.Widgets.Logic return true; } - void SetupKeyBinding(TextFieldWidget textBox, Func getValue, Action setValue) + void SetupKeyBinding(ScrollItemWidget keyWidget, string description, Func getValue, Action setValue) { + keyWidget.Get("FUNCTION").GetText = () => description; + + var textBox = keyWidget.Get("HOTKEY"); + textBox.Text = getValue(); textBox.OnLoseFocus = () => { textBox.Text.Trim(); if (textBox.Text.Length == 0) - textBox.Text = getValue(); + textBox.Text = getValue(); else - setValue(textBox.Text); + setValue(textBox.Text); }; textBox.OnEnterKey = () => { textBox.LoseFocus(); return true; }; diff --git a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs index 753529834d..b40b9f6890 100644 --- a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs +++ b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs @@ -188,19 +188,19 @@ namespace OpenRA.Mods.RA.Widgets return true; } - private bool PerformSwitchToSellMode () + bool PerformSwitchToSellMode() { - World.ToggleInputMode (); + World.ToggleInputMode(); return true; } - private bool PerformSwitchToPowerDownMode () + bool PerformSwitchToPowerDownMode() { - World.ToggleInputMode (); + World.ToggleInputMode(); return true; } - private bool PerformSwitchToRepairMode () + bool PerformSwitchToRepairMode() { World.ToggleInputMode(); return true;