Keyboard support for production palette:

y/u/i/o/p map to Buildings/Defense/Infantry/Vehicles/Aircraft.
Tab or successive y/u/i/o/p will switch tabs within a category.
Successive clicks on category icons will also switch tabs.
Shift + keyboard/click cycles tabs in reverse.
This commit is contained in:
Paul Chote
2011-07-03 08:18:29 +12:00
parent c1f7152857
commit a065ba0338
3 changed files with 65 additions and 30 deletions

View File

@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Cnc.Widgets
readonly World world;
[ObjectCreator.UseCtor]
public ProductionTabsWidget( [ObjectCreator.Param] World world )
public ProductionTabsWidget([ObjectCreator.Param] World world)
{
this.world = world;
Groups = Rules.Info.Values.SelectMany(a => a.Traits.WithInterface<ProductionQueueInfo>())
@@ -213,6 +213,33 @@ namespace OpenRA.Mods.Cnc.Widgets
return (leftPressed || rightPressed);
}
public override bool HandleKeyPressInner(KeyInput e)
{
if (e.Event != KeyInputEvent.Down) return false;
if (e.KeyName == "tab")
{
SelectNextTab(e.Modifiers.HasModifier(Modifiers.Shift));
return true;
}
return false;
}
public void SelectNextTab(bool reverse)
{
if (queueType == null)
return;
var pal = Widget.RootWidget.GetWidget<ProductionPaletteWidget>(PaletteWidget);
var tabs = Groups[queueType].Tabs.ToList();
if (reverse) tabs.Reverse();
var tab = tabs.SkipWhile(q => q.Queue != pal.CurrentQueue)
.Skip(1).FirstOrDefault() ?? tabs.FirstOrDefault();
pal.CurrentQueue = tab != null ? tab.Queue : null;
}
public void SelectQueue(ProductionQueue queue)
{
QueueType = queue.Info.Group;