Convert RA mapchooser to use a grid of minimap images
This commit is contained in:
@@ -188,7 +188,6 @@
|
|||||||
<Compile Include="Widgets\PasswordFieldWidget.cs" />
|
<Compile Include="Widgets\PasswordFieldWidget.cs" />
|
||||||
<Compile Include="Widgets\PerfGraphWidget.cs" />
|
<Compile Include="Widgets\PerfGraphWidget.cs" />
|
||||||
<Compile Include="Widgets\ProgressBarWidget.cs" />
|
<Compile Include="Widgets\ProgressBarWidget.cs" />
|
||||||
<Compile Include="Widgets\ScrollItem.cs" />
|
|
||||||
<Compile Include="Widgets\ScrollPanelWidget.cs" />
|
<Compile Include="Widgets\ScrollPanelWidget.cs" />
|
||||||
<Compile Include="Widgets\ShpImageWidget.cs" />
|
<Compile Include="Widgets\ShpImageWidget.cs" />
|
||||||
<Compile Include="Widgets\SliderWidget.cs" />
|
<Compile Include="Widgets\SliderWidget.cs" />
|
||||||
@@ -202,6 +201,7 @@
|
|||||||
<Compile Include="Widgets\WorldInteractionControllerWidget.cs" />
|
<Compile Include="Widgets\WorldInteractionControllerWidget.cs" />
|
||||||
<Compile Include="World.cs" />
|
<Compile Include="World.cs" />
|
||||||
<Compile Include="WorldUtils.cs" />
|
<Compile Include="WorldUtils.cs" />
|
||||||
|
<Compile Include="Widgets\ScrollItemWidget.cs" />
|
||||||
<Compile Include="Widgets\ListLayout.cs" />
|
<Compile Include="Widgets\ListLayout.cs" />
|
||||||
<Compile Include="Widgets\GridLayout.cs" />
|
<Compile Include="Widgets\GridLayout.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -26,18 +26,18 @@ namespace OpenRA.Widgets
|
|||||||
widget.ContentHeight = widget.ItemSpacing;
|
widget.ContentHeight = widget.ItemSpacing;
|
||||||
pos = new int2(widget.ItemSpacing, widget.ItemSpacing);
|
pos = new int2(widget.ItemSpacing, widget.ItemSpacing);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos.X + widget.ItemSpacing + w.Bounds.Width > widget.Bounds.Width - widget.ScrollbarWidth)
|
if (pos.X + widget.ItemSpacing + w.Bounds.Width > widget.Bounds.Width - widget.ScrollbarWidth)
|
||||||
{
|
{
|
||||||
/* start a new row */
|
/* start a new row */
|
||||||
pos.X = widget.ItemSpacing;
|
pos.X = widget.ItemSpacing;
|
||||||
pos.Y = widget.ContentHeight;
|
pos.Y = widget.ContentHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Bounds.X += pos.X;
|
w.Bounds.X += pos.X;
|
||||||
w.Bounds.Y += pos.Y;
|
w.Bounds.Y += pos.Y;
|
||||||
|
|
||||||
pos.X += widget.Bounds.Width + widget.ItemSpacing;
|
pos.X += w.Bounds.Width + widget.ItemSpacing;
|
||||||
|
|
||||||
widget.ContentHeight = Math.Max(widget.ContentHeight, pos.Y + widget.ItemSpacing + w.Bounds.Height);
|
widget.ContentHeight = Math.Max(widget.ContentHeight, pos.Y + widget.ItemSpacing + w.Bounds.Height);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ namespace OpenRA.Widgets
|
|||||||
public Func<Map> Map = () => null;
|
public Func<Map> Map = () => null;
|
||||||
public Func<Dictionary<int2, Color>> SpawnColors = () => new Dictionary<int2, Color>();
|
public Func<Dictionary<int2, Color>> SpawnColors = () => new Dictionary<int2, Color>();
|
||||||
public Action<MouseInput> OnMouseDown = _ => {};
|
public Action<MouseInput> OnMouseDown = _ => {};
|
||||||
|
public bool IgnoreMouseInput = false;
|
||||||
|
|
||||||
Cache<Map,Bitmap> PreviewCache = new Cache<Map, Bitmap>(stub => Minimap.RenderMapPreview( new Map( stub.Path )));
|
static Cache<Map,Bitmap> PreviewCache = new Cache<Map, Bitmap>(stub => Minimap.RenderMapPreview( new Map( stub.Path )));
|
||||||
|
|
||||||
public MapPreviewWidget() : base() { }
|
public MapPreviewWidget() : base() { }
|
||||||
|
|
||||||
protected MapPreviewWidget(MapPreviewWidget other)
|
protected MapPreviewWidget(MapPreviewWidget other)
|
||||||
: base(other)
|
: base(other)
|
||||||
{
|
{
|
||||||
@@ -32,10 +34,14 @@ namespace OpenRA.Widgets
|
|||||||
Map = other.Map;
|
Map = other.Map;
|
||||||
SpawnColors = other.SpawnColors;
|
SpawnColors = other.SpawnColors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone() { return new MapPreviewWidget(this); }
|
public override Widget Clone() { return new MapPreviewWidget(this); }
|
||||||
|
|
||||||
public override bool HandleMouseInput(MouseInput mi)
|
public override bool HandleMouseInput(MouseInput mi)
|
||||||
{
|
{
|
||||||
|
if (IgnoreMouseInput)
|
||||||
|
return base.HandleMouseInput(mi);
|
||||||
|
|
||||||
if (mi.Event != MouseInputEvent.Down)
|
if (mi.Event != MouseInputEvent.Down)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -70,15 +76,15 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
mapChooserSheet.Texture.SetData( preview );
|
mapChooserSheet.Texture.SetData( preview );
|
||||||
mapChooserSprite = new Sprite( mapChooserSheet, new Rectangle( 0, 0, map.Bounds.Width, map.Bounds.Height ), TextureChannel.Alpha );
|
mapChooserSprite = new Sprite( mapChooserSheet, new Rectangle( 0, 0, map.Bounds.Width, map.Bounds.Height ), TextureChannel.Alpha );
|
||||||
|
|
||||||
// Update map rect
|
|
||||||
PreviewScale = Math.Min(RenderBounds.Width * 1.0f / map.Bounds.Width, RenderBounds.Height * 1.0f / map.Bounds.Height);
|
|
||||||
var size = Math.Max(map.Bounds.Width, map.Bounds.Height);
|
|
||||||
var dw = (int)(PreviewScale * (size - map.Bounds.Width)) / 2;
|
|
||||||
var dh = (int)(PreviewScale * (size - map.Bounds.Height)) / 2;
|
|
||||||
MapRect = new Rectangle(RenderBounds.X + dw, RenderBounds.Y + dh, (int)(map.Bounds.Width * PreviewScale), (int)(map.Bounds.Height * PreviewScale));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update map rect
|
||||||
|
PreviewScale = Math.Min(RenderBounds.Width * 1.0f / map.Bounds.Width, RenderBounds.Height * 1.0f / map.Bounds.Height);
|
||||||
|
var size = Math.Max(map.Bounds.Width, map.Bounds.Height);
|
||||||
|
var dw = (int)(PreviewScale * (size - map.Bounds.Width)) / 2;
|
||||||
|
var dh = (int)(PreviewScale * (size - map.Bounds.Height)) / 2;
|
||||||
|
MapRect = new Rectangle(RenderBounds.X + dw, RenderBounds.Y + dh, (int)(map.Bounds.Width * PreviewScale), (int)(map.Bounds.Height * PreviewScale));
|
||||||
|
|
||||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite( mapChooserSprite,
|
Game.Renderer.RgbaSpriteRenderer.DrawSprite( mapChooserSprite,
|
||||||
new float2(MapRect.Location),
|
new float2(MapRect.Location),
|
||||||
new float2( MapRect.Size ) );
|
new float2( MapRect.Size ) );
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
public class MapChooserLogic
|
public class MapChooserLogic
|
||||||
{
|
{
|
||||||
Map map;
|
Map map;
|
||||||
Widget scrollpanel;
|
ScrollPanelWidget scrollpanel;
|
||||||
ScrollItemWidget itemTemplate;
|
ScrollItemWidget itemTemplate;
|
||||||
string gameMode;
|
string gameMode;
|
||||||
|
|
||||||
@@ -30,14 +30,20 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
{
|
{
|
||||||
map = Game.modData.AvailableMaps[WidgetUtils.ChooseInitialMap(initialMap)];
|
map = Game.modData.AvailableMaps[WidgetUtils.ChooseInitialMap(initialMap)];
|
||||||
|
|
||||||
widget.GetWidget<MapPreviewWidget>("MAP_PREVIEW").Map = () => map;
|
var mapPreview = widget.GetWidget<MapPreviewWidget>("MAP_PREVIEW");
|
||||||
widget.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => map.Title;
|
if (mapPreview != null)
|
||||||
widget.GetWidget<LabelWidget>("CURMAP_AUTHOR").GetText = () => map.Author;
|
mapPreview.Map = () => map;
|
||||||
widget.GetWidget<LabelWidget>("CURMAP_DESC").GetText = () => map.Description;
|
|
||||||
widget.GetWidget<LabelWidget>("CURMAP_DESC_LABEL").IsVisible = () => map.Description != null;
|
if (WidgetUtils.ActiveModTitle() != "Red Alert") // hack
|
||||||
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_TITLE").GetText = () => map.Title;
|
||||||
widget.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => map.PlayerCount.ToString();
|
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_OK").OnClick = () => { Widget.CloseWindow(); onSelect(map); };
|
||||||
widget.GetWidget<ButtonWidget>("BUTTON_CANCEL").OnClick = () => { Widget.CloseWindow(); onExit(); };
|
widget.GetWidget<ButtonWidget>("BUTTON_CANCEL").OnClick = () => { Widget.CloseWindow(); onExit(); };
|
||||||
@@ -80,7 +86,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
void EnumerateMaps()
|
void EnumerateMaps()
|
||||||
{
|
{
|
||||||
scrollpanel.RemoveChildren();
|
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
|
var maps = Game.modData.AvailableMaps
|
||||||
.Where(kv => kv.Value.Selectable)
|
.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 item = ScrollItemWidget.Setup(itemTemplate, () => m == map, () => map = m);
|
||||||
|
|
||||||
var titleLabel = item.GetWidget<LabelWidget>("TITLE");
|
var titleLabel = item.GetWidget<LabelWidget>("TITLE");
|
||||||
|
titleLabel.GetText = () => m.Title;
|
||||||
|
|
||||||
var playersLabel = item.GetWidget<LabelWidget>("PLAYERS");
|
var playersLabel = item.GetWidget<LabelWidget>("PLAYERS");
|
||||||
|
|
||||||
if (playersLabel != null)
|
if (playersLabel != null)
|
||||||
{
|
|
||||||
playersLabel.GetText = () => "{0}".F(m.PlayerCount);
|
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);
|
scrollpanel.AddChild(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,165 +17,53 @@ Background@MAP_CHOOSER:
|
|||||||
ScrollPanel@MAP_LIST:
|
ScrollPanel@MAP_LIST:
|
||||||
Id:MAP_LIST
|
Id:MAP_LIST
|
||||||
X:20
|
X:20
|
||||||
Y:67
|
Y:47
|
||||||
Width:504
|
Width:PARENT_RIGHT - 40
|
||||||
Height:474
|
Height:474
|
||||||
Children:
|
Children:
|
||||||
ScrollItem@MAP_TEMPLATE:
|
ScrollItem@MAP_TEMPLATE:
|
||||||
Id:MAP_TEMPLATE
|
Id:MAP_TEMPLATE
|
||||||
Width:PARENT_RIGHT-27
|
Width:180
|
||||||
Height:25
|
Height:208
|
||||||
X:2
|
X:2
|
||||||
Y:0
|
Y:0
|
||||||
Visible:false
|
Visible:false
|
||||||
Children:
|
Children:
|
||||||
Label@TITLE:
|
Label@TITLE:
|
||||||
X:10
|
X:2
|
||||||
|
Y:PARENT_BOTTOM-47
|
||||||
Id:TITLE
|
Id:TITLE
|
||||||
Width:PARENT_RIGHT-100
|
Width:PARENT_RIGHT-4
|
||||||
Height:25
|
Height:25
|
||||||
Label@TYPE:
|
Align:Center
|
||||||
Id:TYPE
|
Label@DETAILS:
|
||||||
Width:90
|
Id:DETAILS
|
||||||
X:PARENT_RIGHT-100
|
Width:PARENT_RIGHT-4
|
||||||
Align:Right
|
X:2
|
||||||
|
Y:PARENT_BOTTOM-35
|
||||||
|
Align:Center
|
||||||
Height:25
|
Height:25
|
||||||
Container@MAP_LABELS:
|
Font:Tiny
|
||||||
Width:494
|
Label@AUTHOR:
|
||||||
|
Id:AUTHOR
|
||||||
|
Width:PARENT_RIGHT-4
|
||||||
|
X:2
|
||||||
|
Y:PARENT_BOTTOM-26
|
||||||
|
Align:Center
|
||||||
|
Height:25
|
||||||
|
Font:Tiny
|
||||||
|
MapPreview@PREVIEW:
|
||||||
|
Id:PREVIEW
|
||||||
|
X:(PARENT_RIGHT - WIDTH)/2
|
||||||
|
Y:4
|
||||||
|
Width:160
|
||||||
|
Height:160
|
||||||
|
DropDownButton@GAMEMODE_FILTER:
|
||||||
|
Id:GAMEMODE_FILTER
|
||||||
|
X:PARENT_RIGHT - 220
|
||||||
|
Y:17
|
||||||
|
Width:200
|
||||||
Height:25
|
Height:25
|
||||||
X:25
|
|
||||||
Y:40
|
|
||||||
Children:
|
|
||||||
Label@TITLE:
|
|
||||||
Width:125
|
|
||||||
Height:25
|
|
||||||
X:0
|
|
||||||
Y:0
|
|
||||||
Text:Title
|
|
||||||
Align:Center
|
|
||||||
Font:Bold
|
|
||||||
DropDownButton@GAMEMODE_FILTER:
|
|
||||||
Id:GAMEMODE_FILTER
|
|
||||||
X:300
|
|
||||||
Width:200
|
|
||||||
Height:25
|
|
||||||
Background@MAPCHOOSER_MAP_BG:
|
|
||||||
X:PARENT_RIGHT-268
|
|
||||||
Y:50
|
|
||||||
Width:252
|
|
||||||
Height:252
|
|
||||||
Background:dialog3
|
|
||||||
Children:
|
|
||||||
MapPreview@MAP_PREVIEW:
|
|
||||||
Id:MAP_PREVIEW
|
|
||||||
X:4
|
|
||||||
Y:4
|
|
||||||
Width:244
|
|
||||||
Height:244
|
|
||||||
Container@MAP_LABEL_CONTAINER:
|
|
||||||
Width:70
|
|
||||||
Height:200
|
|
||||||
X:PARENT_RIGHT - 255
|
|
||||||
Y:311
|
|
||||||
Children:
|
|
||||||
Label@CURMAP_TITLE_LABEL:
|
|
||||||
Id:CURMAP_TITLE_LABEL
|
|
||||||
X:0
|
|
||||||
Y:0
|
|
||||||
Align:Right
|
|
||||||
Width:70
|
|
||||||
Height:20
|
|
||||||
Text:Title:
|
|
||||||
Font:Bold
|
|
||||||
Label@CURMAP_TITLE:
|
|
||||||
Id:CURMAP_TITLE
|
|
||||||
X:75
|
|
||||||
Y:0
|
|
||||||
Align:Left
|
|
||||||
Width:70
|
|
||||||
Height:20
|
|
||||||
Label@CURMAP_AUTHOR_LABEL:
|
|
||||||
Id:CURMAP_AUTHOR_LABEL
|
|
||||||
X:0
|
|
||||||
Y:20
|
|
||||||
Align:Right
|
|
||||||
Width:70
|
|
||||||
Height:20
|
|
||||||
Text:Author:
|
|
||||||
Font:Bold
|
|
||||||
Label@CURMAP_AUTHOR:
|
|
||||||
Id:CURMAP_AUTHOR
|
|
||||||
X:75
|
|
||||||
Y:20
|
|
||||||
Align:Left
|
|
||||||
Width:175
|
|
||||||
Height:20
|
|
||||||
WordWrap:True
|
|
||||||
Label@CURMAP_SIZE_LABEL:
|
|
||||||
Id:CURMAP_SIZE_LABEL
|
|
||||||
X:0
|
|
||||||
Y:40
|
|
||||||
Align:Right
|
|
||||||
Width:70
|
|
||||||
Height:20
|
|
||||||
Text:Size:
|
|
||||||
Font:Bold
|
|
||||||
Label@CURMAP_SIZE:
|
|
||||||
Id:CURMAP_SIZE
|
|
||||||
X:75
|
|
||||||
Y:40
|
|
||||||
Align:Left
|
|
||||||
Width:70
|
|
||||||
Height:20
|
|
||||||
Label@CURMAP_THEATER_LABEL:
|
|
||||||
Id:CURMAP_THEATER_LABEL
|
|
||||||
X:0
|
|
||||||
Y:60
|
|
||||||
Align:Right
|
|
||||||
Width:70
|
|
||||||
Height:20
|
|
||||||
Text:Theater:
|
|
||||||
Font:Bold
|
|
||||||
Label@CURMAP_THEATER:
|
|
||||||
Id:CURMAP_THEATER
|
|
||||||
X:75
|
|
||||||
Y:60
|
|
||||||
Align:Left
|
|
||||||
Width:70
|
|
||||||
Height:20
|
|
||||||
Label@CURMAP_PLAYERS_LABEL:
|
|
||||||
Id:CURMAP_PLAYERS_LABEL
|
|
||||||
X:0
|
|
||||||
Y:80
|
|
||||||
Align:Right
|
|
||||||
Width:70
|
|
||||||
Height:20
|
|
||||||
Text:Players:
|
|
||||||
Font:Bold
|
|
||||||
Label@CURMAP_PLAYERS:
|
|
||||||
Id:CURMAP_PLAYERS
|
|
||||||
X:75
|
|
||||||
Y:80
|
|
||||||
Align:Left
|
|
||||||
Width:70
|
|
||||||
Height:20
|
|
||||||
Label@CURMAP_DESC_LABEL:
|
|
||||||
Id:CURMAP_DESC_LABEL
|
|
||||||
X:0
|
|
||||||
Y:100
|
|
||||||
Align:Right
|
|
||||||
Width:70
|
|
||||||
Height:20
|
|
||||||
Text:Desc:
|
|
||||||
Font:Bold
|
|
||||||
Label@CURMAP_DESC:
|
|
||||||
Id:CURMAP_DESC
|
|
||||||
X:75
|
|
||||||
Y:100
|
|
||||||
Align:Left
|
|
||||||
Width:170
|
|
||||||
Height:20
|
|
||||||
WordWrap:True
|
|
||||||
Button@BUTTON_OK:
|
Button@BUTTON_OK:
|
||||||
Id:BUTTON_OK
|
Id:BUTTON_OK
|
||||||
X:PARENT_RIGHT - 295
|
X:PARENT_RIGHT - 295
|
||||||
|
|||||||
Reference in New Issue
Block a user