Make production type hotkeys configurable.

This commit is contained in:
Paul Chote
2014-12-28 17:24:12 +13:00
parent a549e1b418
commit d9752c3bdf
7 changed files with 48 additions and 12 deletions

View File

@@ -200,6 +200,12 @@ namespace OpenRA
public Hotkey Production23Key = new Hotkey(Keycode.F11, Modifiers.Ctrl);
public Hotkey Production24Key = new Hotkey(Keycode.F12, Modifiers.Ctrl);
public Hotkey ProductionTypeBuildingKey = new Hotkey(Keycode.E, Modifiers.None);
public Hotkey ProductionTypeDefenseKey = new Hotkey(Keycode.R, Modifiers.None);
public Hotkey ProductionTypeInfantryKey = new Hotkey(Keycode.T, Modifiers.None);
public Hotkey ProductionTypeVehicleKey = new Hotkey(Keycode.Y, Modifiers.None);
public Hotkey ProductionTypeAircraftKey = new Hotkey(Keycode.U, Modifiers.None);
public Hotkey ProductionTypeNavalKey = new Hotkey(Keycode.I, Modifiers.None);
public Hotkey GetProductionHotkey(int index)
{

View File

@@ -32,10 +32,20 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
tabs.QueueGroup = button.ProductionGroup;
};
Func<ButtonWidget, Hotkey> getKey = _ => Hotkey.Invalid;
if (!string.IsNullOrEmpty(button.HotkeyName))
{
var ks = Game.Settings.Keys;
var field = ks.GetType().GetField(button.HotkeyName);
if (field != null)
getKey = _ => (Hotkey)field.GetValue(ks);
}
button.IsDisabled = () => tabs.Groups[button.ProductionGroup].Tabs.Count == 0;
button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift));
button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift));
button.IsHighlighted = () => tabs.QueueGroup == button.ProductionGroup;
button.GetKey = getKey;
var chromeName = button.ProductionGroup.ToLowerInvariant();
var icon = button.Get<ImageWidget>("ICON");

View File

@@ -412,7 +412,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
// Production
{
var hotkeys = new Dictionary<string, string>();
var hotkeys = new Dictionary<string, string>()
{
{ "ProductionTypeBuildingKey", "Building Tab" },
{ "ProductionTypeDefenseKey", "Defense Tab" },
{ "ProductionTypeInfantryKey", "Infantry Tab" },
{ "ProductionTypeVehicleKey", "Vehicle Tab" },
{ "ProductionTypeAircraftKey", "Aircraft Tab" },
{ "ProductionTypeNavalKey", "Naval Tab" }
};
for (var i = 1; i <= 24; i++)
hotkeys.Add("Production{0:D2}Key".F(i), "Slot {0}".F(i));

View File

@@ -37,11 +37,21 @@ namespace OpenRA.Mods.RA.Widgets.Logic
palette.CurrentQueue = queues.FirstOrDefault(q => q.Enabled);
};
Func<ButtonWidget, Hotkey> getKey = _ => Hotkey.Invalid;
if (!string.IsNullOrEmpty(button.HotkeyName))
{
var ks = Game.Settings.Keys;
var field = ks.GetType().GetField(button.HotkeyName);
if (field != null)
getKey = _ => (Hotkey)field.GetValue(ks);
}
button.IsDisabled = () => !queues.Any(q => q.BuildableItems().Any());
button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift));
button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift));
button.OnClick = () => selectTab(false);
button.IsHighlighted = () => queues.Contains(palette.CurrentQueue);
button.GetKey = getKey;
var chromeName = button.ProductionGroup.ToLowerInvariant();
var icon = button.Get<ImageWidget>("ICON");

View File

@@ -15,6 +15,7 @@ namespace OpenRA.Mods.RA.Widgets
public class ProductionTypeButtonWidget : ButtonWidget
{
public readonly string ProductionGroup;
public readonly string HotkeyName;
[ObjectCreator.UseCtor]
public ProductionTypeButtonWidget(Ruleset modRules)

View File

@@ -363,10 +363,10 @@ Container@PLAYER_WIDGETS:
ProductionTypeButton@BUILDING:
Width: 30
Height: 30
Key: e
TooltipText: Buildings
TooltipContainer: TOOLTIP_CONTAINER
ProductionGroup: Building
HotkeyName: ProductionTypeBuildingKey
Children:
Image@ICON:
X: 7
@@ -376,10 +376,10 @@ Container@PLAYER_WIDGETS:
X: 35
Width: 30
Height: 30
Key: r
TooltipText: Defence
TooltipContainer: TOOLTIP_CONTAINER
ProductionGroup: Defence
HotkeyName: ProductionTypeDefenseKey
Children:
Image@ICON:
X: 7
@@ -389,10 +389,10 @@ Container@PLAYER_WIDGETS:
X: 70
Width: 30
Height: 30
Key: t
TooltipText: Infantry
TooltipContainer: TOOLTIP_CONTAINER
ProductionGroup: Infantry
HotkeyName: ProductionTypeInfantryKey
Children:
Image@ICON:
X: 7
@@ -402,10 +402,10 @@ Container@PLAYER_WIDGETS:
X: 105
Width: 30
Height: 30
Key: y
TooltipText: Vehicles
TooltipContainer: TOOLTIP_CONTAINER
ProductionGroup: Vehicle
HotkeyName: ProductionTypeVehicleKey
Children:
Image@ICON:
X: 7
@@ -415,10 +415,10 @@ Container@PLAYER_WIDGETS:
X: 140
Width: 30
Height: 30
Key: u
TooltipText: Aircraft
TooltipContainer: TOOLTIP_CONTAINER
ProductionGroup: Aircraft
HotkeyName: ProductionTypeAircraftKey
Children:
Image@ICON:
X: 7

View File

@@ -248,7 +248,6 @@ Container@PLAYER_WIDGETS:
Children:
ProductionTypeButton@BUILDING:
Logic: AddRaceSuffixLogic
Key: e
Width: 28
Height: 28
VisualHeight: 0
@@ -256,6 +255,7 @@ Container@PLAYER_WIDGETS:
TooltipText: Buildings
TooltipContainer: TOOLTIP_CONTAINER
ProductionGroup: Building
HotkeyName: ProductionTypeBuildingKey
Children:
Image@ICON:
X: 6
@@ -263,7 +263,6 @@ Container@PLAYER_WIDGETS:
ImageCollection: production-icons
ProductionTypeButton@DEFENSE:
Logic: AddRaceSuffixLogic
Key: r
Y: 31
Width: 28
Height: 28
@@ -272,6 +271,7 @@ Container@PLAYER_WIDGETS:
TooltipText: Defense
TooltipContainer: TOOLTIP_CONTAINER
ProductionGroup: Defense
HotkeyName: ProductionTypeDefenseKey
Children:
Image@ICON:
X: 6
@@ -279,7 +279,6 @@ Container@PLAYER_WIDGETS:
ImageCollection: production-icons
ProductionTypeButton@INFANTRY:
Logic: AddRaceSuffixLogic
Key: t
Y: 62
Width: 28
Height: 28
@@ -288,6 +287,7 @@ Container@PLAYER_WIDGETS:
TooltipText: Infantry
TooltipContainer: TOOLTIP_CONTAINER
ProductionGroup: Infantry
HotkeyName: ProductionTypeInfantryKey
Children:
Image@ICON:
X: 6
@@ -295,7 +295,6 @@ Container@PLAYER_WIDGETS:
ImageCollection: production-icons
ProductionTypeButton@VEHICLE:
Logic: AddRaceSuffixLogic
Key: y
Y: 93
Width: 28
Height: 28
@@ -304,6 +303,7 @@ Container@PLAYER_WIDGETS:
TooltipText: Vehicles
TooltipContainer: TOOLTIP_CONTAINER
ProductionGroup: Vehicle
HotkeyName: ProductionTypeVehicleKey
Children:
Image@ICON:
X: 6
@@ -311,7 +311,6 @@ Container@PLAYER_WIDGETS:
ImageCollection: production-icons
ProductionTypeButton@AIRCRAFT:
Logic: AddRaceSuffixLogic
Key: u
Y: 124
Width: 28
Height: 28
@@ -320,6 +319,7 @@ Container@PLAYER_WIDGETS:
TooltipText: Aircraft
TooltipContainer: TOOLTIP_CONTAINER
ProductionGroup: Aircraft
HotkeyName: ProductionTypeAircraftKey
Children:
Image@ICON:
X: 6
@@ -327,7 +327,6 @@ Container@PLAYER_WIDGETS:
ImageCollection: production-icons
ProductionTypeButton@NAVAL:
Logic: AddRaceSuffixLogic
Key: i
Y: 155
Width: 28
Height: 28
@@ -336,6 +335,7 @@ Container@PLAYER_WIDGETS:
TooltipText: Naval
TooltipContainer: TOOLTIP_CONTAINER
ProductionGroup: Ship
HotkeyName: ProductionTypeNavalKey
Children:
Image@ICON:
X: 6