Convert RA mapchooser to use a grid of minimap images

This commit is contained in:
Chris Forbes
2011-10-08 18:48:52 +13:00
parent 957c1cc74c
commit a193eeb202
6 changed files with 96 additions and 176 deletions

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
public class MapChooserLogic
{
Map map;
Widget scrollpanel;
ScrollPanelWidget scrollpanel;
ScrollItemWidget itemTemplate;
string gameMode;
@@ -30,14 +30,20 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
map = Game.modData.AvailableMaps[WidgetUtils.ChooseInitialMap(initialMap)];
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();
var mapPreview = widget.GetWidget<MapPreviewWidget>("MAP_PREVIEW");
if (mapPreview != null)
mapPreview.Map = () => map;
if (WidgetUtils.ActiveModTitle() != "Red Alert") // hack
{
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();
}
widget.GetWidget<ButtonWidget>("BUTTON_OK").OnClick = () => { Widget.CloseWindow(); onSelect(map); };
widget.GetWidget<ButtonWidget>("BUTTON_CANCEL").OnClick = () => { Widget.CloseWindow(); onExit(); };
@@ -80,7 +86,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
void EnumerateMaps()
{
scrollpanel.RemoveChildren();
(scrollpanel as ScrollPanelWidget).ScrollToTop();
// hack for RA's new 2d mapchooser
if (WidgetUtils.ActiveModTitle() == "Red Alert")
scrollpanel.Layout = new GridLayout(scrollpanel);
scrollpanel.ScrollToTop();
var maps = Game.modData.AvailableMaps
.Where(kv => kv.Value.Selectable)
@@ -94,17 +105,32 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var item = ScrollItemWidget.Setup(itemTemplate, () => m == map, () => map = m);
var titleLabel = item.GetWidget<LabelWidget>("TITLE");
titleLabel.GetText = () => m.Title;
var playersLabel = item.GetWidget<LabelWidget>("PLAYERS");
if (playersLabel != null)
{
playersLabel.GetText = () => "{0}".F(m.PlayerCount);
titleLabel.GetText = () => m.Title;
}
else
titleLabel.GetText = () => "{0} ({1})".F(m.Title, m.PlayerCount);
item.GetWidget<LabelWidget>("TYPE").GetText = () => m.Type;
var previewWidget = item.GetWidget<MapPreviewWidget>("PREVIEW");
if (previewWidget != null)
{
previewWidget.IgnoreMouseOver = true;
previewWidget.IgnoreMouseInput = true;
previewWidget.Map = () => m;
}
var typeWidget = item.GetWidget<LabelWidget>("TYPE");
if (typeWidget != null)
typeWidget.GetText = () => m.Type;
var detailsWidget = item.GetWidget<LabelWidget>("DETAILS");
if (detailsWidget != null)
detailsWidget.GetText = () => "{0} ({1})".F(m.Type, m.PlayerCount);
var authorWidget = item.GetWidget<LabelWidget>("AUTHOR");
if (authorWidget != null)
authorWidget.GetText = () => m.Author;
scrollpanel.AddChild(item);
}
}