diff --git a/OpenRa.Game/Harvester.cs b/OpenRa.Game/Harvester.cs index 860fe6d7b0..67e46d22d4 100644 --- a/OpenRa.Game/Harvester.cs +++ b/OpenRa.Game/Harvester.cs @@ -11,11 +11,11 @@ namespace OpenRa.Game { } - public override IOrder Order( int2 xy ) + public override IOrder Order( Game game, int2 xy ) { if( ( fromCell == toCell || moveFraction == 0 ) && fromCell == xy ) return new HarvestOrder( this ); - return base.Order( xy ); + return base.Order( game, xy ); } void AcceptHarvestOrder() diff --git a/OpenRa.Game/IOrderGenerator.cs b/OpenRa.Game/IOrderGenerator.cs index 6dee93001b..74ec7ca9c6 100644 --- a/OpenRa.Game/IOrderGenerator.cs +++ b/OpenRa.Game/IOrderGenerator.cs @@ -6,7 +6,7 @@ namespace OpenRa.Game { interface IOrderGenerator { - //Sprite CurrentCursor( int x, int y ); - IOrder Order( int2 xy ); + IOrder Order( Game game, int2 xy ); + void PrepareOverlay( Game game, int2 xy ); } } diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 49c231ab60..7b1af0f8a8 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -89,6 +89,10 @@ namespace OpenRa.Game game.viewport.Scroll(lastPos - p); lastPos = p; } + + if (game.world.orderGenerator != null) + game.world.orderGenerator.PrepareOverlay(game, + new int2(e.Location.X / 24, e.Location.Y / 24)); } } } diff --git a/OpenRa.Game/Mcv.cs b/OpenRa.Game/Mcv.cs index 5e68fddb79..a5656f3dee 100644 --- a/OpenRa.Game/Mcv.cs +++ b/OpenRa.Game/Mcv.cs @@ -35,12 +35,12 @@ namespace OpenRa.Game }; } - public override IOrder Order( int2 xy ) + public override IOrder Order( Game game, int2 xy ) { if( ( fromCell == toCell || moveFraction == 0 ) && fromCell == xy ) return new DeployMcvOrder( this ); - return base.Order( xy ); + return base.Order( game, xy ); } } } diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs index a3877ed5f7..2d57ce3474 100644 --- a/OpenRa.Game/Sidebar.cs +++ b/OpenRa.Game/Sidebar.cs @@ -48,8 +48,8 @@ namespace OpenRa.Game public void Build(SidebarItem item) { - if( item != null ) - game.world.orderGenerator = new PlaceBuilding( game.players[ 1 ], item.techTreeItem.tag.ToLowerInvariant() ); + if (item != null) + game.world.orderGenerator = new PlaceBuilding(game.players[1], item.techTreeItem.tag.ToLowerInvariant()); } void LoadSprites(string filename) @@ -141,12 +141,18 @@ namespace OpenRa.Game this.buildingName = buildingName; } - public IOrder Order( int2 xy ) + public IOrder Order( Game game, int2 xy ) { + game.world.uiOverlay.KillOverlay(); // todo: check that space is free return new PlaceBuildingOrder( this, xy ); } + public void PrepareOverlay(Game game, int2 xy) + { + game.world.uiOverlay.SetCurrentOverlay(false, xy, 2, 3); + } + class PlaceBuildingOrder : IOrder { PlaceBuilding building; diff --git a/OpenRa.Game/UiOverlay.cs b/OpenRa.Game/UiOverlay.cs index ebb70b987c..3b6b91cdfb 100644 --- a/OpenRa.Game/UiOverlay.cs +++ b/OpenRa.Game/UiOverlay.cs @@ -34,9 +34,31 @@ namespace OpenRa.Game public void Draw() { - spriteRenderer.DrawSprite(buildOk, new float2(48, 48), 0); - spriteRenderer.DrawSprite(buildBlocked, new float2(96, 48), 0); - spriteRenderer.Flush(); + if (!hasOverlay) + return; + + for (int i = 0; i < width; i++) + for (int j = 0; j < height; j++) + spriteRenderer.DrawSprite(blocked ? buildBlocked : buildOk, + 24 * (position + new int2(i, j)), 0); + } + + bool hasOverlay = false, blocked; + int2 position; + int width, height; + + public void KillOverlay() + { + hasOverlay = false; + } + + public void SetCurrentOverlay(bool blocked, int2 cell, int width, int height) + { + hasOverlay = true; + position = cell; + this.width = width; + this.height = height; + this.blocked = blocked; } } } diff --git a/OpenRa.Game/Unit.cs b/OpenRa.Game/Unit.cs index c2d87c567b..8dae1c3ff6 100644 --- a/OpenRa.Game/Unit.cs +++ b/OpenRa.Game/Unit.cs @@ -126,7 +126,9 @@ namespace OpenRa.Game } public int2 Location { get { return toCell; } } - public virtual IOrder Order(int2 xy) { return new MoveOrder(this, xy); } + public virtual IOrder Order(Game game, int2 xy) { return new MoveOrder(this, xy); } public override Sprite[] CurrentImages { get { return animation.Images; } } + + public void PrepareOverlay(Game game, int2 xy) { } } } diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index a9ceb4e37a..8c0685cab3 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -16,7 +16,7 @@ namespace OpenRa.Game Game game; Region region; public IOrderGenerator orderGenerator; - UiOverlay uiOverlay; + public UiOverlay uiOverlay; public World(Renderer renderer, Game game) { @@ -40,7 +40,7 @@ namespace OpenRa.Game float2 xy = (1 / 24.0f) * (new float2(e.Location) + game.viewport.Location); if (orderGenerator != null) { - IOrder order = orderGenerator.Order(new int2((int)xy.X, (int)xy.Y)); + IOrder order = orderGenerator.Order(game, new int2((int)xy.X, (int)xy.Y)); game.Issue(order); } } @@ -52,7 +52,7 @@ namespace OpenRa.Game lastTime = t; Range range = new Range(region.Location, region.Location + region.Size); - + foreach (Actor a in actors) { a.Tick( game, dt );