Add owner name/flag to world tooltip.
This commit is contained in:
@@ -8,9 +8,11 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
using OpenRA.Support;
|
using OpenRA.Support;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
using T = OpenRA.Mods.Cnc.Widgets.CncWorldInteractionControllerWidget;
|
using Type = OpenRA.Mods.Cnc.Widgets.CncWorldInteractionControllerWidget.WorldTooltipType;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||||
{
|
{
|
||||||
@@ -21,15 +23,25 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
[ObjectCreator.Param] TooltipContainerWidget tooltipContainer,
|
[ObjectCreator.Param] TooltipContainerWidget tooltipContainer,
|
||||||
[ObjectCreator.Param] CncWorldInteractionControllerWidget wic)
|
[ObjectCreator.Param] CncWorldInteractionControllerWidget wic)
|
||||||
{
|
{
|
||||||
widget.IsVisible = () => wic.TooltipType != T.WorldTooltipType.None;
|
widget.IsVisible = () => wic.TooltipType != Type.None;
|
||||||
var label = widget.GetWidget<LabelWidget>("LABEL");
|
var label = widget.GetWidget<LabelWidget>("LABEL");
|
||||||
|
var flag = widget.GetWidget<ImageWidget>("FLAG");
|
||||||
|
var owner = widget.GetWidget<LabelWidget>("OWNER");
|
||||||
|
|
||||||
var font = Game.Renderer.Fonts[label.Font];
|
var font = Game.Renderer.Fonts[label.Font];
|
||||||
|
var ownerFont = Game.Renderer.Fonts[owner.Font];
|
||||||
var cachedWidth = 0;
|
var cachedWidth = 0;
|
||||||
var labelText = "";
|
var labelText = "";
|
||||||
|
var showOwner = false;
|
||||||
|
var flagRace = "";
|
||||||
|
var ownerName = "";
|
||||||
|
var ownerColor = Color.White;
|
||||||
|
var doubleHeight = 45;
|
||||||
|
var singleHeight = 25;
|
||||||
|
|
||||||
tooltipContainer.BeforeRender = () =>
|
tooltipContainer.BeforeRender = () =>
|
||||||
{
|
{
|
||||||
labelText = wic.TooltipType == T.WorldTooltipType.Unexplored ? "Unexplored Terrain" :
|
labelText = wic.TooltipType == Type.Unexplored ? "Unexplored Terrain" :
|
||||||
wic.ActorTooltip.Name();
|
wic.ActorTooltip.Name();
|
||||||
var textWidth = font.Measure(labelText).X;
|
var textWidth = font.Measure(labelText).X;
|
||||||
if (textWidth != cachedWidth)
|
if (textWidth != cachedWidth)
|
||||||
@@ -37,9 +49,29 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
label.Bounds.Width = textWidth;
|
label.Bounds.Width = textWidth;
|
||||||
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
|
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
|
||||||
}
|
}
|
||||||
|
var o = wic.ActorTooltip != null ? wic.ActorTooltip.Owner() : null;
|
||||||
|
showOwner = wic.TooltipType == Type.Actor && o != null && !o.NonCombatant;
|
||||||
|
|
||||||
|
if (showOwner)
|
||||||
|
{
|
||||||
|
flagRace = o.Country.Race;
|
||||||
|
ownerName = o.PlayerName;
|
||||||
|
ownerColor = o.ColorRamp.GetColor(0);
|
||||||
|
widget.Bounds.Height = doubleHeight;
|
||||||
|
widget.Bounds.Width = Math.Max(widget.Bounds.Width,
|
||||||
|
owner.Bounds.X + ownerFont.Measure(ownerName).X + 5);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
widget.Bounds.Height = singleHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
label.GetText = () => labelText;
|
label.GetText = () => labelText;
|
||||||
|
flag.IsVisible = () => showOwner;
|
||||||
|
flag.GetImageCollection = () => "flags";
|
||||||
|
flag.GetImageName = () => flagRace;
|
||||||
|
owner.IsVisible = () => showOwner;
|
||||||
|
owner.GetText = () => ownerName;
|
||||||
|
owner.GetColor = () => ownerColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,14 +32,24 @@ Background@WORLD_TOOLTIP:
|
|||||||
Logic:WorldTooltipLogic
|
Logic:WorldTooltipLogic
|
||||||
Background:panel-black
|
Background:panel-black
|
||||||
Width:141
|
Width:141
|
||||||
Height:25
|
|
||||||
Children:
|
Children:
|
||||||
Label@LABEL:
|
Label@LABEL:
|
||||||
Id:LABEL
|
Id:LABEL
|
||||||
X:5
|
X:5
|
||||||
Height:23
|
Height:23
|
||||||
Font:Bold
|
Font:Bold
|
||||||
|
Image:
|
||||||
|
Id:FLAG
|
||||||
|
X:5
|
||||||
|
Y:24
|
||||||
|
Width:32
|
||||||
|
Height:16
|
||||||
|
Label@OWNER:
|
||||||
|
Id:OWNER
|
||||||
|
X:42
|
||||||
|
Y:19
|
||||||
|
Height:23
|
||||||
|
Font:Bold
|
||||||
Background@PRODUCTION_TOOLTIP:
|
Background@PRODUCTION_TOOLTIP:
|
||||||
Id:PRODUCTION_TOOLTIP
|
Id:PRODUCTION_TOOLTIP
|
||||||
Logic:ProductionTooltipLogic
|
Logic:ProductionTooltipLogic
|
||||||
|
|||||||
Reference in New Issue
Block a user