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:
@@ -23,6 +23,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
MenuType menu = MenuType.None;
|
MenuType menu = MenuType.None;
|
||||||
|
|
||||||
Widget ingameRoot;
|
Widget ingameRoot;
|
||||||
|
ProductionTabsWidget queueTabs;
|
||||||
World world;
|
World world;
|
||||||
|
|
||||||
void AddChatLine(Color c, string from, string text)
|
void AddChatLine(Color c, string from, string text)
|
||||||
@@ -35,19 +36,37 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
Game.AddChatLine -= AddChatLine;
|
Game.AddChatLine -= AddChatLine;
|
||||||
Game.BeforeGameStart -= UnregisterEvents;
|
Game.BeforeGameStart -= UnregisterEvents;
|
||||||
|
|
||||||
if (world.LocalPlayer != null)
|
if (queueTabs != null)
|
||||||
{
|
{
|
||||||
var queueTabs = ingameRoot.GetWidget<ProductionTabsWidget>("PRODUCTION_TABS");
|
|
||||||
world.ActorAdded += queueTabs.ActorChanged;
|
world.ActorAdded += queueTabs.ActorChanged;
|
||||||
world.ActorRemoved += queueTabs.ActorChanged;
|
world.ActorRemoved += queueTabs.ActorChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProductionQueue QueueForType(World world, string type)
|
void SetupProductionGroupButton(ButtonWidget button, string group)
|
||||||
{
|
{
|
||||||
return world.ActorsWithTrait<ProductionQueue>()
|
button.IsDisabled = () => queueTabs.Groups[group].Tabs.Count == 0;
|
||||||
.Where(p => p.Actor.Owner == world.LocalPlayer)
|
|
||||||
.Select(p => p.Trait).FirstOrDefault(p => p.Info.Type == type);
|
button.OnMouseUp = mi =>
|
||||||
|
{
|
||||||
|
if (button.IsDisabled())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (queueTabs.QueueType == group)
|
||||||
|
queueTabs.SelectNextTab(mi.Modifiers.HasModifier(Modifiers.Shift));
|
||||||
|
else
|
||||||
|
queueTabs.QueueType = group;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
button.OnKeyPress = e =>
|
||||||
|
{
|
||||||
|
if (queueTabs.QueueType == group)
|
||||||
|
queueTabs.SelectNextTab(e.Modifiers.HasModifier(Modifiers.Shift));
|
||||||
|
else
|
||||||
|
queueTabs.QueueType = group;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
@@ -83,34 +102,18 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
sidebarRoot.GetWidget<LabelWidget>("CASH_DISPLAY").GetText = () =>
|
sidebarRoot.GetWidget<LabelWidget>("CASH_DISPLAY").GetText = () =>
|
||||||
"${0}".F(playerResources.DisplayCash + playerResources.DisplayOre);
|
"${0}".F(playerResources.DisplayCash + playerResources.DisplayOre);
|
||||||
|
|
||||||
var buildPalette = playerWidgets.GetWidget<ProductionPaletteWidget>("PRODUCTION_PALETTE");
|
queueTabs = playerWidgets.GetWidget<ProductionTabsWidget>("PRODUCTION_TABS");
|
||||||
var queueTabs = playerWidgets.GetWidget<ProductionTabsWidget>("PRODUCTION_TABS");
|
|
||||||
|
|
||||||
world.ActorAdded += queueTabs.ActorChanged;
|
world.ActorAdded += queueTabs.ActorChanged;
|
||||||
world.ActorRemoved += queueTabs.ActorChanged;
|
world.ActorRemoved += queueTabs.ActorChanged;
|
||||||
|
|
||||||
var queueTypes = sidebarRoot.GetWidget("PRODUCTION_TYPES");
|
var queueTypes = sidebarRoot.GetWidget("PRODUCTION_TYPES");
|
||||||
|
SetupProductionGroupButton(queueTypes.GetWidget<ButtonWidget>("BUILDING"), "Building");
|
||||||
var buildingTab = queueTypes.GetWidget<ButtonWidget>("BUILDING");
|
SetupProductionGroupButton(queueTypes.GetWidget<ButtonWidget>("DEFENSE"), "Defense");
|
||||||
buildingTab.OnClick = () => queueTabs.QueueType = "Building";
|
SetupProductionGroupButton(queueTypes.GetWidget<ButtonWidget>("INFANTRY"), "Infantry");
|
||||||
buildingTab.IsDisabled = () => queueTabs.Groups["Building"].Tabs.Count == 0;
|
SetupProductionGroupButton(queueTypes.GetWidget<ButtonWidget>("VEHICLE"), "Vehicle");
|
||||||
|
SetupProductionGroupButton(queueTypes.GetWidget<ButtonWidget>("AIRCRAFT"), "Aircraft");
|
||||||
var defenseTab = queueTypes.GetWidget<ButtonWidget>("DEFENSE");
|
|
||||||
defenseTab.OnClick = () => queueTabs.QueueType = "Defense";
|
|
||||||
defenseTab.IsDisabled = () => queueTabs.Groups["Defense"].Tabs.Count == 0;
|
|
||||||
|
|
||||||
var infantryTab = queueTypes.GetWidget<ButtonWidget>("INFANTRY");
|
|
||||||
infantryTab.OnClick = () => queueTabs.QueueType = "Infantry";
|
|
||||||
infantryTab.IsDisabled = () => queueTabs.Groups["Infantry"].Tabs.Count == 0;
|
|
||||||
|
|
||||||
var vehicleTab = queueTypes.GetWidget<ButtonWidget>("VEHICLE");
|
|
||||||
vehicleTab.OnClick = () => queueTabs.QueueType = "Vehicle";
|
|
||||||
vehicleTab.IsDisabled = () => queueTabs.Groups["Vehicle"].Tabs.Count == 0;
|
|
||||||
|
|
||||||
var aircraftTab = queueTypes.GetWidget<ButtonWidget>("AIRCRAFT");
|
|
||||||
aircraftTab.OnClick = () => queueTabs.QueueType = "Aircraft";
|
|
||||||
aircraftTab.IsDisabled = () => queueTabs.Groups["Aircraft"].Tabs.Count == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ingameRoot.GetWidget<ButtonWidget>("OPTIONS_BUTTON").OnClick = () =>
|
ingameRoot.GetWidget<ButtonWidget>("OPTIONS_BUTTON").OnClick = () =>
|
||||||
{
|
{
|
||||||
if (menu != MenuType.None)
|
if (menu != MenuType.None)
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
readonly World world;
|
readonly World world;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ProductionTabsWidget( [ObjectCreator.Param] World world )
|
public ProductionTabsWidget([ObjectCreator.Param] World world)
|
||||||
{
|
{
|
||||||
this.world = world;
|
this.world = world;
|
||||||
Groups = Rules.Info.Values.SelectMany(a => a.Traits.WithInterface<ProductionQueueInfo>())
|
Groups = Rules.Info.Values.SelectMany(a => a.Traits.WithInterface<ProductionQueueInfo>())
|
||||||
@@ -213,6 +213,33 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
return (leftPressed || rightPressed);
|
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)
|
public void SelectQueue(ProductionQueue queue)
|
||||||
{
|
{
|
||||||
QueueType = queue.Info.Group;
|
QueueType = queue.Info.Group;
|
||||||
|
|||||||
@@ -185,30 +185,35 @@ Container@INGAME_ROOT:
|
|||||||
Width:30
|
Width:30
|
||||||
Height:30
|
Height:30
|
||||||
Text: B
|
Text: B
|
||||||
|
Key: y
|
||||||
Button@DEFENSE:
|
Button@DEFENSE:
|
||||||
Id:DEFENSE
|
Id:DEFENSE
|
||||||
X:35
|
X:35
|
||||||
Width:30
|
Width:30
|
||||||
Height:30
|
Height:30
|
||||||
Text: D
|
Text: D
|
||||||
|
Key: u
|
||||||
Button@INFANTRY:
|
Button@INFANTRY:
|
||||||
Id:INFANTRY
|
Id:INFANTRY
|
||||||
X:70
|
X:70
|
||||||
Width:30
|
Width:30
|
||||||
Height:30
|
Height:30
|
||||||
Text: I
|
Text: I
|
||||||
|
Key: i
|
||||||
Button@VEHICLE:
|
Button@VEHICLE:
|
||||||
Id:VEHICLE
|
Id:VEHICLE
|
||||||
X:105
|
X:105
|
||||||
Width:30
|
Width:30
|
||||||
Height:30
|
Height:30
|
||||||
Text: V
|
Text: V
|
||||||
|
Key: o
|
||||||
Button@AIRCRAFT:
|
Button@AIRCRAFT:
|
||||||
Id:AIRCRAFT
|
Id:AIRCRAFT
|
||||||
X:140
|
X:140
|
||||||
Width:30
|
Width:30
|
||||||
Height:30
|
Height:30
|
||||||
Text: H
|
Text: H
|
||||||
|
Key: p
|
||||||
ProductionTabs:
|
ProductionTabs:
|
||||||
Id:PRODUCTION_TABS
|
Id:PRODUCTION_TABS
|
||||||
PaletteWidget:PRODUCTION_PALETTE
|
PaletteWidget:PRODUCTION_PALETTE
|
||||||
|
|||||||
Reference in New Issue
Block a user