From df3581237ea31aafc1dce457f8507cd536519405 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 8 Jul 2010 20:23:19 +1200 Subject: [PATCH] Remove hardcoded cursor bs; move TransformsOnDeploy to Mods.RA. --- OpenRA.Game/OpenRA.Game.csproj | 4 +- OpenRA.Game/Orders/UnitOrderGenerator.cs | 40 +------------------ OpenRA.Game/Traits/Mobile.cs | 10 ++++- OpenRA.Game/Traits/Production.cs | 9 ++++- OpenRA.Game/Traits/TraitsInterfaces.cs | 1 + OpenRA.Mods.Aftermath/ChronoshiftDeploy.cs | 7 +++- .../Activities/TransformIntoActor.cs | 3 +- OpenRA.Mods.RA/AttackBase.cs | 12 +++++- OpenRA.Mods.RA/C4Demolition.cs | 7 +++- OpenRA.Mods.RA/Cargo.cs | 7 +++- OpenRA.Mods.RA/ConstructionYard.cs | 7 +++- OpenRA.Mods.RA/EngineerCapture.cs | 8 +++- OpenRA.Mods.RA/Harvester.cs | 10 ++++- OpenRA.Mods.RA/Helicopter.cs | 7 +++- OpenRA.Mods.RA/Minelayer.cs | 7 +++- OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 2 + OpenRA.Mods.RA/Passenger.cs | 7 +++- OpenRA.Mods.RA/Plane.cs | 9 ++++- OpenRA.Mods.RA/Repairable.cs | 8 +++- OpenRA.Mods.RA/RepairableNear.cs | 7 +++- OpenRA.Mods.RA/Spy.cs | 7 +++- .../TransformsOnDeploy.cs | 22 +++++++++- 22 files changed, 138 insertions(+), 63 deletions(-) rename {OpenRA.Game/Traits => OpenRA.Mods.RA}/Activities/TransformIntoActor.cs (94%) rename {OpenRA.Game/Traits => OpenRA.Mods.RA}/TransformsOnDeploy.cs (76%) diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 81fea38a21..1b7466b8f1 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -132,7 +132,6 @@ - @@ -182,7 +181,6 @@ - @@ -264,5 +262,7 @@ --> + + \ No newline at end of file diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index 9eaf47d474..f4e2a0016f 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -74,7 +74,8 @@ namespace OpenRA.Orders { var p = Game.controller.MousePosition; var c = Order(world, p.ToInt2(), mi) - .Select(o => CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation)) + .Select(o => o.Subject.traits.WithInterface() + .Select(pc => pc.CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation)).FirstOrDefault(a => a != null)) .FirstOrDefault(a => a != null); return c ?? @@ -83,42 +84,5 @@ namespace OpenRA.Orders ? "select" : "default"); } } - - string CursorForOrderString(string s, Actor a, int2 location) - { - switch (s) - { - case "Attack": return "attack"; - case "Heal": return "heal"; - case "C4": return "c4"; - case "Move": - if (a.traits.GetOrDefault().CanEnterCell(location)) - return "move"; - else - return "move-blocked"; - case "DeployTransform": - var depInfo = a.Info.Traits.Get(); - var transInfo = Rules.Info[depInfo.TransformsInto]; - if (transInfo.Traits.Contains()) - { - var bi = transInfo.Traits.Get(); - if (!a.World.CanPlaceBuilding(depInfo.TransformsInto, bi, a.Location + new int2(depInfo.Offset[0], depInfo.Offset[1]), a)) - return "deploy-blocked"; - } - return "deploy"; - - case "Deploy": return "deploy"; - case "Enter": return "enter"; - case "EnterTransport": return "enter"; - case "Deliver": return "enter"; - case "Infiltrate": return "enter"; - case "Capture": return "capture"; - case "Harvest": return "attackmove"; - case "Steal" : return "enter"; - case "BeginMinefield": return "ability"; - default: - return null; - } - } } } diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index c4cafa934f..034ff3d49f 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -37,7 +37,7 @@ namespace OpenRA.Traits public virtual object Create(ActorInitializer init) { return new Mobile(init, this); } } - public class Mobile : IIssueOrder, IResolveOrder, IOccupySpace, IMove + public class Mobile : IIssueOrder, IResolveOrder, IOccupySpace, IMove, IProvideCursor { public readonly Actor self; public readonly MobileInfo Info; @@ -121,6 +121,14 @@ namespace OpenRA.Traits } } } + + public string CursorForOrderString(string s, Actor a, int2 location) + { + if (s != "Move") + return null; + + return (CanEnterCell(location)) ? "move" : "move-blocked"; + } public int2 TopLeft { get { return toCell; } } diff --git a/OpenRA.Game/Traits/Production.cs b/OpenRA.Game/Traits/Production.cs index d92397582e..5245c509fd 100755 --- a/OpenRA.Game/Traits/Production.cs +++ b/OpenRA.Game/Traits/Production.cs @@ -32,7 +32,7 @@ namespace OpenRA.Traits public readonly string[] Produces = { }; } - public class Production : IIssueOrder, IResolveOrder, ITags + public class Production : IIssueOrder, IResolveOrder, ITags, IProvideCursor { public virtual int2? CreationLocation( Actor self, ActorInfo producee ) { @@ -108,7 +108,12 @@ namespace OpenRA.Traits return new Order("Deploy", self); return null; } - + + public string CursorForOrderString(string s, Actor a, int2 location) + { + return (s == "Deploy") ? "deploy" : null; + } + public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "Deploy") diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 0bf21dc4f0..54c88a7082 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -46,6 +46,7 @@ namespace OpenRA.Traits public interface IRender { IEnumerable Render(Actor self); } public interface IIssueOrder { Order IssueOrder( Actor self, int2 xy, MouseInput mi, Actor underCursor ); } public interface IResolveOrder { void ResolveOrder(Actor self, Order order); } + public interface IProvideCursor { string CursorForOrderString(string s, Actor a, int2 location); } public interface INotifySold { void Selling( Actor self ); void Sold( Actor self ); } public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); } diff --git a/OpenRA.Mods.Aftermath/ChronoshiftDeploy.cs b/OpenRA.Mods.Aftermath/ChronoshiftDeploy.cs index 5c357dba98..d739c2d206 100644 --- a/OpenRA.Mods.Aftermath/ChronoshiftDeploy.cs +++ b/OpenRA.Mods.Aftermath/ChronoshiftDeploy.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Aftermath public readonly int ChargeTime = 120; // Seconds } - class ChronoshiftDeploy : IIssueOrder, IResolveOrder, ITick, IPips + class ChronoshiftDeploy : IIssueOrder, IResolveOrder, ITick, IPips, IProvideCursor { // Recharge logic [Sync] @@ -78,6 +78,11 @@ namespace OpenRA.Mods.Aftermath } } + public string CursorForOrderString(string s, Actor a, int2 location) + { + return (s == "Deploy") ? "deploy" : null; + } + // Display 5 pips indicating the current charge status public IEnumerable GetPips(Actor self) { diff --git a/OpenRA.Game/Traits/Activities/TransformIntoActor.cs b/OpenRA.Mods.RA/Activities/TransformIntoActor.cs similarity index 94% rename from OpenRA.Game/Traits/Activities/TransformIntoActor.cs rename to OpenRA.Mods.RA/Activities/TransformIntoActor.cs index be5df15845..e30f733575 100644 --- a/OpenRA.Game/Traits/Activities/TransformIntoActor.cs +++ b/OpenRA.Mods.RA/Activities/TransformIntoActor.cs @@ -19,8 +19,9 @@ #endregion using System; +using OpenRA.Traits; -namespace OpenRA.Traits.Activities +namespace OpenRA.Mods.RA.Activities { class TransformIntoActor : IActivity { diff --git a/OpenRA.Mods.RA/AttackBase.cs b/OpenRA.Mods.RA/AttackBase.cs index b2b38e77e4..040eba6e36 100755 --- a/OpenRA.Mods.RA/AttackBase.cs +++ b/OpenRA.Mods.RA/AttackBase.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA public virtual object Create(ActorInitializer init) { return new AttackBase(init.self); } } - public class AttackBase : IIssueOrder, IResolveOrder, ITick, IExplodeModifier + public class AttackBase : IIssueOrder, IResolveOrder, ITick, IExplodeModifier, IProvideCursor { [Sync] public Actor target; @@ -253,6 +253,16 @@ namespace OpenRA.Mods.RA target = null; } + public string CursorForOrderString(string s, Actor a, int2 location) + { + switch (s) + { + case "Attack": return "attack"; + case "Heal": return "heal"; + default: return null; + } + } + protected virtual void QueueAttack(Actor self, Order order) { /* todo: choose the appropriate weapon, when only one works against this target */ diff --git a/OpenRA.Mods.RA/C4Demolition.cs b/OpenRA.Mods.RA/C4Demolition.cs index 410593a66c..e82232c00e 100644 --- a/OpenRA.Mods.RA/C4Demolition.cs +++ b/OpenRA.Mods.RA/C4Demolition.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA public readonly float C4Delay = 0; } - class C4Demolition : IIssueOrder, IResolveOrder + class C4Demolition : IIssueOrder, IResolveOrder, IProvideCursor { public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { @@ -51,5 +51,10 @@ namespace OpenRA.Mods.RA self.QueueActivity(new Move(self.Location, 0)); } } + + public string CursorForOrderString(string s, Actor a, int2 location) + { + return (s == "C4") ? "c4" : null; + } } } diff --git a/OpenRA.Mods.RA/Cargo.cs b/OpenRA.Mods.RA/Cargo.cs index 1dd5882de3..baa3b52851 100644 --- a/OpenRA.Mods.RA/Cargo.cs +++ b/OpenRA.Mods.RA/Cargo.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA public readonly int UnloadFacing = 0; } - public class Cargo : IPips, IIssueOrder, IResolveOrder + public class Cargo : IPips, IIssueOrder, IResolveOrder, IProvideCursor { List cargo = new List(); @@ -59,6 +59,11 @@ namespace OpenRA.Mods.RA self.QueueActivity(new UnloadCargo()); } } + + public string CursorForOrderString(string s, Actor a, int2 location) + { + return (s == "Deploy") ? "deploy" : null; + } public bool IsFull(Actor self) { diff --git a/OpenRA.Mods.RA/ConstructionYard.cs b/OpenRA.Mods.RA/ConstructionYard.cs index 49116e0307..5d5de112a0 100755 --- a/OpenRA.Mods.RA/ConstructionYard.cs +++ b/OpenRA.Mods.RA/ConstructionYard.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA { class ConstructionYardInfo : TraitInfo { } - public class ConstructionYard : IIssueOrder, IResolveOrder + public class ConstructionYard : IIssueOrder, IResolveOrder, IProvideCursor { public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { @@ -37,6 +37,11 @@ namespace OpenRA.Mods.RA return null; } + public string CursorForOrderString(string s, Actor a, int2 location) + { + return (s == "Deploy") ? "deploy" : null; + } + public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "Deploy") diff --git a/OpenRA.Mods.RA/EngineerCapture.cs b/OpenRA.Mods.RA/EngineerCapture.cs index c25f121008..da6a84cc8c 100644 --- a/OpenRA.Mods.RA/EngineerCapture.cs +++ b/OpenRA.Mods.RA/EngineerCapture.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA public readonly int EngineerDamage = 300; } - class EngineerCapture : IIssueOrder, IResolveOrder + class EngineerCapture : IIssueOrder, IResolveOrder, IProvideCursor { public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) @@ -48,6 +48,12 @@ namespace OpenRA.Mods.RA self, underCursor); } + public string CursorForOrderString(string s, Actor a, int2 location) + { + return (s == "Infiltrate") ? "enter" : + (s == "Capture") ? "capture" : null; + } + public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "Infiltrate" || order.OrderString == "Capture") diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index 66f43baeda..e868972479 100755 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA public object Create(ActorInitializer init) { return new Harvester(init.self, this); } } - public class Harvester : IIssueOrder, IResolveOrder, INotifyDamage, IPips, IRenderModifier, IExplodeModifier + public class Harvester : IIssueOrder, IResolveOrder, INotifyDamage, IPips, IRenderModifier, IExplodeModifier, IProvideCursor { Dictionary contents = new Dictionary(); @@ -113,7 +113,13 @@ namespace OpenRA.Mods.RA return null; } - + + public string CursorForOrderString(string s, Actor a, int2 location) + { + return (s == "Deliver") ? "enter" : + (s == "Harvest") ? "attackmove" : null; + } + public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "Harvest") diff --git a/OpenRA.Mods.RA/Helicopter.cs b/OpenRA.Mods.RA/Helicopter.cs index b42bcf012f..d95257f329 100644 --- a/OpenRA.Mods.RA/Helicopter.cs +++ b/OpenRA.Mods.RA/Helicopter.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA public override object Create( ActorInitializer init ) { return new Helicopter( init ); } } - class Helicopter : Aircraft, ITick, IIssueOrder, IResolveOrder + class Helicopter : Aircraft, ITick, IIssueOrder, IResolveOrder, IProvideCursor { public IDisposable reservation; @@ -61,6 +61,11 @@ namespace OpenRA.Mods.RA return null; } + + public string CursorForOrderString(string s, Actor a, int2 location) + { + return (s == "Enter") ? "enter" : null; + } public void ResolveOrder(Actor self, Order order) { diff --git a/OpenRA.Mods.RA/Minelayer.cs b/OpenRA.Mods.RA/Minelayer.cs index 57640b2538..f019903f28 100644 --- a/OpenRA.Mods.RA/Minelayer.cs +++ b/OpenRA.Mods.RA/Minelayer.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA public readonly string[] RearmBuildings = { "fix" }; } - class Minelayer : IIssueOrder, IResolveOrder + class Minelayer : IIssueOrder, IResolveOrder, IProvideCursor { /* [Sync] when sync can cope with arrays! */ public int2[] minefield = null; [Sync] int2 minefieldStart; @@ -49,6 +49,11 @@ namespace OpenRA.Mods.RA return null; } + public string CursorForOrderString(string s, Actor a, int2 location) + { + return (s == "BeginMinefield") ? "ability" : null; + } + public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "BeginMinefield") diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 49fc099ce1..e26f13fc40 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -202,6 +202,8 @@ + + diff --git a/OpenRA.Mods.RA/Passenger.cs b/OpenRA.Mods.RA/Passenger.cs index 2eb6673a0b..ef4ab6b70a 100644 --- a/OpenRA.Mods.RA/Passenger.cs +++ b/OpenRA.Mods.RA/Passenger.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA public readonly PipType ColorOfCargoPip = PipType.Green; } - class Passenger : IIssueOrder, IResolveOrder + class Passenger : IIssueOrder, IResolveOrder, IProvideCursor { public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { @@ -51,6 +51,11 @@ namespace OpenRA.Mods.RA return new Order("EnterTransport", self, underCursor); } + + public string CursorForOrderString(string s, Actor a, int2 location) + { + return (s == "EnterTransport") ? "enter" : null; + } public void ResolveOrder(Actor self, Order order) { diff --git a/OpenRA.Mods.RA/Plane.cs b/OpenRA.Mods.RA/Plane.cs index b316971316..4cad4b3ce6 100644 --- a/OpenRA.Mods.RA/Plane.cs +++ b/OpenRA.Mods.RA/Plane.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA public override object Create( ActorInitializer init ) { return new Plane( init ); } } - public class Plane : Aircraft, IIssueOrder, IResolveOrder + public class Plane : Aircraft, IIssueOrder, IResolveOrder, IProvideCursor { public IDisposable reservation; @@ -50,7 +50,12 @@ namespace OpenRA.Mods.RA return null; } - + + public string CursorForOrderString(string s, Actor a, int2 location) + { + return (s == "Enter") ? "enter" : null; + } + public void ResolveOrder(Actor self, Order order) { if (reservation != null) diff --git a/OpenRA.Mods.RA/Repairable.cs b/OpenRA.Mods.RA/Repairable.cs index 986c974495..9003b5a070 100644 --- a/OpenRA.Mods.RA/Repairable.cs +++ b/OpenRA.Mods.RA/Repairable.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA { class RepairableInfo : TraitInfo { public readonly string[] RepairBuildings = { "fix" }; } - class Repairable : IIssueOrder, IResolveOrder + class Repairable : IIssueOrder, IResolveOrder, IProvideCursor { public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { @@ -41,9 +41,13 @@ namespace OpenRA.Mods.RA return null; } + public string CursorForOrderString(string s, Actor a, int2 location) + { + return (s == "Enter") ? "enter" : null; + } + public void ResolveOrder(Actor self, Order order) { - if (order.OrderString == "Enter") { var rp = order.TargetActor.traits.GetOrDefault(); diff --git a/OpenRA.Mods.RA/RepairableNear.cs b/OpenRA.Mods.RA/RepairableNear.cs index 5d414a23ff..ecd2542d2b 100644 --- a/OpenRA.Mods.RA/RepairableNear.cs +++ b/OpenRA.Mods.RA/RepairableNear.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA public readonly string[] Buildings = { "spen", "syrd" }; } - class RepairableNear : IIssueOrder, IResolveOrder + class RepairableNear : IIssueOrder, IResolveOrder, IProvideCursor { public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { @@ -46,6 +46,11 @@ namespace OpenRA.Mods.RA return null; } + public string CursorForOrderString(string s, Actor a, int2 location) + { + return (s == "Enter") ? "enter" : null; + } + public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "Enter") diff --git a/OpenRA.Mods.RA/Spy.cs b/OpenRA.Mods.RA/Spy.cs index 52f45f84eb..06965a6e67 100644 --- a/OpenRA.Mods.RA/Spy.cs +++ b/OpenRA.Mods.RA/Spy.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA { class SpyInfo : TraitInfo { } - class Spy : IIssueOrder, IResolveOrder + class Spy : IIssueOrder, IResolveOrder, IProvideCursor { public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { @@ -38,6 +38,11 @@ namespace OpenRA.Mods.RA return new Order("Infiltrate", self, underCursor); } + public string CursorForOrderString(string s, Actor a, int2 location) + { + return (s == "Infiltrate") ? "enter" : null; + } + public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "Infiltrate") diff --git a/OpenRA.Game/Traits/TransformsOnDeploy.cs b/OpenRA.Mods.RA/TransformsOnDeploy.cs similarity index 76% rename from OpenRA.Game/Traits/TransformsOnDeploy.cs rename to OpenRA.Mods.RA/TransformsOnDeploy.cs index 2de9ba5d71..a0f9206497 100644 --- a/OpenRA.Game/Traits/TransformsOnDeploy.cs +++ b/OpenRA.Mods.RA/TransformsOnDeploy.cs @@ -18,9 +18,11 @@ */ #endregion +using OpenRA.Mods.RA.Activities; +using OpenRA.Traits; using OpenRA.Traits.Activities; -namespace OpenRA.Traits +namespace OpenRA.Mods.RA { class TransformsOnDeployInfo : TraitInfo { @@ -33,7 +35,7 @@ namespace OpenRA.Traits public readonly string[] NoTransformSounds = null; } - class TransformsOnDeploy : IIssueOrder, IResolveOrder + class TransformsOnDeploy : IIssueOrder, IResolveOrder, IProvideCursor { public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { @@ -77,5 +79,21 @@ namespace OpenRA.Traits self.QueueActivity(new TransformIntoActor(info.TransformsInto, new int2(info.Offset[0], info.Offset[1]), info.TransferHealthPercentage, info.TransformSounds)); } } + + public string CursorForOrderString(string s, Actor a, int2 location) + { + if (s != "DeployTransform") + return null; + + var depInfo = a.Info.Traits.Get(); + var transInfo = Rules.Info[depInfo.TransformsInto]; + if (transInfo.Traits.Contains()) + { + var bi = transInfo.Traits.Get(); + if (!a.World.CanPlaceBuilding(depInfo.TransformsInto, bi, a.Location + new int2(depInfo.Offset[0], depInfo.Offset[1]), a)) + return "deploy-blocked"; + } + return "deploy"; + } } }