Added IDisabledTrait & rewrote upgrade code using a level-based approach.

Upgradeable traits are notified whenever an upgrade of their declared types are granted or revoked.  The traits maintain their own internal level counter, which is then used to enable or disable the trait functionality.  A trait can register for multiple upgrade types which then all affect the internal level counter.

	IDisabledTrait for identifying (and filtering) disabled traits
	UpgradableTrait provides an abstract base for traits to support upgrade levels
	Added IDisabledTrait support to GlobalButtonOrderGenerator

	Includes rework by pchote with alterations.
This commit is contained in:
atlimit8
2014-10-13 18:09:16 -05:00
parent 76cf5b8b98
commit bbd54cb32f
38 changed files with 545 additions and 415 deletions

View File

@@ -15,26 +15,18 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Display a colored overlay when a timed upgrade is active.")]
public class UpgradeOverlayInfo : ITraitInfo
public class UpgradeOverlayInfo : UpgradableTraitInfo, ITraitInfo
{
[Desc("Upgrade that is required before this overlay is rendered")]
public readonly string RequiresUpgrade = null;
[Desc("Palette to use when rendering the overlay")]
public readonly string Palette = "invuln";
public object Create(ActorInitializer init) { return new UpgradeOverlay(this); }
}
public class UpgradeOverlay : IRenderModifier, IUpgradable
public class UpgradeOverlay : UpgradableTrait<UpgradeOverlayInfo>, IRenderModifier
{
readonly UpgradeOverlayInfo info;
bool enabled;
public UpgradeOverlay(UpgradeOverlayInfo info)
{
this.info = info;
}
: base (info) { }
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
{
@@ -42,22 +34,11 @@ namespace OpenRA.Mods.Common.Traits
{
yield return a;
if (enabled && !a.IsDecoration)
yield return a.WithPalette(wr.Palette(info.Palette))
if (!IsTraitDisabled && !a.IsDecoration)
yield return a.WithPalette(wr.Palette(Info.Palette))
.WithZOffset(a.ZOffset + 1)
.AsDecoration();
}
}
public bool AcceptsUpgrade(string type)
{
return type == info.RequiresUpgrade;
}
public void UpgradeAvailable(Actor self, string type, bool available)
{
if (type == info.RequiresUpgrade)
enabled = available;
}
}
}