Mouse controls are working properly again.
This commit is contained in:
@@ -27,6 +27,9 @@ namespace DepthsBelow
|
|||||||
|
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
|
||||||
|
private bool checkingDirection;
|
||||||
|
private Vector2 directionStart;
|
||||||
|
|
||||||
public Interface(Core core)
|
public Interface(Core core)
|
||||||
{
|
{
|
||||||
this.core = core;
|
this.core = core;
|
||||||
@@ -55,8 +58,9 @@ namespace DepthsBelow
|
|||||||
|
|
||||||
if (args.LeftButton == ButtonState.Pressed)
|
if (args.LeftButton == ButtonState.Pressed)
|
||||||
{
|
{
|
||||||
|
Debug.WriteLine("Left button pressed on UIParent");
|
||||||
// Deselect all units
|
// Deselect all units
|
||||||
if (!ks.IsKeyDown(Keys.LeftControl))
|
/*if (!ks.IsKeyDown(Keys.LeftControl))
|
||||||
{
|
{
|
||||||
foreach (var unit in core.Squad)
|
foreach (var unit in core.Squad)
|
||||||
unit.Selected = false;
|
unit.Selected = false;
|
||||||
@@ -78,16 +82,10 @@ namespace DepthsBelow
|
|||||||
unitFrame.Color = Color.Blue;
|
unitFrame.Color = Color.Blue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send orders with right click
|
|
||||||
if (args.RightButton == ButtonState.Pressed)
|
|
||||||
{
|
|
||||||
foreach (var unit in core.Squad)
|
|
||||||
if (unit.Selected)
|
|
||||||
unit.GetComponent<Component.PathFinder>().Goal = Grid.WorldToGrid(mouseWorldPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hide the selection rectangle
|
// Hide the selection rectangle
|
||||||
//selectionRectangle = Rectangle.Empty;
|
//selectionRectangle = Rectangle.Empty;
|
||||||
@@ -98,46 +96,97 @@ namespace DepthsBelow
|
|||||||
{
|
{
|
||||||
//KeyboardState ks = Keyboard.GetState();
|
//KeyboardState ks = Keyboard.GetState();
|
||||||
MouseState ms = args.MouseState;
|
MouseState ms = args.MouseState;
|
||||||
|
|
||||||
var mousePos = new Point(ms.X, ms.Y);
|
var mousePos = new Point(ms.X, ms.Y);
|
||||||
var mouseRectangle = new Rectangle(mousePos.X, mousePos.Y, 1, 1);
|
var mouseRectangle = new Rectangle(mousePos.X, mousePos.Y, 1, 1);
|
||||||
var mouseWorldPos = core.Camera.ScreenToWorld(new Vector2(mousePos.X, mousePos.Y));
|
var mouseWorldPos = core.Camera.ScreenToWorld(new Vector2(mousePos.X, mousePos.Y));
|
||||||
var mouseWorldRectangle = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 1, 1);
|
var mouseWorldRectangle = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 1, 1);
|
||||||
|
|
||||||
// Show the selection frame
|
// Show the selection frame
|
||||||
var selectFrame = (GUI.Frame)frame["selectionFrame"];
|
if (args.LeftButton == ButtonState.Pressed)
|
||||||
if (!selectFrame.Visible)
|
|
||||||
{
|
{
|
||||||
selectFrame.X = (int)mousePos.X;
|
var selectFrame = (GUI.Frame)frame["selectionFrame"];
|
||||||
selectFrame.Y = (int)mousePos.Y;
|
if (!selectFrame.Visible)
|
||||||
selectFrame.Visible = true;
|
{
|
||||||
|
selectFrame.X = mousePos.X;
|
||||||
|
selectFrame.Y = mousePos.Y;
|
||||||
|
selectFrame.Visible = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.RightButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
// Unit rotation
|
||||||
|
foreach (var unit in core.Squad)
|
||||||
|
{
|
||||||
|
if (unit.Selected && mouseWorldRectangle.Intersects(unit.GetComponent<Component.Collision>().Rectangle))
|
||||||
|
{
|
||||||
|
checkingDirection = true;
|
||||||
|
directionStart = unit.Transform.World + unit.Transform.World.Origin;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// OnRelease
|
// OnRelease
|
||||||
UIParent.OnRelease += delegate(Frame frame, GUIManager.MouseEventArgs args)
|
UIParent.OnRelease += delegate(Frame frame, GUIManager.MouseEventArgs args)
|
||||||
{
|
{
|
||||||
// Show the selection frame
|
KeyboardState ks = Keyboard.GetState();
|
||||||
var selectFrame = (GUI.Frame)frame["selectionFrame"];
|
MouseState ms = args.MouseState;
|
||||||
if (selectFrame.Visible)
|
var mousePos = new Point(ms.X, ms.Y);
|
||||||
{
|
var mouseRectangle = new Rectangle(mousePos.X, mousePos.Y, 1, 1);
|
||||||
var intersectionRectangle = core.Camera.ScreenToWorld(selectFrame.AbsoluteRectangle);
|
var mouseWorldPos = core.Camera.ScreenToWorld(new Vector2(mousePos.X, mousePos.Y));
|
||||||
|
var mouseWorldRectangle = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 1, 1);
|
||||||
|
|
||||||
// Select all units in the rectangle
|
if (args.LeftButton == ButtonState.Pressed)
|
||||||
foreach (var soldier in core.Squad)
|
{
|
||||||
|
// Deselect all units
|
||||||
|
if (!ks.IsKeyDown(Keys.LeftControl))
|
||||||
{
|
{
|
||||||
if (intersectionRectangle.Intersects(soldier.GetComponent<Component.Collision>().Rectangle))
|
foreach (var unit in core.Squad)
|
||||||
{
|
unit.Selected = false;
|
||||||
soldier.Selected = true;
|
|
||||||
foreach (var unitFrame in UnitFrames)
|
foreach (var unitFrame in UnitFrames)
|
||||||
{
|
unitFrame.Color = Color.Black;
|
||||||
if (unitFrame["soldier"] == soldier)
|
|
||||||
unitFrame.Color = Color.Blue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
selectFrame.Visible = false;
|
// Select all soldier units inside the selection rectangle
|
||||||
|
var selectFrame = (GUI.Frame)frame["selectionFrame"];
|
||||||
|
if (selectFrame.Visible)
|
||||||
|
{
|
||||||
|
var intersectionRectangle = core.Camera.ScreenToWorld(selectFrame.AbsoluteRectangle);
|
||||||
|
|
||||||
|
// Select all units in the rectangle
|
||||||
|
foreach (var soldier in core.Squad)
|
||||||
|
{
|
||||||
|
if (intersectionRectangle.Intersects(soldier.GetComponent<Component.Collision>().Rectangle))
|
||||||
|
{
|
||||||
|
soldier.Selected = true;
|
||||||
|
foreach (var unitFrame in UnitFrames)
|
||||||
|
{
|
||||||
|
if (unitFrame["soldier"] == soldier)
|
||||||
|
unitFrame.Color = Color.Blue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
selectFrame.Visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send orders with right click
|
||||||
|
if (args.RightButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
if (checkingDirection)
|
||||||
|
{
|
||||||
|
checkingDirection = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Right button pressed on UIParent");
|
||||||
|
foreach (var unit in core.Squad)
|
||||||
|
if (unit.Selected)
|
||||||
|
unit.GetComponent<Component.PathFinder>().Goal = Grid.WorldToGrid(mouseWorldPos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -433,6 +482,23 @@ namespace DepthsBelow
|
|||||||
selectionFrame.Height = (int)mousePos.Y - selectionFrame.Y;
|
selectionFrame.Height = (int)mousePos.Y - selectionFrame.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update rotations
|
||||||
|
if (checkingDirection)
|
||||||
|
{
|
||||||
|
foreach (var unit in core.Squad)
|
||||||
|
if (unit.Selected)
|
||||||
|
{
|
||||||
|
float directionX = mouseWorldPos.X - unit.Transform.World.X;
|
||||||
|
float directionY = mouseWorldPos.Y - unit.Transform.World.Y;
|
||||||
|
//var mouseDirection = mouseWorldPos;
|
||||||
|
//mouseDirection.Normalize();
|
||||||
|
unit.GetComponent<Component.Transform>().World.Rotation =
|
||||||
|
(float)
|
||||||
|
Math.Atan2(mouseWorldPos.Y - unit.Transform.World.Y - unit.Transform.World.Origin.Y,
|
||||||
|
mouseWorldPos.X - unit.Transform.World.X - unit.Transform.World.Origin.X);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UpdateUnitFrames();
|
UpdateUnitFrames();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,8 @@ namespace DepthsBelow
|
|||||||
Time = gameTime.TotalGameTime,
|
Time = gameTime.TotalGameTime,
|
||||||
LeftButton = ButtonState.Pressed
|
LeftButton = ButtonState.Pressed
|
||||||
};
|
};
|
||||||
OnPress(ms, gameTime);
|
GUIManager.RaiseAt("OnPress", mouseEvent, new Point(ms.X, ms.Y));
|
||||||
|
|
||||||
}
|
}
|
||||||
if (ms.MiddleButton == ButtonState.Pressed && lastMouseState.MiddleButton == ButtonState.Released)
|
if (ms.MiddleButton == ButtonState.Pressed && lastMouseState.MiddleButton == ButtonState.Released)
|
||||||
{
|
{
|
||||||
@@ -117,7 +118,8 @@ namespace DepthsBelow
|
|||||||
Time = gameTime.TotalGameTime,
|
Time = gameTime.TotalGameTime,
|
||||||
MiddleButton = ButtonState.Pressed
|
MiddleButton = ButtonState.Pressed
|
||||||
};
|
};
|
||||||
OnPress(ms, gameTime);
|
GUIManager.RaiseAt("OnPress", mouseEvent, new Point(ms.X, ms.Y));
|
||||||
|
|
||||||
}
|
}
|
||||||
if (ms.RightButton == ButtonState.Pressed && lastMouseState.RightButton == ButtonState.Released)
|
if (ms.RightButton == ButtonState.Pressed && lastMouseState.RightButton == ButtonState.Released)
|
||||||
{
|
{
|
||||||
@@ -127,24 +129,42 @@ namespace DepthsBelow
|
|||||||
Time = gameTime.TotalGameTime,
|
Time = gameTime.TotalGameTime,
|
||||||
RightButton = ButtonState.Pressed
|
RightButton = ButtonState.Pressed
|
||||||
};
|
};
|
||||||
OnPress(ms, gameTime);
|
GUIManager.RaiseAt("OnPress", mouseEvent, new Point(ms.X, ms.Y));
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnRelease events
|
// OnRelease events
|
||||||
if (ms.LeftButton == ButtonState.Released && lastMouseState.LeftButton == ButtonState.Pressed)
|
if (ms.LeftButton == ButtonState.Released && lastMouseState.LeftButton == ButtonState.Pressed)
|
||||||
{
|
{
|
||||||
OnClick(ms, gameTime);
|
var mouseEvent = new GUIManager.MouseEventArgs()
|
||||||
OnRelease(ms, gameTime);
|
{
|
||||||
|
MouseState = ms,
|
||||||
|
Time = gameTime.TotalGameTime,
|
||||||
|
LeftButton = ButtonState.Pressed
|
||||||
|
};
|
||||||
|
GUIManager.RaiseAt("OnClick", mouseEvent, new Point(ms.X, ms.Y));
|
||||||
|
GUIManager.RaiseAt("OnRelease", mouseEvent, new Point(ms.X, ms.Y));
|
||||||
}
|
}
|
||||||
if (ms.MiddleButton == ButtonState.Released && lastMouseState.MiddleButton == ButtonState.Pressed)
|
if (ms.MiddleButton == ButtonState.Released && lastMouseState.MiddleButton == ButtonState.Pressed)
|
||||||
{
|
{
|
||||||
OnClick(ms, gameTime);
|
var mouseEvent = new GUIManager.MouseEventArgs()
|
||||||
OnRelease(ms, gameTime);
|
{
|
||||||
|
MouseState = ms,
|
||||||
|
Time = gameTime.TotalGameTime,
|
||||||
|
MiddleButton = ButtonState.Pressed
|
||||||
|
};
|
||||||
|
GUIManager.RaiseAt("OnClick", mouseEvent, new Point(ms.X, ms.Y));
|
||||||
|
GUIManager.RaiseAt("OnRelease", mouseEvent, new Point(ms.X, ms.Y));
|
||||||
}
|
}
|
||||||
if (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed)
|
if (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed)
|
||||||
{
|
{
|
||||||
OnClick(ms, gameTime);
|
var mouseEvent = new GUIManager.MouseEventArgs()
|
||||||
OnRelease(ms, gameTime);
|
{
|
||||||
|
MouseState = ms,
|
||||||
|
Time = gameTime.TotalGameTime,
|
||||||
|
RightButton = ButtonState.Pressed
|
||||||
|
};
|
||||||
|
GUIManager.RaiseAt("OnClick", mouseEvent, new Point(ms.X, ms.Y));
|
||||||
|
GUIManager.RaiseAt("OnRelease", mouseEvent, new Point(ms.X, ms.Y));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: OnClick events
|
// TODO: OnClick events
|
||||||
@@ -243,7 +263,7 @@ namespace DepthsBelow
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
// Send orders with right click
|
// Send orders with right click
|
||||||
if (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed)
|
/*if (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed)
|
||||||
{
|
{
|
||||||
if (checkingDirection == false)
|
if (checkingDirection == false)
|
||||||
{
|
{
|
||||||
@@ -254,8 +274,9 @@ namespace DepthsBelow
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}*/
|
||||||
if (ms.RightButton == ButtonState.Pressed)
|
|
||||||
|
/*if (ms.RightButton == ButtonState.Pressed)
|
||||||
{
|
{
|
||||||
foreach (var unit in core.Squad)
|
foreach (var unit in core.Squad)
|
||||||
{
|
{
|
||||||
@@ -277,25 +298,13 @@ namespace DepthsBelow
|
|||||||
float directionY = mouseWorldPos.Y - unit.Transform.World.Y;
|
float directionY = mouseWorldPos.Y - unit.Transform.World.Y;
|
||||||
var mouseDirection = mouseWorldPos;
|
var mouseDirection = mouseWorldPos;
|
||||||
mouseDirection.Normalize();
|
mouseDirection.Normalize();
|
||||||
//float angle = (float)Math.Acos(Vector2.Dot(new Vector2(0, 1), mouseDirection)) * MathHelper.TwoPi;
|
unit.GetComponent<Component.Transform>().World.Rotation = (float)Math.Atan2(mouseWorldPos.Y - unit.Transform.World.Y - unit.Transform.World.Origin.Y, mouseWorldPos.X - unit.Transform.World.X - unit.Transform.World.Origin.X);
|
||||||
/*if (directionX < 0)
|
|
||||||
{
|
|
||||||
directionX *= -1;
|
|
||||||
unit.GetComponent<Component.Transform>().World.Rotation = (float)Math.Atan(directionY / directionX);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*/
|
|
||||||
unit.GetComponent<Component.Transform>().World.Rotation = (float)Math.Atan2(mouseWorldPos.Y - unit.Transform.World.Y - unit.Transform.World.Origin.Y, mouseWorldPos.X - unit.Transform.World.X - unit.Transform.World.Origin.X);/*
|
|
||||||
}*/
|
|
||||||
//Console.WriteLine(angle);
|
|
||||||
//unit.GetComponent<Component.Transform>().World.Rotation = angle;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
checkingDirection = false;
|
checkingDirection = false;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
// Grid highlighting
|
// Grid highlighting
|
||||||
Point mouseGridPos = Grid.WorldToGrid(mouseWorldPos);
|
Point mouseGridPos = Grid.WorldToGrid(mouseWorldPos);
|
||||||
|
|||||||
Reference in New Issue
Block a user