diff --git a/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs index 6b396d4504..50d7f2a1ae 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs @@ -333,8 +333,11 @@ namespace OpenRA.Mods.Cnc.Widgets }; if (showBotOptions) - foreach (var bot in Rules.Info["player"].Traits.WithInterface().Select(t => t.Name)) + foreach (var b in Rules.Info["player"].Traits.WithInterface().Select(t => t.Name)) + { + var bot = b; options.Add(new SlotDropDownOption("Bot: {0}".F(bot), "slot_bot {0} {1}".F(slot.Index, bot), () => slot.Bot == bot)); + } Func setupItem = (o, itemTemplate) => { diff --git a/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs index 099fbad90f..9695f19cb5 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs @@ -190,89 +190,84 @@ namespace OpenRA.Mods.RA.Widgets.Delegates { return orderManager.LobbyInfo.ClientInSlot( slot ); } - - bool ShowSlotDropDown(Session.Slot slot, ButtonWidget name, bool showBotOptions) + + class SlotDropDownOption { - var dropDownOptions = new List> + public string Title; + public string Order; + public Func Selected; + + public SlotDropDownOption(string title, string order, Func selected) { - new Pair( "Open", - () => orderManager.IssueOrder( Order.Command( "slot_open " + slot.Index ) )), - new Pair( "Closed", - () => orderManager.IssueOrder( Order.Command( "slot_close " + slot.Index ) )), - }; - - if (showBotOptions) - { - var bots = Rules.Info["player"].Traits.WithInterface().Select(t => t.Name); - bots.Do(bot => - dropDownOptions.Add(new Pair("Bot: {0}".F(bot), - () => orderManager.IssueOrder(Order.Command("slot_bot {0} {1}".F(slot.Index, bot)))))); + Title = title; + Order = order; + Selected = selected; } - - DropDownButtonWidget.ShowDropDown( name, - dropDownOptions, - (ac, w) => new LabelWidget + } + + bool ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot, bool showBotOptions) + { + var options = new List() + { + new SlotDropDownOption("Open", "slot_open "+slot.Index, () => (!slot.Closed && slot.Bot == null)), + new SlotDropDownOption("Closed", "slot_close "+slot.Index, () => slot.Closed) + }; + + if (showBotOptions) + foreach (var b in Rules.Info["player"].Traits.WithInterface().Select(t => t.Name)) { - Bounds = new Rectangle(0, 0, w, 24), - Text = " {0}".F(ac.First), - OnMouseUp = mi => { ac.Second(); return true; }, - }); + var bot = b; + options.Add(new SlotDropDownOption("Bot: {0}".F(bot), "slot_bot {0} {1}".F(slot.Index, bot), () => slot.Bot == bot)); + } + Func setupItem = (o, itemTemplate) => + { + var item = ScrollItemWidget.Setup(itemTemplate, + o.Selected, + () => orderManager.IssueOrder(Order.Command(o.Order))); + item.GetWidget("LABEL").GetText = () => o.Title; + return item; + }; + + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, options, setupItem); return true; } - bool ShowRaceDropDown(Session.Slot s, ButtonWidget race) + bool ShowRaceDropDown(DropDownButtonWidget dropdown, Session.Slot slot) { - if (Map.Players[s.MapPlayer].LockRace) + if (Map.Players[slot.MapPlayer].LockRace) return false; - - var dropDownOptions = new List>(); - foreach (var c in CountryNames) + + var sr = GetClientInSlot(slot).Country; + Func setupItem = (race, itemTemplate) => { - var cc = c; - dropDownOptions.Add(new Pair( cc.Key, - () => orderManager.IssueOrder( Order.Command("race "+cc.Key) )) ); + var item = ScrollItemWidget.Setup(itemTemplate, + () => sr == race, + () => orderManager.IssueOrder(Order.Command("race "+race))); + item.GetWidget("LABEL").GetText = () => CountryNames[race]; + var flag = item.GetWidget("FLAG"); + flag.GetImageCollection = () => "flags"; + flag.GetImageName = () => race; + return item; }; - - DropDownButtonWidget.ShowDropDown( race, - dropDownOptions, - (ac, w) => - { - var ret = new LabelWidget - { - Bounds = new Rectangle(0, 0, w, 24), - Text = " {0}".F(CountryNames[ac.First]), - OnMouseUp = mi => { ac.Second(); return true; }, - }; - - ret.AddChild(new ImageWidget - { - Bounds = new Rectangle(5, 5, 40, 15), - GetImageName = () => ac.First, - GetImageCollection = () => "flags", - }); - return ret; - }); + + dropdown.ShowDropDown("RACE_DROPDOWN_TEMPLATE", 150, CountryNames.Keys.ToList(), setupItem); return true; } - - bool ShowTeamDropDown(ButtonWidget team) + + bool ShowTeamDropDown(DropDownButtonWidget dropdown, Session.Slot slot) { - var dropDownOptions = new List>(); - for (int i = 0; i <= Map.PlayerCount; i++) + var c = GetClientInSlot(slot); + Func setupItem = (ii, itemTemplate) => { - var ii = i; - dropDownOptions.Add(new Pair( ii == 0 ? "-" : ii.ToString(), - () => orderManager.IssueOrder( Order.Command("team "+ii) )) ); + var item = ScrollItemWidget.Setup(itemTemplate, + () => c.Team == ii, + () => orderManager.IssueOrder(Order.Command("team "+ii))); + item.GetWidget("LABEL").GetText = () => ii == 0 ? "-" : ii.ToString(); + return item; }; - - DropDownButtonWidget.ShowDropDown( team, - dropDownOptions, - (ac, w) => new LabelWidget - { - Bounds = new Rectangle(0, 0, w, 24), - Text = " {0}".F(ac.First), - OnMouseUp = mi => { ac.Second(); return true; }, - }); + + var options = Graphics.Util.MakeArray(Map.PlayerCount, i => i).ToList(); + dropdown.ShowDropDown("TEAM_DROPDOWN_TEMPLATE", 150, options, setupItem); return true; } @@ -327,18 +322,18 @@ namespace OpenRA.Mods.RA.Widgets.Delegates if (slot.Spectator) { template = EmptySlotTemplateHost.Clone(); - var name = template.GetWidget("NAME"); + var name = template.GetWidget("NAME"); name.GetText = () => s.Closed ? "Closed" : "Open"; - name.OnMouseDown = _ => ShowSlotDropDown(s, name, false); + name.OnMouseDown = _ => ShowSlotDropDown(name, s, false); var btn = template.GetWidget("JOIN"); btn.GetText = () => "Spectate in this slot"; } else { template = EmptySlotTemplateHost.Clone(); - var name = template.GetWidget("NAME"); + var name = template.GetWidget("NAME"); name.GetText = () => s.Closed ? "Closed" : (s.Bot == null) ? "Open" : s.Bot; - name.OnMouseDown = _ => ShowSlotDropDown(s, name, Map.Players[ s.MapPlayer ].AllowBots); + name.OnMouseDown = _ => ShowSlotDropDown(name, s, Map.Players[ s.MapPlayer ].AllowBots); } } else @@ -393,8 +388,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates var colorBlock = color.GetWidget("COLORBLOCK"); colorBlock.GetColor = () => c.ColorRamp.GetColor(0); - var faction = template.GetWidget("FACTION"); - faction.OnMouseDown = _ => ShowRaceDropDown(s, faction); + var faction = template.GetWidget("FACTION"); + faction.OnMouseDown = _ => ShowRaceDropDown(faction, s); var factionname = faction.GetWidget("FACTIONNAME"); factionname.GetText = () => CountryNames[c.Country]; @@ -402,8 +397,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates factionflag.GetImageName = () => c.Country; factionflag.GetImageCollection = () => "flags"; - var team = template.GetWidget("TEAM"); - team.OnMouseDown = _ => ShowTeamDropDown(team); + var team = template.GetWidget("TEAM"); + team.OnMouseDown = _ => ShowTeamDropDown(team, s); team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString(); var status = template.GetWidget("STATUS"); diff --git a/mods/cnc/chrome/dropdowns.yaml b/mods/cnc/chrome/dropdowns.yaml index 353a3125af..c63d957746 100644 --- a/mods/cnc/chrome/dropdowns.yaml +++ b/mods/cnc/chrome/dropdowns.yaml @@ -89,4 +89,49 @@ ScrollPanel@LABEL_DROPDOWN_TEMPLATE: Id:LABEL X:10 Width:PARENT_RIGHT-20 - Height:25 \ No newline at end of file + Height:25 + +ScrollPanel@RACE_DROPDOWN_TEMPLATE: + Id:RACE_DROPDOWN_TEMPLATE + Width:DROPDOWN_WIDTH + Background:panel-black + Children: + ScrollItem@TEMPLATE: + Id:TEMPLATE + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Image@FLAG: + Id:FLAG + X:5 + Y:5 + Width:30 + Height:15 + Label@LABEL: + Id:LABEL + X:40 + Width:60 + Height:25 + +ScrollPanel@TEAM_DROPDOWN_TEMPLATE: + Id:TEAM_DROPDOWN_TEMPLATE + Width:DROPDOWN_WIDTH + Background:panel-black + Children: + ScrollItem@TEMPLATE: + Id:TEMPLATE + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Label@LABEL: + Id:LABEL + X:0 + Width:PARENT_RIGHT + Height:25 + Align:Center \ No newline at end of file diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index 5ac11a8c9e..f4494c937b 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -380,48 +380,4 @@ Container@SERVER_LOBBY: Y:499 Width:140 Height:35 - Text:Start Game - -ScrollPanel@RACE_DROPDOWN_TEMPLATE: - Id:RACE_DROPDOWN_TEMPLATE - Width:DROPDOWN_WIDTH - Background:panel-black - Children: - ScrollItem@TEMPLATE: - Id:TEMPLATE - Width:PARENT_RIGHT-27 - Height:25 - X:2 - Y:0 - Visible:false - Children: - Image@FLAG: - Id:FLAG - X:5 - Y:5 - Width:30 - Height:15 - Label@LABEL: - Id:LABEL - X:40 - Width:60 - Height:25 -ScrollPanel@TEAM_DROPDOWN_TEMPLATE: - Id:TEAM_DROPDOWN_TEMPLATE - Width:DROPDOWN_WIDTH - Background:panel-black - Children: - ScrollItem@TEMPLATE: - Id:TEMPLATE - Width:PARENT_RIGHT-27 - Height:25 - X:2 - Y:0 - Visible:false - Children: - Label@LABEL: - Id:LABEL - X:0 - Width:PARENT_RIGHT - Height:25 - Align:Center \ No newline at end of file + Text:Start Game \ No newline at end of file diff --git a/mods/ra/chrome/dropdowns.yaml b/mods/ra/chrome/dropdowns.yaml new file mode 100644 index 0000000000..53ade7769a --- /dev/null +++ b/mods/ra/chrome/dropdowns.yaml @@ -0,0 +1,60 @@ +ScrollPanel@LABEL_DROPDOWN_TEMPLATE: + Id:LABEL_DROPDOWN_TEMPLATE + Width:DROPDOWN_WIDTH + Children: + ScrollItem@TEMPLATE: + Id:TEMPLATE + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Label@LABEL: + Id:LABEL + X:10 + Width:PARENT_RIGHT-20 + Height:25 + +ScrollPanel@RACE_DROPDOWN_TEMPLATE: + Id:RACE_DROPDOWN_TEMPLATE + Width:DROPDOWN_WIDTH + Children: + ScrollItem@TEMPLATE: + Id:TEMPLATE + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Image@FLAG: + Id:FLAG + X:5 + Y:5 + Width:30 + Height:15 + Label@LABEL: + Id:LABEL + X:40 + Width:60 + Height:25 + +ScrollPanel@TEAM_DROPDOWN_TEMPLATE: + Id:TEAM_DROPDOWN_TEMPLATE + Width:DROPDOWN_WIDTH + Children: + ScrollItem@TEMPLATE: + Id:TEMPLATE + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Label@LABEL: + Id:LABEL + X:0 + Width:PARENT_RIGHT + Height:25 + Align:Center \ No newline at end of file diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index 1e81618e31..fb1d94277a 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -61,7 +61,7 @@ ChromeLayout: mods/ra/chrome/gamelobby.yaml mods/ra/chrome/serverbrowser.yaml mods/ra/chrome/replaybrowser.yaml - + mods/ra/chrome/dropdowns.yaml Weapons: mods/ra/weapons.yaml