From 0d25b6b5c969bcd3078f25d7b76a3233088a883d Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 31 Dec 2011 10:36:53 +1300 Subject: [PATCH] use spacebar to go to last attack event --- OpenRA.Mods.RA/Player/BaseAttackNotifier.cs | 6 +++--- OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs | 21 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs b/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs index 7def1b2376..00dfc1e916 100644 --- a/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs +++ b/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs @@ -27,8 +27,8 @@ namespace OpenRA.Mods.RA { BaseAttackNotifierInfo info; - public int lastAttackTime; - public int2 lastAttackLocation; + public int lastAttackTime = -1; + public float2 lastAttackLocation; public BaseAttackNotifier(BaseAttackNotifierInfo info) { this.info = info; } @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA if (self.World.FrameNumber - lastAttackTime > info.NotifyInterval * 25) Sound.PlayToPlayer(self.Owner, info.Audio); - lastAttackLocation = self.Location; + lastAttackLocation = self.CenterLocation / Game.CellSize; lastAttackTime = self.World.FrameNumber; } } diff --git a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs index 09a615d831..efb183becc 100644 --- a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs +++ b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs @@ -29,6 +29,8 @@ namespace OpenRA.Mods.RA.Widgets public string DeployKey = "f"; public string StanceCycleKey = "z"; public string BaseCycleKey = "backspace"; + public string GotoLastEventKey = "space"; + public readonly OrderManager OrderManager; [ObjectCreator.UseCtor] @@ -52,6 +54,9 @@ namespace OpenRA.Mods.RA.Widgets if (e.KeyName == BaseCycleKey) return CycleBases(); + if (e.KeyName == GotoLastEventKey) + return GotoLastEvent(); + if (!World.Selection.Actors.Any()) return false; @@ -162,5 +167,21 @@ namespace OpenRA.Mods.RA.Widgets Game.viewport.Center(World.Selection.Actors); return true; } + + bool GotoLastEvent() + { + if (World.LocalPlayer == null) + return true; + + var eventNotifier = World.LocalPlayer.PlayerActor.TraitOrDefault(); + if (eventNotifier == null) + return true; + + if (eventNotifier.lastAttackTime < 0) + return true; + + Game.viewport.Center(eventNotifier.lastAttackLocation); + return true; + } } } \ No newline at end of file