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>();