From cd913a8401144854feb3faef97d497a31de59201 Mon Sep 17 00:00:00 2001 From: Simon Holmberg Date: Mon, 22 Oct 2012 17:05:26 +0200 Subject: [PATCH] Mouse buttons properly recognized in interface. Also file mode changes. I don't care. --- .gitignore | 0 DepthsBelow.sln | 0 DepthsBelow/DepthsBelow/Camera.cs | 0 .../DepthsBelow/Component/Collision.cs | 0 .../DepthsBelow/Component/Component.cs | 0 .../DepthsBelow/Component/Flashlight.cs | 8 +-- .../DepthsBelow/Component/SpriteRenderer.cs | 0 DepthsBelow/DepthsBelow/Component/Stat.cs | 0 DepthsBelow/DepthsBelow/DepthsBelow.csproj | 2 +- .../DepthsBelow/DepthsBelow.csproj.user | 0 DepthsBelow/DepthsBelow/Entity.cs | 0 DepthsBelow/DepthsBelow/GUIManager.cs | 5 ++ DepthsBelow/DepthsBelow/Game.ico | Bin DepthsBelow/DepthsBelow/GameThumbnail.png | Bin DepthsBelow/DepthsBelow/Grid.cs | 0 DepthsBelow/DepthsBelow/Interface.cs | 40 +++++++------ DepthsBelow/DepthsBelow/MonsterSpawn.cs | 0 DepthsBelow/DepthsBelow/MouseInput.cs | 53 ++++++++++++++---- DepthsBelow/DepthsBelow/Program.cs | 0 .../DepthsBelow/Properties/AssemblyInfo.cs | 0 DepthsBelow/DepthsBelow/Shot.cs | 0 DepthsBelow/DepthsBelow/SmallEnemy.cs | 0 .../DepthsBelowContent/images/Enter.bmp | Bin .../DepthsBelowContent/images/FireBall.PNG | Bin .../DepthsBelowContent/images/Monster.png | Bin .../DepthsBelowContent/images/Shot2.bmp | Bin .../DepthsBelowContent/images/soldier.png | Bin README.md | 0 28 files changed, 75 insertions(+), 33 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 DepthsBelow.sln mode change 100644 => 100755 DepthsBelow/DepthsBelow/Camera.cs mode change 100644 => 100755 DepthsBelow/DepthsBelow/Component/Collision.cs mode change 100644 => 100755 DepthsBelow/DepthsBelow/Component/Component.cs mode change 100644 => 100755 DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs mode change 100644 => 100755 DepthsBelow/DepthsBelow/Component/Stat.cs mode change 100644 => 100755 DepthsBelow/DepthsBelow/DepthsBelow.csproj mode change 100644 => 100755 DepthsBelow/DepthsBelow/DepthsBelow.csproj.user mode change 100644 => 100755 DepthsBelow/DepthsBelow/Entity.cs mode change 100644 => 100755 DepthsBelow/DepthsBelow/Game.ico mode change 100644 => 100755 DepthsBelow/DepthsBelow/GameThumbnail.png mode change 100644 => 100755 DepthsBelow/DepthsBelow/Grid.cs mode change 100644 => 100755 DepthsBelow/DepthsBelow/MonsterSpawn.cs mode change 100644 => 100755 DepthsBelow/DepthsBelow/Program.cs mode change 100644 => 100755 DepthsBelow/DepthsBelow/Properties/AssemblyInfo.cs mode change 100644 => 100755 DepthsBelow/DepthsBelow/Shot.cs mode change 100644 => 100755 DepthsBelow/DepthsBelow/SmallEnemy.cs mode change 100644 => 100755 DepthsBelow/DepthsBelowContent/images/Enter.bmp mode change 100644 => 100755 DepthsBelow/DepthsBelowContent/images/FireBall.PNG mode change 100644 => 100755 DepthsBelow/DepthsBelowContent/images/Monster.png mode change 100644 => 100755 DepthsBelow/DepthsBelowContent/images/Shot2.bmp mode change 100644 => 100755 DepthsBelow/DepthsBelowContent/images/soldier.png mode change 100644 => 100755 README.md diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/DepthsBelow.sln b/DepthsBelow.sln old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/Camera.cs b/DepthsBelow/DepthsBelow/Camera.cs old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/Component/Collision.cs b/DepthsBelow/DepthsBelow/Component/Collision.cs old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/Component/Component.cs b/DepthsBelow/DepthsBelow/Component/Component.cs old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/Component/Flashlight.cs b/DepthsBelow/DepthsBelow/Component/Flashlight.cs index 33e2c5f..bddad6e 100755 --- a/DepthsBelow/DepthsBelow/Component/Flashlight.cs +++ b/DepthsBelow/DepthsBelow/Component/Flashlight.cs @@ -14,7 +14,7 @@ namespace DepthsBelow.Component public float Intensity = 1f; public float Angle = 0; public Vector2 Position { get; private set; } - public Vector2 Offset; + public Vector2 Origin; public Texture2D Texture; public Color Color; @@ -25,19 +25,19 @@ namespace DepthsBelow.Component { Texture = GameServices.GetService().Load("images/lights/spot"); Color = Color.White; - Offset = new Vector2(-50, -60); + Origin = new Vector2(50, 60); } public override void Update(GameTime gameTime) { - Position = Parent.Transform.World + Parent.Transform.World.Origin + Offset; + Position = Parent.Transform.World + Parent.Transform.World.Origin; Angle = Parent.Transform.World.Rotation; } public void Draw(SpriteBatch spriteBatch) { if (IsOn) - spriteBatch.Draw(Texture, Position, null, Color * Intensity, 0, Vector2.Zero, Scale, SpriteEffects.None, 0); + spriteBatch.Draw(Texture, Position, null, Color * Intensity, Angle, Origin, Scale, SpriteEffects.None, 0); } } diff --git a/DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs b/DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/Component/Stat.cs b/DepthsBelow/DepthsBelow/Component/Stat.cs old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/DepthsBelow.csproj b/DepthsBelow/DepthsBelow/DepthsBelow.csproj old mode 100644 new mode 100755 index ee4dfb7..ac52dfa --- a/DepthsBelow/DepthsBelow/DepthsBelow.csproj +++ b/DepthsBelow/DepthsBelow/DepthsBelow.csproj @@ -71,7 +71,7 @@ true - true + false diff --git a/DepthsBelow/DepthsBelow/DepthsBelow.csproj.user b/DepthsBelow/DepthsBelow/DepthsBelow.csproj.user old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/Entity.cs b/DepthsBelow/DepthsBelow/Entity.cs old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/GUIManager.cs b/DepthsBelow/DepthsBelow/GUIManager.cs index 7edc7bb..c321edb 100755 --- a/DepthsBelow/DepthsBelow/GUIManager.cs +++ b/DepthsBelow/DepthsBelow/GUIManager.cs @@ -22,6 +22,11 @@ namespace DepthsBelow /// public MouseState MouseState; + public ButtonState LeftButton; + public ButtonState MiddleButton; + public ButtonState RightButton; + public int ScrollWheelValue; + /// /// The time of the click, since the start of the program. /// diff --git a/DepthsBelow/DepthsBelow/Game.ico b/DepthsBelow/DepthsBelow/Game.ico old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/GameThumbnail.png b/DepthsBelow/DepthsBelow/GameThumbnail.png old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/Grid.cs b/DepthsBelow/DepthsBelow/Grid.cs old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/Interface.cs b/DepthsBelow/DepthsBelow/Interface.cs index 7749f59..e89dc84 100755 --- a/DepthsBelow/DepthsBelow/Interface.cs +++ b/DepthsBelow/DepthsBelow/Interface.cs @@ -52,37 +52,41 @@ namespace DepthsBelow var mouseWorldPos = core.Camera.ScreenToWorld(new Vector2(mousePos.X, mousePos.Y)); var mouseWorldRectangle = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 1, 1); - // Deselect all units - if (!ks.IsKeyDown(Keys.LeftControl)) + if (args.LeftButton == ButtonState.Pressed) { - foreach (var unit in core.Squad) - unit.Selected = false; - - foreach (var unitFrame in UnitFrames) - unitFrame.Color = Color.Black; - } - - // Select all units in the rectangle - foreach (var soldier in core.Squad) - { - if (mouseWorldRectangle.Intersects(soldier.GetComponent().Rectangle)) + // Deselect all units + if (!ks.IsKeyDown(Keys.LeftControl)) { - soldier.Selected = true; + foreach (var unit in core.Squad) + unit.Selected = false; foreach (var unitFrame in UnitFrames) + unitFrame.Color = Color.Black; + } + + // Select all units in the rectangle + foreach (var soldier in core.Squad) + { + if (mouseWorldRectangle.Intersects(soldier.GetComponent().Rectangle)) { - if (unitFrame["soldier"] == soldier) - unitFrame.Color = Color.Blue; + soldier.Selected = true; + + foreach (var unitFrame in UnitFrames) + { + if (unitFrame["soldier"] == soldier) + unitFrame.Color = Color.Blue; + } } } } // Send orders with right click - if (ks.IsKeyDown(Keys.LeftControl)) + if (args.RightButton == ButtonState.Pressed) + { foreach (var unit in core.Squad) if (unit.Selected) unit.GetComponent().Goal = Grid.WorldToGrid(mouseWorldPos); - + } // Hide the selection rectangle //selectionRectangle = Rectangle.Empty; diff --git a/DepthsBelow/DepthsBelow/MonsterSpawn.cs b/DepthsBelow/DepthsBelow/MonsterSpawn.cs old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/MouseInput.cs b/DepthsBelow/DepthsBelow/MouseInput.cs index 431c005..032fd90 100755 --- a/DepthsBelow/DepthsBelow/MouseInput.cs +++ b/DepthsBelow/DepthsBelow/MouseInput.cs @@ -98,23 +98,56 @@ namespace DepthsBelow Rectangle mouseWorldRectangle = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 1, 1); KeyboardState ks = Keyboard.GetState(); - // OnPress event - if ( - (ms.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released) - || (ms.RightButton == ButtonState.Pressed && lastMouseState.RightButton == ButtonState.Released) - ) + // OnPress events + if (ms.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released) + { + var mouseEvent = new GUIManager.MouseEventArgs() + { + MouseState = ms, + Time = gameTime.TotalGameTime, + LeftButton = ButtonState.Pressed + }; + OnPress(ms, gameTime); + } + if (ms.MiddleButton == ButtonState.Pressed && lastMouseState.MiddleButton == ButtonState.Released) + { + var mouseEvent = new GUIManager.MouseEventArgs() + { + MouseState = ms, + Time = gameTime.TotalGameTime, + MiddleButton = ButtonState.Pressed + }; + OnPress(ms, gameTime); + } + if (ms.RightButton == ButtonState.Pressed && lastMouseState.RightButton == ButtonState.Released) + { + var mouseEvent = new GUIManager.MouseEventArgs() + { + MouseState = ms, + Time = gameTime.TotalGameTime, + RightButton = ButtonState.Pressed + }; OnPress(ms, gameTime); + } - // OnRelease event - if ( - (ms.LeftButton == ButtonState.Released && lastMouseState.LeftButton == ButtonState.Pressed) - || (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed) - ) + // OnRelease events + if (ms.LeftButton == ButtonState.Released && lastMouseState.LeftButton == ButtonState.Pressed) { OnClick(ms, gameTime); OnRelease(ms, gameTime); + } + if (ms.MiddleButton == ButtonState.Released && lastMouseState.MiddleButton == ButtonState.Pressed) + { + OnClick(ms, gameTime); + OnRelease(ms, gameTime); + } + if (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed) + { + OnClick(ms, gameTime); + OnRelease(ms, gameTime); } + // TODO: OnClick events // Tooltip stuff var tooltip = core.Lua.GetObject("ToolTip"); diff --git a/DepthsBelow/DepthsBelow/Program.cs b/DepthsBelow/DepthsBelow/Program.cs old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/Properties/AssemblyInfo.cs b/DepthsBelow/DepthsBelow/Properties/AssemblyInfo.cs old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/Shot.cs b/DepthsBelow/DepthsBelow/Shot.cs old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelow/SmallEnemy.cs b/DepthsBelow/DepthsBelow/SmallEnemy.cs old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelowContent/images/Enter.bmp b/DepthsBelow/DepthsBelowContent/images/Enter.bmp old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelowContent/images/FireBall.PNG b/DepthsBelow/DepthsBelowContent/images/FireBall.PNG old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelowContent/images/Monster.png b/DepthsBelow/DepthsBelowContent/images/Monster.png old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelowContent/images/Shot2.bmp b/DepthsBelow/DepthsBelowContent/images/Shot2.bmp old mode 100644 new mode 100755 diff --git a/DepthsBelow/DepthsBelowContent/images/soldier.png b/DepthsBelow/DepthsBelowContent/images/soldier.png old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755