Divide the shroud selector into groups.
This commit is contained in:
@@ -9,7 +9,9 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.Network;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||||
@@ -32,18 +34,40 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
|
|
||||||
static string LabelForPlayer(Player p)
|
static string LabelForPlayer(Player p)
|
||||||
{
|
{
|
||||||
return p != null ? p.PlayerName == "Everyone" ? "Combined view" : "{0}'s view".F(p.PlayerName) : "World view";
|
if (p == null)
|
||||||
|
return "Disable shroud";
|
||||||
|
|
||||||
|
if (p.InternalName == "Everyone")
|
||||||
|
return "Combined view";
|
||||||
|
|
||||||
|
return p.PlayerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ObserverShroudSelectorLogic(Widget widget, World world)
|
public ObserverShroudSelectorLogic(Widget widget, World world)
|
||||||
{
|
{
|
||||||
var views = world.Players.Where(p => (p.NonCombatant && p.Spectating)
|
var groups = new Dictionary<string, IEnumerable<CameraOption>>();
|
||||||
|| !p.NonCombatant).Concat(new[] { (Player)null }).Select(
|
|
||||||
p => new CameraOption(LabelForPlayer(p),
|
var teams = world.Players.Where(p => !p.NonCombatant)
|
||||||
() => world.RenderPlayer == p,
|
.GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.ClientIndex) ?? new Session.Client()).Team).OrderBy(g => g.Key);
|
||||||
() => world.RenderPlayer = p
|
var noTeams = teams.Count() == 1;
|
||||||
)).ToArray();
|
|
||||||
|
foreach (var t in teams)
|
||||||
|
{
|
||||||
|
var team = t.Select(p => new CameraOption(LabelForPlayer(p),
|
||||||
|
() => world.RenderPlayer == p,
|
||||||
|
() => world.RenderPlayer = p));
|
||||||
|
|
||||||
|
var label = noTeams ? "Players" : t.Key == 0 ? "No Team" : "Team {0}".F(t.Key);
|
||||||
|
groups.Add(label, team);
|
||||||
|
}
|
||||||
|
|
||||||
|
var combined = world.Players.First(p => p.InternalName == "Everyone");
|
||||||
|
groups.Add("Other", new List<CameraOption>()
|
||||||
|
{
|
||||||
|
new CameraOption(LabelForPlayer(combined), () => world.RenderPlayer == combined, () => world.RenderPlayer = combined),
|
||||||
|
new CameraOption(LabelForPlayer(null), () => world.RenderPlayer == null, () => world.RenderPlayer = null)
|
||||||
|
});
|
||||||
|
|
||||||
var shroudSelector = widget.Get<DropDownButtonWidget>("SHROUD_SELECTOR");
|
var shroudSelector = widget.Get<DropDownButtonWidget>("SHROUD_SELECTOR");
|
||||||
shroudSelector.GetText = () => LabelForPlayer(world.RenderPlayer);
|
shroudSelector.GetText = () => LabelForPlayer(world.RenderPlayer);
|
||||||
@@ -55,7 +79,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
item.Get<LabelWidget>("LABEL").GetText = () => option.Label;
|
item.Get<LabelWidget>("LABEL").GetText = () => option.Label;
|
||||||
return item;
|
return item;
|
||||||
};
|
};
|
||||||
shroudSelector.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", views.Length * 30, views, setupItem);
|
shroudSelector.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 400, groups, setupItem);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user