Merge pull request #12284 from reaperrr/interface-cleanups02

More explicit interface cleanups
This commit is contained in:
Paul Chote
2016-10-30 18:40:43 +00:00
committed by GitHub
23 changed files with 77 additions and 38 deletions

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits.Render
}
}
class WithGateSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, INotifyBuildComplete, IWallConnector, ITick
class WithGateSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, IWallConnector, ITick
{
readonly WithGateSpriteBodyInfo gateInfo;
readonly Gate gate;
@@ -83,12 +83,12 @@ namespace OpenRA.Mods.Common.Traits.Render
return int2.Lerp(0, DefaultAnimation.CurrentSequence.Length - 1, gate.Position, gate.OpenPosition);
}
public override void DamageStateChanged(Actor self, AttackInfo e)
protected override void DamageStateChanged(Actor self)
{
UpdateState(self);
}
public override void BuildingComplete(Actor self)
protected override void OnBuildComplete(Actor self)
{
UpdateState(self);
UpdateNeighbours(self);
@@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Traits.Render
rb.SetDirty();
}
public void RemovedFromWorld(Actor self)
void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)
{
UpdateNeighbours(self);
}

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits.Render
playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>();
}
public void BuildingComplete(Actor self)
void INotifyBuildComplete.BuildingComplete(Actor self)
{
wsb.DefaultAnimation.PlayFetchIndex(wsb.NormalizeSequence(self, info.Sequence),
() => playerResources.ResourceCapacity != 0
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits.Render
: 0);
}
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
{
playerResources = newOwner.PlayerActor.Trait<PlayerResources>();

View File

@@ -75,12 +75,17 @@ namespace OpenRA.Mods.Common.Traits.Render
return RenderSprites.NormalizeSequence(DefaultAnimation, self.GetDamageState(), sequence);
}
// TODO: Get rid of INotifyBuildComplete in favor of using the upgrade system
public virtual void BuildingComplete(Actor self)
protected virtual void OnBuildComplete(Actor self)
{
DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence));
}
// TODO: Get rid of INotifyBuildComplete in favor of using the upgrade system
void INotifyBuildComplete.BuildingComplete(Actor self)
{
OnBuildComplete(self);
}
public void PlayCustomAnimation(Actor self, string name, Action after = null)
{
DefaultAnimation.PlayThen(NormalizeSequence(self, name), () =>
@@ -112,10 +117,15 @@ namespace OpenRA.Mods.Common.Traits.Render
DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence));
}
public virtual void DamageStateChanged(Actor self, AttackInfo e)
protected virtual void DamageStateChanged(Actor self)
{
if (DefaultAnimation.CurrentSequence != null)
DefaultAnimation.ReplaceAnim(NormalizeSequence(self, DefaultAnimation.CurrentSequence.Name));
}
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{
DamageStateChanged(self);
}
}
}

View File

@@ -113,13 +113,13 @@ namespace OpenRA.Mods.Common.Traits.Render
return RenderSprites.NormalizeSequence(DefaultAnimation, self.GetDamageState(), sequence);
}
public virtual void DamageStateChanged(Actor self, AttackInfo e)
protected virtual void DamageStateChanged(Actor self)
{
if (DefaultAnimation.CurrentSequence != null)
DefaultAnimation.ReplaceAnim(NormalizeSequence(self, DefaultAnimation.CurrentSequence.Name));
}
public virtual void Tick(Actor self)
protected virtual void Tick(Actor self)
{
if (Info.AimSequence == null)
return;
@@ -128,6 +128,17 @@ namespace OpenRA.Mods.Common.Traits.Render
DefaultAnimation.ReplaceAnim(sequence);
}
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{
DamageStateChanged(self);
}
void ITick.Tick(Actor self)
{
// Split into a protected method to allow subclassing
Tick(self);
}
void INotifyBuildComplete.BuildingComplete(Actor self) { buildComplete = true; }
void INotifySold.Selling(Actor self) { buildComplete = false; }
void INotifySold.Sold(Actor self) { }

View File

@@ -54,9 +54,9 @@ namespace OpenRA.Mods.Common.Traits.Render
turreted.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
}
public override void DamageStateChanged(Actor self, AttackInfo e)
protected override void DamageStateChanged(Actor self)
{
base.DamageStateChanged(self, e);
base.DamageStateChanged(self);
turreted.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
}
}

View File

@@ -101,12 +101,12 @@ namespace OpenRA.Mods.Common.Traits.Render
wallInfo = info;
}
public override void DamageStateChanged(Actor self, AttackInfo e)
protected override void DamageStateChanged(Actor self)
{
DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), () => adjacent);
}
public void Tick(Actor self)
void ITick.Tick(Actor self)
{
if (!dirty)
return;
@@ -136,7 +136,7 @@ namespace OpenRA.Mods.Common.Traits.Render
dirty = false;
}
public override void BuildingComplete(Actor self)
protected override void OnBuildComplete(Actor self)
{
DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), () => adjacent);
UpdateNeighbours(self);