Clean up map previews. Fixes #5665.
This commit is contained in:
1
AUTHORS
1
AUTHORS
@@ -50,6 +50,7 @@ Also thanks to:
|
||||
* Lesueur Benjamin (Valkirie)
|
||||
* Maarten Meuris (Nyerguds)
|
||||
* Mark Olson (markolson)
|
||||
* Matija Hustic (matija-hustic)
|
||||
* Matthew Gatland (mgatland)
|
||||
* Matthew Uzzell (MUzzell)
|
||||
* Max621
|
||||
|
||||
@@ -26,9 +26,6 @@ namespace OpenRA.Widgets
|
||||
public readonly string Country;
|
||||
public readonly int SpawnPoint;
|
||||
|
||||
public SpawnOccupant()
|
||||
{
|
||||
}
|
||||
public SpawnOccupant(Session.Client client)
|
||||
{
|
||||
Color = client.Color;
|
||||
@@ -38,6 +35,7 @@ namespace OpenRA.Widgets
|
||||
Country = client.Country;
|
||||
SpawnPoint = client.SpawnPoint;
|
||||
}
|
||||
|
||||
public SpawnOccupant(GameInformation.Player player)
|
||||
{
|
||||
Color = player.Color;
|
||||
@@ -51,34 +49,58 @@ namespace OpenRA.Widgets
|
||||
|
||||
public class MapPreviewWidget : Widget
|
||||
{
|
||||
public Func<MapPreview> Preview = () => null;
|
||||
public Func<Dictionary<CPos, SpawnOccupant>> SpawnOccupants = () => new Dictionary<CPos, SpawnOccupant>();
|
||||
public Action<MouseInput> OnMouseDown = _ => {};
|
||||
public bool IgnoreMouseInput = false;
|
||||
public bool ShowSpawnPoints = true;
|
||||
public readonly bool IgnoreMouseInput = false;
|
||||
public readonly bool ShowSpawnPoints = true;
|
||||
|
||||
public readonly string TooltipContainer;
|
||||
public readonly string TooltipTemplate = "SPAWN_TOOLTIP";
|
||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
readonly Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
|
||||
readonly Sprite spawnClaimed, spawnUnclaimed;
|
||||
readonly SpriteFont spawnFont;
|
||||
readonly Color spawnColor, spawnContrastColor;
|
||||
readonly int2 spawnLabelOffset;
|
||||
|
||||
public Func<MapPreview> Preview = () => null;
|
||||
public Func<Dictionary<CPos, SpawnOccupant>> SpawnOccupants = () => new Dictionary<CPos, SpawnOccupant>();
|
||||
public Action<MouseInput> OnMouseDown = _ => { };
|
||||
public int TooltipSpawnIndex = -1;
|
||||
|
||||
Rectangle MapRect;
|
||||
float PreviewScale = 0;
|
||||
Rectangle mapRect;
|
||||
float previewScale = 0;
|
||||
Sprite minimap;
|
||||
|
||||
public MapPreviewWidget()
|
||||
{
|
||||
tooltipContainer = Exts.Lazy(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
|
||||
spawnClaimed = ChromeProvider.GetImage("lobby-bits", "spawn-claimed");
|
||||
spawnUnclaimed = ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed");
|
||||
spawnFont = Game.Renderer.Fonts[ChromeMetrics.Get<string>("SpawnFont")];
|
||||
spawnColor = ChromeMetrics.Get<Color>("SpawnColor");
|
||||
spawnContrastColor = ChromeMetrics.Get<Color>("SpawnContrastColor");
|
||||
spawnLabelOffset = ChromeMetrics.Get<int2>("SpawnLabelOffset");
|
||||
}
|
||||
|
||||
protected MapPreviewWidget(MapPreviewWidget other)
|
||||
: base(other)
|
||||
{
|
||||
Preview = other.Preview;
|
||||
SpawnOccupants = other.SpawnOccupants;
|
||||
|
||||
IgnoreMouseInput = other.IgnoreMouseInput;
|
||||
ShowSpawnPoints = other.ShowSpawnPoints;
|
||||
TooltipTemplate = other.TooltipTemplate;
|
||||
TooltipContainer = other.TooltipContainer;
|
||||
SpawnOccupants = other.SpawnOccupants;
|
||||
|
||||
tooltipContainer = Exts.Lazy(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
|
||||
spawnClaimed = ChromeProvider.GetImage("lobby-bits", "spawn-claimed");
|
||||
spawnUnclaimed = ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed");
|
||||
spawnFont = Game.Renderer.Fonts[ChromeMetrics.Get<string>("SpawnFont")];
|
||||
spawnColor = ChromeMetrics.Get<Color>("SpawnColor");
|
||||
spawnContrastColor = ChromeMetrics.Get<Color>("SpawnContrastColor");
|
||||
spawnLabelOffset = ChromeMetrics.Get<int2>("SpawnLabelOffset");
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new MapPreviewWidget(this); }
|
||||
@@ -98,7 +120,7 @@ namespace OpenRA.Widgets
|
||||
public override void MouseEntered()
|
||||
{
|
||||
if (TooltipContainer != null)
|
||||
tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() {{ "preview", this }});
|
||||
tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() { { "preview", this } });
|
||||
}
|
||||
|
||||
public override void MouseExited()
|
||||
@@ -110,10 +132,11 @@ namespace OpenRA.Widgets
|
||||
public int2 ConvertToPreview(CPos point)
|
||||
{
|
||||
var preview = Preview();
|
||||
return new int2(MapRect.X + (int)(PreviewScale*(point.X - preview.Bounds.Left)) , MapRect.Y + (int)(PreviewScale*(point.Y - preview.Bounds.Top)));
|
||||
var dx = (int)(previewScale * (point.X - preview.Bounds.Left));
|
||||
var dy = (int)(previewScale * (point.Y - preview.Bounds.Top));
|
||||
return new int2(mapRect.X + dx, mapRect.Y + dy);
|
||||
}
|
||||
|
||||
Sprite minimap;
|
||||
public override void Draw()
|
||||
{
|
||||
var preview = Preview();
|
||||
@@ -127,14 +150,14 @@ namespace OpenRA.Widgets
|
||||
return;
|
||||
|
||||
// Update map rect
|
||||
PreviewScale = Math.Min(RenderBounds.Width / minimap.size.X, RenderBounds.Height / minimap.size.Y);
|
||||
var w = (int)(PreviewScale * minimap.size.X);
|
||||
var h = (int)(PreviewScale * minimap.size.Y);
|
||||
previewScale = Math.Min(RenderBounds.Width / minimap.size.X, RenderBounds.Height / minimap.size.Y);
|
||||
var w = (int)(previewScale * minimap.size.X);
|
||||
var h = (int)(previewScale * minimap.size.Y);
|
||||
var x = RenderBounds.X + (RenderBounds.Width - w) / 2;
|
||||
var y = RenderBounds.Y + (RenderBounds.Height - h) / 2;
|
||||
MapRect = new Rectangle(x, y, w, h);
|
||||
mapRect = new Rectangle(x, y, w, h);
|
||||
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(minimap, new float2(MapRect.Location), new float2(MapRect.Size));
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(minimap, new float2(mapRect.Location), new float2(mapRect.Size));
|
||||
|
||||
TooltipSpawnIndex = -1;
|
||||
if (ShowSpawnPoints)
|
||||
@@ -146,20 +169,19 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
var owned = colors.ContainsKey(p);
|
||||
var pos = ConvertToPreview(p);
|
||||
var sprite = ChromeProvider.GetImage("lobby-bits", owned ? "spawn-claimed" : "spawn-unclaimed");
|
||||
var sprite = owned ? spawnClaimed : spawnUnclaimed;
|
||||
var offset = new int2(sprite.bounds.Width, sprite.bounds.Height) / 2;
|
||||
|
||||
if (owned)
|
||||
WidgetUtils.FillEllipseWithColor(new Rectangle(pos.X - offset.X + 1, pos.Y - offset.Y + 1, sprite.bounds.Width - 2, sprite.bounds.Height - 2), colors[p]);
|
||||
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(sprite, pos - offset);
|
||||
var fonts = Game.Renderer.Fonts[ChromeMetrics.Get<string>("SpawnFont")];
|
||||
var number = Convert.ToChar('A' + spawnPoints.IndexOf(p)).ToString();
|
||||
offset = fonts.Measure(number) / 2;
|
||||
offset.Y += 1; // Does not center well vertically for some reason
|
||||
fonts.DrawTextWithContrast(number, pos - offset, ChromeMetrics.Get<Color>("SpawnColor"), ChromeMetrics.Get<Color>("SpawnContrastColor"), 1);
|
||||
var textOffset = spawnFont.Measure(number) / 2 + spawnLabelOffset;
|
||||
|
||||
if (((pos - Viewport.LastMousePos).ToFloat2() * offset.ToFloat2()).LengthSquared < 1)
|
||||
spawnFont.DrawTextWithContrast(number, pos - textOffset, spawnColor, spawnContrastColor, 1);
|
||||
|
||||
if (((pos - Viewport.LastMousePos).ToFloat2() / offset.ToFloat2()).LengthSquared <= 1)
|
||||
TooltipSpawnIndex = spawnPoints.IndexOf(p) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,16 +92,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
Func<int, ScrollItemWidget, ScrollItemWidget> setupItem = (ii, itemTemplate) =>
|
||||
{
|
||||
var spawnPoint = spawnPoints.ToList()[ii];
|
||||
var item = ScrollItemWidget.Setup(itemTemplate,
|
||||
() => client.SpawnPoint == spawnPoint,
|
||||
() => SetSpawnPoint(orderManager, client, spawnPoint));
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => spawnPoint == 0 ? "-" : Convert.ToChar('A' - 1 + spawnPoint).ToString();
|
||||
() => client.SpawnPoint == ii,
|
||||
() => SetSpawnPoint(orderManager, client, ii));
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => ii == 0 ? "-" : Convert.ToChar('A' - 1 + ii).ToString();
|
||||
return item;
|
||||
};
|
||||
|
||||
var options = Exts.MakeArray(spawnPoints.Count(), i => i).ToList();
|
||||
dropdown.ShowDropDown("SPAWN_DROPDOWN_TEMPLATE", 150, options, setupItem);
|
||||
dropdown.ShowDropDown("SPAWN_DROPDOWN_TEMPLATE", 150, spawnPoints, setupItem);
|
||||
}
|
||||
|
||||
public static void ShowRaceDropDown(DropDownButtonWidget dropdown, Session.Client client,
|
||||
@@ -171,9 +169,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
if (!orderManager.LocalClient.IsObserver && orderManager.LocalClient.State == Session.ClientState.Ready)
|
||||
return;
|
||||
|
||||
var spawnSize = new float2(ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed").bounds.Size);
|
||||
var selectedSpawn = preview.SpawnPoints
|
||||
.Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(sp), i))
|
||||
.Where(a => ((a.First - mi.Location).ToFloat2() / new float2(ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed").bounds.Width / 2, ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed").bounds.Height / 2)).LengthSquared <= 1)
|
||||
.Where(a => ((a.First - mi.Location).ToFloat2() / spawnSize * 2).LengthSquared <= 1)
|
||||
.Select(a => a.Second + 1)
|
||||
.FirstOrDefault();
|
||||
|
||||
|
||||
@@ -107,8 +107,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
titleLabel.GetText = () => preview.Title;
|
||||
|
||||
var previewWidget = item.Get<MapPreviewWidget>("PREVIEW");
|
||||
previewWidget.IgnoreMouseOver = true;
|
||||
previewWidget.IgnoreMouseInput = true;
|
||||
previewWidget.Preview = () => preview;
|
||||
|
||||
var detailsWidget = item.GetOrNull<LabelWidget>("DETAILS");
|
||||
|
||||
@@ -48,6 +48,8 @@ Container@MAPCHOOSER_PANEL:
|
||||
Y: 4
|
||||
Width: 173
|
||||
Height: 173
|
||||
IgnoreMouseOver: true
|
||||
IgnoreMouseInput: true
|
||||
Label@TITLE:
|
||||
X: 2
|
||||
Y: PARENT_BOTTOM-48
|
||||
|
||||
@@ -23,3 +23,4 @@ Metrics:
|
||||
SpawnFont: TinyBold
|
||||
SpawnColor: 255,255,255
|
||||
SpawnContrastColor: 0,0,0
|
||||
SpawnLabelOffset: 0,1
|
||||
|
||||
@@ -23,3 +23,4 @@ Metrics:
|
||||
SpawnFont: TinyBold
|
||||
SpawnColor: 255,255,255
|
||||
SpawnContrastColor: 0,0,0
|
||||
SpawnLabelOffset: 0,1
|
||||
|
||||
@@ -31,6 +31,8 @@ Background@MAPCHOOSER_PANEL:
|
||||
Y: 4
|
||||
Width: 184
|
||||
Height: 184
|
||||
IgnoreMouseOver: true
|
||||
IgnoreMouseInput: true
|
||||
Label@TITLE:
|
||||
X: 2
|
||||
Y: PARENT_BOTTOM-48
|
||||
|
||||
@@ -23,3 +23,4 @@ Metrics:
|
||||
SpawnFont: TinyBold
|
||||
SpawnColor: 255,255,255
|
||||
SpawnContrastColor: 0,0,0
|
||||
SpawnLabelOffset: 0,1
|
||||
|
||||
@@ -23,3 +23,4 @@ Metrics:
|
||||
SpawnFont: TinyBold
|
||||
SpawnColor: 255,255,255
|
||||
SpawnContrastColor: 0,0,0
|
||||
SpawnLabelOffset: 0,1
|
||||
|
||||
Reference in New Issue
Block a user