game mode selector in map chooser
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
@@ -43,6 +44,36 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
scrollpanel = widget.GetWidget<ScrollPanelWidget>("MAP_LIST");
|
||||
itemTemplate = scrollpanel.GetWidget<ScrollItemWidget>("MAP_TEMPLATE");
|
||||
|
||||
var gameModeDropdown = widget.GetWidget<DropDownButtonWidget>("GAMEMODE_FILTER");
|
||||
if (gameModeDropdown != null)
|
||||
{
|
||||
var selectableMaps = Game.modData.AvailableMaps.Where(m => m.Value.Selectable);
|
||||
var gameModes = selectableMaps
|
||||
.GroupBy(m => m.Value.Type)
|
||||
.Select(g => Pair.New(g.Key, g.Count())).ToList();
|
||||
|
||||
// 'all game types' extra item
|
||||
gameModes.Insert( 0, Pair.New( null as string, selectableMaps.Count() ) );
|
||||
|
||||
Func<Pair<string,int>, string> showItem =
|
||||
x => "{0} ({1})".F( x.First ?? "All Game Types", x.Second );
|
||||
|
||||
Func<Pair<string,int>, ScrollItemWidget, ScrollItemWidget> setupItem = (ii, template) =>
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(template,
|
||||
() => gameMode == ii.First,
|
||||
() => { gameMode = ii.First; EnumerateMaps(); });
|
||||
item.GetWidget<LabelWidget>("LABEL").GetText = () => showItem(ii);
|
||||
return item;
|
||||
};
|
||||
|
||||
gameModeDropdown.OnClick = () =>
|
||||
gameModeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, gameModes, setupItem);
|
||||
|
||||
gameModeDropdown.GetText = () => showItem(gameModes.First(m => m.First == gameMode));
|
||||
}
|
||||
|
||||
EnumerateMaps();
|
||||
}
|
||||
|
||||
|
||||
@@ -59,17 +59,10 @@ Background@MAP_CHOOSER:
|
||||
Text:Title
|
||||
Align:Center
|
||||
Font:Bold
|
||||
Label@PLAYERS:
|
||||
Text:Players
|
||||
Font:Bold
|
||||
Width:50
|
||||
X:304
|
||||
Height:25
|
||||
Label@TYPE:
|
||||
Text:Type
|
||||
Font:Bold
|
||||
Width:50
|
||||
X:420
|
||||
DropDownButton@GAMEMODE_FILTER:
|
||||
Id:GAMEMODE_FILTER
|
||||
X:300
|
||||
Width:200
|
||||
Height:25
|
||||
Background@MAPCHOOSER_MAP_BG:
|
||||
X:PARENT_RIGHT-268
|
||||
|
||||
Reference in New Issue
Block a user