From 7711a0bf013074ed63dc9926a6f1493a6ca5e781 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 17 Nov 2009 19:59:54 +1300 Subject: [PATCH] Region is dead. long live IHandleInput. also tab-switching in chrome --- OpenRa.Game/Chrome.cs | 8 ++- OpenRa.Game/Graphics/Region.cs | 94 ---------------------------------- 2 files changed, 6 insertions(+), 96 deletions(-) delete mode 100644 OpenRa.Game/Graphics/Region.cs diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index ead8a64b81..858eede278 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -105,16 +105,20 @@ namespace OpenRa.Game foreach (var q in tabSprites) { + var groupName = q.Key; if (!Rules.TechTree.BuildableItems(Game.LocalPlayer, q.Key).Any()) continue; - var index = q.Key == "Building" ? 2 : 0; + var index = q.Key == currentTab ? 2 : 0; chromeRenderer.DrawSprite(q.Value[index], new float2(x, y), 0); + + buildItems.Add(Pair.New(new Rectangle(x, y, 27, 40), (Action)(isLmb => currentTab = groupName))); y += 40; } chromeRenderer.Flush(); - DrawBuildPalette("Building"); + DrawBuildPalette(currentTab); } + string currentTab = "Building"; static string[] groups = new string[] { "Building", "Defense", "Vehicle", "Ship", "Infantry", "Plane" }; Dictionary sprites; diff --git a/OpenRa.Game/Graphics/Region.cs b/OpenRa.Game/Graphics/Region.cs deleted file mode 100644 index 78319996cb..0000000000 --- a/OpenRa.Game/Graphics/Region.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using System.Drawing; -using System.Windows.Forms; - -namespace OpenRa.Game.Graphics -{ - class Region - { - int2 location; - Viewport viewport; - - public int2 Location - { - get { return location + new int2( (int)viewport.Location.X, (int)viewport.Location.Y ); } // WTF HACK HACK HACK - } - - public int2 Position { get { return location; } } - public readonly float2 Size; - - Action drawFunction; - Action mouseHandler; - Rectangle rect; - public bool UseScissor = true; - public bool AlwaysWantMovement = false; - - static int2 MakeSize(Viewport v, DockStyle d, int size) - { - switch (d) - { - case DockStyle.Top: - case DockStyle.Bottom: - return new int2(v.Width, size); - - case DockStyle.Left: - case DockStyle.Right: - return new int2(size, v.Height); - - default: - throw new NotImplementedException(); - } - } - - public bool HandleMouseInput(MouseInput mi) - { - if (mouseHandler != null) mouseHandler(new MouseInput - { - Button = mi.Button, - Event = mi.Event, - Location = mi.Location - location - }); - return mouseHandler != null; - } - - public static Region Create(Viewport v, DockStyle d, int size, Action f, Action m) - { - int2 s = MakeSize(v, d, size); - - switch (d) - { - case DockStyle.Top: - case DockStyle.Left: - return new Region(int2.Zero, s, v, f, m); - - case DockStyle.Right: - case DockStyle.Bottom: - return new Region(new int2( v.Width - s.X, v.Height - s.Y ), s, v, f, m); - - default: - throw new NotImplementedException(); - } - } - - Region(int2 location, int2 size, Viewport viewport, Action drawFunction, Action mouseHandler) - { - this.location = location; - this.Size = size; - this.drawFunction = drawFunction; - this.viewport = viewport; - this.mouseHandler = mouseHandler; - rect = new Rectangle(location.X, location.Y, size.X, size.Y); - } - - public bool Contains(int2 point) { return rect.Contains(point.ToPoint()); } - - public void Draw(Renderer renderer) - { - if (UseScissor) - renderer.Device.EnableScissor((int)location.X, (int)location.Y, (int)Size.X, (int)Size.Y); - drawFunction(); - if (UseScissor) - renderer.Device.DisableScissor(); - } - } -}