From a3dba77f99aa9d4aba0acd54fded031b34297165 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 31 Oct 2009 23:17:59 +1300 Subject: [PATCH] much better building support; phantom selection is dead AGAIN. --- OpenRa.Game/IOrderGenerator.cs | 1 + OpenRa.Game/MainWindow.cs | 2 ++ OpenRa.Game/PlaceBuilding.cs | 4 +++- OpenRa.Game/Player.cs | 6 ++++- OpenRa.Game/Sidebar.cs | 39 +++++++++++++++++++++++++------ OpenRa.Game/UnitOrderGenerator.cs | 7 +++++- sequences.xml | 12 ++++++++-- 7 files changed, 59 insertions(+), 12 deletions(-) diff --git a/OpenRa.Game/IOrderGenerator.cs b/OpenRa.Game/IOrderGenerator.cs index a53877f95c..91b4e913b9 100644 --- a/OpenRa.Game/IOrderGenerator.cs +++ b/OpenRa.Game/IOrderGenerator.cs @@ -8,5 +8,6 @@ namespace OpenRa.Game { IEnumerable Order( int2 xy, bool lmb ); void PrepareOverlay( int2 xy ); + void Tick(); } } diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 63772bb59c..d8a0498712 100755 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -80,6 +80,8 @@ namespace OpenRa.Game { Game.Tick(); Game.viewport.cursor = Game.controller.ChooseCursor(); + if (Game.controller.orderGenerator != null) + Game.controller.orderGenerator.Tick(); Application.DoEvents(); } } diff --git a/OpenRa.Game/PlaceBuilding.cs b/OpenRa.Game/PlaceBuilding.cs index aa8e2f1817..e8ed8766e7 100644 --- a/OpenRa.Game/PlaceBuilding.cs +++ b/OpenRa.Game/PlaceBuilding.cs @@ -48,6 +48,8 @@ namespace OpenRa.Game public void PrepareOverlay(int2 xy) { Game.worldRenderer.uiOverlay.SetCurrentOverlay(xy, Name); - } + } + + public void Tick() { } } } diff --git a/OpenRa.Game/Player.cs b/OpenRa.Game/Player.cs index 3545bd1221..17beb34a8f 100644 --- a/OpenRa.Game/Player.cs +++ b/OpenRa.Game/Player.cs @@ -86,12 +86,14 @@ namespace OpenRa.Game public int RemainingCost { get; private set; } public bool Paused = false, Done = false; + public Action OnComplete; - public ProductionItem( string item, int time, int cost ) + public ProductionItem( string item, int time, int cost, Action onComplete ) { Item = item; RemainingTime = TotalTime = time; RemainingCost = TotalCost = cost; + OnComplete = onComplete; } public void Tick( Player player ) @@ -107,6 +109,8 @@ namespace OpenRa.Game // item finished; do whatever needs done. Done = true; + if (OnComplete != null) + OnComplete(); } } } diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs index 5ef12c8517..f1954ba9eb 100644 --- a/OpenRa.Game/Sidebar.cs +++ b/OpenRa.Game/Sidebar.cs @@ -16,6 +16,8 @@ namespace OpenRa.Game SpriteRenderer spriteRenderer, clockRenderer; Sprite blank; + Animation ready; + Animation cantBuild; readonly GRegion region; public GRegion Region { get { return region; } } @@ -49,6 +51,11 @@ namespace OpenRa.Game } blank = SheetBuilder.Add(new Size((int)spriteWidth, (int)spriteHeight), 16); + ready = new Animation("pips"); + ready.PlayRepeating("ready"); + + cantBuild = new Animation("clock"); + cantBuild.PlayFetchIndex("idle", () => 0); } const int NumClockFrames = 54; @@ -125,7 +132,12 @@ namespace OpenRa.Game void Paint() { PopulateItemList(); - foreach( SidebarItem i in items ) + + foreach( var i in items ) /* draw the buttons */ + i.Paint(spriteRenderer, region.Location); + spriteRenderer.Flush(); + + foreach( var i in items ) /* draw the status overlays */ { var group = Rules.UnitCategory[ i.Tag ]; var producing = player.Producing( group ); @@ -133,8 +145,12 @@ namespace OpenRa.Game { clockAnimations[ group ].Tick(); clockRenderer.DrawSprite( clockAnimations[ group ].Image, region.Location.ToFloat2() + i.location, 0 ); + + if (producing.Done) + clockRenderer.DrawSprite(ready.Image, region.Location.ToFloat2() + i.location + new float2((64 - ready.Image.size.X) / 2, 2), 0); } - i.Paint( spriteRenderer, region.Location ); + else if (producing != null) + clockRenderer.DrawSprite(cantBuild.Image, region.Location.ToFloat2() + i.location, 0); } Fill(region.Size.Y + region.Location.Y, new float2(region.Location.X, buildPos + region.Location.Y)); @@ -153,6 +169,11 @@ namespace OpenRa.Game return null; } + static bool IsAutoCompleting(string group) + { + return group != "Building"; + } + void MouseHandler(MouseInput mi) { var point = mi.Location.ToFloat2(); @@ -172,17 +193,21 @@ namespace OpenRa.Game * (25 * 60) /* frames per min */ /* todo: build acceleration, if we do that */ / 1000; + Action complete = null; + if (IsAutoCompleting(group)) complete = () => Build(item); + player.BeginProduction(group, - new ProductionItem(item.Tag, (int)time, ui.Cost)); - //Build(item); + new ProductionItem(item.Tag, (int)time, ui.Cost, complete)); } - else if (producing.Item == item.Tag) + else if (producing.Item == item.Tag && producing.Done) { Build(item); } } - else if( mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down ) - player.CancelProduction( Rules.UnitCategory[ item.Tag ] ); + else if (mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down) + { + player.CancelProduction(Rules.UnitCategory[item.Tag]); + } } } } diff --git a/OpenRa.Game/UnitOrderGenerator.cs b/OpenRa.Game/UnitOrderGenerator.cs index 7f0eac9b80..14950bed02 100755 --- a/OpenRa.Game/UnitOrderGenerator.cs +++ b/OpenRa.Game/UnitOrderGenerator.cs @@ -24,6 +24,11 @@ namespace OpenRa.Game } } - public void PrepareOverlay( int2 xy ) { } + public void Tick() + { + selection.RemoveAll(a => a.IsDead); + } + + public void PrepareOverlay(int2 xy) {} } } diff --git a/sequences.xml b/sequences.xml index bfc25aa657..a6988ecffe 100644 --- a/sequences.xml +++ b/sequences.xml @@ -1,4 +1,4 @@ - +