From 7d42fb1bf0e8355eb7c6f9c971c890f9c1f9dee6 Mon Sep 17 00:00:00 2001 From: Simon Holmberg Date: Wed, 24 Oct 2012 01:27:20 +0200 Subject: [PATCH] Scratch that. NOW they're working properly. --- DepthsBelow/DepthsBelow/Camera.cs | 14 ++++++-------- DepthsBelow/DepthsBelow/Core.cs | 9 +++++++++ DepthsBelow/DepthsBelow/GUI/Frame.cs | 10 +++++++++- DepthsBelow/DepthsBelow/Interface.cs | 7 ++++++- DepthsBelow/DepthsBelow/MouseInput.cs | 7 ++++--- .../DepthsBelowContent.contentproj | 7 +++++++ .../DepthsBelowContent/images/selection.png | Bin 0 -> 2856 bytes 7 files changed, 41 insertions(+), 13 deletions(-) create mode 100755 DepthsBelow/DepthsBelowContent/images/selection.png diff --git a/DepthsBelow/DepthsBelow/Camera.cs b/DepthsBelow/DepthsBelow/Camera.cs index 80850aa..fa93355 100755 --- a/DepthsBelow/DepthsBelow/Camera.cs +++ b/DepthsBelow/DepthsBelow/Camera.cs @@ -38,9 +38,8 @@ namespace DepthsBelow public Rectangle ScreenToWorld(Rectangle screenRectangle) { var pos = ScreenToWorld(new Vector2(screenRectangle.X, screenRectangle.Y)); - screenRectangle.X = (int)pos.X; - screenRectangle.Y = (int)pos.Y; - return screenRectangle; + var size = ScreenToWorld(new Vector2(screenRectangle.X + screenRectangle.Width, screenRectangle.Y + screenRectangle.Height)) - pos; + return new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y); } public Vector2 WorldToScreen(Vector2 worldPos) @@ -48,12 +47,11 @@ namespace DepthsBelow return Vector2.Transform(worldPos, Transform); } - public Rectangle WorldToScreen(Rectangle screenRectangle) + public Rectangle WorldToScreen(Rectangle worldRectangle) { - var pos = WorldToScreen(new Vector2(screenRectangle.X, screenRectangle.Y)); - screenRectangle.X = (int)pos.X; - screenRectangle.Y = (int)pos.Y; - return screenRectangle; + var pos = WorldToScreen(new Vector2(worldRectangle.X, worldRectangle.Y)); + var size = WorldToScreen(new Vector2(worldRectangle.X + worldRectangle.Width, worldRectangle.Y + worldRectangle.Height)) - pos; + return new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y); } public void Update(GameTime gameTime) diff --git a/DepthsBelow/DepthsBelow/Core.cs b/DepthsBelow/DepthsBelow/Core.cs index 85d19d2..36b7dcf 100755 --- a/DepthsBelow/DepthsBelow/Core.cs +++ b/DepthsBelow/DepthsBelow/Core.cs @@ -210,6 +210,15 @@ namespace DepthsBelow } } +#if DEBUG + var debugTexture = new Texture2D(GraphicsDevice, 1, 1); + debugTexture.SetData(new Color[] { Color.White }); + foreach (var collisionComponent in EntityManager.GetComponents()) + { + spriteBatch.Draw(debugTexture, collisionComponent.Rectangle, Color.Red * 0.5f); + } +#endif + // Draw mouse input visuals MouseInput.Draw(spriteBatch); diff --git a/DepthsBelow/DepthsBelow/GUI/Frame.cs b/DepthsBelow/DepthsBelow/GUI/Frame.cs index ef73e92..7295fe6 100755 --- a/DepthsBelow/DepthsBelow/GUI/Frame.cs +++ b/DepthsBelow/DepthsBelow/GUI/Frame.cs @@ -383,7 +383,15 @@ namespace DepthsBelow.GUI if (Visible) { if (Texture != null) - spriteBatch.Draw(Texture, AbsoluteRectangle, Color); + spriteBatch.Draw(Texture, + AbsoluteRectangle, + null, + Color, + 0, + Vector2.Zero, + ((Width < 0) ? SpriteEffects.FlipHorizontally : 0) + | ((Height < 0) ? SpriteEffects.FlipVertically : 0), + 0); /*foreach (var child in Children) child.Draw(spriteBatch);*/ diff --git a/DepthsBelow/DepthsBelow/Interface.cs b/DepthsBelow/DepthsBelow/Interface.cs index 66771f0..b1de90d 100755 --- a/DepthsBelow/DepthsBelow/Interface.cs +++ b/DepthsBelow/DepthsBelow/Interface.cs @@ -153,8 +153,13 @@ namespace DepthsBelow var selectFrame = (GUI.Frame)frame["selectionFrame"]; if (selectFrame.Visible) { + Console.WriteLine("Before: " + selectFrame.AbsoluteRectangle.X + ", " + selectFrame.AbsoluteRectangle.Y + ", " + selectFrame.AbsoluteRectangle.Width + ", " + selectFrame.AbsoluteRectangle.Height); + var intersectionRectangle = core.Camera.ScreenToWorld(selectFrame.AbsoluteRectangle); + Console.WriteLine("After: " + intersectionRectangle.X + ", " + intersectionRectangle.Y + ", " + intersectionRectangle.Width + ", " + intersectionRectangle.Height); + + // Select all units in the rectangle foreach (var soldier in core.Squad) { @@ -192,7 +197,7 @@ namespace DepthsBelow var button = new GUI.Button(UIParent); button.SetTexture("images/Enter"); - button.X = 100; + button.X = 200; button.Y = 100; button.Width = 55; button.Height = 40; diff --git a/DepthsBelow/DepthsBelow/MouseInput.cs b/DepthsBelow/DepthsBelow/MouseInput.cs index 743f094..8b86d43 100755 --- a/DepthsBelow/DepthsBelow/MouseInput.cs +++ b/DepthsBelow/DepthsBelow/MouseInput.cs @@ -41,8 +41,9 @@ namespace DepthsBelow selectionTexture = new Texture2D(core.GraphicsDevice, 1, 1); selectionTexture.SetData(new Color[] { Color.White }); - gridTexture = new Texture2D(core.GraphicsDevice, 1, 1); - gridTexture.SetData(new Color[] { Color.White }); + //gridTexture = new Texture2D(core.GraphicsDevice, 1, 1); + //gridTexture.SetData(new Color[] { Color.White }); + gridTexture = GameServices.GetService().Load("images/selection"); } public void OnPress(MouseState ms, GameTime gameTime) @@ -317,7 +318,7 @@ namespace DepthsBelow public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(selectionTexture, selectionRectangle, Color.Red * 0.5f); - spriteBatch.Draw(gridTexture, gridRectangle, Color.Yellow * 0.3f); + spriteBatch.Draw(gridTexture, gridRectangle, Color.White * 0.7f); if (checkingDirection == true) { diff --git a/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj b/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj index fb93e08..90a9c05 100755 --- a/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj +++ b/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj @@ -224,6 +224,13 @@ TextureProcessor + + + selection + TextureImporter + TextureProcessor + +