From 1020d456647a8412ab052531d0c001681c2c0abc Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 14 Mar 2014 13:30:03 +1300 Subject: [PATCH] Split lobby map preview into its own logic class. --- OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 + OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs | 64 ++++++++----------- .../Widgets/Logic/LobbyMapPreviewLogic.cs | 44 +++++++++++++ mods/cnc/chrome/lobby-mappreview.yaml | 36 +++++++++++ mods/cnc/chrome/lobby.yaml | 37 +---------- mods/cnc/mod.yaml | 1 + mods/d2k/mod.yaml | 1 + mods/ra/chrome/lobby-mappreview.yaml | 36 +++++++++++ mods/ra/chrome/lobby.yaml | 37 +---------- mods/ra/mod.yaml | 1 + mods/ts/mod.yaml | 1 + 11 files changed, 154 insertions(+), 105 deletions(-) create mode 100644 OpenRA.Mods.RA/Widgets/Logic/LobbyMapPreviewLogic.cs create mode 100644 mods/cnc/chrome/lobby-mappreview.yaml create mode 100644 mods/ra/chrome/lobby-mappreview.yaml diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 87dd4e031a..454ae9097b 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -487,6 +487,7 @@ + diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 0c42be7d1b..739301a51a 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -23,6 +23,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic { static readonly Action DoNothing = () => { }; + public MapPreview Map = MapCache.UnknownMap; + readonly Action onStart; readonly Action onExit; readonly OrderManager orderManager; @@ -41,7 +43,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic ScrollPanelWidget players; Dictionary countryNames; - MapPreview preview = MapCache.UnknownMap; ColorPreviewManagerWidget colorPreview; @@ -108,6 +109,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic if (name != null) name.GetText = () => orderManager.LobbyInfo.GlobalSettings.ServerName; + Ui.LoadWidget("LOBBY_MAP_PREVIEW", lobby.Get("MAP_PREVIEW_ROOT"), new WidgetArgs + { + { "orderManager", orderManager }, + { "lobby", this } + }); + UpdateCurrentMap(); players = Ui.LoadWidget("LOBBY_PLAYER_BIN", lobby.Get("PLAYER_BIN_ROOT"), new WidgetArgs()); players.IsVisible = () => panel == PanelType.Players; @@ -125,23 +132,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic colorPreview = lobby.Get("COLOR_MANAGER"); colorPreview.Color = Game.Settings.Player.Color; - var mapPreview = lobby.Get("MAP_PREVIEW"); - mapPreview.Preview = () => preview; - mapPreview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint(orderManager, mapPreview, preview, mi); - mapPreview.SpawnClients = () => LobbyUtils.GetSpawnClients(orderManager, preview); - - var mapTitle = lobby.GetOrNull("MAP_TITLE"); - if (mapTitle != null) - mapTitle.GetText = () => preview.Title; - - var mapType = lobby.GetOrNull("MAP_TYPE"); - if (mapType != null) - mapType.GetText = () => preview.Type; - - var mapAuthor = lobby.GetOrNull("MAP_AUTHOR"); - if (mapAuthor != null) - mapAuthor.GetText = () => "Created by {0}".F(preview.Author); - countryNames = Rules.Info["world"].Traits.WithInterface() .Where(c => c.Selectable) .ToDictionary(a => a.Race, a => a.Name); @@ -166,7 +156,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs() { - { "initialMap", preview.Uid }, + { "initialMap", Map.Uid }, { "onExit", DoNothing }, { "onSelect", onSelect } }); @@ -300,7 +290,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic if (allowCheats != null) { allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats; - allowCheats.IsDisabled = () => preview.Status != MapStatus.Available || preview.Map.Options.Cheats.HasValue || configurationDisabled(); + allowCheats.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.Cheats.HasValue || configurationDisabled(); allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command( "allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats))); } @@ -309,7 +299,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic if (crates != null) { crates.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Crates; - crates.IsDisabled = () => preview.Status != MapStatus.Available || preview.Map.Options.Crates.HasValue || configurationDisabled(); + crates.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.Crates.HasValue || configurationDisabled(); crates.OnClick = () => orderManager.IssueOrder(Order.Command( "crates {0}".F(!orderManager.LobbyInfo.GlobalSettings.Crates))); } @@ -318,7 +308,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic if (allybuildradius != null) { allybuildradius.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllyBuildRadius; - allybuildradius.IsDisabled = () => preview.Status != MapStatus.Available || preview.Map.Options.AllyBuildRadius.HasValue || configurationDisabled(); + allybuildradius.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.AllyBuildRadius.HasValue || configurationDisabled(); allybuildradius.OnClick = () => orderManager.IssueOrder(Order.Command( "allybuildradius {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllyBuildRadius))); } @@ -327,7 +317,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic if (fragileAlliance != null) { fragileAlliance.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.FragileAlliances; - fragileAlliance.IsDisabled = () => preview.Status != MapStatus.Available || preview.Map.Options.FragileAlliances.HasValue || configurationDisabled(); + fragileAlliance.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.FragileAlliances.HasValue || configurationDisabled(); fragileAlliance.OnClick = () => orderManager.IssueOrder(Order.Command( "fragilealliance {0}".F(!orderManager.LobbyInfo.GlobalSettings.FragileAlliances))); } @@ -335,12 +325,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic var difficulty = optionsBin.GetOrNull("DIFFICULTY_DROPDOWNBUTTON"); if (difficulty != null) { - difficulty.IsVisible = () => preview.Status == MapStatus.Available && preview.Map.Options.Difficulties.Any(); - difficulty.IsDisabled = () => preview.Status != MapStatus.Available || configurationDisabled(); + difficulty.IsVisible = () => Map.Status == MapStatus.Available && Map.Map.Options.Difficulties.Any(); + difficulty.IsDisabled = () => Map.Status != MapStatus.Available || configurationDisabled(); difficulty.GetText = () => orderManager.LobbyInfo.GlobalSettings.Difficulty; difficulty.OnMouseDown = _ => { - var options = preview.Map.Options.Difficulties.Select(d => new DropDownOption + var options = Map.Map.Options.Difficulties.Select(d => new DropDownOption { Title = d, IsSelected = () => orderManager.LobbyInfo.GlobalSettings.Difficulty == d, @@ -372,8 +362,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic var classes = Rules.Info["world"].Traits.WithInterface() .Select(a => a.Class).Distinct(); - startingUnits.IsDisabled = () => preview.Status != MapStatus.Available || !preview.Map.Options.ConfigurableStartingUnits || configurationDisabled(); - startingUnits.GetText = () => preview.Status != MapStatus.Available || !preview.Map.Options.ConfigurableStartingUnits ? "Not Available" : className(orderManager.LobbyInfo.GlobalSettings.StartingUnitsClass); + startingUnits.IsDisabled = () => Map.Status != MapStatus.Available || !Map.Map.Options.ConfigurableStartingUnits || configurationDisabled(); + startingUnits.GetText = () => Map.Status != MapStatus.Available || !Map.Map.Options.ConfigurableStartingUnits ? "Not Available" : className(orderManager.LobbyInfo.GlobalSettings.StartingUnitsClass); startingUnits.OnMouseDown = _ => { var options = classes.Select(c => new DropDownOption @@ -399,8 +389,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic var startingCash = optionsBin.GetOrNull("STARTINGCASH_DROPDOWNBUTTON"); if (startingCash != null) { - startingCash.IsDisabled = () => preview.Status != MapStatus.Available || preview.Map.Options.StartingCash.HasValue || configurationDisabled(); - startingCash.GetText = () => preview.Status != MapStatus.Available || preview.Map.Options.StartingCash.HasValue ? "Not Available" : "${0}".F(orderManager.LobbyInfo.GlobalSettings.StartingCash); + startingCash.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.StartingCash.HasValue || configurationDisabled(); + startingCash.GetText = () => Map.Status != MapStatus.Available || Map.Map.Options.StartingCash.HasValue ? "Not Available" : "${0}".F(orderManager.LobbyInfo.GlobalSettings.StartingCash); startingCash.OnMouseDown = _ => { var options = Rules.Info["player"].Traits.Get().SelectableCash.Select(c => new DropDownOption @@ -425,7 +415,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic if (enableShroud != null) { enableShroud.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Shroud; - enableShroud.IsDisabled = () => preview.Status != MapStatus.Available || preview.Map.Options.Shroud.HasValue || configurationDisabled(); + enableShroud.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.Shroud.HasValue || configurationDisabled(); enableShroud.OnClick = () => orderManager.IssueOrder(Order.Command( "shroud {0}".F(!orderManager.LobbyInfo.GlobalSettings.Shroud))); } @@ -434,7 +424,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic if (enableFog != null) { enableFog.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Fog; - enableFog.IsDisabled = () => preview.Status != MapStatus.Available || preview.Map.Options.Fog.HasValue || configurationDisabled(); + enableFog.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.Fog.HasValue || configurationDisabled(); enableFog.OnClick = () => orderManager.IssueOrder(Order.Command( "fog {0}".F(!orderManager.LobbyInfo.GlobalSettings.Fog))); } @@ -533,11 +523,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic void UpdateCurrentMap() { var uid = orderManager.LobbyInfo.GlobalSettings.Map; - if (preview.Uid == uid) + if (Map.Uid == uid) return; - preview = Game.modData.MapCache[uid]; - if (preview.Status != MapStatus.Available) + Map = Game.modData.MapCache[uid]; + if (Map.Status != MapStatus.Available) { if (Game.Settings.Game.AllowDownloading) { @@ -550,7 +540,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic // Restore default starting cash if the last map set it to something invalid var pri = Rules.Info["player"].Traits.Get(); - if (!preview.Map.Options.StartingCash.HasValue && !pri.SelectableCash.Contains(orderManager.LobbyInfo.GlobalSettings.StartingCash)) + if (!Map.Map.Options.StartingCash.HasValue && !pri.SelectableCash.Contains(orderManager.LobbyInfo.GlobalSettings.StartingCash)) orderManager.IssueOrder(Order.Command("startingcash {0}".F(pri.DefaultCash))); } @@ -600,7 +590,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, colorPreview); LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, countryNames); - LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, preview.SpawnPoints.Count); + LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, Map.SpawnPoints.Count); LobbyUtils.SetupEditableReadyWidget(template, slot, client, orderManager); } else diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyMapPreviewLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyMapPreviewLogic.cs new file mode 100644 index 0000000000..c01303bdc7 --- /dev/null +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyMapPreviewLogic.cs @@ -0,0 +1,44 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using OpenRA.Network; +using OpenRA.Traits; +using OpenRA.Widgets; + +namespace OpenRA.Mods.RA.Widgets.Logic +{ + public class LobbyMapPreviewLogic + { + [ObjectCreator.UseCtor] + internal LobbyMapPreviewLogic(Widget widget, OrderManager orderManager, LobbyLogic lobby) + { + var mapPreview = widget.Get("MAP_PREVIEW"); + mapPreview.Preview = () => lobby.Map; + mapPreview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint(orderManager, mapPreview, lobby.Map, mi); + mapPreview.SpawnClients = () => LobbyUtils.GetSpawnClients(orderManager, lobby.Map); + + var mapTitle = widget.GetOrNull("MAP_TITLE"); + if (mapTitle != null) + mapTitle.GetText = () => lobby.Map.Title; + + var mapType = widget.GetOrNull("MAP_TYPE"); + if (mapType != null) + mapType.GetText = () => lobby.Map.Type; + + var mapAuthor = widget.GetOrNull("MAP_AUTHOR"); + if (mapAuthor != null) + mapAuthor.GetText = () => "Created by {0}".F(lobby.Map.Author); + } + } +} diff --git a/mods/cnc/chrome/lobby-mappreview.yaml b/mods/cnc/chrome/lobby-mappreview.yaml new file mode 100644 index 0000000000..d3c1e7dae5 --- /dev/null +++ b/mods/cnc/chrome/lobby-mappreview.yaml @@ -0,0 +1,36 @@ +Container@LOBBY_MAP_PREVIEW: + Logic:LobbyMapPreviewLogic + X:PARENT_RIGHT-15-WIDTH + Y:30 + Width:194 + Height:250 + Children: + Background@MAP_BG: + Width:PARENT_RIGHT + Height:194 + Background:panel-gray + Children: + MapPreview@MAP_PREVIEW: + X:1 + Y:1 + Width:PARENT_RIGHT-2 + Height:PARENT_BOTTOM-2 + TooltipContainer:TOOLTIP_CONTAINER + Label@MAP_TITLE: + Y:197 + Width:PARENT_RIGHT + Height:25 + Font:Bold + Align:Center + Label@MAP_TYPE: + Y:212 + Width:PARENT_RIGHT + Height:25 + Font:TinyBold + Align:Center + Label@MAP_AUTHOR: + Y:225 + Width:PARENT_RIGHT + Height:25 + Font:Tiny + Align:Center diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index 1ce1394529..95102cd59b 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -17,40 +17,9 @@ Container@SERVER_LOBBY: Height:500 Background:panel-black Children: - Background@MAP_BG: - X:PARENT_RIGHT-15-WIDTH - Y:30 - Width:194 - Height:194 - Background:panel-gray - Children: - MapPreview@MAP_PREVIEW: - X:1 - Y:1 - Width:192 - Height:192 - TooltipContainer:TOOLTIP_CONTAINER - Label@MAP_TITLE: - X:PARENT_RIGHT-15-WIDTH - Y:227 - Width:194 - Height:25 - Font:Bold - Align:Center - Label@MAP_TYPE: - X:PARENT_RIGHT-15-WIDTH - Y:242 - Width:194 - Height:25 - Font:TinyBold - Align:Center - Label@MAP_AUTHOR: - X:PARENT_RIGHT-15-WIDTH - Y:255 - Width:194 - Height:25 - Font:Tiny - Align:Center + Container@MAP_PREVIEW_ROOT: + Width:PARENT_RIGHT + Height:PARENT_BOTTOM Container@LABEL_CONTAINER: X:20 Y:5 diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 15e6a85a68..878eda946f 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -79,6 +79,7 @@ ChromeLayout: mods/cnc/chrome/createserver.yaml mods/cnc/chrome/directconnect.yaml mods/cnc/chrome/lobby.yaml + mods/cnc/chrome/lobby-mappreview.yaml mods/cnc/chrome/lobby-playerbin.yaml mods/cnc/chrome/connection.yaml mods/cnc/chrome/mapchooser.yaml diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index 39a4603872..283417e3ce 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -69,6 +69,7 @@ ChromeLayout: mods/ra/chrome/settings.yaml mods/ra/chrome/credits.yaml mods/ra/chrome/lobby.yaml + mods/ra/chrome/lobby-mappreview.yaml mods/d2k/chrome/lobby-playerbin.yaml mods/ra/chrome/lobby-dialogs.yaml mods/d2k/chrome/color-picker.yaml diff --git a/mods/ra/chrome/lobby-mappreview.yaml b/mods/ra/chrome/lobby-mappreview.yaml new file mode 100644 index 0000000000..3dfb153feb --- /dev/null +++ b/mods/ra/chrome/lobby-mappreview.yaml @@ -0,0 +1,36 @@ +Container@LOBBY_MAP_PREVIEW: + Logic:LobbyMapPreviewLogic + X:PARENT_RIGHT-20-WIDTH + Y:67 + Width:214 + Height:250 + Children: + Background@MAP_BG: + Width:PARENT_RIGHT + Height:214 + Background:dialog3 + Children: + MapPreview@MAP_PREVIEW: + X:2 + Y:2 + Width:210 + Height:210 + TooltipContainer:TOOLTIP_CONTAINER + Label@MAP_TITLE: + Y:215 + Width:PARENT_RIGHT + Height:25 + Font:Bold + Align:Center + Label@MAP_TYPE: + Y:230 + Width:PARENT_RIGHT + Height:25 + Font:TinyBold + Align:Center + Label@MAP_AUTHOR: + Y:243 + Width:PARENT_RIGHT + Height:25 + Font:Tiny + Align:Center \ No newline at end of file diff --git a/mods/ra/chrome/lobby.yaml b/mods/ra/chrome/lobby.yaml index ab6c67213d..b6e20e96ae 100644 --- a/mods/ra/chrome/lobby.yaml +++ b/mods/ra/chrome/lobby.yaml @@ -13,40 +13,9 @@ Background@SERVER_LOBBY: Width:PARENT_RIGHT Height:20 Font:Bold - Background@MAP_BG: - X:PARENT_RIGHT-20-WIDTH - Y:67 - Width:214 - Height:214 - Background:dialog3 - Children: - MapPreview@MAP_PREVIEW: - X:2 - Y:2 - Width:210 - Height:210 - TooltipContainer:TOOLTIP_CONTAINER - Label@MAP_TITLE: - X:PARENT_RIGHT-20-WIDTH - Y:282 - Width:214 - Height:25 - Font:Bold - Align:Center - Label@MAP_TYPE: - X:PARENT_RIGHT-20-WIDTH - Y:297 - Width:214 - Height:25 - Font:TinyBold - Align:Center - Label@MAP_AUTHOR: - X:PARENT_RIGHT-20-WIDTH - Y:310 - Width:214 - Height:25 - Font:Tiny - Align:Center + Container@MAP_PREVIEW_ROOT: + Width:PARENT_RIGHT + Height:PARENT_BOTTOM Container@LABEL_CONTAINER: X:25 Y:40 diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index fad79b75dd..e4ae6b2457 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -83,6 +83,7 @@ ChromeLayout: mods/ra/chrome/settings.yaml mods/ra/chrome/credits.yaml mods/ra/chrome/lobby.yaml + mods/ra/chrome/lobby-mappreview.yaml mods/ra/chrome/lobby-playerbin.yaml mods/ra/chrome/lobby-dialogs.yaml mods/ra/chrome/color-picker.yaml diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index d5947892af..dcb87352bc 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -108,6 +108,7 @@ ChromeLayout: mods/ra/chrome/settings.yaml mods/ra/chrome/credits.yaml mods/ra/chrome/lobby.yaml + mods/ra/chrome/lobby-mappreview.yaml mods/ra/chrome/lobby-playerbin.yaml mods/ra/chrome/lobby-dialogs.yaml mods/ts/chrome/color-picker.yaml