Remove color caches
This commit is contained in:
committed by
Matthias Mailänder
parent
239891070d
commit
6b463f9d9e
@@ -75,9 +75,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
this.info = info;
|
||||
|
||||
startcolor = info.StartColorUsePlayerColor ? Color.FromArgb(info.StartColorAlpha, Player.ActorColor(self)) : Color.FromArgb(info.StartColorAlpha, info.StartColor);
|
||||
endcolor = info.EndColorUsePlayerColor ? Color.FromArgb(info.EndColorAlpha, Player.ActorColor(self)) : Color.FromArgb(info.EndColorAlpha, info.EndColor ?? startcolor);
|
||||
trail = new ContrailRenderable(self.World, startcolor, endcolor, info.StartWidth, info.EndWidth ?? info.StartWidth, info.TrailLength, info.TrailDelay, info.ZOffset);
|
||||
startcolor = Color.FromArgb(info.StartColorAlpha, info.StartColor);
|
||||
endcolor = Color.FromArgb(info.EndColorAlpha, info.EndColor ?? startcolor);
|
||||
trail = new ContrailRenderable(self.World, self,
|
||||
startcolor, info.StartColorUsePlayerColor,
|
||||
endcolor, info.EndColor == null ? info.StartColorUsePlayerColor : info.EndColorUsePlayerColor,
|
||||
info.StartWidth,
|
||||
info.EndWidth ?? info.StartWidth,
|
||||
info.TrailLength, info.TrailDelay, info.ZOffset);
|
||||
|
||||
body = self.Trait<BodyOrientation>();
|
||||
}
|
||||
@@ -106,7 +111,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
||||
{
|
||||
trail = new ContrailRenderable(self.World, startcolor, endcolor, info.StartWidth, info.EndWidth ?? info.StartWidth, info.TrailLength, info.TrailDelay, info.ZOffset);
|
||||
trail = new ContrailRenderable(self.World, self,
|
||||
startcolor, info.StartColorUsePlayerColor,
|
||||
endcolor, info.EndColor == null ? info.StartColorUsePlayerColor : info.EndColorUsePlayerColor,
|
||||
info.StartWidth,
|
||||
info.EndWidth ?? info.StartWidth,
|
||||
info.TrailLength, info.TrailDelay, info.ZOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits.Render
|
||||
@@ -26,14 +25,13 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
public override object Create(ActorInitializer init) { return new RenderDebugState(init.Self, this); }
|
||||
}
|
||||
|
||||
sealed class RenderDebugState : INotifyAddedToWorld, INotifyOwnerChanged, INotifyCreated, IRenderAnnotationsWhenSelected
|
||||
sealed class RenderDebugState : INotifyAddedToWorld, INotifyCreated, IRenderAnnotationsWhenSelected
|
||||
{
|
||||
readonly DebugVisualizations debugVis;
|
||||
readonly SpriteFont font;
|
||||
readonly WVec offset;
|
||||
SquadManagerBotModule[] squadManagerModules;
|
||||
|
||||
Color color;
|
||||
string tagString;
|
||||
|
||||
public RenderDebugState(Actor self, RenderDebugStateInfo info)
|
||||
@@ -42,7 +40,6 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
var yOffset = buildingInfo?.Dimensions.Y ?? 1;
|
||||
offset = new WVec(0, 512 * yOffset, 0);
|
||||
|
||||
color = self.OwnerColor();
|
||||
font = Game.Renderer.Fonts[info.Font];
|
||||
|
||||
debugVis = self.World.WorldActor.TraitOrDefault<DebugVisualizations>();
|
||||
@@ -58,13 +55,12 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
tagString = self.ToString();
|
||||
}
|
||||
|
||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) => color = self.OwnerColor();
|
||||
|
||||
IEnumerable<IRenderable> IRenderAnnotationsWhenSelected.RenderAnnotations(Actor self, WorldRenderer wr)
|
||||
{
|
||||
if (debugVis == null || !debugVis.ActorTags)
|
||||
yield break;
|
||||
|
||||
var color = self.OwnerColor();
|
||||
yield return new TextAnnotationRenderable(font, self.CenterPosition - offset, 0, color, tagString);
|
||||
|
||||
// Get the actor's activity.
|
||||
|
||||
@@ -45,14 +45,14 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
public class WithNameTagDecoration : WithDecorationBase<WithNameTagDecorationInfo>, INotifyOwnerChanged
|
||||
{
|
||||
readonly SpriteFont font;
|
||||
readonly WithNameTagDecorationInfo info;
|
||||
string name;
|
||||
Color color;
|
||||
|
||||
public WithNameTagDecoration(Actor self, WithNameTagDecorationInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
font = Game.Renderer.Fonts[info.Font];
|
||||
color = info.UsePlayerColor ? self.OwnerColor() : info.Color;
|
||||
this.info = info;
|
||||
|
||||
name = self.Owner.PlayerName;
|
||||
if (name.Length > info.MaxLength)
|
||||
@@ -67,15 +67,12 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
var size = font.Measure(name);
|
||||
return new IRenderable[]
|
||||
{
|
||||
new UITextRenderable(font, self.CenterPosition, screenPos - size / 2, 0, color, name)
|
||||
new UITextRenderable(font, self.CenterPosition, screenPos - size / 2, 0, info.UsePlayerColor ? self.OwnerColor() : info.Color, name)
|
||||
};
|
||||
}
|
||||
|
||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
{
|
||||
if (Info.UsePlayerColor)
|
||||
color = self.OwnerColor();
|
||||
|
||||
name = self.Owner.PlayerName;
|
||||
if (name.Length > Info.MaxLength)
|
||||
name = name[..Info.MaxLength];
|
||||
|
||||
@@ -45,20 +45,16 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
public override object Create(ActorInitializer init) { return new WithTextControlGroupDecoration(init.Self, this); }
|
||||
}
|
||||
|
||||
public class WithTextControlGroupDecoration : IDecoration, INotifyOwnerChanged
|
||||
public class WithTextControlGroupDecoration : IDecoration
|
||||
{
|
||||
readonly WithTextControlGroupDecorationInfo info;
|
||||
readonly SpriteFont font;
|
||||
readonly CachedTransform<int, string> label;
|
||||
|
||||
Color color;
|
||||
|
||||
public WithTextControlGroupDecoration(Actor self, WithTextControlGroupDecorationInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
font = Game.Renderer.Fonts[info.Font];
|
||||
color = info.UsePlayerColor ? self.OwnerColor() : info.Color;
|
||||
|
||||
label = new CachedTransform<int, string>(g => self.World.ControlGroups.Groups[g]);
|
||||
}
|
||||
|
||||
@@ -74,14 +70,8 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
var screenPos = container.GetDecorationOrigin(self, wr, info.Position, info.Margin);
|
||||
return new IRenderable[]
|
||||
{
|
||||
new UITextRenderable(font, self.CenterPosition, screenPos, 0, color, text)
|
||||
new UITextRenderable(font, self.CenterPosition, screenPos, 0, info.UsePlayerColor ? self.OwnerColor() : info.Color, text)
|
||||
};
|
||||
}
|
||||
|
||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
{
|
||||
if (info.UsePlayerColor)
|
||||
color = self.OwnerColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user