diff --git a/OpenRA.Mods.RA/Widgets/Logic/ObserverShroudSelectorLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ObserverShroudSelectorLogic.cs index 1c0d1cca15..8ad31630a8 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ObserverShroudSelectorLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ObserverShroudSelectorLogic.cs @@ -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 IsSelected; - public Action OnClick; + public readonly string Label; + public readonly Color Color; + public readonly string Race; + public readonly Func IsSelected; + public readonly Action OnClick; - public CameraOption(string label, Func 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() { - 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("SHROUD_SELECTOR"); - shroudSelector.GetText = () => LabelForPlayer(world.RenderPlayer); shroudSelector.OnMouseDown = _ => { Func setupItem = (option, template) => { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); - item.Get("LABEL").GetText = () => option.Label; + var showFlag = option.Race != null; + + var label = item.Get("LABEL"); + label.IsVisible = () => showFlag; + label.GetText = () => option.Label; + label.GetColor = () => option.Color; + + var flag = item.Get("FLAG"); + flag.IsVisible = () => showFlag; + flag.GetImageCollection = () => "flags"; + flag.GetImageName = () => option.Race; + + var labelAlt = item.Get("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("LABEL"); + shroudLabel.IsVisible = () => selected.Race != null; + shroudLabel.GetText = () => selected.Label; + shroudLabel.GetColor = () => selected.Color; + + var shroudFlag = shroudSelector.Get("FLAG"); + shroudFlag.IsVisible = () => selected.Race != null; + shroudFlag.GetImageCollection = () => "flags"; + shroudFlag.GetImageName = () => selected.Race; + + var shroudLabelAlt = shroudSelector.Get("NOFLAG_LABEL"); + shroudLabelAlt.IsVisible = () => selected.Race == null; + shroudLabelAlt.GetText = () => selected.Label; + shroudLabelAlt.GetColor = () => selected.Color; + + selected = disableShroud; } } } diff --git a/mods/cnc/chrome/dialogs.yaml b/mods/cnc/chrome/dialogs.yaml index 322b8d44af..c10968cc89 100644 --- a/mods/cnc/chrome/dialogs.yaml +++ b/mods/cnc/chrome/dialogs.yaml @@ -64,6 +64,43 @@ ScrollPanel@TEAM_DROPDOWN_TEMPLATE: Height:25 Align:Center +ScrollPanel@SPECTATOR_DROPDOWN_TEMPLATE: + Width:DROPDOWN_WIDTH + Background:panel-black + Children: + ScrollItem@HEADER: + Width:PARENT_RIGHT-27 + Height:13 + X:2 + Y:0 + Visible:false + Children: + Label@LABEL: + Font:TinyBold + Width:PARENT_RIGHT + Height:10 + Align:Center + ScrollItem@TEMPLATE: + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Image@FLAG: + X:4 + Y:4 + Width:32 + Height:16 + Label@LABEL: + X:40 + Width:60 + Height:25 + Label@NOFLAG_LABEL: + X:5 + Width:PARENT_RIGHT + Height:25 + Container@CONFIRM_PROMPT: X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM - 90)/2 diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index f264c4cd39..7a98ec4073 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -158,6 +158,20 @@ Container@OBSERVER_WIDGETS: Width:168 Height:25 Font:Bold + Children: + Image@FLAG: + X:4 + Y:4 + Width:32 + Height:16 + Label@LABEL: + X:40 + Width:60 + Height:25 + Label@NOFLAG_LABEL: + X:5 + Width:PARENT_RIGHT + Height:25 Container@PLAYER_WIDGETS: Children: diff --git a/mods/d2k/chrome/dropdowns.yaml b/mods/d2k/chrome/dropdowns.yaml new file mode 100644 index 0000000000..450c7e2e14 --- /dev/null +++ b/mods/d2k/chrome/dropdowns.yaml @@ -0,0 +1,80 @@ +ScrollPanel@LABEL_DROPDOWN_TEMPLATE: + Width:DROPDOWN_WIDTH + Children: + ScrollItem@HEADER: + BaseName:scrollheader + Width:PARENT_RIGHT-27 + Height:13 + X:2 + Y:0 + Visible:false + Children: + Label@LABEL: + Font:TinyBold + Width:PARENT_RIGHT + Height:10 + Align:Center + ScrollItem@TEMPLATE: + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Label@LABEL: + X:10 + Width:PARENT_RIGHT-20 + Height:25 + +ScrollPanel@TEAM_DROPDOWN_TEMPLATE: + Width:DROPDOWN_WIDTH + Children: + ScrollItem@TEMPLATE: + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Label@LABEL: + X:0 + Width:PARENT_RIGHT + Height:25 + Align:Center + +ScrollPanel@SPECTATOR_DROPDOWN_TEMPLATE: + Width:DROPDOWN_WIDTH + Children: + ScrollItem@HEADER: + BaseName:scrollheader + Width:PARENT_RIGHT-27 + Height:13 + X:2 + Y:0 + Visible:false + Children: + Label@LABEL: + Font:TinyBold + Width:PARENT_RIGHT + Height:10 + Align:Center + ScrollItem@TEMPLATE: + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Image@FLAG: + Width:23 + Height:23 + X:4 + Y:2 + Label@LABEL: + X:34 + Width:60 + Height:25 + Label@NOFLAG_LABEL: + X:5 + Width:PARENT_RIGHT + Height:25 diff --git a/mods/d2k/chrome/ingame-observer.yaml b/mods/d2k/chrome/ingame-observer.yaml new file mode 100644 index 0000000000..e72dd8a65d --- /dev/null +++ b/mods/d2k/chrome/ingame-observer.yaml @@ -0,0 +1,113 @@ +Container@OBSERVER_WIDGETS: + Children: + Button@INGAME_STATS_BUTTON: + X:162 + Y:0 + Width:160 + Height:25 + Text:Statistics (F1) + Font:Bold + Key:f1 + Background@RADAR_BG: + X:WINDOW_RIGHT-255 + Y:5 + Width:250 + Height:250 + Children: + Radar@INGAME_RADAR: + X:10 + Y:10 + Width:PARENT_RIGHT-19 + Height:PARENT_BOTTOM-19 + WorldInteractionController:INTERACTION_CONTROLLER + Background@OBSERVER_CONTROL_BG: + X:WINDOW_RIGHT-255 + Y:260 + Width:250 + Height:55 + Children: + DropDownButton@SHROUD_SELECTOR: + Logic:ObserverShroudSelectorLogic + X:15 + Y:15 + Width:220 + Height:25 + Font:Bold + Children: + Image@FLAG: + Width:23 + Height:23 + X:4 + Y:2 + Label@LABEL: + X:34 + Width:60 + Height:25 + Label@NOFLAG_LABEL: + X:5 + Width:PARENT_RIGHT + Height:25 + Container@REPLAY_PLAYER: + Logic:ReplayControlBarLogic + X:PARENT_RIGHT/2 - 80 + Y:35 + Width:160 + Height:35 + Visible:false + Children: + Button@BUTTON_PAUSE: + X:15 + Y:15 + Width:25 + Height:25 + IgnoreChildMouseOver:true + Children: + Image@IMAGE_PAUSE: + X:0 + Y:0 + Width:25 + Height:25 + ImageCollection:music + ImageName:pause + Button@BUTTON_SLOW: + X:50 + Y:15 + Width:25 + Height:25 + IgnoreChildMouseOver:true + Children: + Image@IMAGE_SLOW: + X:4 + Y:0 + Width:25 + Height:25 + ImageCollection:music + ImageName:slowmo + Button@BUTTON_NORMALSPEED: + X:85 + Y:15 + Width:25 + Height:25 + IgnoreChildMouseOver:true + Children: + Image@IMAGE_PLAY: + X:0 + Y:0 + Width:25 + Height:25 + ImageCollection:music + ImageName:play + Button@BUTTON_FASTFORWARD: + X:120 + Y:15 + Width:25 + Height:25 + IgnoreChildMouseOver:true + Children: + Image@IMAGE_FASTFORWARD: + X:4 + Y:0 + Width:25 + Height:25 + ImageCollection:music + ImageName:fastforward diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index f8e876d9c9..6fab881eb4 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -62,7 +62,7 @@ ChromeLayout: mods/ra/chrome/ingame-diplomacy.yaml mods/ra/chrome/ingame-fmvplayer.yaml mods/ra/chrome/ingame-menu.yaml - mods/ra/chrome/ingame-observer.yaml + mods/d2k/chrome/ingame-observer.yaml mods/ra/chrome/ingame-observerstats.yaml mods/d2k/chrome/ingame-player.yaml mods/d2k/chrome/mainmenu.yaml @@ -79,7 +79,7 @@ ChromeLayout: mods/ra/chrome/connection.yaml mods/ra/chrome/directconnect.yaml mods/ra/chrome/replaybrowser.yaml - mods/ra/chrome/dropdowns.yaml + mods/d2k/chrome/dropdowns.yaml mods/ra/chrome/modchooser.yaml mods/ra/chrome/cheats.yaml mods/ra/chrome/musicplayer.yaml diff --git a/mods/ra/chrome/dropdowns.yaml b/mods/ra/chrome/dropdowns.yaml index 92b8ac3c3e..9bcc479319 100644 --- a/mods/ra/chrome/dropdowns.yaml +++ b/mods/ra/chrome/dropdowns.yaml @@ -40,4 +40,41 @@ ScrollPanel@TEAM_DROPDOWN_TEMPLATE: X:0 Width:PARENT_RIGHT Height:25 - Align:Center \ No newline at end of file + Align:Center + +ScrollPanel@SPECTATOR_DROPDOWN_TEMPLATE: + Width:DROPDOWN_WIDTH + Children: + ScrollItem@HEADER: + BaseName:scrollheader + Width:PARENT_RIGHT-27 + Height:13 + X:2 + Y:0 + Visible:false + Children: + Label@LABEL: + Font:TinyBold + Width:PARENT_RIGHT + Height:10 + Align:Center + ScrollItem@TEMPLATE: + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Image@FLAG: + X:4 + Y:4 + Width:32 + Height:16 + Label@LABEL: + X:40 + Width:60 + Height:25 + Label@NOFLAG_LABEL: + X:5 + Width:PARENT_RIGHT + Height:25 diff --git a/mods/ra/chrome/ingame-observer.yaml b/mods/ra/chrome/ingame-observer.yaml index 8d6cd4fc45..ebb3cf3082 100644 --- a/mods/ra/chrome/ingame-observer.yaml +++ b/mods/ra/chrome/ingame-observer.yaml @@ -33,6 +33,20 @@ Container@OBSERVER_WIDGETS: Width:220 Height:25 Font:Bold + Children: + Image@FLAG: + X:4 + Y:4 + Width:32 + Height:16 + Label@LABEL: + X:40 + Width:60 + Height:25 + Label@NOFLAG_LABEL: + X:5 + Width:PARENT_RIGHT + Height:25 Container@REPLAY_PLAYER: Logic:ReplayControlBarLogic X:PARENT_RIGHT/2 - 80