Mouse buttons properly recognized in interface.

Also file mode changes. I don't care.
This commit is contained in:
2012-10-22 17:05:26 +02:00
parent 5f44eb257b
commit cd913a8401
28 changed files with 75 additions and 33 deletions
Regular → Executable
View File
Regular → Executable
View File
View File
View File
View File
@@ -14,7 +14,7 @@ namespace DepthsBelow.Component
public float Intensity = 1f; public float Intensity = 1f;
public float Angle = 0; public float Angle = 0;
public Vector2 Position { get; private set; } public Vector2 Position { get; private set; }
public Vector2 Offset; public Vector2 Origin;
public Texture2D Texture; public Texture2D Texture;
public Color Color; public Color Color;
@@ -25,19 +25,19 @@ namespace DepthsBelow.Component
{ {
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/lights/spot"); Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/lights/spot");
Color = Color.White; Color = Color.White;
Offset = new Vector2(-50, -60); Origin = new Vector2(50, 60);
} }
public override void Update(GameTime gameTime) 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; Angle = Parent.Transform.World.Rotation;
} }
public void Draw(SpriteBatch spriteBatch) public void Draw(SpriteBatch spriteBatch)
{ {
if (IsOn) 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);
} }
} }
View File
View File
+1 -1
View File
@@ -71,7 +71,7 @@
<GenerateManifests>true</GenerateManifests> <GenerateManifests>true</GenerateManifests>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<SignManifests>true</SignManifests> <SignManifests>false</SignManifests>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="LuaInterface, Version=2.0.0.16708, Culture=neutral, processorArchitecture=x86"> <Reference Include="LuaInterface, Version=2.0.0.16708, Culture=neutral, processorArchitecture=x86">
View File
View File
+5
View File
@@ -22,6 +22,11 @@ namespace DepthsBelow
/// </summary> /// </summary>
public MouseState MouseState; public MouseState MouseState;
public ButtonState LeftButton;
public ButtonState MiddleButton;
public ButtonState RightButton;
public int ScrollWheelValue;
/// <summary> /// <summary>
/// The time of the click, since the start of the program. /// The time of the click, since the start of the program.
/// </summary> /// </summary>
Regular → Executable
View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Regular → Executable
View File
+22 -18
View File
@@ -52,37 +52,41 @@ namespace DepthsBelow
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);
// Deselect all units if (args.LeftButton == ButtonState.Pressed)
if (!ks.IsKeyDown(Keys.LeftControl))
{ {
foreach (var unit in core.Squad) // Deselect all units
unit.Selected = false; if (!ks.IsKeyDown(Keys.LeftControl))
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<Component.Collision>().Rectangle))
{ {
soldier.Selected = true; foreach (var unit in core.Squad)
unit.Selected = false;
foreach (var unitFrame in UnitFrames) 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<Component.Collision>().Rectangle))
{ {
if (unitFrame["soldier"] == soldier) soldier.Selected = true;
unitFrame.Color = Color.Blue;
foreach (var unitFrame in UnitFrames)
{
if (unitFrame["soldier"] == soldier)
unitFrame.Color = Color.Blue;
}
} }
} }
} }
// Send orders with right click // Send orders with right click
if (ks.IsKeyDown(Keys.LeftControl)) if (args.RightButton == ButtonState.Pressed)
{
foreach (var unit in core.Squad) foreach (var unit in core.Squad)
if (unit.Selected) if (unit.Selected)
unit.GetComponent<Component.PathFinder>().Goal = Grid.WorldToGrid(mouseWorldPos); unit.GetComponent<Component.PathFinder>().Goal = Grid.WorldToGrid(mouseWorldPos);
}
// Hide the selection rectangle // Hide the selection rectangle
//selectionRectangle = Rectangle.Empty; //selectionRectangle = Rectangle.Empty;
View File
+43 -10
View File
@@ -98,23 +98,56 @@ namespace DepthsBelow
Rectangle mouseWorldRectangle = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 1, 1); Rectangle mouseWorldRectangle = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 1, 1);
KeyboardState ks = Keyboard.GetState(); KeyboardState ks = Keyboard.GetState();
// OnPress event // OnPress events
if ( if (ms.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released)
(ms.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released) {
|| (ms.RightButton == ButtonState.Pressed && lastMouseState.RightButton == ButtonState.Released) var mouseEvent = new GUIManager.MouseEventArgs()
) {
MouseState = ms,
Time = gameTime.TotalGameTime,
LeftButton = ButtonState.Pressed
};
OnPress(ms, gameTime); 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 // OnRelease events
if ( if (ms.LeftButton == ButtonState.Released && lastMouseState.LeftButton == ButtonState.Pressed)
(ms.LeftButton == ButtonState.Released && lastMouseState.LeftButton == ButtonState.Pressed) {
|| (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == 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); OnClick(ms, gameTime);
OnRelease(ms, gameTime); OnRelease(ms, gameTime);
} }
// TODO: OnClick events
// Tooltip stuff // Tooltip stuff
var tooltip = core.Lua.GetObject<GUI.Frame>("ToolTip"); var tooltip = core.Lua.GetObject<GUI.Frame>("ToolTip");
View File
View File
Regular → Executable
View File
View File
View File

Before

Width:  |  Height:  |  Size: 670 B

After

Width:  |  Height:  |  Size: 670 B

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

Before

Width:  |  Height:  |  Size: 222 B

After

Width:  |  Height:  |  Size: 222 B

View File

Before

Width:  |  Height:  |  Size: 405 B

After

Width:  |  Height:  |  Size: 405 B

Regular → Executable
View File