added a new hotkey to cycle production buildings except conyards

This commit is contained in:
Matthias Mailänder
2013-12-07 11:56:05 +01:00
parent 316161a3e0
commit b72ea8c227
3 changed files with 29 additions and 0 deletions

View File

@@ -157,6 +157,7 @@ namespace OpenRA.GameRules
public Hotkey NextProductionTabKey = new Hotkey(Keycode.PAGEDOWN, Modifiers.None);
public Hotkey PreviousProductionTabKey = new Hotkey(Keycode.PAGEUP, Modifiers.None);
public Hotkey CycleProductionBuildingsKey = new Hotkey(Keycode.TAB, Modifiers.None);
public Hotkey ToggleStatusBarsKey = new Hotkey(Keycode.INSERT, Modifiers.None);

View File

@@ -259,6 +259,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ "NextProductionTabKey", "Next production tab" },
{ "PreviousProductionTabKey", "Previous production tab" },
{ "CycleProductionBuildingsKey", "Cycle production facilities" },
{ "ToggleStatusBarsKey", "Toggle status bars" },
};

View File

@@ -47,9 +47,13 @@ namespace OpenRA.Mods.RA.Widgets
{
var key = Hotkey.FromKeyInput(e);
var ks = Game.Settings.Keys;
if (key == ks.CycleBaseKey)
return CycleBases();
if (key == ks.CycleProductionBuildingsKey)
return CycleProductionBuildings();
if (key == ks.ToLastEventKey)
return ToLastEvent();
@@ -199,6 +203,29 @@ namespace OpenRA.Mods.RA.Widgets
return ToSelection();
}
bool CycleProductionBuildings()
{
var facilities = world.ActorsWithTrait<Production>()
.Where(a => a.Actor.Owner == world.LocalPlayer && !a.Actor.HasTrait<BaseBuilding>())
.ToArray();
if (!facilities.Any())
return true;
var next = facilities
.Select(b => b.Actor)
.SkipWhile(b => !world.Selection.Actors.Contains(b))
.Skip(1)
.FirstOrDefault();
if (next == null)
next = facilities.Select(b => b.Actor).First();
world.Selection.Combine(world, new Actor[] { next }, false, true);
return ToSelection();
}
bool ToLastEvent()
{
if (world.LocalPlayer == null)