Hook up observer view keybindings. Fixes #4435.
Uses 0-9 to select view (plus shift to cycle backwards), '-' for combined shroud and '=' for world view.
This commit is contained in:
@@ -165,6 +165,9 @@ namespace OpenRA.GameRules
|
|||||||
public Hotkey DeployKey = new Hotkey(Keycode.F, Modifiers.None);
|
public Hotkey DeployKey = new Hotkey(Keycode.F, Modifiers.None);
|
||||||
public Hotkey StanceCycleKey = new Hotkey(Keycode.Z, Modifiers.None);
|
public Hotkey StanceCycleKey = new Hotkey(Keycode.Z, Modifiers.None);
|
||||||
public Hotkey GuardKey = new Hotkey(Keycode.D, Modifiers.None);
|
public Hotkey GuardKey = new Hotkey(Keycode.D, Modifiers.None);
|
||||||
|
|
||||||
|
public Hotkey ObserverCombinedView = new Hotkey(Keycode.MINUS, Modifiers.None);
|
||||||
|
public Hotkey ObserverWorldView = new Hotkey(Keycode.EQUALS, Modifiers.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class IrcSettings
|
public class IrcSettings
|
||||||
|
|||||||
@@ -20,9 +20,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
public class ObserverShroudSelectorLogic
|
public class ObserverShroudSelectorLogic
|
||||||
{
|
{
|
||||||
CameraOption selected;
|
CameraOption selected;
|
||||||
|
CameraOption combined, disableShroud;
|
||||||
|
IOrderedEnumerable<IGrouping<int, CameraOption>> teams;
|
||||||
|
|
||||||
class CameraOption
|
class CameraOption
|
||||||
{
|
{
|
||||||
|
public readonly Player Player;
|
||||||
public readonly string Label;
|
public readonly string Label;
|
||||||
public readonly Color Color;
|
public readonly Color Color;
|
||||||
public readonly string Race;
|
public readonly string Race;
|
||||||
@@ -31,6 +34,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
|
|
||||||
public CameraOption(ObserverShroudSelectorLogic logic, Player p)
|
public CameraOption(ObserverShroudSelectorLogic logic, Player p)
|
||||||
{
|
{
|
||||||
|
Player = p;
|
||||||
Label = p.PlayerName;
|
Label = p.PlayerName;
|
||||||
Color = p.Color.RGB;
|
Color = p.Color.RGB;
|
||||||
Race = p.Country.Race;
|
Race = p.Country.Race;
|
||||||
@@ -40,6 +44,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
|
|
||||||
public CameraOption(ObserverShroudSelectorLogic logic, World w, string label, Player p)
|
public CameraOption(ObserverShroudSelectorLogic logic, World w, string label, Player p)
|
||||||
{
|
{
|
||||||
|
Player = p;
|
||||||
Label = label;
|
Label = label;
|
||||||
Color = Color.White;
|
Color = Color.White;
|
||||||
Race = null;
|
Race = null;
|
||||||
@@ -53,23 +58,21 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
{
|
{
|
||||||
var groups = new Dictionary<string, IEnumerable<CameraOption>>();
|
var groups = new Dictionary<string, IEnumerable<CameraOption>>();
|
||||||
|
|
||||||
var teams = world.Players.Where(p => !p.NonCombatant)
|
teams = world.Players.Where(p => !p.NonCombatant)
|
||||||
.GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.ClientIndex) ?? new Session.Client()).Team).OrderBy(g => g.Key);
|
.Select(p => new CameraOption(this, p))
|
||||||
var noTeams = teams.Count() == 1;
|
.GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.Player.ClientIndex) ?? new Session.Client()).Team)
|
||||||
|
.OrderBy(g => g.Key);
|
||||||
|
|
||||||
|
var noTeams = teams.Count() == 1;
|
||||||
foreach (var t in teams)
|
foreach (var t in teams)
|
||||||
{
|
{
|
||||||
var label = noTeams ? "Players" : t.Key == 0 ? "No Team" : "Team {0}".F(t.Key);
|
var label = noTeams ? "Players" : t.Key == 0 ? "No Team" : "Team {0}".F(t.Key);
|
||||||
groups.Add(label, t.Select(p => new CameraOption(this, p)));
|
groups.Add(label, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
var combined = world.Players.First(p => p.InternalName == "Everyone");
|
combined = new CameraOption(this, world, "All Players", world.Players.First(p => p.InternalName == "Everyone"));
|
||||||
var disableShroud = new CameraOption(this, world, "Disable Shroud", null);
|
disableShroud = new CameraOption(this, world, "Disable Shroud", null);
|
||||||
groups.Add("Other", new List<CameraOption>()
|
groups.Add("Other", new List<CameraOption>() { combined, disableShroud });
|
||||||
{
|
|
||||||
new CameraOption(this, world, "All Players", combined),
|
|
||||||
disableShroud
|
|
||||||
});
|
|
||||||
|
|
||||||
var shroudSelector = widget.Get<DropDownButtonWidget>("SHROUD_SELECTOR");
|
var shroudSelector = widget.Get<DropDownButtonWidget>("SHROUD_SELECTOR");
|
||||||
shroudSelector.OnMouseDown = _ =>
|
shroudSelector.OnMouseDown = _ =>
|
||||||
@@ -115,7 +118,51 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
shroudLabelAlt.GetText = () => selected.Label;
|
shroudLabelAlt.GetText = () => selected.Label;
|
||||||
shroudLabelAlt.GetColor = () => selected.Color;
|
shroudLabelAlt.GetColor = () => selected.Color;
|
||||||
|
|
||||||
|
var keyhandler = shroudSelector.Get<LogicKeyListenerWidget>("SHROUD_KEYHANDLER");
|
||||||
|
keyhandler.OnKeyPress = HandleKeyPress;
|
||||||
|
|
||||||
selected = disableShroud;
|
selected = disableShroud;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool HandleKeyPress(KeyInput e)
|
||||||
|
{
|
||||||
|
if (e.Event == KeyInputEvent.Down)
|
||||||
|
{
|
||||||
|
var h = Hotkey.FromKeyInput(e);
|
||||||
|
if (h == Game.Settings.Keys.ObserverCombinedView)
|
||||||
|
{
|
||||||
|
selected = combined;
|
||||||
|
selected.OnClick();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (h == Game.Settings.Keys.ObserverWorldView)
|
||||||
|
{
|
||||||
|
selected = disableShroud;
|
||||||
|
selected.OnClick();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.Key >= Keycode.NUMBER_0 && e.Key <= Keycode.NUMBER_9)
|
||||||
|
{
|
||||||
|
var key = (int)e.Key - (int)Keycode.NUMBER_0;
|
||||||
|
var team = teams.Where(t => t.Key == key).SelectMany(s => s);
|
||||||
|
if (!team.Any())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (e.Modifiers == Modifiers.Shift)
|
||||||
|
team = team.Reverse();
|
||||||
|
|
||||||
|
selected = team.SkipWhile(t => t.Player != selected.Player).Skip(1).FirstOrDefault() ?? team.FirstOrDefault();
|
||||||
|
selected.OnClick();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -279,6 +279,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
{ "GuardKey", "Guard" }
|
{ "GuardKey", "Guard" }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var observerHotkeys = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{ "ObserverCombinedView", "All Players" },
|
||||||
|
{ "ObserverWorldView", "Disable Shroud" }
|
||||||
|
};
|
||||||
|
|
||||||
var gs = Game.Settings.Game;
|
var gs = Game.Settings.Game;
|
||||||
var ks = Game.Settings.Keys;
|
var ks = Game.Settings.Keys;
|
||||||
|
|
||||||
@@ -304,6 +310,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
foreach (var kv in specialHotkeys)
|
foreach (var kv in specialHotkeys)
|
||||||
BindHotkeyPref(kv, ks, globalTemplate, hotkeyList);
|
BindHotkeyPref(kv, ks, globalTemplate, hotkeyList);
|
||||||
|
|
||||||
|
var observerHeader = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {});
|
||||||
|
observerHeader.Get<LabelWidget>("LABEL").GetText = () => "Observer Commands";
|
||||||
|
hotkeyList.AddChild(observerHeader);
|
||||||
|
|
||||||
|
foreach (var kv in observerHotkeys)
|
||||||
|
BindHotkeyPref(kv, ks, globalTemplate, hotkeyList);
|
||||||
|
|
||||||
var unitHeader = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {});
|
var unitHeader = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {});
|
||||||
unitHeader.Get<LabelWidget>("LABEL").GetText = () => "Unit Commands";
|
unitHeader.Get<LabelWidget>("LABEL").GetText = () => "Unit Commands";
|
||||||
hotkeyList.AddChild(unitHeader);
|
hotkeyList.AddChild(unitHeader);
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ Container@OBSERVER_WIDGETS:
|
|||||||
Height:25
|
Height:25
|
||||||
Font:Bold
|
Font:Bold
|
||||||
Children:
|
Children:
|
||||||
|
LogicKeyListener@SHROUD_KEYHANDLER:
|
||||||
Image@FLAG:
|
Image@FLAG:
|
||||||
X:4
|
X:4
|
||||||
Y:4
|
Y:4
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ Container@OBSERVER_WIDGETS:
|
|||||||
Height:25
|
Height:25
|
||||||
Font:Bold
|
Font:Bold
|
||||||
Children:
|
Children:
|
||||||
|
LogicKeyListener@SHROUD_KEYHANDLER:
|
||||||
Image@FLAG:
|
Image@FLAG:
|
||||||
Width:23
|
Width:23
|
||||||
Height:23
|
Height:23
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ Container@OBSERVER_WIDGETS:
|
|||||||
Height:25
|
Height:25
|
||||||
Font:Bold
|
Font:Bold
|
||||||
Children:
|
Children:
|
||||||
|
LogicKeyListener@SHROUD_KEYHANDLER:
|
||||||
Image@FLAG:
|
Image@FLAG:
|
||||||
X:4
|
X:4
|
||||||
Y:4
|
Y:4
|
||||||
|
|||||||
Reference in New Issue
Block a user