key config settings code cleanup

- move label and textfield widget lookup into SetupKeyBinding
- fix wonkey indentions
- remove explicit private in WorldCommandWidget
This commit is contained in:
Matthias Mailänder
2013-03-01 19:10:47 +01:00
parent 1f99b1ec8e
commit b31f830cb1
2 changed files with 23 additions and 41 deletions

View File

@@ -129,72 +129,50 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var specialHotkeyTemplate = specialHotkeyList.Get<ScrollItemWidget>("SPECIALHOTKEY_TEMPLATE"); var specialHotkeyTemplate = specialHotkeyList.Get<ScrollItemWidget>("SPECIALHOTKEY_TEMPLATE");
var pauseKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); var pauseKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {});
pauseKey.Get<LabelWidget>("FUNCTION").GetText = () => "Pause the game:"; SetupKeyBinding(pauseKey, "Pause the game:", () => keyConfig.PauseKey, k => keyConfig.PauseKey = k);
SetupKeyBinding(pauseKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.PauseKey, k => keyConfig.PauseKey = k);
specialHotkeyList.AddChild(pauseKey); specialHotkeyList.AddChild(pauseKey);
var viewportToBase = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); var viewportToBase = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {});
viewportToBase.Get<LabelWidget>("FUNCTION").GetText = () => "Move Viewport to Base:"; SetupKeyBinding(viewportToBase, "Move Viewport to Base:", () => keyConfig.CycleBaseKey, k => keyConfig.CycleBaseKey = k);
SetupKeyBinding(viewportToBase.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.CycleBaseKey, k => keyConfig.CycleBaseKey = k);
specialHotkeyList.AddChild(viewportToBase); specialHotkeyList.AddChild(viewportToBase);
var lastEventKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); var lastEventKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {});
lastEventKey.Get<LabelWidget>("FUNCTION").GetText = () => "Move Viewport to Last Event:"; SetupKeyBinding(lastEventKey, "Move Viewport to Last Event:", () => keyConfig.GotoLastEventKey, k => keyConfig.GotoLastEventKey = k);
SetupKeyBinding(lastEventKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.GotoLastEventKey, k => keyConfig.GotoLastEventKey = k);
specialHotkeyList.AddChild(lastEventKey); specialHotkeyList.AddChild(lastEventKey);
var sellKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); var sellKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {});
sellKey.Get<LabelWidget>("FUNCTION").GetText = () => "Switch to Sell-Cursor:"; SetupKeyBinding(sellKey, "Switch to Sell-Cursor:", () => keyConfig.SellKey, k => keyConfig.SellKey = k);
SetupKeyBinding(sellKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.SellKey, k => keyConfig.SellKey = k);
specialHotkeyList.AddChild(sellKey); specialHotkeyList.AddChild(sellKey);
var powerDownKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); var powerDownKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {});
powerDownKey.Get<LabelWidget>("FUNCTION").GetText = () => "Switch to Power-Down-Cursor:"; SetupKeyBinding(powerDownKey, "Switch to Power-Down-Cursor:", () => keyConfig.PowerDownKey, k => keyConfig.PowerDownKey = k);
SetupKeyBinding(powerDownKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.PowerDownKey, k => keyConfig.PowerDownKey = k);
specialHotkeyList.AddChild(powerDownKey); specialHotkeyList.AddChild(powerDownKey);
var repairKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); var repairKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {});
repairKey.Get<LabelWidget>("FUNCTION").GetText = () => "Switch to Repair-Cursor:"; SetupKeyBinding(repairKey, "Switch to Repair-Cursor:", () => keyConfig.RepairKey, k => keyConfig.RepairKey = k);
SetupKeyBinding(repairKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.RepairKey, k => keyConfig.RepairKey = k);
specialHotkeyList.AddChild(repairKey); specialHotkeyList.AddChild(repairKey);
var unitCommandHotkeyList = keys.Get<ScrollPanelWidget>("UNITCOMMANDHOTKEY_LIST"); var unitCommandHotkeyList = keys.Get<ScrollPanelWidget>("UNITCOMMANDHOTKEY_LIST");
var unitCommandHotkeyTemplate = unitCommandHotkeyList.Get<ScrollItemWidget>("UNITCOMMANDHOTKEY_TEMPLATE"); var unitCommandHotkeyTemplate = unitCommandHotkeyList.Get<ScrollItemWidget>("UNITCOMMANDHOTKEY_TEMPLATE");
var attackKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); var attackKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {});
attackKey.Get<LabelWidget>("FUNCTION").GetText = () => "Attack Move:"; SetupKeyBinding(attackKey, "Attack Move:", () => keyConfig.AttackMoveKey, k => keyConfig.AttackMoveKey = k);
SetupKeyBinding(attackKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.AttackMoveKey, k => keyConfig.AttackMoveKey = k);
unitCommandHotkeyList.AddChild(attackKey); unitCommandHotkeyList.AddChild(attackKey);
var stopKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); var stopKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {});
stopKey.Get<LabelWidget>("FUNCTION").GetText = () => "Stop:"; SetupKeyBinding(stopKey, "Stop:", () => keyConfig.StopKey, k => keyConfig.StopKey = k);
SetupKeyBinding(stopKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.StopKey, k => keyConfig.StopKey = k);
unitCommandHotkeyList.AddChild(stopKey); unitCommandHotkeyList.AddChild(stopKey);
var scatterKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); var scatterKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {});
scatterKey.Get<LabelWidget>("FUNCTION").GetText = () => "Scatter:"; SetupKeyBinding(scatterKey, "Scatter:", () => keyConfig.ScatterKey, k => keyConfig.ScatterKey = k);
SetupKeyBinding(scatterKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.ScatterKey, k => keyConfig.ScatterKey = k);
unitCommandHotkeyList.AddChild(scatterKey); unitCommandHotkeyList.AddChild(scatterKey);
var stanceCycleKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); var stanceCycleKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {});
stanceCycleKey.Get<LabelWidget>("FUNCTION").GetText = () => "Cycle Stance:"; SetupKeyBinding(stanceCycleKey, "Cycle Stance:", () => keyConfig.StanceCycleKey, k => keyConfig.StanceCycleKey = k);
SetupKeyBinding(stanceCycleKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.StanceCycleKey, k => keyConfig.StanceCycleKey = k);
unitCommandHotkeyList.AddChild(stanceCycleKey); unitCommandHotkeyList.AddChild(stanceCycleKey);
var deployKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); var deployKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {});
deployKey.Get<LabelWidget>("FUNCTION").GetText = () => "Deploy:"; SetupKeyBinding(deployKey, "Deploy:", () => keyConfig.DeployKey, k => keyConfig.DeployKey = k);
SetupKeyBinding(deployKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.DeployKey, k => keyConfig.DeployKey = k);
unitCommandHotkeyList.AddChild(deployKey); unitCommandHotkeyList.AddChild(deployKey);
// Debug // Debug
@@ -276,8 +254,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return true; return true;
} }
void SetupKeyBinding(TextFieldWidget textBox, Func<string> getValue, Action<string> setValue) void SetupKeyBinding(ScrollItemWidget keyWidget, string description, Func<string> getValue, Action<string> setValue)
{ {
keyWidget.Get<LabelWidget>("FUNCTION").GetText = () => description;
var textBox = keyWidget.Get<TextFieldWidget>("HOTKEY");
textBox.Text = getValue(); textBox.Text = getValue();
textBox.OnLoseFocus = () => textBox.OnLoseFocus = () =>

View File

@@ -188,19 +188,19 @@ namespace OpenRA.Mods.RA.Widgets
return true; return true;
} }
private bool PerformSwitchToSellMode () bool PerformSwitchToSellMode()
{ {
World.ToggleInputMode<SellOrderGenerator>(); World.ToggleInputMode<SellOrderGenerator>();
return true; return true;
} }
private bool PerformSwitchToPowerDownMode () bool PerformSwitchToPowerDownMode()
{ {
World.ToggleInputMode<PowerDownOrderGenerator>(); World.ToggleInputMode<PowerDownOrderGenerator>();
return true; return true;
} }
private bool PerformSwitchToRepairMode () bool PerformSwitchToRepairMode()
{ {
World.ToggleInputMode<RepairOrderGenerator>(); World.ToggleInputMode<RepairOrderGenerator>();
return true; return true;