SpyToolTip - Display tooltip of disguised unit to other players, and a modified one for the local player.

This commit is contained in:
alzeih
2011-03-13 14:12:40 +13:00
parent 26f1452930
commit cf8cfdc42d
5 changed files with 98 additions and 15 deletions

View File

@@ -64,6 +64,12 @@ namespace OpenRA.Traits
public interface INotifyOtherCaptured { void OnActorCaptured(Actor self, Actor captured, Actor captor, Player oldOwner, Player newOwner); } public interface INotifyOtherCaptured { void OnActorCaptured(Actor self, Actor captured, Actor captor, Player oldOwner, Player newOwner); }
public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); } public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); }
public interface IStoreOre { int Capacity { get; }} public interface IStoreOre { int Capacity { get; }}
public interface IToolTip
{
string Name();
Player Owner();
Stance Stance();
}
public interface IDisable { bool Disabled { get; } } public interface IDisable { bool Disabled { get; } }
public interface IExplodeModifier { bool ShouldExplode(Actor self); } public interface IExplodeModifier { bool ShouldExplode(Actor self); }

View File

@@ -19,12 +19,67 @@ using OpenRA.Mods.RA.Render;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class SpyToolTipInfo : TooltipInfo, ITraitPrerequisite<SpyInfo>
{
public override object Create (ActorInitializer init) { return new SpyToolTip(init.self, this); }
}
class SpyToolTip : IToolTip
{
Actor self;
TooltipInfo Info;
Spy spy;
public string Name()
{
if (spy.Disguised)
{
if (self.Owner == self.World.LocalPlayer)
return "{0} ({1})".F(Info.Name, spy.disguisedAsName);
return spy.disguisedAsName;
}
return Info.Name;
}
public Player Owner()
{
if (spy.Disguised)
{
if (self.Owner == self.World.LocalPlayer)
return self.Owner;
return spy.disguisedAsPlayer;
}
return self.Owner;
}
public Stance Stance()
{
if (spy.Disguised)
{
if (self.Owner == self.World.LocalPlayer)
return self.World.LocalPlayer.Stances[self.Owner];
return self.World.LocalPlayer.Stances[spy.disguisedAsPlayer];
}
return self.World.LocalPlayer.Stances[self.Owner];
}
public SpyToolTip( Actor self, TooltipInfo info )
{
this.self = self;
Info = info;
spy = self.Trait<Spy>();
}
}
class SpyInfo : TraitInfo<Spy> { } class SpyInfo : TraitInfo<Spy> { }
class Spy : IIssueOrder, IResolveOrder, IOrderVoice class Spy : IIssueOrder, IResolveOrder, IOrderVoice
{ {
public Player disguisedAsPlayer; public Player disguisedAsPlayer;
public string disguisedAsSprite; public string disguisedAsSprite, disguisedAsName;
public bool Disguised { get { return disguisedAsPlayer != null; } }
public IEnumerable<IOrderTargeter> Orders public IEnumerable<IOrderTargeter> Orders
{ {
@@ -57,13 +112,17 @@ namespace OpenRA.Mods.RA
if (order.OrderString == "Disguise") if (order.OrderString == "Disguise")
{ {
var target = order.TargetActor == self ? null : order.TargetActor; var target = order.TargetActor == self ? null : order.TargetActor;
if (target != null && target.IsInWorld) if (target != null && target.IsInWorld)
{ {
disguisedAsPlayer = target.Owner; var tooltip = target.Trait<Tooltip>();
disguisedAsName = tooltip.Name();
disguisedAsPlayer = tooltip.Owner();
disguisedAsSprite = target.Trait<RenderSimple>().GetImage(target); disguisedAsSprite = target.Trait<RenderSimple>().GetImage(target);
} }
else else
{ {
disguisedAsName = null;
disguisedAsPlayer = null; disguisedAsPlayer = null;
disguisedAsSprite = null; disguisedAsSprite = null;
} }

View File

@@ -17,14 +17,33 @@ namespace OpenRA.Mods.RA
public readonly int Cost = 0; public readonly int Cost = 0;
} }
public class TooltipInfo : TraitInfo<Tooltip> public class TooltipInfo : ITraitInfo
{ {
public readonly string Description = ""; public readonly string Description = "";
public readonly string Name = ""; public readonly string Name = "";
public readonly string Icon = null; public readonly string Icon = null;
public readonly string[] AlternateName = { }; public readonly string[] AlternateName = { };
}
public virtual object Create (ActorInitializer init) { return new Tooltip(init.self, this); }
}
public class Valued { } public class Valued { }
public class Tooltip { }
public class Tooltip : IToolTip
{
Actor self;
TooltipInfo Info;
public string Name() { return Info.Name; }
public Player Owner() { return self.Owner; }
public Stance Stance() { return self.World.LocalPlayer.Stances[self.Owner]; }
public Tooltip( Actor self, TooltipInfo info )
{
this.self = self;
Info = info;
}
}
} }

View File

@@ -13,6 +13,7 @@ using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Widgets; using OpenRA.Widgets;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Widgets namespace OpenRA.Mods.RA.Widgets
{ {
@@ -53,13 +54,11 @@ namespace OpenRA.Mods.RA.Widgets
if (actor == null) if (actor == null)
return; return;
var name = actor.Info.Traits.Contains<TooltipInfo>() var tooltip = actor.TraitsImplementing<IToolTip>().FirstOrDefault();
? actor.Info.Traits.Get<TooltipInfo>().Name
: actor.Info.Name; var name = tooltip != null ? tooltip.Name() : actor.Info.Name;
var owner = (actor.Owner.NonCombatant) var owner = (tooltip != null && !tooltip.Owner().NonCombatant) ? "{0}".F(tooltip.Owner().PlayerName) : "";
? "" : "{0}".F(actor.Owner.PlayerName); var stance = (tooltip != null && tooltip.Owner() != actor.World.LocalPlayer && !tooltip.Owner().NonCombatant) ? " ({0})".F(tooltip.Stance()) : "";
var stance = (actor.Owner == world.LocalPlayer || actor.Owner.NonCombatant)
? "" : " ({0})".F(world.LocalPlayer.Stances[actor.Owner]);
var nameSize = Game.Renderer.BoldFont.Measure(name); var nameSize = Game.Renderer.BoldFont.Measure(name);
var ownerSize = Game.Renderer.RegularFont.Measure(owner); var ownerSize = Game.Renderer.RegularFont.Measure(owner);

View File

@@ -181,7 +181,7 @@ SPY:
BuiltAt: tent BuiltAt: tent
Valued: Valued:
Cost: 500 Cost: 500
Tooltip: SpyToolTip:
Name: Spy Name: Spy
Description: Infiltrates enemy structures to gather \nintelligence. Exact effect depends on the \nbuilding infiltrated.\n Strong vs Nothing\n Weak vs Everything\n Special Ability: Disguised Description: Infiltrates enemy structures to gather \nintelligence. Exact effect depends on the \nbuilding infiltrated.\n Strong vs Nothing\n Weak vs Everything\n Special Ability: Disguised
Selectable: Selectable: