diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index b171b7ac55..982507eeb7 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -1,4 +1,4 @@ - + Debug @@ -85,7 +85,6 @@ - @@ -139,4 +138,4 @@ copy "$(TargetPath)" "$(SolutionDir)mods/cnc/" cd "$(SolutionDir)" - + \ No newline at end of file diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs index 2a08a9c179..e33ee65353 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs @@ -151,7 +151,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic return sc; }; - CountryNames = Rules.Info["world"].Traits.WithInterface() + CountryNames = Rules.Info["world"].Traits.WithInterface() .ToDictionary(a => a.Race, a => a.Name); CountryNames.Add("random", "Any"); diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncMapChooserLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncMapChooserLogic.cs deleted file mode 100644 index fa300b5fb4..0000000000 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncMapChooserLogic.cs +++ /dev/null @@ -1,70 +0,0 @@ -#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.Linq; -using OpenRA.Widgets; - -namespace OpenRA.Mods.Cnc.Widgets.Logic -{ - public class CncMapChooserLogic - { - Map map; - Widget scrollpanel; - ScrollItemWidget itemTemplate; - - [ObjectCreator.UseCtor] - internal CncMapChooserLogic([ObjectCreator.Param] Widget widget, - [ObjectCreator.Param] string initialMap, - [ObjectCreator.Param] Action onExit, - [ObjectCreator.Param] Action onSelect) - { - map = Game.modData.AvailableMaps[ WidgetUtils.ChooseInitialMap(initialMap) ]; - - var panel = widget.GetWidget("MAPCHOOSER_PANEL"); - - panel.GetWidget("MAP_PREVIEW").Map = () => map; - panel.GetWidget("CURMAP_TITLE").GetText = () => map.Title; - panel.GetWidget("CURMAP_AUTHOR").GetText = () => map.Author; - panel.GetWidget("CURMAP_DESC").GetText = () => map.Description; - panel.GetWidget("CURMAP_DESC_LABEL").IsVisible = () => map.Description != null; - panel.GetWidget("CURMAP_SIZE").GetText = () => "{0}x{1}".F(map.Bounds.Width, map.Bounds.Height); - panel.GetWidget("CURMAP_THEATER").GetText = () => Rules.TileSets[map.Tileset].Name; - panel.GetWidget("CURMAP_PLAYERS").GetText = () => map.PlayerCount.ToString(); - - panel.GetWidget("BUTTON_OK").OnClick = () => { Widget.CloseWindow(); onSelect(map); }; - panel.GetWidget("BUTTON_CANCEL").OnClick = () => { Widget.CloseWindow(); onExit(); }; - - scrollpanel = panel.GetWidget("MAP_LIST"); - itemTemplate = scrollpanel.GetWidget("MAP_TEMPLATE"); - EnumerateMaps(); - } - - void EnumerateMaps() - { - scrollpanel.RemoveChildren(); - - var maps = Game.modData.AvailableMaps - .Where( kv => kv.Value.Selectable ) - .OrderBy( kv => kv.Value.PlayerCount ) - .ThenBy( kv => kv.Value.Title ); - - foreach (var kv in maps) - { - var m = kv.Value; - var item = ScrollItemWidget.Setup(itemTemplate, () => m == map, () => map = m); - item.GetWidget("TITLE").GetText = () => m.Title; - item.GetWidget("PLAYERS").GetText = () => "{0}".F(m.PlayerCount); - item.GetWidget("TYPE").GetText = () => m.Type; - scrollpanel.AddChild(item); - } - } - } -} diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 475284a954..aa57ac454b 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -93,17 +93,25 @@ namespace OpenRA.Mods.RA.Widgets.Logic return sc; }; - CountryNames = Rules.Info["world"].Traits.WithInterface() + CountryNames = Rules.Info["world"].Traits.WithInterface() .ToDictionary(a => a.Race, a => a.Name); CountryNames.Add("random", "Random"); var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON"); mapButton.OnClick = () => { + var onSelect = new Action(m => + { + orderManager.IssueOrder(Order.Command("map " + m.Uid)); + Game.Settings.Server.Map = m.Uid; + Game.Settings.Save(); + }); + Widget.OpenWindow("MAP_CHOOSER", new WidgetArgs() { - { "orderManager", orderManager }, - { "mapName", MapUid } + { "initialMap", MapUid }, + { "onExit", () => {} }, + { "onSelect", onSelect } }); }; diff --git a/OpenRA.Mods.RA/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/MapChooserLogic.cs index 5492280d71..8433f8136a 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/MapChooserLogic.cs @@ -8,47 +8,39 @@ */ #endregion +using System; using System.Linq; -using OpenRA.Network; using OpenRA.Widgets; namespace OpenRA.Mods.RA.Widgets.Logic { public class MapChooserLogic { - Map Map = null; + Map map; Widget scrollpanel; ScrollItemWidget itemTemplate; [ObjectCreator.UseCtor] - internal MapChooserLogic( - [ObjectCreator.Param( "widget" )] Widget bg, - [ObjectCreator.Param] OrderManager orderManager, - [ObjectCreator.Param] string mapName ) + internal MapChooserLogic([ObjectCreator.Param] Widget widget, + [ObjectCreator.Param] string initialMap, + [ObjectCreator.Param] Action onExit, + [ObjectCreator.Param] Action onSelect) { - if (mapName != null) - Map = Game.modData.AvailableMaps[mapName]; - else - Map = Game.modData.AvailableMaps.FirstOrDefault(m => m.Value.Selectable).Value; + map = Game.modData.AvailableMaps[WidgetUtils.ChooseInitialMap(initialMap)]; - bg.GetWidget("MAP_PREVIEW").Map = () => Map; - bg.GetWidget("CURMAP_TITLE").GetText = () => Map.Title; - bg.GetWidget("CURMAP_AUTHOR").GetText = () => Map.Author; - bg.GetWidget("CURMAP_DESC").GetText = () => Map.Description; - bg.GetWidget("CURMAP_DESC_LABEL").IsVisible = () => Map.Description != null; - bg.GetWidget("CURMAP_SIZE").GetText = () => "{0}x{1}".F(Map.Bounds.Width, Map.Bounds.Height); - bg.GetWidget("CURMAP_THEATER").GetText = () => Rules.TileSets[Map.Tileset].Name; - bg.GetWidget("CURMAP_PLAYERS").GetText = () => Map.PlayerCount.ToString(); + widget.GetWidget("MAP_PREVIEW").Map = () => map; + widget.GetWidget("CURMAP_TITLE").GetText = () => map.Title; + widget.GetWidget("CURMAP_AUTHOR").GetText = () => map.Author; + widget.GetWidget("CURMAP_DESC").GetText = () => map.Description; + widget.GetWidget("CURMAP_DESC_LABEL").IsVisible = () => map.Description != null; + widget.GetWidget("CURMAP_SIZE").GetText = () => "{0}x{1}".F(map.Bounds.Width, map.Bounds.Height); + widget.GetWidget("CURMAP_THEATER").GetText = () => Rules.TileSets[map.Tileset].Name; + widget.GetWidget("CURMAP_PLAYERS").GetText = () => map.PlayerCount.ToString(); - bg.GetWidget("BUTTON_OK").OnClick = () => - { - orderManager.IssueOrder(Order.Command("map " + Map.Uid)); - Widget.CloseWindow(); - }; + widget.GetWidget("BUTTON_OK").OnClick = () => { Widget.CloseWindow(); onSelect(map); }; + widget.GetWidget("BUTTON_CANCEL").OnClick = () => { Widget.CloseWindow(); onExit(); }; - bg.GetWidget("BUTTON_CANCEL").OnClick = () => Widget.CloseWindow(); - - scrollpanel = bg.GetWidget("MAP_LIST"); + scrollpanel = widget.GetWidget("MAP_LIST"); itemTemplate = scrollpanel.GetWidget("MAP_TEMPLATE"); EnumerateMaps(); } @@ -56,16 +48,19 @@ namespace OpenRA.Mods.RA.Widgets.Logic void EnumerateMaps() { scrollpanel.RemoveChildren(); - foreach (var kv in Game.modData.AvailableMaps.OrderBy(kv => kv.Value.PlayerCount).ThenBy(kv => kv.Value.Title)) - { - var map = kv.Value; - if (!map.Selectable) - continue; - var item = ScrollItemWidget.Setup(itemTemplate, () => Map == map, () => Map = map); - item.GetWidget("TITLE").GetText = () => map.Title; - item.GetWidget("PLAYERS").GetText = () => "{0}".F(map.PlayerCount); - item.GetWidget("TYPE").GetText = () => map.Type; + var maps = Game.modData.AvailableMaps + .Where(kv => kv.Value.Selectable) + .OrderBy(kv => kv.Value.PlayerCount) + .ThenBy(kv => kv.Value.Title); + + foreach (var kv in maps) + { + var m = kv.Value; + var item = ScrollItemWidget.Setup(itemTemplate, () => m == map, () => map = m); + item.GetWidget("TITLE").GetText = () => m.Title; + item.GetWidget("PLAYERS").GetText = () => "{0}".F(m.PlayerCount); + item.GetWidget("TYPE").GetText = () => m.Type; scrollpanel.AddChild(item); } } diff --git a/mods/cnc/chrome/mapchooser.yaml b/mods/cnc/chrome/mapchooser.yaml index 20b6642c13..7489276c37 100644 --- a/mods/cnc/chrome/mapchooser.yaml +++ b/mods/cnc/chrome/mapchooser.yaml @@ -1,6 +1,6 @@ Container@MAPCHOOSER_PANEL: Id:MAPCHOOSER_PANEL - Logic:CncMapChooserLogic + Logic:MapChooserLogic X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM - 500)/2 Width:740 @@ -204,4 +204,4 @@ Container@MAPCHOOSER_PANEL: Y:499 Width:140 Height:35 - Text:Ok \ No newline at end of file + Text:Ok