Make RenderSprites aware of EffectiveOwner. Fixes #5526.

This commit is contained in:
Paul Chote
2014-06-02 18:21:06 +12:00
parent ca9148c2d5
commit c0d7c7d840
4 changed files with 39 additions and 40 deletions

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Traits
public virtual object Create(ActorInitializer init) { return new RenderSprites(init.self); } public virtual object Create(ActorInitializer init) { return new RenderSprites(init.self); }
} }
public class RenderSprites : IRender, ITick, INotifyOwnerChanged public class RenderSprites : IRender, ITick, INotifyOwnerChanged, INotifyEffectiveOwnerChanged
{ {
class AnimationWrapper class AnimationWrapper
{ {
@@ -78,12 +78,12 @@ namespace OpenRA.Traits
return () => facing.Facing; return () => facing.Facing;
} }
RenderSpritesInfo Info; readonly RenderSpritesInfo info;
string cachedImage = null; string cachedImage = null;
public RenderSprites(Actor self) public RenderSprites(Actor self)
{ {
Info = self.Info.Traits.Get<RenderSpritesInfo>(); info = self.Info.Traits.Get<RenderSpritesInfo>();
} }
public static string GetImage(ActorInfo actor) public static string GetImage(ActorInfo actor)
@@ -100,11 +100,6 @@ namespace OpenRA.Traits
return cachedImage = GetImage(self.Info); return cachedImage = GetImage(self.Info);
} }
protected virtual string PaletteName(Actor self)
{
return Info.Palette ?? Info.PlayerPalette + self.Owner.InternalName;
}
protected void UpdatePalette() protected void UpdatePalette()
{ {
foreach (var anim in anims.Values) foreach (var anim in anims.Values)
@@ -112,6 +107,7 @@ namespace OpenRA.Traits
} }
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) { UpdatePalette(); } public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) { UpdatePalette(); }
public void OnEffectiveOwnerChanged(Actor self, Player oldEffectiveOwner, Player newEffectiveOwner) { UpdatePalette(); }
public virtual IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr) public virtual IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr)
{ {
@@ -121,9 +117,12 @@ namespace OpenRA.Traits
continue; continue;
if (a.PaletteReference == null) if (a.PaletteReference == null)
a.CachePalette(wr, self.Owner); {
var owner = self.EffectiveOwner != null && self.EffectiveOwner.Disguised ? self.EffectiveOwner.Owner : self.Owner;
a.CachePalette(wr, owner);
}
foreach (var r in a.Animation.Render(self, wr, a.PaletteReference, Info.Scale)) foreach (var r in a.Animation.Render(self, wr, a.PaletteReference, info.Scale))
yield return r; yield return r;
} }
} }
@@ -139,8 +138,8 @@ namespace OpenRA.Traits
// Use defaults // Use defaults
if (palette == null) if (palette == null)
{ {
palette = Info.Palette ?? Info.PlayerPalette; palette = info.Palette ?? info.PlayerPalette;
isPlayerPalette = Info.Palette == null; isPlayerPalette = info.Palette == null;
} }
anims.Add(key, new AnimationWrapper(anim, palette, isPlayerPalette)); anims.Add(key, new AnimationWrapper(anim, palette, isPlayerPalette));
@@ -173,7 +172,7 @@ namespace OpenRA.Traits
{ {
return anims.Values.Where(b => b.IsVisible return anims.Values.Where(b => b.IsVisible
&& b.Animation.Animation.CurrentSequence != null) && b.Animation.Animation.CurrentSequence != null)
.Select(a => (a.Animation.Animation.Image.size*Info.Scale).ToInt2()) .Select(a => (a.Animation.Animation.Image.size*info.Scale).ToInt2())
.FirstOrDefault(); .FirstOrDefault();
} }
} }

View File

@@ -77,6 +77,7 @@ namespace OpenRA.Traits
public interface INotifyProduction { void UnitProduced(Actor self, Actor other, CPos exit); } public interface INotifyProduction { void UnitProduced(Actor self, Actor other, CPos exit); }
public interface INotifyDelivery { void IncomingDelivery(Actor self); void Delivered(Actor self); } public interface INotifyDelivery { void IncomingDelivery(Actor self); void Delivered(Actor self); }
public interface INotifyOwnerChanged { void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner); } public interface INotifyOwnerChanged { void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner); }
public interface INotifyEffectiveOwnerChanged { void OnEffectiveOwnerChanged(Actor self, Player oldEffectiveOwner, Player newEffectiveOwner); }
public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); } public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); }
public interface INotifyHarvest { void Harvested(Actor self, ResourceType resource); } public interface INotifyHarvest { void Harvested(Actor self, ResourceType resource); }
public interface ISeedableResource { void Seed(Actor self); } public interface ISeedableResource { void Seed(Actor self); }

View File

@@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA
} }
} }
public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued ) public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
{ {
if (order.OrderID == "Disguise") if (order.OrderID == "Disguise")
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor }; return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
@@ -90,12 +90,8 @@ 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 && order.TargetActor.IsInWorld ? order.TargetActor : null;
DisguiseAs(self, target);
if (target != null && target.IsInWorld)
DisguiseAs(target);
else
DropDisguise();
} }
} }
@@ -112,22 +108,29 @@ namespace OpenRA.Mods.RA
return AsPlayer.Color.RGB; return AsPlayer.Color.RGB;
} }
void DisguiseAs(Actor target) void DisguiseAs(Actor self, Actor target)
{ {
var tooltip = target.TraitsImplementing<IToolTip>().FirstOrDefault(); var oldEffectiveOwner = AsPlayer;
AsName = tooltip.Name();
AsPlayer = tooltip.Owner(); if (target != null)
AsSprite = target.Trait<RenderSprites>().GetImage(target); {
var tooltip = target.TraitsImplementing<IToolTip>().FirstOrDefault();
AsName = tooltip.Name();
AsPlayer = tooltip.Owner();
AsSprite = target.Trait<RenderSprites>().GetImage(target);
}
else
{
AsName = null;
AsPlayer = null;
AsSprite = null;
}
foreach (var t in self.TraitsImplementing<INotifyEffectiveOwnerChanged>())
t.OnEffectiveOwnerChanged(self, oldEffectiveOwner, AsPlayer);
} }
void DropDisguise() public void Attacking(Actor self, Target target, Armament a, Barrel barrel) { DisguiseAs(self, null); }
{
AsName = null;
AsPlayer = null;
AsSprite = null;
}
public void Attacking(Actor self, Target target, Armament a, Barrel barrel) { DropDisguise(); }
} }
class IgnoresDisguiseInfo : TraitInfo<IgnoresDisguise> {} class IgnoresDisguiseInfo : TraitInfo<IgnoresDisguise> {}

View File

@@ -8,9 +8,11 @@
*/ */
#endregion #endregion
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render namespace OpenRA.Mods.RA.Render
{ {
class RenderDisguiseInfo : RenderInfantryProneInfo class RenderDisguiseInfo : RenderInfantryProneInfo, Requires<DisguiseInfo>
{ {
public override object Create(ActorInitializer init) { return new RenderDisguise(init.self, this); } public override object Create(ActorInitializer init) { return new RenderDisguise(init.self, this); }
} }
@@ -29,12 +31,6 @@ namespace OpenRA.Mods.RA.Render
intendedSprite = disguise.AsSprite; intendedSprite = disguise.AsSprite;
} }
protected override string PaletteName(Actor self)
{
var player = disguise.AsPlayer ?? self.Owner;
return info.Palette ?? info.PlayerPalette + player.InternalName;
}
public override void Tick(Actor self) public override void Tick(Actor self)
{ {
if (disguise.AsSprite != intendedSprite) if (disguise.AsSprite != intendedSprite)