Add support for generic tooltip names.
This commit is contained in:
@@ -32,7 +32,7 @@ namespace OpenRA.Traits
|
|||||||
public IRenderable[] Renderables { private get; set; }
|
public IRenderable[] Renderables { private get; set; }
|
||||||
public Player Owner;
|
public Player Owner;
|
||||||
|
|
||||||
public string TooltipName;
|
public ITooltipInfo TooltipInfo;
|
||||||
public Player TooltipOwner;
|
public Player TooltipOwner;
|
||||||
|
|
||||||
public int HP;
|
public int HP;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace OpenRA.Traits
|
|||||||
[Flags]
|
[Flags]
|
||||||
public enum Stance
|
public enum Stance
|
||||||
{
|
{
|
||||||
|
None = 0,
|
||||||
Enemy = 1,
|
Enemy = 1,
|
||||||
Neutral = 2,
|
Neutral = 2,
|
||||||
Ally = 4,
|
Ally = 4,
|
||||||
@@ -125,10 +126,17 @@ namespace OpenRA.Traits
|
|||||||
bool Disguised { get; }
|
bool Disguised { get; }
|
||||||
Player Owner { get; }
|
Player Owner { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IToolTip
|
public interface IToolTip
|
||||||
{
|
{
|
||||||
string Name();
|
ITooltipInfo TooltipInfo { get; }
|
||||||
Player Owner();
|
Player Owner { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ITooltipInfo
|
||||||
|
{
|
||||||
|
string TooltipForPlayerStance(Stance stance);
|
||||||
|
bool IsOwnerRowVisible { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IDisable { bool Disabled { get; } }
|
public interface IDisable { bool Disabled { get; } }
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ namespace OpenRA.Widgets
|
|||||||
}
|
}
|
||||||
|
|
||||||
var frozen = world.ScreenMap.FrozenActorsAt(world.RenderPlayer, worldRenderer.Viewport.ViewToWorldPx(Viewport.LastMousePos))
|
var frozen = world.ScreenMap.FrozenActorsAt(world.RenderPlayer, worldRenderer.Viewport.ViewToWorldPx(Viewport.LastMousePos))
|
||||||
.Where(a => a.TooltipName != null && a.IsValid)
|
.Where(a => a.TooltipInfo != null && a.IsValid)
|
||||||
.WithHighestSelectionPriority();
|
.WithHighestSelectionPriority();
|
||||||
|
|
||||||
if (frozen != null)
|
if (frozen != null)
|
||||||
|
|||||||
@@ -36,28 +36,28 @@ namespace OpenRA.Mods.RA
|
|||||||
disguise = self.Trait<Disguise>();
|
disguise = self.Trait<Disguise>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name()
|
public ITooltipInfo TooltipInfo
|
||||||
{
|
{
|
||||||
if (disguise.Disguised)
|
get
|
||||||
{
|
{
|
||||||
if (self.Owner == self.World.LocalPlayer)
|
return disguise.Disguised ? disguise.AsTooltipInfo : info;
|
||||||
return "{0} ({1})".F(info.Name, disguise.AsName);
|
|
||||||
|
|
||||||
return disguise.AsName;
|
|
||||||
}
|
}
|
||||||
return info.Name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player Owner()
|
public Player Owner
|
||||||
{
|
{
|
||||||
if (disguise.Disguised)
|
get
|
||||||
{
|
{
|
||||||
if (self.Owner == self.World.LocalPlayer)
|
if (disguise.Disguised)
|
||||||
return self.Owner;
|
{
|
||||||
|
if (self.Owner == self.World.LocalPlayer)
|
||||||
|
return self.Owner;
|
||||||
|
|
||||||
return disguise.AsPlayer;
|
return disguise.AsPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.Owner;
|
||||||
}
|
}
|
||||||
return self.Owner;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,9 +65,9 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
class Disguise : IEffectiveOwner, IIssueOrder, IResolveOrder, IOrderVoice, IRadarColorModifier, INotifyAttack
|
class Disguise : IEffectiveOwner, IIssueOrder, IResolveOrder, IOrderVoice, IRadarColorModifier, INotifyAttack
|
||||||
{
|
{
|
||||||
public Player AsPlayer;
|
public Player AsPlayer { get; private set; }
|
||||||
public string AsSprite;
|
public string AsSprite { get; private set; }
|
||||||
public string AsName;
|
public ITooltipInfo AsTooltipInfo { get; private set; }
|
||||||
|
|
||||||
public bool Disguised { get { return AsPlayer != null; } }
|
public bool Disguised { get { return AsPlayer != null; } }
|
||||||
public Player Owner { get { return AsPlayer; } }
|
public Player Owner { get { return AsPlayer; } }
|
||||||
@@ -117,13 +117,13 @@ namespace OpenRA.Mods.RA
|
|||||||
if (target != null)
|
if (target != null)
|
||||||
{
|
{
|
||||||
var tooltip = target.TraitsImplementing<IToolTip>().FirstOrDefault();
|
var tooltip = target.TraitsImplementing<IToolTip>().FirstOrDefault();
|
||||||
AsName = tooltip.Name();
|
AsTooltipInfo = tooltip.TooltipInfo;
|
||||||
AsPlayer = tooltip.Owner();
|
AsPlayer = tooltip.Owner;
|
||||||
AsSprite = target.Trait<RenderSprites>().GetImage(target);
|
AsSprite = target.Trait<RenderSprites>().GetImage(target);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AsName = null;
|
AsTooltipInfo = null;
|
||||||
AsPlayer = null;
|
AsPlayer = null;
|
||||||
AsSprite = null;
|
AsSprite = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,8 +101,8 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
if (tooltip.Value != null)
|
if (tooltip.Value != null)
|
||||||
{
|
{
|
||||||
actor.TooltipName = tooltip.Value.Name();
|
actor.TooltipInfo = tooltip.Value.TooltipInfo;
|
||||||
actor.TooltipOwner = tooltip.Value.Owner();
|
actor.TooltipOwner = tooltip.Value.Owner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,29 +13,58 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
[Desc("Shown in the build palette widget.")]
|
[Desc("Shown in the build palette widget.")]
|
||||||
public class TooltipInfo : ITraitInfo
|
public class TooltipInfo : ITraitInfo, ITooltipInfo
|
||||||
{
|
{
|
||||||
[Translate] public readonly string Description = "";
|
[Translate] public readonly string Description = "";
|
||||||
[Translate] public readonly string Name = "";
|
[Translate] public readonly string Name = "";
|
||||||
|
|
||||||
|
[Desc("An optional generic name (i.e. \"Soldier\" or \"Structure\")" +
|
||||||
|
"to be shown to chosen players.")]
|
||||||
|
[Translate] public readonly string GenericName = null;
|
||||||
|
|
||||||
|
[Desc("Prefix generic tooltip name with 'Enemy' or 'Allied'.")]
|
||||||
|
public readonly bool GenericStancePrefix = true;
|
||||||
|
|
||||||
|
[Desc("Player stances that the generic name should be shown to.")]
|
||||||
|
public readonly Stance GenericVisibility = Stance.None;
|
||||||
|
|
||||||
|
[Desc("Show the actor's owner and their faction flag")]
|
||||||
|
public readonly bool ShowOwnerRow = true;
|
||||||
|
|
||||||
[Desc("Sequence of the actor that contains the cameo.")]
|
[Desc("Sequence of the actor that contains the cameo.")]
|
||||||
public readonly string Icon = "icon";
|
public readonly string Icon = "icon";
|
||||||
|
|
||||||
public virtual object Create(ActorInitializer init) { return new Tooltip(init.self, this); }
|
public virtual object Create(ActorInitializer init) { return new Tooltip(init.self, this); }
|
||||||
|
|
||||||
|
public string TooltipForPlayerStance(Stance stance)
|
||||||
|
{
|
||||||
|
if (stance == Stance.None || !GenericVisibility.HasFlag(stance))
|
||||||
|
return Name;
|
||||||
|
|
||||||
|
if (GenericStancePrefix && stance == Stance.Ally)
|
||||||
|
return "Allied " + GenericName;
|
||||||
|
|
||||||
|
if (GenericStancePrefix && stance == Stance.Enemy)
|
||||||
|
return "Enemy " + GenericName;
|
||||||
|
|
||||||
|
return GenericName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsOwnerRowVisible { get { return ShowOwnerRow; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Tooltip : IToolTip
|
public class Tooltip : IToolTip
|
||||||
{
|
{
|
||||||
Actor self;
|
readonly Actor self;
|
||||||
TooltipInfo Info;
|
readonly TooltipInfo info;
|
||||||
|
|
||||||
public string Name() { return Info.Name; }
|
public ITooltipInfo TooltipInfo { get { return info; } }
|
||||||
public Player Owner() { return self.Owner; }
|
public Player Owner { get { return self.Owner; } }
|
||||||
|
|
||||||
public Tooltip(Actor self, TooltipInfo info)
|
public Tooltip(Actor self, TooltipInfo info)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
Info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using OpenRA.Traits;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||||
@@ -17,7 +18,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
public class WorldTooltipLogic
|
public class WorldTooltipLogic
|
||||||
{
|
{
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public WorldTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, ViewportControllerWidget viewport)
|
public WorldTooltipLogic(Widget widget, World world, TooltipContainerWidget tooltipContainer, ViewportControllerWidget viewport)
|
||||||
{
|
{
|
||||||
widget.IsVisible = () => viewport.TooltipType != WorldTooltipType.None;
|
widget.IsVisible = () => viewport.TooltipType != WorldTooltipType.None;
|
||||||
var label = widget.Get<LabelWidget>("LABEL");
|
var label = widget.Get<LabelWidget>("LABEL");
|
||||||
@@ -41,20 +42,32 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
if (viewport == null || viewport.TooltipType == WorldTooltipType.None)
|
if (viewport == null || viewport.TooltipType == WorldTooltipType.None)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
showOwner = false;
|
||||||
|
|
||||||
Player o = null;
|
Player o = null;
|
||||||
switch (viewport.TooltipType)
|
switch (viewport.TooltipType)
|
||||||
{
|
{
|
||||||
case WorldTooltipType.Unexplored:
|
case WorldTooltipType.Unexplored:
|
||||||
labelText = "Unexplored Terrain";
|
labelText = "Unexplored Terrain";
|
||||||
break;
|
break;
|
||||||
case WorldTooltipType.Actor:
|
case WorldTooltipType.Actor:
|
||||||
labelText = viewport.ActorTooltip.Name();
|
{
|
||||||
o = viewport.ActorTooltip.Owner();
|
o = viewport.ActorTooltip.Owner;
|
||||||
break;
|
showOwner = !o.NonCombatant && viewport.ActorTooltip.TooltipInfo.IsOwnerRowVisible;
|
||||||
case WorldTooltipType.FrozenActor:
|
|
||||||
labelText = viewport.FrozenActorTooltip.TooltipName;
|
var stance = o == null || world.RenderPlayer == null? Stance.None : o.Stances[world.RenderPlayer];
|
||||||
o = viewport.FrozenActorTooltip.TooltipOwner;
|
labelText = viewport.ActorTooltip.TooltipInfo.TooltipForPlayerStance(stance);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
case WorldTooltipType.FrozenActor:
|
||||||
|
{
|
||||||
|
o = viewport.FrozenActorTooltip.TooltipOwner;
|
||||||
|
showOwner = !o.NonCombatant && viewport.FrozenActorTooltip.TooltipInfo.IsOwnerRowVisible;
|
||||||
|
|
||||||
|
var stance = o == null || world.RenderPlayer == null? Stance.None : o.Stances[world.RenderPlayer];
|
||||||
|
labelText = viewport.FrozenActorTooltip.TooltipInfo.TooltipForPlayerStance(stance);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var textWidth = font.Measure(labelText).X;
|
var textWidth = font.Measure(labelText).X;
|
||||||
@@ -64,8 +77,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
|
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
showOwner = o != null && !o.NonCombatant;
|
|
||||||
|
|
||||||
if (showOwner)
|
if (showOwner)
|
||||||
{
|
{
|
||||||
flagRace = o.Country.Race;
|
flagRace = o.Country.Race;
|
||||||
|
|||||||
Reference in New Issue
Block a user