Add a hotkey to select the current production facility

This commit is contained in:
Ivaylo Draganov
2019-12-21 23:11:36 +02:00
committed by Paul Chote
parent 7ffc689037
commit 1bcad55c1f
6 changed files with 34 additions and 0 deletions

View File

@@ -55,6 +55,7 @@ namespace OpenRA.Mods.Common.Widgets
// Note: LinterHotkeyNames assumes that these are disabled by default
public readonly string HotkeyPrefix = null;
public readonly int HotkeyCount = 0;
public readonly HotkeyReference SelectProductionBuildingHotkey = new HotkeyReference();
public readonly string ClockAnimation = "clock";
public readonly string ClockSequence = "idle";
@@ -367,6 +368,9 @@ namespace OpenRA.Mods.Common.Widgets
if (e.Event == KeyInputEvent.Up || CurrentQueue == null)
return false;
if (SelectProductionBuildingHotkey.IsActivatedBy(e))
return SelectProductionBuilding();
var batchModifiers = e.Modifiers.HasModifier(Modifiers.Shift) ? Modifiers.Shift : Modifiers.None;
// HACK: enable production if the shift key is pressed
@@ -375,6 +379,28 @@ namespace OpenRA.Mods.Common.Widgets
return toBuild != null ? HandleEvent(toBuild, MouseButton.Left, batchModifiers) : false;
}
bool SelectProductionBuilding()
{
var viewport = worldRenderer.Viewport;
var selection = World.Selection;
if (CurrentQueue == null)
return true;
var facility = CurrentQueue.MostLikelyProducer().Actor;
if (facility == null)
return true;
if (selection.Actors.Count() == 1 && selection.Contains(facility))
viewport.Center(selection.Actors);
else
selection.Combine(World, new[] { facility }, false, true);
Game.Sound.PlayNotification(World.Map.Rules, null, "Sounds", ClickSound, null);
return true;
}
public void RefreshIcons()
{
icons = new Dictionary<Rectangle, ProductionIcon>();

View File

@@ -1838,6 +1838,7 @@ Container@PLAYER_WIDGETS:
HoldText: On Hold
HotkeyPrefix: Production
HotkeyCount: 24
SelectProductionBuildingHotkey: SelectProductionBuilding
ProductionTabs@PRODUCTION_TABS:
Logic: AddFactionSuffixLogic, ProductionTabsLogic
PaletteWidget: PRODUCTION_PALETTE

View File

@@ -2,6 +2,10 @@ CycleProductionBuildings: TAB
Description: Next facility
Types: Production, Player, Spectator
SelectProductionBuilding:
Description: Current facility
Types: Production, Player
Production01: F1
Description: Slot 01
Types: ProductionSlot, Player

View File

@@ -492,6 +492,7 @@ Container@PLAYER_WIDGETS:
MaximumRows: 6
HotkeyPrefix: Production
HotkeyCount: 24
SelectProductionBuildingHotkey: SelectProductionBuilding
ClickSound: TabClick
Container@PRODUCTION_TYPES:
X: 6

View File

@@ -448,6 +448,7 @@ Container@PLAYER_WIDGETS:
IconSpriteOffset: -1, -1
HotkeyPrefix: Production
HotkeyCount: 24
SelectProductionBuildingHotkey: SelectProductionBuilding
Container@PALETTE_FOREGROUND:
Children:
Image@ROW_TEMPLATE:

View File

@@ -491,6 +491,7 @@ Container@PLAYER_WIDGETS:
MaximumRows: 6
HotkeyPrefix: Production
HotkeyCount: 24
SelectProductionBuildingHotkey: SelectProductionBuilding
Container@PRODUCTION_TYPES:
X: 0
Y: 0 - 32