#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.IO; 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[ CncWidgetUtils.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); } } } }