Add tooltips to production statistics #12820
This commit is contained in:
@@ -220,6 +220,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
template.Get<ObserverProductionIconsWidget>("PRODUCTION_ICONS").GetPlayer = () => player;
|
template.Get<ObserverProductionIconsWidget>("PRODUCTION_ICONS").GetPlayer = () => player;
|
||||||
template.Get<ObserverSupportPowerIconsWidget>("SUPPORT_POWER_ICONS").GetPlayer = () => player;
|
template.Get<ObserverSupportPowerIconsWidget>("SUPPORT_POWER_ICONS").GetPlayer = () => player;
|
||||||
|
template.IgnoreChildMouseOver = false;
|
||||||
|
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
public class ProductionTooltipLogic : ChromeLogic
|
public class ProductionTooltipLogic : ChromeLogic
|
||||||
{
|
{
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, ProductionPaletteWidget palette, World world)
|
public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, Player player, Func<ProductionIcon> getTooltipIcon)
|
||||||
{
|
{
|
||||||
var mapRules = palette.World.Map.Rules;
|
var world = player.World;
|
||||||
var pm = palette.World.LocalPlayer.PlayerActor.Trait<PowerManager>();
|
var mapRules = world.Map.Rules;
|
||||||
var pr = palette.World.LocalPlayer.PlayerActor.Trait<PlayerResources>();
|
var pm = player.PlayerActor.Trait<PowerManager>();
|
||||||
|
var pr = player.PlayerActor.Trait<PlayerResources>();
|
||||||
|
|
||||||
widget.IsVisible = () => palette.TooltipIcon != null;
|
widget.IsVisible = () => getTooltipIcon() != null && getTooltipIcon().Actor != null;
|
||||||
var nameLabel = widget.Get<LabelWidget>("NAME");
|
var nameLabel = widget.Get<LabelWidget>("NAME");
|
||||||
var hotkeyLabel = widget.Get<LabelWidget>("HOTKEY");
|
var hotkeyLabel = widget.Get<LabelWidget>("HOTKEY");
|
||||||
var requiresLabel = widget.Get<LabelWidget>("REQUIRES");
|
var requiresLabel = widget.Get<LabelWidget>("REQUIRES");
|
||||||
@@ -49,10 +50,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
tooltipContainer.BeforeRender = () =>
|
tooltipContainer.BeforeRender = () =>
|
||||||
{
|
{
|
||||||
if (palette.TooltipIcon == null)
|
var tooltipIcon = getTooltipIcon();
|
||||||
|
if (tooltipIcon == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var actor = palette.TooltipIcon.Actor;
|
var actor = tooltipIcon.Actor;
|
||||||
if (actor == null || actor == lastActor)
|
if (actor == null || actor == lastActor)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -63,7 +65,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
nameLabel.GetText = () => name;
|
nameLabel.GetText = () => name;
|
||||||
|
|
||||||
var hotkey = palette.TooltipIcon.Hotkey;
|
var hotkey = tooltipIcon.Hotkey;
|
||||||
var nameWidth = font.Measure(name).X;
|
var nameWidth = font.Measure(name).X;
|
||||||
var hotkeyText = "({0})".F(hotkey.DisplayString());
|
var hotkeyText = "({0})".F(hotkey.DisplayString());
|
||||||
var hotkeyWidth = hotkey.IsValid() ? font.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X : 0;
|
var hotkeyWidth = hotkey.IsValid() ? font.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X : 0;
|
||||||
@@ -84,8 +86,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
powerIcon.IsVisible = () => power != 0;
|
powerIcon.IsVisible = () => power != 0;
|
||||||
|
|
||||||
var lowpower = pm.PowerState != PowerState.Normal;
|
var lowpower = pm.PowerState != PowerState.Normal;
|
||||||
var time = palette.CurrentQueue == null ? 0 : palette.CurrentQueue.GetBuildTime(actor, buildable)
|
var time = tooltipIcon.ProductionQueue == null ? 0 : tooltipIcon.ProductionQueue.GetBuildTime(actor, buildable)
|
||||||
* (lowpower ? palette.CurrentQueue.Info.LowPowerSlowdown : 1);
|
* (lowpower ? tooltipIcon.ProductionQueue.Info.LowPowerSlowdown : 1);
|
||||||
var timeString = WidgetUtils.FormatTime(time, world.Timestep);
|
var timeString = WidgetUtils.FormatTime(time, world.Timestep);
|
||||||
timeLabel.GetText = () => timeString;
|
timeLabel.GetText = () => timeString;
|
||||||
timeLabel.GetColor = () => lowpower ? Color.Red : Color.White;
|
timeLabel.GetColor = () => lowpower ? Color.Red : Color.White;
|
||||||
|
|||||||
@@ -22,11 +22,12 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
public class ObserverProductionIconsWidget : Widget
|
public class ObserverProductionIconsWidget : Widget
|
||||||
{
|
{
|
||||||
|
public readonly string TooltipTemplate = "PRODUCTION_TOOLTIP";
|
||||||
|
public readonly string TooltipContainer;
|
||||||
public Func<Player> GetPlayer;
|
public Func<Player> GetPlayer;
|
||||||
readonly World world;
|
readonly World world;
|
||||||
readonly WorldRenderer worldRenderer;
|
readonly WorldRenderer worldRenderer;
|
||||||
readonly int timestep;
|
readonly int timestep;
|
||||||
Dictionary<ProductionQueue, Animation> clocks;
|
|
||||||
|
|
||||||
public int IconWidth = 32;
|
public int IconWidth = 32;
|
||||||
public int IconHeight = 24;
|
public int IconHeight = 24;
|
||||||
@@ -36,6 +37,17 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
public string ClockSequence = "idle";
|
public string ClockSequence = "idle";
|
||||||
public string ClockPalette = "chrome";
|
public string ClockPalette = "chrome";
|
||||||
|
|
||||||
|
public ProductionIcon TooltipIcon { get; private set; }
|
||||||
|
public Func<ProductionIcon> GetTooltipIcon;
|
||||||
|
|
||||||
|
Dictionary<ProductionQueue, Animation> clocks;
|
||||||
|
float2 iconSize;
|
||||||
|
Rectangle[] iconRects = new Rectangle[0];
|
||||||
|
ProductionIcon[] icons;
|
||||||
|
Rectangle renderBounds;
|
||||||
|
int lastIconIdx;
|
||||||
|
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ObserverProductionIconsWidget(World world, WorldRenderer worldRenderer)
|
public ObserverProductionIconsWidget(World world, WorldRenderer worldRenderer)
|
||||||
{
|
{
|
||||||
@@ -43,6 +55,10 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
this.worldRenderer = worldRenderer;
|
this.worldRenderer = worldRenderer;
|
||||||
clocks = new Dictionary<ProductionQueue, Animation>();
|
clocks = new Dictionary<ProductionQueue, Animation>();
|
||||||
timestep = world.IsReplay ? world.WorldActor.Trait<MapOptions>().GameSpeed.Timestep : world.Timestep;
|
timestep = world.IsReplay ? world.WorldActor.Trait<MapOptions>().GameSpeed.Timestep : world.Timestep;
|
||||||
|
GetTooltipIcon = () => TooltipIcon;
|
||||||
|
tooltipContainer = Exts.Lazy(() =>
|
||||||
|
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||||
|
iconSize = new float2(IconWidth, IconHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ObserverProductionIconsWidget(ObserverProductionIconsWidget other)
|
protected ObserverProductionIconsWidget(ObserverProductionIconsWidget other)
|
||||||
@@ -57,10 +73,21 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
IconWidth = other.IconWidth;
|
IconWidth = other.IconWidth;
|
||||||
IconHeight = other.IconHeight;
|
IconHeight = other.IconHeight;
|
||||||
IconSpacing = other.IconSpacing;
|
IconSpacing = other.IconSpacing;
|
||||||
|
iconSize = new float2(IconWidth, IconHeight);
|
||||||
|
|
||||||
ClockAnimation = other.ClockAnimation;
|
ClockAnimation = other.ClockAnimation;
|
||||||
ClockSequence = other.ClockSequence;
|
ClockSequence = other.ClockSequence;
|
||||||
ClockPalette = other.ClockPalette;
|
ClockPalette = other.ClockPalette;
|
||||||
|
|
||||||
|
TooltipIcon = other.TooltipIcon;
|
||||||
|
GetTooltipIcon = () => TooltipIcon;
|
||||||
|
|
||||||
|
TooltipTemplate = other.TooltipTemplate;
|
||||||
|
TooltipContainer = other.TooltipContainer;
|
||||||
|
|
||||||
|
tooltipContainer = Exts.Lazy(() =>
|
||||||
|
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||||
|
renderBounds = Rectangle.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
@@ -73,15 +100,22 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
.Where(a => a.Actor.Owner == player)
|
.Where(a => a.Actor.Owner == player)
|
||||||
.Select((a, i) => new { a.Trait, i });
|
.Select((a, i) => new { a.Trait, i });
|
||||||
|
|
||||||
|
if (renderBounds != RenderBounds)
|
||||||
|
{
|
||||||
|
renderBounds = RenderBounds;
|
||||||
|
InitIcons(renderBounds);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
for (var i = 0; i < icons.Length; i++)
|
||||||
|
icons[i].Actor = null;
|
||||||
|
|
||||||
foreach (var queue in queues)
|
foreach (var queue in queues)
|
||||||
|
{
|
||||||
if (!clocks.ContainsKey(queue.Trait))
|
if (!clocks.ContainsKey(queue.Trait))
|
||||||
clocks.Add(queue.Trait, new Animation(world, ClockAnimation));
|
clocks.Add(queue.Trait, new Animation(world, ClockAnimation));
|
||||||
|
|
||||||
var iconSize = new float2(IconWidth, IconHeight);
|
|
||||||
foreach (var queue in queues)
|
|
||||||
{
|
|
||||||
var current = queue.Trait.CurrentItem();
|
var current = queue.Trait.CurrentItem();
|
||||||
if (current == null)
|
if (current == null || queue.i >= icons.Length)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var faction = queue.Trait.Actor.Owner.Faction.InternalName;
|
var faction = queue.Trait.Actor.Owner.Faction.InternalName;
|
||||||
@@ -93,9 +127,12 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
var icon = new Animation(world, rsi.GetImage(actor, world.Map.Rules.Sequences, faction));
|
var icon = new Animation(world, rsi.GetImage(actor, world.Map.Rules.Sequences, faction));
|
||||||
var bi = actor.TraitInfo<BuildableInfo>();
|
var bi = actor.TraitInfo<BuildableInfo>();
|
||||||
icon.Play(bi.Icon);
|
icon.Play(bi.Icon);
|
||||||
var location = new float2(RenderBounds.Location) + new float2(queue.i * (IconWidth + IconSpacing), 0);
|
var location = new float2(iconRects[queue.i].Location);
|
||||||
WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer.Palette(bi.IconPalette), 0.5f);
|
WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer.Palette(bi.IconPalette), 0.5f);
|
||||||
|
|
||||||
|
icons[queue.i].Actor = actor;
|
||||||
|
icons[queue.i].ProductionQueue = queue.Trait;
|
||||||
|
|
||||||
var pio = queue.Trait.Actor.Owner.PlayerActor.TraitsImplementing<IProductionIconOverlay>()
|
var pio = queue.Trait.Actor.Owner.PlayerActor.TraitsImplementing<IProductionIconOverlay>()
|
||||||
.FirstOrDefault(p => p.IsOverlayActive(actor));
|
.FirstOrDefault(p => p.IsOverlayActive(actor));
|
||||||
if (pio != null)
|
if (pio != null)
|
||||||
@@ -132,5 +169,52 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
return new ObserverProductionIconsWidget(this);
|
return new ObserverProductionIconsWidget(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void MouseEntered()
|
||||||
|
{
|
||||||
|
if (TooltipContainer != null)
|
||||||
|
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
||||||
|
new WidgetArgs() { { "player", GetPlayer() }, { "getTooltipIcon", GetTooltipIcon } });
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void MouseExited()
|
||||||
|
{
|
||||||
|
if (TooltipContainer == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
tooltipContainer.Value.RemoveTooltip();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Tick()
|
||||||
|
{
|
||||||
|
if (TooltipIcon != null && iconRects[lastIconIdx].Contains(Viewport.LastMousePos))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (var i = 0; i < iconRects.Length; i++)
|
||||||
|
{
|
||||||
|
if (iconRects[i].Contains(Viewport.LastMousePos))
|
||||||
|
{
|
||||||
|
lastIconIdx = i;
|
||||||
|
TooltipIcon = icons[i];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TooltipIcon = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InitIcons(Rectangle renderBounds)
|
||||||
|
{
|
||||||
|
var iconWidthWithSpacing = IconWidth + IconSpacing;
|
||||||
|
var numOfIcons = renderBounds.Width / iconWidthWithSpacing;
|
||||||
|
iconRects = new Rectangle[numOfIcons];
|
||||||
|
icons = new ProductionIcon[numOfIcons];
|
||||||
|
|
||||||
|
for (var i = 0; i < numOfIcons; i++)
|
||||||
|
{
|
||||||
|
iconRects[i] = new Rectangle(renderBounds.X + i * iconWidthWithSpacing, renderBounds.Y, IconWidth, IconHeight);
|
||||||
|
icons[i] = new ProductionIcon();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
public PaletteReference IconDarkenPalette;
|
public PaletteReference IconDarkenPalette;
|
||||||
public float2 Pos;
|
public float2 Pos;
|
||||||
public List<ProductionItem> Queued;
|
public List<ProductionItem> Queued;
|
||||||
|
public ProductionQueue ProductionQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ProductionPaletteWidget : Widget
|
public class ProductionPaletteWidget : Widget
|
||||||
@@ -66,6 +67,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
public event Action<int, int> OnIconCountChanged = (a, b) => { };
|
public event Action<int, int> OnIconCountChanged = (a, b) => { };
|
||||||
|
|
||||||
public ProductionIcon TooltipIcon { get; private set; }
|
public ProductionIcon TooltipIcon { get; private set; }
|
||||||
|
public Func<ProductionIcon> GetTooltipIcon;
|
||||||
public readonly World World;
|
public readonly World World;
|
||||||
readonly OrderManager orderManager;
|
readonly OrderManager orderManager;
|
||||||
|
|
||||||
@@ -98,6 +100,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
this.orderManager = orderManager;
|
this.orderManager = orderManager;
|
||||||
World = world;
|
World = world;
|
||||||
this.worldRenderer = worldRenderer;
|
this.worldRenderer = worldRenderer;
|
||||||
|
GetTooltipIcon = () => TooltipIcon;
|
||||||
tooltipContainer = Exts.Lazy(() =>
|
tooltipContainer = Exts.Lazy(() =>
|
||||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||||
|
|
||||||
@@ -164,7 +167,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
if (TooltipContainer != null)
|
if (TooltipContainer != null)
|
||||||
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
||||||
new WidgetArgs() { { "world", World }, { "palette", this } });
|
new WidgetArgs() { { "player", World.LocalPlayer }, { "getTooltipIcon", GetTooltipIcon } });
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void MouseExited()
|
public override void MouseExited()
|
||||||
@@ -351,7 +354,8 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
IconClockPalette = worldRenderer.Palette(ClockPalette),
|
IconClockPalette = worldRenderer.Palette(ClockPalette),
|
||||||
IconDarkenPalette = worldRenderer.Palette(NotBuildablePalette),
|
IconDarkenPalette = worldRenderer.Palette(NotBuildablePalette),
|
||||||
Pos = new float2(rect.Location),
|
Pos = new float2(rect.Location),
|
||||||
Queued = CurrentQueue.AllQueued().Where(a => a.Item == item.Name).ToList()
|
Queued = currentQueue.AllQueued().Where(a => a.Item == item.Name).ToList(),
|
||||||
|
ProductionQueue = currentQueue
|
||||||
};
|
};
|
||||||
|
|
||||||
icons.Add(rect, pi);
|
icons.Add(rect, pi);
|
||||||
|
|||||||
@@ -457,6 +457,7 @@ Background@INGAME_OBSERVERSTATS_BG:
|
|||||||
Y: 0
|
Y: 0
|
||||||
Width: 320
|
Width: 320
|
||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
ObserverSupportPowerIcons@SUPPORT_POWER_ICONS:
|
ObserverSupportPowerIcons@SUPPORT_POWER_ICONS:
|
||||||
X: 535
|
X: 535
|
||||||
Y: 0
|
Y: 0
|
||||||
|
|||||||
@@ -457,6 +457,7 @@ Background@INGAME_OBSERVERSTATS_BG:
|
|||||||
Y: 0
|
Y: 0
|
||||||
Width: 320
|
Width: 320
|
||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
ObserverSupportPowerIcons@SUPPORT_POWER_ICONS:
|
ObserverSupportPowerIcons@SUPPORT_POWER_ICONS:
|
||||||
X: 535
|
X: 535
|
||||||
Y: 0
|
Y: 0
|
||||||
|
|||||||
@@ -458,6 +458,7 @@ Background@INGAME_OBSERVERSTATS_BG:
|
|||||||
Width: 320
|
Width: 320
|
||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
ClockPalette: iconclock
|
ClockPalette: iconclock
|
||||||
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
ObserverSupportPowerIcons@SUPPORT_POWER_ICONS:
|
ObserverSupportPowerIcons@SUPPORT_POWER_ICONS:
|
||||||
X: 535
|
X: 535
|
||||||
Y: 0
|
Y: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user