remove duplication between CncMapChooserLogic and MapChooserLogic
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -85,7 +85,6 @@
|
||||
<Compile Include="Widgets\Logic\CncInstallFromCDLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncInstallLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncLobbyLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncMapChooserLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncMenuLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncModBrowserLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncMusicPlayerLogic.cs" />
|
||||
@@ -139,4 +138,4 @@
|
||||
copy "$(TargetPath)" "$(SolutionDir)mods/cnc/"
|
||||
cd "$(SolutionDir)"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -151,7 +151,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
return sc;
|
||||
};
|
||||
|
||||
CountryNames = Rules.Info["world"].Traits.WithInterface<OpenRA.Traits.CountryInfo>()
|
||||
CountryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
|
||||
.ToDictionary(a => a.Race, a => a.Name);
|
||||
CountryNames.Add("random", "Any");
|
||||
|
||||
|
||||
@@ -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<Map> onSelect)
|
||||
{
|
||||
map = Game.modData.AvailableMaps[ WidgetUtils.ChooseInitialMap(initialMap) ];
|
||||
|
||||
var panel = widget.GetWidget("MAPCHOOSER_PANEL");
|
||||
|
||||
panel.GetWidget<MapPreviewWidget>("MAP_PREVIEW").Map = () => map;
|
||||
panel.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => map.Title;
|
||||
panel.GetWidget<LabelWidget>("CURMAP_AUTHOR").GetText = () => map.Author;
|
||||
panel.GetWidget<LabelWidget>("CURMAP_DESC").GetText = () => map.Description;
|
||||
panel.GetWidget<LabelWidget>("CURMAP_DESC_LABEL").IsVisible = () => map.Description != null;
|
||||
panel.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => "{0}x{1}".F(map.Bounds.Width, map.Bounds.Height);
|
||||
panel.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => Rules.TileSets[map.Tileset].Name;
|
||||
panel.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => map.PlayerCount.ToString();
|
||||
|
||||
panel.GetWidget<ButtonWidget>("BUTTON_OK").OnClick = () => { Widget.CloseWindow(); onSelect(map); };
|
||||
panel.GetWidget<ButtonWidget>("BUTTON_CANCEL").OnClick = () => { Widget.CloseWindow(); onExit(); };
|
||||
|
||||
scrollpanel = panel.GetWidget<ScrollPanelWidget>("MAP_LIST");
|
||||
itemTemplate = scrollpanel.GetWidget<ScrollItemWidget>("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<LabelWidget>("TITLE").GetText = () => m.Title;
|
||||
item.GetWidget<LabelWidget>("PLAYERS").GetText = () => "{0}".F(m.PlayerCount);
|
||||
item.GetWidget<LabelWidget>("TYPE").GetText = () => m.Type;
|
||||
scrollpanel.AddChild(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,17 +93,25 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
return sc;
|
||||
};
|
||||
|
||||
CountryNames = Rules.Info["world"].Traits.WithInterface<OpenRA.Traits.CountryInfo>()
|
||||
CountryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
|
||||
.ToDictionary(a => a.Race, a => a.Name);
|
||||
CountryNames.Add("random", "Random");
|
||||
|
||||
var mapButton = lobby.GetWidget<ButtonWidget>("CHANGEMAP_BUTTON");
|
||||
mapButton.OnClick = () =>
|
||||
{
|
||||
var onSelect = new Action<Map>(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 }
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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<Map> 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<MapPreviewWidget>("MAP_PREVIEW").Map = () => Map;
|
||||
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => Map.Title;
|
||||
bg.GetWidget<LabelWidget>("CURMAP_AUTHOR").GetText = () => Map.Author;
|
||||
bg.GetWidget<LabelWidget>("CURMAP_DESC").GetText = () => Map.Description;
|
||||
bg.GetWidget<LabelWidget>("CURMAP_DESC_LABEL").IsVisible = () => Map.Description != null;
|
||||
bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => "{0}x{1}".F(Map.Bounds.Width, Map.Bounds.Height);
|
||||
bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => Rules.TileSets[Map.Tileset].Name;
|
||||
bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => Map.PlayerCount.ToString();
|
||||
widget.GetWidget<MapPreviewWidget>("MAP_PREVIEW").Map = () => map;
|
||||
widget.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => map.Title;
|
||||
widget.GetWidget<LabelWidget>("CURMAP_AUTHOR").GetText = () => map.Author;
|
||||
widget.GetWidget<LabelWidget>("CURMAP_DESC").GetText = () => map.Description;
|
||||
widget.GetWidget<LabelWidget>("CURMAP_DESC_LABEL").IsVisible = () => map.Description != null;
|
||||
widget.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => "{0}x{1}".F(map.Bounds.Width, map.Bounds.Height);
|
||||
widget.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => Rules.TileSets[map.Tileset].Name;
|
||||
widget.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => map.PlayerCount.ToString();
|
||||
|
||||
bg.GetWidget<ButtonWidget>("BUTTON_OK").OnClick = () =>
|
||||
{
|
||||
orderManager.IssueOrder(Order.Command("map " + Map.Uid));
|
||||
Widget.CloseWindow();
|
||||
};
|
||||
widget.GetWidget<ButtonWidget>("BUTTON_OK").OnClick = () => { Widget.CloseWindow(); onSelect(map); };
|
||||
widget.GetWidget<ButtonWidget>("BUTTON_CANCEL").OnClick = () => { Widget.CloseWindow(); onExit(); };
|
||||
|
||||
bg.GetWidget<ButtonWidget>("BUTTON_CANCEL").OnClick = () => Widget.CloseWindow();
|
||||
|
||||
scrollpanel = bg.GetWidget<ScrollPanelWidget>("MAP_LIST");
|
||||
scrollpanel = widget.GetWidget<ScrollPanelWidget>("MAP_LIST");
|
||||
itemTemplate = scrollpanel.GetWidget<ScrollItemWidget>("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<LabelWidget>("TITLE").GetText = () => map.Title;
|
||||
item.GetWidget<LabelWidget>("PLAYERS").GetText = () => "{0}".F(map.PlayerCount);
|
||||
item.GetWidget<LabelWidget>("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<LabelWidget>("TITLE").GetText = () => m.Title;
|
||||
item.GetWidget<LabelWidget>("PLAYERS").GetText = () => "{0}".F(m.PlayerCount);
|
||||
item.GetWidget<LabelWidget>("TYPE").GetText = () => m.Type;
|
||||
scrollpanel.AddChild(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
Text:Ok
|
||||
|
||||
Reference in New Issue
Block a user