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

@@ -188,7 +188,6 @@
<Compile Include="Widgets\PasswordFieldWidget.cs" />
<Compile Include="Widgets\PerfGraphWidget.cs" />
<Compile Include="Widgets\ProgressBarWidget.cs" />
<Compile Include="Widgets\ScrollItem.cs" />
<Compile Include="Widgets\ScrollPanelWidget.cs" />
<Compile Include="Widgets\ShpImageWidget.cs" />
<Compile Include="Widgets\SliderWidget.cs" />
@@ -202,6 +201,7 @@
<Compile Include="Widgets\WorldInteractionControllerWidget.cs" />
<Compile Include="World.cs" />
<Compile Include="WorldUtils.cs" />
<Compile Include="Widgets\ScrollItemWidget.cs" />
<Compile Include="Widgets\ListLayout.cs" />
<Compile Include="Widgets\GridLayout.cs" />
</ItemGroup>

View File

@@ -26,18 +26,18 @@ namespace OpenRA.Widgets
widget.ContentHeight = widget.ItemSpacing;
pos = new int2(widget.ItemSpacing, widget.ItemSpacing);
}
if (pos.X + widget.ItemSpacing + w.Bounds.Width > widget.Bounds.Width - widget.ScrollbarWidth)
{
/* start a new row */
pos.X = widget.ItemSpacing;
pos.Y = widget.ContentHeight;
}
w.Bounds.X += pos.X;
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);
}

View File

@@ -21,10 +21,12 @@ namespace OpenRA.Widgets
public Func<Map> Map = () => null;
public Func<Dictionary<int2, Color>> SpawnColors = () => new Dictionary<int2, Color>();
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() { }
protected MapPreviewWidget(MapPreviewWidget other)
: base(other)
{
@@ -32,10 +34,14 @@ namespace OpenRA.Widgets
Map = other.Map;
SpawnColors = other.SpawnColors;
}
public override Widget Clone() { return new MapPreviewWidget(this); }
public override bool HandleMouseInput(MouseInput mi)
{
if (IgnoreMouseInput)
return base.HandleMouseInput(mi);
if (mi.Event != MouseInputEvent.Down)
return false;
@@ -70,15 +76,15 @@ namespace OpenRA.Widgets
mapChooserSheet.Texture.SetData( preview );
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,
new float2(MapRect.Location),
new float2( MapRect.Size ) );