Replace map type with a category list.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
@@ -28,8 +29,8 @@ namespace OpenRA.Mods.Common.Lint
|
||||
if (map.Title == null)
|
||||
emitError("Map does not define a valid title.");
|
||||
|
||||
if (map.Type == null)
|
||||
emitError("Map does not define a valid type.");
|
||||
if (!map.Categories.Any())
|
||||
emitError("Map does not define any categories.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -994,6 +994,14 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
yaml.Nodes.Add(new MiniYamlNode("LockPreview", new MiniYaml("True")));
|
||||
}
|
||||
|
||||
// Format 10 -> 11 replaced the single map type field with a list of categories
|
||||
if (mapFormat < 11)
|
||||
{
|
||||
var type = yaml.Nodes.First(n => n.Key == "Type");
|
||||
yaml.Nodes.Add(new MiniYamlNode("Categories", type.Value));
|
||||
yaml.Nodes.Remove(type);
|
||||
}
|
||||
|
||||
if (mapFormat < Map.SupportedMapFormat)
|
||||
{
|
||||
yaml.Nodes.First(n => n.Key == "MapFormat").Value = new MiniYaml(Map.SupportedMapFormat.ToString());
|
||||
|
||||
@@ -96,12 +96,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var titleText = widget.Get<LabelWidget>("TITLE");
|
||||
var titleTextNoTabs = widget.GetOrNull<LabelWidget>("TITLE_NO_TABS");
|
||||
|
||||
var mapTitle = world.Map.Title;
|
||||
var firstCategory = world.Map.Categories.FirstOrDefault();
|
||||
if (firstCategory != null)
|
||||
mapTitle = firstCategory + ": " + mapTitle;
|
||||
|
||||
titleText.IsVisible = () => numTabs > 1 || (numTabs == 1 && titleTextNoTabs == null);
|
||||
titleText.GetText = () => string.Concat(world.Map.Type, ": ", world.Map.Title);
|
||||
titleText.GetText = () => mapTitle;
|
||||
if (titleTextNoTabs != null)
|
||||
{
|
||||
titleTextNoTabs.IsVisible = () => numTabs == 1;
|
||||
titleTextNoTabs.GetText = () => string.Concat(world.Map.Type, ": ", world.Map.Title);
|
||||
titleTextNoTabs.GetText = () => mapTitle;
|
||||
}
|
||||
|
||||
var bg = widget.Get<BackgroundWidget>("BACKGROUND");
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
@@ -43,7 +44,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
var typeLabel = available.GetOrNull<LabelWidget>("MAP_TYPE");
|
||||
if (typeLabel != null)
|
||||
typeLabel.GetText = () => lobby.Map.Type;
|
||||
{
|
||||
var type = new CachedTransform<MapPreview, string>(m => lobby.Map.Categories.FirstOrDefault() ?? "");
|
||||
typeLabel.GetText = () => type.Update(lobby.Map);
|
||||
}
|
||||
|
||||
var authorLabel = available.GetOrNull<LabelWidget>("MAP_AUTHOR");
|
||||
if (authorLabel != null)
|
||||
@@ -65,13 +69,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
preview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint(orderManager, preview, lobby.Map, mi);
|
||||
preview.SpawnOccupants = () => LobbyUtils.GetSpawnOccupants(orderManager.LobbyInfo, lobby.Map);
|
||||
|
||||
var title = invalid.GetOrNull<LabelWidget>("MAP_TITLE");
|
||||
if (title != null)
|
||||
title.GetText = () => lobby.Map.Title;
|
||||
var titleLabel = invalid.GetOrNull<LabelWidget>("MAP_TITLE");
|
||||
if (titleLabel != null)
|
||||
titleLabel.GetText = () => lobby.Map.Title;
|
||||
|
||||
var type = invalid.GetOrNull<LabelWidget>("MAP_TYPE");
|
||||
if (type != null)
|
||||
type.GetText = () => lobby.Map.Type;
|
||||
var typeLabel = invalid.GetOrNull<LabelWidget>("MAP_TYPE");
|
||||
if (typeLabel != null)
|
||||
{
|
||||
var type = new CachedTransform<MapPreview, string>(m => lobby.Map.Categories.FirstOrDefault() ?? "");
|
||||
typeLabel.GetText = () => type.Update(lobby.Map);
|
||||
}
|
||||
}
|
||||
|
||||
var download = widget.GetOrNull("MAP_DOWNLOADABLE");
|
||||
@@ -84,17 +91,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
preview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint(orderManager, preview, lobby.Map, mi);
|
||||
preview.SpawnOccupants = () => LobbyUtils.GetSpawnOccupants(orderManager.LobbyInfo, lobby.Map);
|
||||
|
||||
var title = download.GetOrNull<LabelWidget>("MAP_TITLE");
|
||||
if (title != null)
|
||||
title.GetText = () => lobby.Map.Title;
|
||||
var titleLabel = download.GetOrNull<LabelWidget>("MAP_TITLE");
|
||||
if (titleLabel != null)
|
||||
titleLabel.GetText = () => lobby.Map.Title;
|
||||
|
||||
var type = download.GetOrNull<LabelWidget>("MAP_TYPE");
|
||||
if (type != null)
|
||||
type.GetText = () => lobby.Map.Type;
|
||||
var typeLabel = download.GetOrNull<LabelWidget>("MAP_TYPE");
|
||||
if (typeLabel != null)
|
||||
{
|
||||
var type = new CachedTransform<MapPreview, string>(m => lobby.Map.Categories.FirstOrDefault() ?? "");
|
||||
typeLabel.GetText = () => type.Update(lobby.Map);
|
||||
}
|
||||
|
||||
var author = download.GetOrNull<LabelWidget>("MAP_AUTHOR");
|
||||
if (author != null)
|
||||
author.GetText = () => "Created by {0}".F(lobby.Map.Author);
|
||||
var authorLabel = download.GetOrNull<LabelWidget>("MAP_AUTHOR");
|
||||
if (authorLabel != null)
|
||||
authorLabel.GetText = () => "Created by {0}".F(lobby.Map.Author);
|
||||
|
||||
var install = download.GetOrNull<ButtonWidget>("MAP_INSTALL");
|
||||
if (install != null)
|
||||
@@ -116,13 +126,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
preview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint(orderManager, preview, lobby.Map, mi);
|
||||
preview.SpawnOccupants = () => LobbyUtils.GetSpawnOccupants(orderManager.LobbyInfo, lobby.Map);
|
||||
|
||||
var title = progress.GetOrNull<LabelWidget>("MAP_TITLE");
|
||||
if (title != null)
|
||||
title.GetText = () => lobby.Map.Title;
|
||||
var titleLabel = progress.GetOrNull<LabelWidget>("MAP_TITLE");
|
||||
if (titleLabel != null)
|
||||
titleLabel.GetText = () => lobby.Map.Title;
|
||||
|
||||
var type = progress.GetOrNull<LabelWidget>("MAP_TYPE");
|
||||
if (type != null)
|
||||
type.GetText = () => lobby.Map.Type;
|
||||
var typeLabel = progress.GetOrNull<LabelWidget>("MAP_TYPE");
|
||||
if (typeLabel != null)
|
||||
if (typeLabel != null)
|
||||
{
|
||||
var type = new CachedTransform<MapPreview, string>(m => lobby.Map.Categories.FirstOrDefault() ?? "");
|
||||
typeLabel.GetText = () => type.Update(lobby.Map);
|
||||
}
|
||||
|
||||
var statusSearching = progress.GetOrNull("MAP_STATUS_SEARCHING");
|
||||
if (statusSearching != null)
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
string selectedUid;
|
||||
Action<string> onSelect;
|
||||
|
||||
string gameMode;
|
||||
string category;
|
||||
string mapFilter;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
@@ -170,30 +170,43 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
if (gameModeDropdown != null)
|
||||
{
|
||||
var gameModes = tabMaps[tab]
|
||||
.GroupBy(m => m.Type)
|
||||
.Select(g => Pair.New(g.Key, g.Count())).ToList();
|
||||
var categoryDict = new Dictionary<string, int>();
|
||||
foreach (var map in tabMaps[tab])
|
||||
{
|
||||
foreach (var category in map.Categories)
|
||||
{
|
||||
var count = 0;
|
||||
categoryDict.TryGetValue(category, out count);
|
||||
categoryDict[category] = count + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Order categories alphabetically
|
||||
var categories = categoryDict
|
||||
.Select(kv => Pair.New(kv.Key, kv.Value))
|
||||
.OrderBy(p => p.First)
|
||||
.ToList();
|
||||
|
||||
// 'all game types' extra item
|
||||
gameModes.Insert(0, Pair.New(null as string, tabMaps[tab].Count()));
|
||||
categories.Insert(0, Pair.New(null as string, tabMaps[tab].Count()));
|
||||
|
||||
Func<Pair<string, int>, string> showItem = x => "{0} ({1})".F(x.First ?? "All Game Types", x.Second);
|
||||
Func<Pair<string, int>, string> showItem = x => "{0} ({1})".F(x.First ?? "All Maps", x.Second);
|
||||
|
||||
Func<Pair<string, int>, ScrollItemWidget, ScrollItemWidget> setupItem = (ii, template) =>
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(template,
|
||||
() => gameMode == ii.First,
|
||||
() => { gameMode = ii.First; EnumerateMaps(tab, itemTemplate); });
|
||||
() => category == ii.First,
|
||||
() => { category = ii.First; EnumerateMaps(tab, itemTemplate); });
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => showItem(ii);
|
||||
return item;
|
||||
};
|
||||
|
||||
gameModeDropdown.OnClick = () =>
|
||||
gameModeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, gameModes, setupItem);
|
||||
gameModeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, categories, setupItem);
|
||||
|
||||
gameModeDropdown.GetText = () =>
|
||||
{
|
||||
var item = gameModes.FirstOrDefault(m => m.First == gameMode);
|
||||
var item = categories.FirstOrDefault(m => m.First == category);
|
||||
if (item == default(Pair<string, int>))
|
||||
item.First = "No matches";
|
||||
|
||||
@@ -209,7 +222,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
playerCountFilter = -1;
|
||||
|
||||
var maps = tabMaps[tab]
|
||||
.Where(m => gameMode == null || m.Type == gameMode)
|
||||
.Where(m => category == null || m.Categories.Contains(category))
|
||||
.Where(m => mapFilter == null ||
|
||||
(m.Title != null && m.Title.IndexOf(mapFilter, StringComparison.OrdinalIgnoreCase) >= 0) ||
|
||||
(m.Author != null && m.Author.IndexOf(mapFilter, StringComparison.OrdinalIgnoreCase) >= 0) ||
|
||||
@@ -251,7 +264,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
var detailsWidget = item.GetOrNull<LabelWidget>("DETAILS");
|
||||
if (detailsWidget != null)
|
||||
detailsWidget.GetText = () => "{0} ({1} players)".F(preview.Type, preview.PlayerCount);
|
||||
{
|
||||
var type = preview.Categories.FirstOrDefault();
|
||||
var details = "";
|
||||
if (type != null)
|
||||
details = type + " ";
|
||||
|
||||
details += "({0} players)".F(preview.PlayerCount);
|
||||
detailsWidget.GetText = () => details;
|
||||
}
|
||||
|
||||
var authorWidget = item.GetOrNull<LabelWidget>("AUTHOR");
|
||||
if (authorWidget != null)
|
||||
|
||||
@@ -83,7 +83,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
var type = panel.GetOrNull<LabelWidget>("MAP_TYPE");
|
||||
if (type != null)
|
||||
type.GetText = () => selectedReplay.GameInfo.MapPreview.Type;
|
||||
{
|
||||
var mapType = new CachedTransform<MapPreview, string>(m => m.Categories.FirstOrDefault() ?? "");
|
||||
type.GetText = () => mapType.Update(selectedReplay.GameInfo.MapPreview);
|
||||
}
|
||||
|
||||
panel.Get<LabelWidget>("DURATION").GetText = () => WidgetUtils.FormatTimeSeconds((int)selectedReplay.GameInfo.Duration.TotalSeconds);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user