From 983f56e840bcd7b5beb2d38d28aa48ec7aa97687 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@993157c7-ee19-0410-b2c4-bb4e9862e678> Date: Tue, 24 Jul 2007 04:53:11 +0000 Subject: [PATCH] git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1332 993157c7-ee19-0410-b2c4-bb4e9862e678 --- OpenRa.Game/MainWindow.cs | 9 ++++++- OpenRa.Game/Sidebar.cs | 48 +++++++++++++++++++++++++++++++++---- OpenRa.TechTree/TechTree.cs | 1 + todo.todo | 5 ++++ 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 972b0954f1..6aca770271 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -75,7 +75,14 @@ namespace OpenRa.Game if (e.Button == MouseButtons.Left) { - float2 xy = ( 1 / 24.0f ) * ( new float2( e.Location ) + game.viewport.Location ); + float2 point = new float2(e.Location) + game.viewport.Location; + RectangleF rect = new RectangleF(sidebar.Location.ToPointF(), new SizeF(sidebar.Width, game.viewport.Height)); + if (rect.Contains(point.ToPointF())) + { + sidebar.Build(sidebar.FindSpriteAtPoint(point)); + return; + } + float2 xy = (1 / 24.0f) * point; IOrder order = game.world.myUnit.Order( new int2( (int)xy.X, (int)xy.Y ) ); game.Issue( order ); } diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs index e78a9627c5..50689d69de 100644 --- a/OpenRa.Game/Sidebar.cs +++ b/OpenRa.Game/Sidebar.cs @@ -19,6 +19,13 @@ namespace OpenRa.Game Dictionary sprites = new Dictionary(); Viewport viewport; + const float spriteWidth = 64, spriteHeight = 48; + + public float Width + { + get { return spriteWidth * 2; } + } + public Sidebar(Race race, Renderer renderer, Viewport viewport) { @@ -31,7 +38,12 @@ namespace OpenRa.Game LoadSprites("buildings.txt"); LoadSprites("units.txt"); - blank = SheetBuilder.Add(new Size(64, 48), 16); + blank = SheetBuilder.Add(new Size((int)spriteWidth, (int)spriteHeight), 16); + } + + public bool Build(string key) + { + return techTree.Build(key); } void LoadSprites(string filename) @@ -46,7 +58,7 @@ namespace OpenRa.Game void DrawSprite(Sprite s, ref float2 p) { spriteRenderer.DrawSprite(s, p, 0); - p.Y += 48; + p.Y += spriteHeight; } void Fill(float height, float2 p) @@ -55,10 +67,17 @@ namespace OpenRa.Game DrawSprite(blank, ref p); } + float2 location; + + public float2 Location + { + get { return location; } + } + public void Paint( Game game ) { - float2 buildPos = viewport.Location + new float2(viewport.Size.X - 128, 0); - float2 unitPos = viewport.Location + new float2(viewport.Size.X - 64, 0); + float2 buildPos = location = viewport.Location + new float2(viewport.Size.X - spriteWidth * 2, 0); + float2 unitPos = viewport.Location + new float2(viewport.Size.X - spriteWidth, 0); foreach (Item i in techTree.BuildableItems) { @@ -76,5 +95,26 @@ namespace OpenRa.Game spriteRenderer.Flush(); } + + public string FindSpriteAtPoint(float2 point) + { + float y1 = 0, y2 = 0; + foreach (Item i in techTree.BuildableItems) + { + RectangleF rect; + if (i.IsStructure) + { + rect = new RectangleF(location.X, location.Y + y1, spriteWidth, spriteHeight); + y1 += 48; + } + else + { + rect = new RectangleF(location.X + spriteWidth, location.Y + y2, spriteWidth, spriteHeight); + y2 += 48; + } + if (rect.Contains(point.ToPointF())) return i.tag; + } + return null; + } } } diff --git a/OpenRa.TechTree/TechTree.cs b/OpenRa.TechTree/TechTree.cs index 6e259683d2..a107df9f49 100644 --- a/OpenRa.TechTree/TechTree.cs +++ b/OpenRa.TechTree/TechTree.cs @@ -65,6 +65,7 @@ namespace OpenRa.TechTree public bool Build(string key, bool force) { + if (string.IsNullOrEmpty(key)) return false; Item b = objects[key]; if (!force && !b.CanBuild) return false; built.Add(key); diff --git a/todo.todo b/todo.todo index 04a6e82064..56b54fee02 100644 --- a/todo.todo +++ b/todo.todo @@ -1,5 +1,10 @@ OpenRA ------------------------------------------------------ +[ ] Sidebar + [x] Click handling going ~beedee + [ ] Building needs to have some sort of timer + [ ] Need a better order to sort items in (rather than what the collection chucks at us by default) + [ ] Actually make built units appear in the world/allow them to be placed in the world [ ] Multiplayer!