Add flags and player colours to the observer selector.

This commit is contained in:
Paul Chote
2014-03-22 16:20:06 +13:00
parent 104b520b21
commit 2c8fc4603a
8 changed files with 360 additions and 30 deletions

View File

@@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Network;
using OpenRA.Widgets;
@@ -18,31 +19,35 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
public class ObserverShroudSelectorLogic
{
CameraOption selected;
class CameraOption
{
public string Label;
public Func<bool> IsSelected;
public Action OnClick;
public readonly string Label;
public readonly Color Color;
public readonly string Race;
public readonly Func<bool> IsSelected;
public readonly Action OnClick;
public CameraOption(string label, Func<bool> isSelected, Action onClick)
public CameraOption(ObserverShroudSelectorLogic logic, Player p)
{
Label = p.PlayerName;
Color = p.Color.RGB;
Race = p.Country.Race;
IsSelected = () => p.World.RenderPlayer == p;
OnClick = () => { p.World.RenderPlayer = p; logic.selected = this; };
}
public CameraOption(ObserverShroudSelectorLogic logic, World w, string label, Player p)
{
Label = label;
IsSelected = isSelected;
OnClick = onClick;
Color = Color.White;
Race = null;
IsSelected = () => w.RenderPlayer == p;
OnClick = () => { w.RenderPlayer = p; logic.selected = this; };
}
}
static string LabelForPlayer(Player p)
{
if (p == null)
return "Disable shroud";
if (p.InternalName == "Everyone")
return "Combined view";
return p.PlayerName;
}
[ObjectCreator.UseCtor]
public ObserverShroudSelectorLogic(Widget widget, World world)
{
@@ -54,33 +59,63 @@ namespace OpenRA.Mods.RA.Widgets.Logic
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);
groups.Add(label, t.Select(p => new CameraOption(this, p)));
}
var combined = world.Players.First(p => p.InternalName == "Everyone");
var disableShroud = new CameraOption(this, world, "Disable Shroud", null);
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)
new CameraOption(this, world, "All Players", combined),
disableShroud
});
var shroudSelector = widget.Get<DropDownButtonWidget>("SHROUD_SELECTOR");
shroudSelector.GetText = () => LabelForPlayer(world.RenderPlayer);
shroudSelector.OnMouseDown = _ =>
{
Func<CameraOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
item.Get<LabelWidget>("LABEL").GetText = () => option.Label;
var showFlag = option.Race != null;
var label = item.Get<LabelWidget>("LABEL");
label.IsVisible = () => showFlag;
label.GetText = () => option.Label;
label.GetColor = () => option.Color;
var flag = item.Get<ImageWidget>("FLAG");
flag.IsVisible = () => showFlag;
flag.GetImageCollection = () => "flags";
flag.GetImageName = () => option.Race;
var labelAlt = item.Get<LabelWidget>("NOFLAG_LABEL");
labelAlt.IsVisible = () => !showFlag;
labelAlt.GetText = () => option.Label;
labelAlt.GetColor = () => option.Color;
return item;
};
shroudSelector.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 400, groups, setupItem);
shroudSelector.ShowDropDown("SPECTATOR_DROPDOWN_TEMPLATE", 400, groups, setupItem);
};
var shroudLabel = shroudSelector.Get<LabelWidget>("LABEL");
shroudLabel.IsVisible = () => selected.Race != null;
shroudLabel.GetText = () => selected.Label;
shroudLabel.GetColor = () => selected.Color;
var shroudFlag = shroudSelector.Get<ImageWidget>("FLAG");
shroudFlag.IsVisible = () => selected.Race != null;
shroudFlag.GetImageCollection = () => "flags";
shroudFlag.GetImageName = () => selected.Race;
var shroudLabelAlt = shroudSelector.Get<LabelWidget>("NOFLAG_LABEL");
shroudLabelAlt.IsVisible = () => selected.Race == null;
shroudLabelAlt.GetText = () => selected.Label;
shroudLabelAlt.GetColor = () => selected.Color;
selected = disableShroud;
}
}
}