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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Network; using OpenRA.Network;
using OpenRA.Widgets; using OpenRA.Widgets;
@@ -18,31 +19,35 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
public class ObserverShroudSelectorLogic public class ObserverShroudSelectorLogic
{ {
CameraOption selected;
class CameraOption class CameraOption
{ {
public string Label; public readonly string Label;
public Func<bool> IsSelected; public readonly Color Color;
public Action OnClick; 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; Label = label;
IsSelected = isSelected; Color = Color.White;
OnClick = onClick; 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] [ObjectCreator.UseCtor]
public ObserverShroudSelectorLogic(Widget widget, World world) public ObserverShroudSelectorLogic(Widget widget, World world)
{ {
@@ -54,33 +59,63 @@ namespace OpenRA.Mods.RA.Widgets.Logic
foreach (var t in teams) 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); 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 combined = world.Players.First(p => p.InternalName == "Everyone");
var disableShroud = new CameraOption(this, world, "Disable Shroud", null);
groups.Add("Other", new List<CameraOption>() groups.Add("Other", new List<CameraOption>()
{ {
new CameraOption(LabelForPlayer(combined), () => world.RenderPlayer == combined, () => world.RenderPlayer = combined), new CameraOption(this, world, "All Players", combined),
new CameraOption(LabelForPlayer(null), () => world.RenderPlayer == null, () => world.RenderPlayer = null) disableShroud
}); });
var shroudSelector = widget.Get<DropDownButtonWidget>("SHROUD_SELECTOR"); var shroudSelector = widget.Get<DropDownButtonWidget>("SHROUD_SELECTOR");
shroudSelector.GetText = () => LabelForPlayer(world.RenderPlayer);
shroudSelector.OnMouseDown = _ => shroudSelector.OnMouseDown = _ =>
{ {
Func<CameraOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => Func<CameraOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{ {
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); 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; 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;
} }
} }
} }

View File

@@ -64,6 +64,43 @@ ScrollPanel@TEAM_DROPDOWN_TEMPLATE:
Height:25 Height:25
Align:Center 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: Container@CONFIRM_PROMPT:
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - 90)/2 Y:(WINDOW_BOTTOM - 90)/2

View File

@@ -158,6 +158,20 @@ Container@OBSERVER_WIDGETS:
Width:168 Width:168
Height:25 Height:25
Font:Bold 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: Container@PLAYER_WIDGETS:
Children: Children:

View File

@@ -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

View File

@@ -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

View File

@@ -62,7 +62,7 @@ ChromeLayout:
mods/ra/chrome/ingame-diplomacy.yaml mods/ra/chrome/ingame-diplomacy.yaml
mods/ra/chrome/ingame-fmvplayer.yaml mods/ra/chrome/ingame-fmvplayer.yaml
mods/ra/chrome/ingame-menu.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/ra/chrome/ingame-observerstats.yaml
mods/d2k/chrome/ingame-player.yaml mods/d2k/chrome/ingame-player.yaml
mods/d2k/chrome/mainmenu.yaml mods/d2k/chrome/mainmenu.yaml
@@ -79,7 +79,7 @@ ChromeLayout:
mods/ra/chrome/connection.yaml mods/ra/chrome/connection.yaml
mods/ra/chrome/directconnect.yaml mods/ra/chrome/directconnect.yaml
mods/ra/chrome/replaybrowser.yaml mods/ra/chrome/replaybrowser.yaml
mods/ra/chrome/dropdowns.yaml mods/d2k/chrome/dropdowns.yaml
mods/ra/chrome/modchooser.yaml mods/ra/chrome/modchooser.yaml
mods/ra/chrome/cheats.yaml mods/ra/chrome/cheats.yaml
mods/ra/chrome/musicplayer.yaml mods/ra/chrome/musicplayer.yaml

View File

@@ -40,4 +40,41 @@ ScrollPanel@TEAM_DROPDOWN_TEMPLATE:
X:0 X:0
Width:PARENT_RIGHT Width:PARENT_RIGHT
Height:25 Height:25
Align:Center 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

View File

@@ -33,6 +33,20 @@ Container@OBSERVER_WIDGETS:
Width:220 Width:220
Height:25 Height:25
Font:Bold 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: Container@REPLAY_PLAYER:
Logic:ReplayControlBarLogic Logic:ReplayControlBarLogic
X:PARENT_RIGHT/2 - 80 X:PARENT_RIGHT/2 - 80