Make control group hotkeys configurable
- Split control groups management to its own interface - Add hotkeys for selecting, creating, adding to and combining with control groups - Add a ControlGroups widget to manage the player interaction
This commit is contained in:
committed by
abcdefg30
parent
04b456d6c2
commit
7a93b9ea8c
@@ -11,8 +11,6 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -174,77 +172,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
foreach (var ns in worldNotifySelection)
|
||||
ns.SelectionChanged();
|
||||
}
|
||||
|
||||
foreach (var cg in controlGroups.Values)
|
||||
{
|
||||
// note: NOT `!a.IsInWorld`, since that would remove things that are in transports.
|
||||
cg.RemoveAll(a => a.Disposed || a.Owner != world.LocalPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
readonly Cache<int, List<Actor>> controlGroups = new Cache<int, List<Actor>>(_ => new List<Actor>());
|
||||
|
||||
public void DoControlGroup(World world, WorldRenderer worldRenderer, int group, Modifiers mods, int multiTapCount)
|
||||
{
|
||||
var addModifier = Platform.CurrentPlatform == PlatformType.OSX ? Modifiers.Meta : Modifiers.Ctrl;
|
||||
if (mods.HasModifier(addModifier))
|
||||
{
|
||||
if (actors.Count == 0)
|
||||
return;
|
||||
|
||||
if (!mods.HasModifier(Modifiers.Shift))
|
||||
controlGroups[group].Clear();
|
||||
|
||||
for (var i = 0; i < 10; i++) // all control groups
|
||||
controlGroups[i].RemoveAll(a => actors.Contains(a));
|
||||
|
||||
controlGroups[group].AddRange(actors.Where(a => a.Owner == world.LocalPlayer));
|
||||
return;
|
||||
}
|
||||
|
||||
var groupActors = controlGroups[group].Where(a => a.IsInWorld);
|
||||
|
||||
if (mods.HasModifier(Modifiers.Alt) || multiTapCount >= 2)
|
||||
{
|
||||
worldRenderer.Viewport.Center(groupActors);
|
||||
return;
|
||||
}
|
||||
|
||||
Combine(world, groupActors, mods.HasModifier(Modifiers.Shift), false);
|
||||
}
|
||||
|
||||
public void AddToControlGroup(Actor a, int group)
|
||||
{
|
||||
if (!controlGroups[group].Contains(a))
|
||||
controlGroups[group].Add(a);
|
||||
}
|
||||
|
||||
public void RemoveFromControlGroup(Actor a)
|
||||
{
|
||||
var group = GetControlGroupForActor(a);
|
||||
if (group.HasValue)
|
||||
controlGroups[group.Value].Remove(a);
|
||||
}
|
||||
|
||||
public int? GetControlGroupForActor(Actor a)
|
||||
{
|
||||
return controlGroups.Where(g => g.Value.Contains(a))
|
||||
.Select(g => (int?)g.Key)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
List<MiniYamlNode> IGameSaveTraitData.IssueTraitData(Actor self)
|
||||
{
|
||||
var groups = controlGroups
|
||||
.Where(cg => cg.Value.Any())
|
||||
.Select(cg => new MiniYamlNode(cg.Key.ToString(),
|
||||
FieldSaver.FormatValue(cg.Value.Select(a => a.ActorID).ToArray())))
|
||||
.ToList();
|
||||
|
||||
return new List<MiniYamlNode>()
|
||||
{
|
||||
new MiniYamlNode("Selection", FieldSaver.FormatValue(Actors.Select(a => a.ActorID).ToArray())),
|
||||
new MiniYamlNode("Groups", new MiniYaml("", groups))
|
||||
new MiniYamlNode("Selection", FieldSaver.FormatValue(Actors.Select(a => a.ActorID).ToArray()))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -257,17 +191,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
.Select(a => self.World.GetActorById(a)).Where(a => a != null);
|
||||
Combine(self.World, selected, false, false);
|
||||
}
|
||||
|
||||
var groupsNode = data.FirstOrDefault(n => n.Key == "Groups");
|
||||
if (groupsNode != null)
|
||||
{
|
||||
foreach (var n in groupsNode.Value.Nodes)
|
||||
{
|
||||
var group = FieldLoader.GetValue<uint[]>(n.Key, n.Value.Value)
|
||||
.Select(a => self.World.GetActorById(a)).Where(a => a != null);
|
||||
controlGroups[int.Parse(n.Key)].AddRange(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user