Added tooltip to support powers in spec ui
This commit is contained in:
@@ -19,9 +19,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
public class SupportPowerTooltipLogic : ChromeLogic
|
public class SupportPowerTooltipLogic : ChromeLogic
|
||||||
{
|
{
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public SupportPowerTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, SupportPowersWidget palette, World world)
|
public SupportPowerTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, Func<SupportPowersWidget.SupportPowerIcon> getTooltipIcon, World world)
|
||||||
{
|
{
|
||||||
widget.IsVisible = () => palette.TooltipIcon != null && palette.TooltipIcon.Power.Info != null;
|
widget.IsVisible = () => getTooltipIcon() != null && getTooltipIcon().Power.Info != 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 timeLabel = widget.Get<LabelWidget>("TIME");
|
var timeLabel = widget.Get<LabelWidget>("TIME");
|
||||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
tooltipContainer.BeforeRender = () =>
|
tooltipContainer.BeforeRender = () =>
|
||||||
{
|
{
|
||||||
var icon = palette.TooltipIcon;
|
var icon = getTooltipIcon();
|
||||||
if (icon == null || icon.Power == null || icon.Power.Instances.Count == 0)
|
if (icon == null || icon.Power == null || icon.Power.Instances.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
lastRemainingSeconds = remainingSeconds;
|
lastRemainingSeconds = remainingSeconds;
|
||||||
};
|
};
|
||||||
|
|
||||||
timeLabel.GetColor = () => palette.TooltipIcon != null && !palette.TooltipIcon.Power.Active
|
timeLabel.GetColor = () => getTooltipIcon() != null && !getTooltipIcon().Power.Active
|
||||||
? Color.Red : Color.White;
|
? Color.Red : Color.White;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,12 +21,19 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
public class ObserverSupportPowerIconsWidget : Widget
|
public class ObserverSupportPowerIconsWidget : Widget
|
||||||
{
|
{
|
||||||
|
public readonly string TooltipTemplate = "SUPPORT_POWER_TOOLTIP";
|
||||||
|
public readonly string TooltipContainer;
|
||||||
readonly Animation icon;
|
readonly Animation icon;
|
||||||
readonly World world;
|
readonly World world;
|
||||||
readonly WorldRenderer worldRenderer;
|
readonly WorldRenderer worldRenderer;
|
||||||
readonly Dictionary<string, Animation> clocks;
|
readonly Dictionary<string, Animation> clocks;
|
||||||
readonly int timestep;
|
readonly int timestep;
|
||||||
|
|
||||||
|
readonly Lazy<TooltipContainerWidget> tooltipContainer;
|
||||||
|
|
||||||
|
public Func<SupportPowersWidget.SupportPowerIcon> GetTooltipIcon;
|
||||||
|
public SupportPowersWidget.SupportPowerIcon TooltipIcon { get; private set; }
|
||||||
|
|
||||||
public int IconWidth = 32;
|
public int IconWidth = 32;
|
||||||
public int IconHeight = 24;
|
public int IconHeight = 24;
|
||||||
public int IconSpacing = 1;
|
public int IconSpacing = 1;
|
||||||
@@ -36,6 +43,10 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
public string ClockPalette = "chrome";
|
public string ClockPalette = "chrome";
|
||||||
public Func<Player> GetPlayer;
|
public Func<Player> GetPlayer;
|
||||||
|
|
||||||
|
readonly List<SupportPowersWidget.SupportPowerIcon> supportPowerIconsIcons = new List<SupportPowersWidget.SupportPowerIcon>();
|
||||||
|
readonly List<Rectangle> supportPowerIconsBounds = new List<Rectangle>();
|
||||||
|
int lastIconIdx;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ObserverSupportPowerIconsWidget(World world, WorldRenderer worldRenderer)
|
public ObserverSupportPowerIconsWidget(World world, WorldRenderer worldRenderer)
|
||||||
{
|
{
|
||||||
@@ -48,6 +59,9 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
timestep = world.Timestep;
|
timestep = world.Timestep;
|
||||||
if (world.IsReplay)
|
if (world.IsReplay)
|
||||||
timestep = world.WorldActor.Trait<MapOptions>().GameSpeed.Timestep;
|
timestep = world.WorldActor.Trait<MapOptions>().GameSpeed.Timestep;
|
||||||
|
|
||||||
|
tooltipContainer = Exts.Lazy(() =>
|
||||||
|
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ObserverSupportPowerIconsWidget(ObserverSupportPowerIconsWidget other)
|
protected ObserverSupportPowerIconsWidget(ObserverSupportPowerIconsWidget other)
|
||||||
@@ -67,22 +81,38 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
|
supportPowerIconsIcons.Clear();
|
||||||
|
supportPowerIconsBounds.Clear();
|
||||||
|
|
||||||
var player = GetPlayer();
|
var player = GetPlayer();
|
||||||
if (player == null)
|
if (player == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var powers = player.PlayerActor.Trait<SupportPowerManager>().Powers
|
var powers = player.PlayerActor.Trait<SupportPowerManager>().Powers
|
||||||
.Where(x => !x.Value.Disabled).Select((a, i) => new { a, i });
|
.Where(x => !x.Value.Disabled).Select((a, i) => new { a, i })
|
||||||
|
.ToList();
|
||||||
|
|
||||||
foreach (var power in powers)
|
foreach (var power in powers)
|
||||||
{
|
{
|
||||||
if (!clocks.ContainsKey(power.a.Key))
|
if (!clocks.ContainsKey(power.a.Key))
|
||||||
clocks.Add(power.a.Key, new Animation(world, ClockAnimation));
|
clocks.Add(power.a.Key, new Animation(world, ClockAnimation));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bounds.Width = powers.Count() * (IconWidth + IconSpacing);
|
||||||
|
|
||||||
var iconSize = new float2(IconWidth, IconHeight);
|
var iconSize = new float2(IconWidth, IconHeight);
|
||||||
foreach (var power in powers)
|
foreach (var power in powers)
|
||||||
{
|
{
|
||||||
@@ -92,6 +122,10 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
icon.Play(item.Info.Icon);
|
icon.Play(item.Info.Icon);
|
||||||
var location = new float2(RenderBounds.Location) + new float2(power.i * (IconWidth + IconSpacing), 0);
|
var location = new float2(RenderBounds.Location) + new float2(power.i * (IconWidth + IconSpacing), 0);
|
||||||
|
|
||||||
|
supportPowerIconsIcons.Add(new SupportPowersWidget.SupportPowerIcon { Power = item });
|
||||||
|
supportPowerIconsBounds.Add(new Rectangle((int)location.X, (int)location.Y, (int)iconSize.X, (int)iconSize.Y));
|
||||||
|
|
||||||
WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer.Palette(item.Info.IconPalette), 0.5f);
|
WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer.Palette(item.Info.IconPalette), 0.5f);
|
||||||
|
|
||||||
var clock = clocks[power.a.Key];
|
var clock = clocks[power.a.Key];
|
||||||
@@ -120,5 +154,46 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
return new ObserverSupportPowerIconsWidget(this);
|
return new ObserverSupportPowerIconsWidget(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void MouseEntered()
|
||||||
|
{
|
||||||
|
if (TooltipContainer == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
||||||
|
new WidgetArgs() { { "world", worldRenderer.World }, { "player", GetPlayer() }, { "getTooltipIcon", GetTooltipIcon } });
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void MouseExited()
|
||||||
|
{
|
||||||
|
if (TooltipContainer == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
tooltipContainer.Value.RemoveTooltip();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Tick()
|
||||||
|
{
|
||||||
|
if (lastIconIdx >= supportPowerIconsBounds.Count)
|
||||||
|
{
|
||||||
|
TooltipIcon = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TooltipIcon != null && supportPowerIconsBounds[lastIconIdx].Contains(Viewport.LastMousePos))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (var i = 0; i < supportPowerIconsBounds.Count; i++)
|
||||||
|
{
|
||||||
|
if (!supportPowerIconsBounds[i].Contains(Viewport.LastMousePos))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
lastIconIdx = i;
|
||||||
|
TooltipIcon = supportPowerIconsIcons[i];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TooltipIcon = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
Dictionary<Rectangle, SupportPowerIcon> icons = new Dictionary<Rectangle, SupportPowerIcon>();
|
Dictionary<Rectangle, SupportPowerIcon> icons = new Dictionary<Rectangle, SupportPowerIcon>();
|
||||||
|
|
||||||
public SupportPowerIcon TooltipIcon { get; private set; }
|
public SupportPowerIcon TooltipIcon { get; private set; }
|
||||||
|
public Func<SupportPowerIcon> GetTooltipIcon;
|
||||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||||
HotkeyReference[] hotkeys;
|
HotkeyReference[] hotkeys;
|
||||||
|
|
||||||
@@ -92,6 +93,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
this.modData = modData;
|
this.modData = modData;
|
||||||
this.worldRenderer = worldRenderer;
|
this.worldRenderer = worldRenderer;
|
||||||
|
GetTooltipIcon = () => TooltipIcon;
|
||||||
spm = world.LocalPlayer.PlayerActor.Trait<SupportPowerManager>();
|
spm = world.LocalPlayer.PlayerActor.Trait<SupportPowerManager>();
|
||||||
tooltipContainer = Exts.Lazy(() =>
|
tooltipContainer = Exts.Lazy(() =>
|
||||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||||
@@ -239,7 +241,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
||||||
new WidgetArgs() { { "world", worldRenderer.World }, { "player", spm.Self.Owner }, { "palette", this } });
|
new WidgetArgs() { { "world", worldRenderer.World }, { "player", spm.Self.Owner }, { "getTooltipIcon", GetTooltipIcon } });
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void MouseExited()
|
public override void MouseExited()
|
||||||
|
|||||||
@@ -982,6 +982,7 @@ Container@OBSERVER_WIDGETS:
|
|||||||
Y: 0
|
Y: 0
|
||||||
Width: 0
|
Width: 0
|
||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
ScrollItem@COMBAT_PLAYER_TEMPLATE:
|
ScrollItem@COMBAT_PLAYER_TEMPLATE:
|
||||||
X: 0
|
X: 0
|
||||||
Y: 0
|
Y: 0
|
||||||
@@ -1155,6 +1156,7 @@ Container@PLAYER_WIDGETS:
|
|||||||
X: 1
|
X: 1
|
||||||
Y: 1
|
Y: 1
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
|
TooltipTemplate: SUPPORT_POWER_TOOLTIP_FACTIONSUFFIX
|
||||||
ReadyText: Ready
|
ReadyText: Ready
|
||||||
HoldText: On Hold
|
HoldText: On Hold
|
||||||
HotkeyPrefix: SupportPower
|
HotkeyPrefix: SupportPower
|
||||||
|
|||||||
@@ -287,6 +287,31 @@ Background@PRODUCTION_TOOLTIP_FACTIONSUFFIX:
|
|||||||
Font: Bold
|
Font: Bold
|
||||||
|
|
||||||
Background@SUPPORT_POWER_TOOLTIP:
|
Background@SUPPORT_POWER_TOOLTIP:
|
||||||
|
Logic: SupportPowerTooltipLogic
|
||||||
|
Background: panel-black
|
||||||
|
Width: 200
|
||||||
|
Height: 25
|
||||||
|
Children:
|
||||||
|
Label@NAME:
|
||||||
|
X: 5
|
||||||
|
Height: 20
|
||||||
|
Font: Bold
|
||||||
|
Label@HOTKEY:
|
||||||
|
Visible: false
|
||||||
|
Height: 20
|
||||||
|
TextColor: FFFF00
|
||||||
|
Font: Bold
|
||||||
|
Label@TIME:
|
||||||
|
Y: 6
|
||||||
|
Font: TinyBold
|
||||||
|
VAlign: Top
|
||||||
|
Label@DESC:
|
||||||
|
X: 5
|
||||||
|
Y: 20
|
||||||
|
Font: TinyBold
|
||||||
|
VAlign: Top
|
||||||
|
|
||||||
|
Background@SUPPORT_POWER_TOOLTIP_FACTIONSUFFIX:
|
||||||
Logic: SupportPowerTooltipLogic, AddFactionSuffixLogic
|
Logic: SupportPowerTooltipLogic, AddFactionSuffixLogic
|
||||||
Background: panel-black
|
Background: panel-black
|
||||||
Width: 200
|
Width: 200
|
||||||
|
|||||||
@@ -879,6 +879,7 @@ Container@OBSERVER_WIDGETS:
|
|||||||
Y: 0
|
Y: 0
|
||||||
Width: 0
|
Width: 0
|
||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
ScrollItem@COMBAT_PLAYER_TEMPLATE:
|
ScrollItem@COMBAT_PLAYER_TEMPLATE:
|
||||||
X: 0
|
X: 0
|
||||||
Y: 0
|
Y: 0
|
||||||
|
|||||||
@@ -925,6 +925,7 @@ Container@OBSERVER_WIDGETS:
|
|||||||
Y: 0
|
Y: 0
|
||||||
Width: 0
|
Width: 0
|
||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
ScrollItem@COMBAT_PLAYER_TEMPLATE:
|
ScrollItem@COMBAT_PLAYER_TEMPLATE:
|
||||||
X: 0
|
X: 0
|
||||||
Y: 0
|
Y: 0
|
||||||
|
|||||||
@@ -889,6 +889,7 @@ Container@OBSERVER_WIDGETS:
|
|||||||
Width: 0
|
Width: 0
|
||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
ClockPalette: iconclock
|
ClockPalette: iconclock
|
||||||
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
ScrollItem@COMBAT_PLAYER_TEMPLATE:
|
ScrollItem@COMBAT_PLAYER_TEMPLATE:
|
||||||
X: 0
|
X: 0
|
||||||
Y: 0
|
Y: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user