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:
@@ -11,40 +11,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class DisableUpgradeInfo : ITraitInfo
|
||||
public class DisableUpgradeInfo : UpgradableTraitInfo, ITraitInfo
|
||||
{
|
||||
public readonly string RequiresUpgrade = "disable";
|
||||
|
||||
public object Create(ActorInitializer init) { return new DisableUpgrade(this); }
|
||||
}
|
||||
|
||||
public class DisableUpgrade : IUpgradable, IDisable, IDisableMove
|
||||
public class DisableUpgrade : UpgradableTrait<DisableUpgradeInfo>, IDisable, IDisableMove
|
||||
{
|
||||
readonly DisableUpgradeInfo info;
|
||||
bool enabled;
|
||||
|
||||
public DisableUpgrade(DisableUpgradeInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
: base(info) { }
|
||||
|
||||
public bool AcceptsUpgrade(string type)
|
||||
{
|
||||
return type == info.RequiresUpgrade;
|
||||
}
|
||||
|
||||
public void UpgradeAvailable(Actor self, string type, bool available)
|
||||
{
|
||||
if (type == info.RequiresUpgrade)
|
||||
enabled = available;
|
||||
}
|
||||
|
||||
public bool Disabled { get { return enabled; } }
|
||||
|
||||
public bool MoveDisabled(Actor self) { return enabled; }
|
||||
// Disable the actor when this trait is enabled.
|
||||
public bool Disabled { get { return !IsTraitDisabled; } }
|
||||
public bool MoveDisabled(Actor self) { return !IsTraitDisabled; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user