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">
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -85,7 +85,6 @@
|
|||||||
<Compile Include="Widgets\Logic\CncInstallFromCDLogic.cs" />
|
<Compile Include="Widgets\Logic\CncInstallFromCDLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\CncInstallLogic.cs" />
|
<Compile Include="Widgets\Logic\CncInstallLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\CncLobbyLogic.cs" />
|
<Compile Include="Widgets\Logic\CncLobbyLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\CncMapChooserLogic.cs" />
|
|
||||||
<Compile Include="Widgets\Logic\CncMenuLogic.cs" />
|
<Compile Include="Widgets\Logic\CncMenuLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\CncModBrowserLogic.cs" />
|
<Compile Include="Widgets\Logic\CncModBrowserLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\CncMusicPlayerLogic.cs" />
|
<Compile Include="Widgets\Logic\CncMusicPlayerLogic.cs" />
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
return sc;
|
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);
|
.ToDictionary(a => a.Race, a => a.Name);
|
||||||
CountryNames.Add("random", "Any");
|
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;
|
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);
|
.ToDictionary(a => a.Race, a => a.Name);
|
||||||
CountryNames.Add("random", "Random");
|
CountryNames.Add("random", "Random");
|
||||||
|
|
||||||
var mapButton = lobby.GetWidget<ButtonWidget>("CHANGEMAP_BUTTON");
|
var mapButton = lobby.GetWidget<ButtonWidget>("CHANGEMAP_BUTTON");
|
||||||
mapButton.OnClick = () =>
|
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()
|
Widget.OpenWindow("MAP_CHOOSER", new WidgetArgs()
|
||||||
{
|
{
|
||||||
{ "orderManager", orderManager },
|
{ "initialMap", MapUid },
|
||||||
{ "mapName", MapUid }
|
{ "onExit", () => {} },
|
||||||
|
{ "onSelect", onSelect }
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -8,47 +8,39 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Network;
|
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||||
{
|
{
|
||||||
public class MapChooserLogic
|
public class MapChooserLogic
|
||||||
{
|
{
|
||||||
Map Map = null;
|
Map map;
|
||||||
Widget scrollpanel;
|
Widget scrollpanel;
|
||||||
ScrollItemWidget itemTemplate;
|
ScrollItemWidget itemTemplate;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
internal MapChooserLogic(
|
internal MapChooserLogic([ObjectCreator.Param] Widget widget,
|
||||||
[ObjectCreator.Param( "widget" )] Widget bg,
|
[ObjectCreator.Param] string initialMap,
|
||||||
[ObjectCreator.Param] OrderManager orderManager,
|
[ObjectCreator.Param] Action onExit,
|
||||||
[ObjectCreator.Param] string mapName )
|
[ObjectCreator.Param] Action<Map> onSelect)
|
||||||
{
|
{
|
||||||
if (mapName != null)
|
map = Game.modData.AvailableMaps[WidgetUtils.ChooseInitialMap(initialMap)];
|
||||||
Map = Game.modData.AvailableMaps[mapName];
|
|
||||||
else
|
|
||||||
Map = Game.modData.AvailableMaps.FirstOrDefault(m => m.Value.Selectable).Value;
|
|
||||||
|
|
||||||
bg.GetWidget<MapPreviewWidget>("MAP_PREVIEW").Map = () => Map;
|
widget.GetWidget<MapPreviewWidget>("MAP_PREVIEW").Map = () => map;
|
||||||
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => Map.Title;
|
widget.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => map.Title;
|
||||||
bg.GetWidget<LabelWidget>("CURMAP_AUTHOR").GetText = () => Map.Author;
|
widget.GetWidget<LabelWidget>("CURMAP_AUTHOR").GetText = () => map.Author;
|
||||||
bg.GetWidget<LabelWidget>("CURMAP_DESC").GetText = () => Map.Description;
|
widget.GetWidget<LabelWidget>("CURMAP_DESC").GetText = () => map.Description;
|
||||||
bg.GetWidget<LabelWidget>("CURMAP_DESC_LABEL").IsVisible = () => Map.Description != null;
|
widget.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);
|
widget.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;
|
widget.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => Rules.TileSets[map.Tileset].Name;
|
||||||
bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => Map.PlayerCount.ToString();
|
widget.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => map.PlayerCount.ToString();
|
||||||
|
|
||||||
bg.GetWidget<ButtonWidget>("BUTTON_OK").OnClick = () =>
|
widget.GetWidget<ButtonWidget>("BUTTON_OK").OnClick = () => { Widget.CloseWindow(); onSelect(map); };
|
||||||
{
|
widget.GetWidget<ButtonWidget>("BUTTON_CANCEL").OnClick = () => { Widget.CloseWindow(); onExit(); };
|
||||||
orderManager.IssueOrder(Order.Command("map " + Map.Uid));
|
|
||||||
Widget.CloseWindow();
|
|
||||||
};
|
|
||||||
|
|
||||||
bg.GetWidget<ButtonWidget>("BUTTON_CANCEL").OnClick = () => Widget.CloseWindow();
|
scrollpanel = widget.GetWidget<ScrollPanelWidget>("MAP_LIST");
|
||||||
|
|
||||||
scrollpanel = bg.GetWidget<ScrollPanelWidget>("MAP_LIST");
|
|
||||||
itemTemplate = scrollpanel.GetWidget<ScrollItemWidget>("MAP_TEMPLATE");
|
itemTemplate = scrollpanel.GetWidget<ScrollItemWidget>("MAP_TEMPLATE");
|
||||||
EnumerateMaps();
|
EnumerateMaps();
|
||||||
}
|
}
|
||||||
@@ -56,16 +48,19 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
void EnumerateMaps()
|
void EnumerateMaps()
|
||||||
{
|
{
|
||||||
scrollpanel.RemoveChildren();
|
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);
|
var maps = Game.modData.AvailableMaps
|
||||||
item.GetWidget<LabelWidget>("TITLE").GetText = () => map.Title;
|
.Where(kv => kv.Value.Selectable)
|
||||||
item.GetWidget<LabelWidget>("PLAYERS").GetText = () => "{0}".F(map.PlayerCount);
|
.OrderBy(kv => kv.Value.PlayerCount)
|
||||||
item.GetWidget<LabelWidget>("TYPE").GetText = () => map.Type;
|
.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);
|
scrollpanel.AddChild(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Container@MAPCHOOSER_PANEL:
|
Container@MAPCHOOSER_PANEL:
|
||||||
Id:MAPCHOOSER_PANEL
|
Id:MAPCHOOSER_PANEL
|
||||||
Logic:CncMapChooserLogic
|
Logic:MapChooserLogic
|
||||||
X:(WINDOW_RIGHT - WIDTH)/2
|
X:(WINDOW_RIGHT - WIDTH)/2
|
||||||
Y:(WINDOW_BOTTOM - 500)/2
|
Y:(WINDOW_BOTTOM - 500)/2
|
||||||
Width:740
|
Width:740
|
||||||
|
|||||||
Reference in New Issue
Block a user