Initial commit: OpenRA game engine
Fork from OpenRA/OpenRA with one-click launch script (start-ra.cmd) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Lint;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||
{
|
||||
[ChromeLogicArgsHotkeys("CycleBasesKey")]
|
||||
public class CycleBasesHotkeyLogic : SingleHotkeyBaseLogic
|
||||
{
|
||||
readonly Viewport viewport;
|
||||
readonly ISelection selection;
|
||||
readonly World world;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public CycleBasesHotkeyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, World world, Dictionary<string, MiniYaml> logicArgs)
|
||||
: base(widget, modData, "CycleBasesKey", "WORLD_KEYHANDLER", logicArgs)
|
||||
{
|
||||
viewport = worldRenderer.Viewport;
|
||||
selection = world.Selection;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
protected override bool OnHotkeyActivated(KeyInput e)
|
||||
{
|
||||
var player = world.RenderPlayer ?? world.LocalPlayer;
|
||||
|
||||
var bases = world.ActorsHavingTrait<BaseBuilding>()
|
||||
.Where(a => a.Owner == player)
|
||||
.OrderByDescending(a => a.IsPrimaryBuilding())
|
||||
.ThenBy(a => a.ActorID)
|
||||
.ToList();
|
||||
|
||||
// If no BaseBuilding exist pick the first selectable Building.
|
||||
if (bases.Count == 0)
|
||||
{
|
||||
var building = world.ActorsHavingTrait<Building>()
|
||||
.FirstOrDefault(a => a.Owner == player && a.Info.HasTraitInfo<SelectableInfo>());
|
||||
|
||||
// No buildings left
|
||||
if (building == null)
|
||||
return true;
|
||||
|
||||
selection.Combine(world, [building], false, true);
|
||||
viewport.Center(selection.Actors);
|
||||
return true;
|
||||
}
|
||||
|
||||
var next = bases
|
||||
.SkipWhile(b => !selection.Contains(b))
|
||||
.Skip(1)
|
||||
.FirstOrDefault();
|
||||
|
||||
next ??= bases[0];
|
||||
|
||||
selection.Combine(world, [next], false, true);
|
||||
viewport.Center(selection.Actors);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Lint;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||
{
|
||||
[ChromeLogicArgsHotkeys("CycleHarvestersKey")]
|
||||
public class CycleHarvestersHotkeyLogic : SingleHotkeyBaseLogic
|
||||
{
|
||||
readonly Viewport viewport;
|
||||
readonly ISelection selection;
|
||||
readonly World world;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public CycleHarvestersHotkeyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, World world, Dictionary<string, MiniYaml> logicArgs)
|
||||
: base(widget, modData, "CycleHarvestersKey", "WORLD_KEYHANDLER", logicArgs)
|
||||
{
|
||||
viewport = worldRenderer.Viewport;
|
||||
selection = world.Selection;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
protected override bool OnHotkeyActivated(KeyInput e)
|
||||
{
|
||||
var player = world.RenderPlayer ?? world.LocalPlayer;
|
||||
|
||||
var harvesters = world.ActorsHavingTrait<Harvester>()
|
||||
.Where(a => a.IsInWorld && a.Owner == player)
|
||||
.ToList();
|
||||
|
||||
if (harvesters.Count == 0)
|
||||
return true;
|
||||
|
||||
var next = harvesters
|
||||
.SkipWhile(b => !selection.Contains(b))
|
||||
.Skip(1)
|
||||
.FirstOrDefault();
|
||||
|
||||
next ??= harvesters[0];
|
||||
|
||||
selection.Combine(world, [next], false, true);
|
||||
viewport.Center(selection.Actors);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Lint;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||
{
|
||||
[ChromeLogicArgsHotkeys("CycleProductionActorsKey")]
|
||||
public class CycleProductionActorsHotkeyLogic : SingleHotkeyBaseLogic
|
||||
{
|
||||
readonly Viewport viewport;
|
||||
readonly ISelection selection;
|
||||
readonly World world;
|
||||
|
||||
readonly string clickSound = ChromeMetrics.Get<string>("ClickSound");
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public CycleProductionActorsHotkeyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, World world, Dictionary<string, MiniYaml> logicArgs)
|
||||
: base(widget, modData, "CycleProductionActorsKey", "WORLD_KEYHANDLER", logicArgs)
|
||||
{
|
||||
viewport = worldRenderer.Viewport;
|
||||
selection = world.Selection;
|
||||
this.world = world;
|
||||
|
||||
if (logicArgs.TryGetValue("ClickSound", out var yaml))
|
||||
clickSound = yaml.Value;
|
||||
}
|
||||
|
||||
protected override bool OnHotkeyActivated(KeyInput e)
|
||||
{
|
||||
var player = world.RenderPlayer ?? world.LocalPlayer;
|
||||
|
||||
var facilities = world.ActorsHavingTrait<Production>()
|
||||
.Where(a => a.Owner == player && a.OccupiesSpace != null && !a.Info.HasTraitInfo<BaseBuildingInfo>()
|
||||
&& a.TraitsImplementing<Production>().Any(t => !t.IsTraitDisabled))
|
||||
.OrderBy(f => f.TraitsImplementing<Production>().First(t => !t.IsTraitDisabled).Info.Produces[0])
|
||||
.ToList();
|
||||
|
||||
if (facilities.Count == 0)
|
||||
return true;
|
||||
|
||||
var next = facilities
|
||||
.SkipWhile(b => !selection.Contains(b))
|
||||
.Skip(1)
|
||||
.FirstOrDefault();
|
||||
|
||||
next ??= facilities[0];
|
||||
|
||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Sounds", clickSound, null);
|
||||
|
||||
selection.Combine(world, [next], false, true);
|
||||
viewport.Center(selection.Actors);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Mods.Common.Lint;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||
{
|
||||
[ChromeLogicArgsHotkeys("CycleStatusBarsKey")]
|
||||
public class CycleStatusBarsHotkeyLogic : SingleHotkeyBaseLogic
|
||||
{
|
||||
readonly StatusBarsType[] options = [StatusBarsType.Standard, StatusBarsType.DamageShow, StatusBarsType.AlwaysShow];
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public CycleStatusBarsHotkeyLogic(Widget widget, ModData modData, Dictionary<string, MiniYaml> logicArgs)
|
||||
: base(widget, modData, "CycleStatusBarsKey", "WORLD_KEYHANDLER", logicArgs) { }
|
||||
|
||||
protected override bool OnHotkeyActivated(KeyInput e)
|
||||
{
|
||||
Game.Settings.Game.StatusBars = options[(options.IndexOf(Game.Settings.Game.StatusBars) + 1) % options.Length];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Mods.Common.Lint;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||
{
|
||||
[ChromeLogicArgsHotkeys("EditorQuickSaveKey")]
|
||||
public class EditorQuickSaveHotkeyLogic : SingleHotkeyBaseLogic
|
||||
{
|
||||
readonly World world;
|
||||
readonly ModData modData;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public EditorQuickSaveHotkeyLogic(Widget widget, ModData modData, World world, Dictionary<string, MiniYaml> logicArgs)
|
||||
: base(widget, modData, "QuickSaveKey", "GLOBAL_KEYHANDLER", logicArgs)
|
||||
{
|
||||
this.world = world;
|
||||
this.modData = modData;
|
||||
}
|
||||
|
||||
protected override bool OnHotkeyActivated(KeyInput keyInput)
|
||||
{
|
||||
var actionManager = world.WorldActor.TraitOrDefault<EditorActionManager>();
|
||||
if (actionManager != null && (!actionManager.Modified || actionManager.SaveFailed))
|
||||
return false;
|
||||
|
||||
var map = world.Map;
|
||||
void SaveMap(string combinedPath)
|
||||
{
|
||||
var editorActorLayer = world.WorldActor.Trait<EditorActorLayer>();
|
||||
|
||||
var actorDefinitions = editorActorLayer.Save();
|
||||
if (actorDefinitions != null)
|
||||
map.ActorDefinitions = actorDefinitions;
|
||||
|
||||
var playerDefinitions = editorActorLayer.Players.ToMiniYaml();
|
||||
if (playerDefinitions != null)
|
||||
map.PlayerDefinitions = playerDefinitions;
|
||||
|
||||
var package = (IReadWritePackage)map.Package;
|
||||
SaveMapLogic.SaveMapInner(map, package, world, modData);
|
||||
}
|
||||
|
||||
SaveMapLogic.SaveMap(modData, world, map, map.Package?.Name, SaveMap);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Lint;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||
{
|
||||
[ChromeLogicArgsHotkeys("JumpToLastEventKey")]
|
||||
public class JumpToLastEventHotkeyLogic : SingleHotkeyBaseLogic
|
||||
{
|
||||
readonly Viewport viewport;
|
||||
readonly RadarPings radarPings;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public JumpToLastEventHotkeyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, World world, Dictionary<string, MiniYaml> logicArgs)
|
||||
: base(widget, modData, "JumpToLastEventKey", "WORLD_KEYHANDLER", logicArgs)
|
||||
{
|
||||
viewport = worldRenderer.Viewport;
|
||||
radarPings = world.WorldActor.TraitOrDefault<RadarPings>();
|
||||
}
|
||||
|
||||
protected override bool OnHotkeyActivated(KeyInput e)
|
||||
{
|
||||
if (radarPings == null || radarPings.LastPingPosition == null)
|
||||
return true;
|
||||
|
||||
viewport.Center(radarPings.LastPingPosition.Value);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Lint;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||
{
|
||||
[ChromeLogicArgsHotkeys("JumpToSelectedActorsKey")]
|
||||
public class JumpToSelectedActorsHotkeyLogic : SingleHotkeyBaseLogic
|
||||
{
|
||||
readonly Viewport viewport;
|
||||
readonly ISelection selection;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public JumpToSelectedActorsHotkeyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, World world, Dictionary<string, MiniYaml> logicArgs)
|
||||
: base(widget, modData, "JumpToSelectedActorsKey", "WORLD_KEYHANDLER", logicArgs)
|
||||
{
|
||||
viewport = worldRenderer.Viewport;
|
||||
selection = world.Selection;
|
||||
}
|
||||
|
||||
protected override bool OnHotkeyActivated(KeyInput e)
|
||||
{
|
||||
viewport.Center(selection.Actors);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Mods.Common.Lint;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||
{
|
||||
[ChromeLogicArgsHotkeys("PauseKey")]
|
||||
public class PauseHotkeyLogic : SingleHotkeyBaseLogic
|
||||
{
|
||||
readonly World world;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public PauseHotkeyLogic(Widget widget, ModData modData, World world, Dictionary<string, MiniYaml> logicArgs)
|
||||
: base(widget, modData, "PauseKey", "WORLD_KEYHANDLER", logicArgs)
|
||||
{
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
protected override bool OnHotkeyActivated(KeyInput e)
|
||||
{
|
||||
// Disable pausing for spectators and defeated players unless they are the game host
|
||||
if (!Game.IsHost && (world.LocalPlayer == null || world.LocalPlayer.WinState == WinState.Lost))
|
||||
return false;
|
||||
|
||||
world.SetPauseState(!world.Paused);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Lint;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||
{
|
||||
[ChromeLogicArgsHotkeys("RemoveFromControlGroupKey")]
|
||||
public class RemoveFromControlGroupHotkeyLogic : SingleHotkeyBaseLogic
|
||||
{
|
||||
readonly ISelection selection;
|
||||
readonly World world;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public RemoveFromControlGroupHotkeyLogic(Widget widget, ModData modData, World world, Dictionary<string, MiniYaml> logicArgs)
|
||||
: base(widget, modData, "RemoveFromControlGroupKey", "PLAYER_KEYHANDLER", logicArgs)
|
||||
{
|
||||
selection = world.Selection;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
protected override bool OnHotkeyActivated(KeyInput e)
|
||||
{
|
||||
var selectedActors = selection.Actors
|
||||
.Where(a => a.Owner == world.LocalPlayer && a.IsInWorld && !a.IsDead)
|
||||
.ToArray();
|
||||
|
||||
foreach (var a in selectedActors)
|
||||
world.ControlGroups.RemoveFromControlGroup(a);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Lint;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||
{
|
||||
[ChromeLogicArgsHotkeys("ResetZoomKey")]
|
||||
public class ResetZoomHotkeyLogic : SingleHotkeyBaseLogic
|
||||
{
|
||||
readonly Viewport viewport;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ResetZoomHotkeyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, Dictionary<string, MiniYaml> logicArgs)
|
||||
: base(widget, modData, "ResetZoomKey", "WORLD_KEYHANDLER", logicArgs)
|
||||
{
|
||||
viewport = worldRenderer.Viewport;
|
||||
}
|
||||
|
||||
protected override bool OnHotkeyActivated(KeyInput e)
|
||||
{
|
||||
viewport.ToggleZoom();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Lint;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||
{
|
||||
[ChromeLogicArgsHotkeys("SelectAllUnitsKey")]
|
||||
public class SelectAllUnitsHotkeyLogic : SingleHotkeyBaseLogic
|
||||
{
|
||||
readonly World world;
|
||||
readonly WorldRenderer worldRenderer;
|
||||
readonly ISelection selection;
|
||||
|
||||
public readonly string ClickSound = ChromeMetrics.Get<string>("ClickSound");
|
||||
|
||||
[FluentReference("units")]
|
||||
const string SelectedUnitsAcrossScreen = "selected-units-across-screen";
|
||||
|
||||
[FluentReference("units")]
|
||||
const string SelectedUnitsAcrossMap = "selected-units-across-map";
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public SelectAllUnitsHotkeyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, World world, Dictionary<string, MiniYaml> logicArgs)
|
||||
: base(widget, modData, "SelectAllUnitsKey", "WORLD_KEYHANDLER", logicArgs)
|
||||
{
|
||||
this.world = world;
|
||||
this.worldRenderer = worldRenderer;
|
||||
selection = world.Selection;
|
||||
}
|
||||
|
||||
protected override bool OnHotkeyActivated(KeyInput e)
|
||||
{
|
||||
if (world.IsGameOver)
|
||||
return false;
|
||||
|
||||
var eligiblePlayers = SelectionUtils.GetPlayersToIncludeInSelection(world);
|
||||
|
||||
// Select actors on the screen which belong to the current player(s)
|
||||
var newSelection = SelectionUtils.SelectActorsOnScreen(world, worldRenderer, null, eligiblePlayers).SubsetWithHighestSelectionPriority(e.Modifiers).ToList();
|
||||
|
||||
// Check if selecting actors on the screen has selected new units
|
||||
if (newSelection.Count > selection.Actors.Count)
|
||||
TextNotificationsManager.AddFeedbackLine(SelectedUnitsAcrossScreen, "units", newSelection.Count);
|
||||
else
|
||||
{
|
||||
// Select actors in the world that have highest selection priority
|
||||
newSelection = SelectionUtils.SelectActorsInWorld(world, null, eligiblePlayers).SubsetWithHighestSelectionPriority(e.Modifiers).ToList();
|
||||
TextNotificationsManager.AddFeedbackLine(SelectedUnitsAcrossMap, "units", newSelection.Count);
|
||||
}
|
||||
|
||||
selection.Combine(world, newSelection, false, false);
|
||||
|
||||
Game.Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Sounds", ClickSound, null);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Lint;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||
{
|
||||
[ChromeLogicArgsHotkeys("SelectUnitsByTypeKey")]
|
||||
public class SelectUnitsByTypeHotkeyLogic : SingleHotkeyBaseLogic
|
||||
{
|
||||
readonly World world;
|
||||
readonly WorldRenderer worldRenderer;
|
||||
readonly ISelection selection;
|
||||
|
||||
public readonly string ClickSound = ChromeMetrics.Get<string>("ClickSound");
|
||||
public readonly string ClickDisabledSound = ChromeMetrics.Get<string>("ClickDisabledSound");
|
||||
|
||||
[FluentReference]
|
||||
const string NothingSelected = "nothing-selected";
|
||||
|
||||
[FluentReference("units")]
|
||||
const string SelectedUnitsAcrossScreen = "selected-units-across-screen";
|
||||
|
||||
[FluentReference("units")]
|
||||
const string SelectedUnitsAcrossMap = "selected-units-across-map";
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public SelectUnitsByTypeHotkeyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, World world, Dictionary<string, MiniYaml> logicArgs)
|
||||
: base(widget, modData, "SelectUnitsByTypeKey", "WORLD_KEYHANDLER", logicArgs)
|
||||
{
|
||||
this.world = world;
|
||||
this.worldRenderer = worldRenderer;
|
||||
selection = world.Selection;
|
||||
}
|
||||
|
||||
protected override bool OnHotkeyActivated(KeyInput e)
|
||||
{
|
||||
if (world.IsGameOver)
|
||||
return false;
|
||||
|
||||
if (selection.Actors.Count == 0)
|
||||
{
|
||||
TextNotificationsManager.AddFeedbackLine(NothingSelected);
|
||||
Game.Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Sounds", ClickDisabledSound, null);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
var eligiblePlayers = SelectionUtils.GetPlayersToIncludeInSelection(world);
|
||||
|
||||
var ownedActors = selection.Actors
|
||||
.Where(x => !x.IsDead && eligiblePlayers.Contains(x.Owner))
|
||||
.ToList();
|
||||
|
||||
if (ownedActors.Count == 0)
|
||||
return false;
|
||||
|
||||
// Get all the selected actors' selection classes
|
||||
var selectedClasses = ownedActors
|
||||
.Select(a => a.Trait<ISelectable>().Class)
|
||||
.ToHashSet();
|
||||
|
||||
// Select actors on the screen that have the same selection class as one of the already selected actors
|
||||
var newSelection = SelectionUtils.SelectActorsOnScreen(world, worldRenderer, selectedClasses, eligiblePlayers).ToList();
|
||||
|
||||
// Check if selecting actors on the screen has selected new units
|
||||
if (newSelection.Count > selection.Actors.Count)
|
||||
TextNotificationsManager.AddFeedbackLine(SelectedUnitsAcrossScreen, "units", newSelection.Count);
|
||||
else
|
||||
{
|
||||
// Select actors in the world that have the same selection class as one of the already selected actors
|
||||
newSelection = SelectionUtils.SelectActorsInWorld(world, selectedClasses, eligiblePlayers).ToList();
|
||||
TextNotificationsManager.AddFeedbackLine(SelectedUnitsAcrossMap, "units", newSelection.Count);
|
||||
}
|
||||
|
||||
selection.Combine(world, newSelection, true, false);
|
||||
|
||||
Game.Sound.PlayNotification(world.Map.Rules, world.LocalPlayer, "Sounds", ClickSound, null);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Lint;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||
{
|
||||
[ChromeLogicArgsHotkeys("TogglePlayerStanceColorKey")]
|
||||
public class TogglePlayerStanceColorHotkeyLogic : SingleHotkeyBaseLogic
|
||||
{
|
||||
readonly World world;
|
||||
readonly WorldRenderer worldRenderer;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public TogglePlayerStanceColorHotkeyLogic(Widget widget, World world, WorldRenderer worldRenderer, ModData modData, Dictionary<string, MiniYaml> logicArgs)
|
||||
: base(widget, modData, "TogglePlayerStanceColorKey", "WORLD_KEYHANDLER", logicArgs)
|
||||
{
|
||||
this.world = world;
|
||||
this.worldRenderer = worldRenderer;
|
||||
}
|
||||
|
||||
protected override bool OnHotkeyActivated(KeyInput e)
|
||||
{
|
||||
Game.Settings.Game.UsePlayerStanceColors ^= true;
|
||||
Player.SetupRelationshipColors(world.Players, world.LocalPlayer, worldRenderer, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user