Selecting stairs based on WorldRect in editor, disable input if window not active, disable traveling if no locations are selected

This commit is contained in:
Regalis
2016-01-27 22:27:51 +02:00
parent 8cc12b6988
commit 7637bc441f
21 changed files with 95 additions and 77 deletions
+1 -1
View File
@@ -183,7 +183,7 @@ namespace Barotrauma
} }
else else
{ {
Vector2 mousePos = new Vector2(PlayerInput.GetMouseState.X, PlayerInput.GetMouseState.Y); Vector2 mousePos = PlayerInput.MousePosition;
Vector2 offset = mousePos - new Vector2(resolution.X / 2.0f, resolution.Y / 2.0f); Vector2 offset = mousePos - new Vector2(resolution.X / 2.0f, resolution.Y / 2.0f);
+10 -10
View File
@@ -70,18 +70,18 @@ namespace Barotrauma
} }
} }
//try try
//{ {
Coroutines[i].MoveNext(); Coroutines[i].MoveNext();
// } }
// catch (Exception e) catch (Exception e)
// { {
//#if DEBUG #if DEBUG
// DebugConsole.ThrowError("Coroutine " + Coroutines[i] + " threw an exception: " + e.Message); DebugConsole.ThrowError("Coroutine " + Coroutines[i] + " threw an exception: " + e.Message);
//#endif #endif
// Coroutines.RemoveAt(i); Coroutines.RemoveAt(i);
// } }
} }
} }
+1 -1
View File
@@ -99,7 +99,7 @@ namespace Barotrauma
//textBox.Update(deltaTime); //textBox.Update(deltaTime);
if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.Enter) && textBox.Text != "") if (PlayerInput.KeyDown(Keys.Enter) && textBox.Text != "")
{ {
NewMessage(textBox.Text, Color.White); NewMessage(textBox.Text, Color.White);
ExecuteCommand(textBox.Text, game); ExecuteCommand(textBox.Text, game);
+1 -1
View File
@@ -300,7 +300,7 @@ namespace Barotrauma
if (rect.Contains(PlayerInput.MousePosition)) if (rect.Contains(PlayerInput.MousePosition))
{ {
clicked = (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed); clicked = PlayerInput.LeftButtonDown();
color = clicked ? new Color(100, 100, 100) : new Color(250, 250, 250); color = clicked ? new Color(100, 100, 100) : new Color(250, 250, 250);
+1 -1
View File
@@ -152,7 +152,7 @@ namespace Barotrauma
if (rect.Contains(PlayerInput.MousePosition) && CanBeSelected && Enabled && (MouseOn == null || MouseOn == this || IsParentOf(MouseOn))) if (rect.Contains(PlayerInput.MousePosition) && CanBeSelected && Enabled && (MouseOn == null || MouseOn == this || IsParentOf(MouseOn)))
{ {
state = ComponentState.Hover; state = ComponentState.Hover;
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed) if (PlayerInput.LeftButtonDown())
{ {
if (OnPressed != null) if (OnPressed != null)
{ {
+2 -2
View File
@@ -152,7 +152,7 @@ namespace Barotrauma
if (style != null) style.Apply(textBlock, this); if (style != null) style.Apply(textBlock, this);
textBlock.Padding = new Vector4(3.0f, 0.0f, 3.0f, 0.0f); textBlock.Padding = new Vector4(3.0f, 0.0f, 3.0f, 0.0f);
previousMouse = PlayerInput.GetMouseState; //previousMouse = PlayerInput.GetMouseState;
CaretEnabled = true; CaretEnabled = true;
//SetTextPos(); //SetTextPos();
@@ -171,7 +171,7 @@ namespace Barotrauma
if (keyboardDispatcher.Subscriber == this) keyboardDispatcher.Subscriber = null; if (keyboardDispatcher.Subscriber == this) keyboardDispatcher.Subscriber = null;
} }
MouseState previousMouse; //MouseState previousMouse;
public override void Update(float deltaTime) public override void Update(float deltaTime)
{ {
if (!Visible) return; if (!Visible) return;
+1 -1
View File
@@ -61,7 +61,7 @@ namespace Barotrauma
box.State = ComponentState.Hover; box.State = ComponentState.Hover;
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed) if (PlayerInput.LeftButtonDown())
{ {
box.State = ComponentState.Selected; box.State = ComponentState.Selected;
} }
@@ -326,10 +326,10 @@ namespace Barotrauma
if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition)) if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition))
{ {
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed) if (PlayerInput.LeftButtonDown())
{ {
slotRect.X = PlayerInput.GetMouseState.X - slotRect.Width / 2; slotRect.X = (int)PlayerInput.MousePosition.X - slotRect.Width / 2;
slotRect.Y = PlayerInput.GetMouseState.Y - slotRect.Height / 2; slotRect.Y = (int)PlayerInput.MousePosition.Y - slotRect.Height / 2;
DrawSlot(spriteBatch, slotRect, draggingItem, false, false); DrawSlot(spriteBatch, slotRect, draggingItem, false, false);
} }
@@ -136,7 +136,7 @@ namespace Barotrauma.Items.Components
ignoredBodies.Add(limb.body.FarseerBody); ignoredBodies.Add(limb.body.FarseerBody);
} }
Vector2 rayStart = item.WorldPosition + TransformedBarrelPos; Vector2 rayStart = item.WorldPosition;
Vector2 rayEnd = targetPosition; Vector2 rayEnd = targetPosition;
Body targetBody = Submarine.PickBody( Body targetBody = Submarine.PickBody(
@@ -351,7 +351,7 @@ namespace Barotrauma.Items.Components
if (selectedNodeIndex == null && draggingWire == null)// && !MapEntity.SelectedAny) if (selectedNodeIndex == null && draggingWire == null)// && !MapEntity.SelectedAny)
{ {
if (PlayerInput.LeftButtonDown() && PlayerInput.GetOldMouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released) if (PlayerInput.LeftButtonClicked())
{ {
MapEntity.DisableSelect = true; MapEntity.DisableSelect = true;
MapEntity.SelectEntity(item); MapEntity.SelectEntity(item);
+5 -5
View File
@@ -205,10 +205,10 @@ namespace Barotrauma
if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition) && draggingItem.Container == this.Owner) if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition) && draggingItem.Container == this.Owner)
{ {
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed) if (PlayerInput.LeftButtonDown())
{ {
slotRect.X = PlayerInput.GetMouseState.X - slotRect.Width / 2; slotRect.X = (int)PlayerInput.MousePosition.X - slotRect.Width / 2;
slotRect.Y = PlayerInput.GetMouseState.Y - slotRect.Height / 2; slotRect.Y = (int)PlayerInput.MousePosition.Y - slotRect.Height / 2;
//GUI.DrawRectangle(spriteBatch, rect, Color.White, true); //GUI.DrawRectangle(spriteBatch, rect, Color.White, true);
//draggingItem.sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), Color.White); //draggingItem.sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), Color.White);
@@ -261,12 +261,12 @@ namespace Barotrauma
{ {
if (draggingItem == null) if (draggingItem == null)
{ {
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed) if (PlayerInput.LeftButtonDown())
{ {
draggingItem = item; draggingItem = item;
} }
} }
else if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released) else if (PlayerInput.LeftButtonReleased())
{ {
if (PlayerInput.DoubleClicked()) if (PlayerInput.DoubleClicked())
{ {
+2 -3
View File
@@ -114,8 +114,7 @@ namespace Barotrauma
if (placePosition == Vector2.Zero) if (placePosition == Vector2.Zero)
{ {
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed) if (PlayerInput.LeftButtonDown()) placePosition = position;
placePosition = position;
} }
else else
{ {
@@ -124,7 +123,7 @@ namespace Barotrauma
if (resizeVertical) if (resizeVertical)
placeSize.Y = Math.Max(placePosition.Y - position.Y, size.Y); placeSize.Y = Math.Max(placePosition.Y - position.Y, size.Y);
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released) if (PlayerInput.LeftButtonReleased())
{ {
var item = new Item(new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y), this, Submarine.Loaded); var item = new Item(new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y), this, Submarine.Loaded);
placePosition = Vector2.Zero; placePosition = Vector2.Zero;
+8 -8
View File
@@ -253,7 +253,7 @@ namespace Barotrauma
return; return;
} }
if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.Delete)) if (PlayerInput.KeyDown(Keys.Delete))
{ {
foreach (MapEntity e in selectedList) e.Remove(); foreach (MapEntity e in selectedList) e.Remove();
selectedList.Clear(); selectedList.Clear();
@@ -283,7 +283,7 @@ namespace Barotrauma
//started moving selected entities //started moving selected entities
if (startMovingPos != Vector2.Zero) if (startMovingPos != Vector2.Zero)
{ {
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released) if (PlayerInput.LeftButtonReleased())
{ {
//mouse released -> move the entities to the new position of the mouse //mouse released -> move the entities to the new position of the mouse
@@ -320,10 +320,10 @@ namespace Barotrauma
e.isHighlighted = true; e.isHighlighted = true;
} }
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released) if (PlayerInput.LeftButtonReleased())
{ {
if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.LeftControl) || if (PlayerInput.KeyDown(Keys.LeftControl) ||
PlayerInput.GetKeyboardState.IsKeyDown(Keys.RightControl)) PlayerInput.KeyDown(Keys.RightControl))
{ {
foreach (MapEntity e in newSelection) foreach (MapEntity e in newSelection)
{ {
@@ -353,8 +353,8 @@ namespace Barotrauma
else else
{ {
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed && if (PlayerInput.LeftButtonDown() &&
PlayerInput.GetKeyboardState.IsKeyUp(Keys.Space)) PlayerInput.KeyUp(Keys.Space))
{ {
//if clicking a selected entity, start moving it //if clicking a selected entity, start moving it
foreach (MapEntity e in selectedList) foreach (MapEntity e in selectedList)
@@ -377,7 +377,7 @@ namespace Barotrauma
{ {
if (GUIComponent.MouseOn != null) return; if (GUIComponent.MouseOn != null) return;
Vector2 position = new Vector2(PlayerInput.GetMouseState.X, PlayerInput.GetMouseState.Y); Vector2 position = PlayerInput.MousePosition;
position = cam.ScreenToWorld(position); position = cam.ScreenToWorld(position);
if (startMovingPos != Vector2.Zero) if (startMovingPos != Vector2.Zero)
+3 -3
View File
@@ -134,7 +134,7 @@ namespace Barotrauma
GUI.DrawLine(spriteBatch, new Vector2(position.X, -(position.Y - GameMain.GraphicsHeight)), new Vector2(position.X, -(position.Y + GameMain.GraphicsHeight)), Color.White); GUI.DrawLine(spriteBatch, new Vector2(position.X, -(position.Y - GameMain.GraphicsHeight)), new Vector2(position.X, -(position.Y + GameMain.GraphicsHeight)), Color.White);
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed) placePosition = position; if (PlayerInput.LeftButtonDown()) placePosition = position;
} }
else else
{ {
@@ -152,7 +152,7 @@ namespace Barotrauma
newRect.Location -= Submarine.Loaded.Position.ToPoint(); newRect.Location -= Submarine.Loaded.Position.ToPoint();
} }
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released) if (PlayerInput.LeftButtonReleased())
{ {
object[] lobject = new object[] { this, newRect }; object[] lobject = new object[] { this, newRect };
constructor.Invoke(lobject); constructor.Invoke(lobject);
@@ -164,7 +164,7 @@ namespace Barotrauma
GUI.DrawRectangle(spriteBatch, newRect, Color.DarkBlue); GUI.DrawRectangle(spriteBatch, newRect, Color.DarkBlue);
} }
if (PlayerInput.GetMouseState.RightButton == ButtonState.Pressed) if (PlayerInput.RightButtonDown())
{ {
placePosition = Vector2.Zero; placePosition = Vector2.Zero;
selected = null; selected = null;
+3 -3
View File
@@ -283,11 +283,11 @@ namespace Barotrauma
if (StairDirection == Direction.Left) if (StairDirection == Direction.Left)
{ {
return MathUtils.LineToPointDistance(new Vector2(rect.X, rect.Y), new Vector2(rect.Right, rect.Y - rect.Height), position)< 40.0f; return MathUtils.LineToPointDistance(new Vector2(WorldRect.X, WorldRect.Y), new Vector2(WorldRect.Right, WorldRect.Y - WorldRect.Height), position) < 40.0f;
} }
else else
{ {
return MathUtils.LineToPointDistance(new Vector2(rect.X,rect.Y-rect.Height), new Vector2(rect.Right, rect.Y), position) <40.0f; return MathUtils.LineToPointDistance(new Vector2(WorldRect.X, WorldRect.Y - rect.Height), new Vector2(WorldRect.Right, WorldRect.Y), position) < 40.0f;
} }
} }
} }
+3 -3
View File
@@ -124,7 +124,7 @@ namespace Barotrauma
if (placePosition == Vector2.Zero) if (placePosition == Vector2.Zero)
{ {
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed) if (PlayerInput.LeftButtonDown())
placePosition = Submarine.MouseToWorldGrid(cam); placePosition = Submarine.MouseToWorldGrid(cam);
newRect.X = (int)position.X; newRect.X = (int)position.X;
@@ -140,7 +140,7 @@ namespace Barotrauma
newRect = Submarine.AbsRect(placePosition, placeSize); newRect = Submarine.AbsRect(placePosition, placeSize);
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released) if (PlayerInput.LeftButtonReleased())
{ {
if (Submarine.Loaded != null) if (Submarine.Loaded != null)
{ {
@@ -161,7 +161,7 @@ namespace Barotrauma
GUI.DrawRectangle(spriteBatch, new Rectangle(newRect.X - GameMain.GraphicsWidth, -newRect.Y, newRect.Width + GameMain.GraphicsWidth*2, newRect.Height), Color.White); GUI.DrawRectangle(spriteBatch, new Rectangle(newRect.X - GameMain.GraphicsWidth, -newRect.Y, newRect.Width + GameMain.GraphicsWidth*2, newRect.Height), Color.White);
GUI.DrawRectangle(spriteBatch, new Rectangle(newRect.X, -newRect.Y - GameMain.GraphicsHeight, newRect.Width, newRect.Height + GameMain.GraphicsHeight*2), Color.White); GUI.DrawRectangle(spriteBatch, new Rectangle(newRect.X, -newRect.Y - GameMain.GraphicsHeight, newRect.Width, newRect.Height + GameMain.GraphicsHeight*2), Color.White);
if (PlayerInput.GetMouseState.RightButton == ButtonState.Pressed) selected = null; if (PlayerInput.RightButtonDown()) selected = null;
} }
} }
} }
+1 -1
View File
@@ -258,7 +258,7 @@ namespace Barotrauma
public static Vector2 MouseToWorldGrid(Camera cam) public static Vector2 MouseToWorldGrid(Camera cam)
{ {
Vector2 position = new Vector2(PlayerInput.GetMouseState.X, PlayerInput.GetMouseState.Y); Vector2 position = PlayerInput.MousePosition;
position = cam.ScreenToWorld(position); position = cam.ScreenToWorld(position);
return VectorToWorldGrid(position); return VectorToWorldGrid(position);
+45 -28
View File
@@ -214,14 +214,14 @@ namespace Barotrauma
get { return new Vector2(mouseState.Position.X, mouseState.Position.Y); } get { return new Vector2(mouseState.Position.X, mouseState.Position.Y); }
} }
public static MouseState GetMouseState //public static MouseState GetMouseState
{ //{
get { return mouseState; } // get { return mouseState; }
} //}
public static MouseState GetOldMouseState //public static MouseState GetOldMouseState
{ //{
get { return oldMouseState; } // get { return oldMouseState; }
} //}
public static bool MouseInsideWindow public static bool MouseInsideWindow
{ {
@@ -231,74 +231,91 @@ namespace Barotrauma
public static Vector2 MouseSpeed public static Vector2 MouseSpeed
{ {
get get
{ {
return MousePosition - new Vector2(oldMouseState.X, oldMouseState.Y); return GameMain.Instance.IsActive ? MousePosition - new Vector2(oldMouseState.X, oldMouseState.Y) : Vector2.Zero;
} }
} }
public static KeyboardState GetKeyboardState public static KeyboardState GetKeyboardState
{ {
get { return keyboardState; } get { return keyboardState; }
} }
public static KeyboardState GetOldKeyboardState public static KeyboardState GetOldKeyboardState
{ {
get { return oldKeyboardState; } get { return oldKeyboardState; }
} }
public static int ScrollWheelSpeed public static int ScrollWheelSpeed
{ {
get { return mouseState.ScrollWheelValue - oldMouseState.ScrollWheelValue; } get { return GameMain.Instance.IsActive ? mouseState.ScrollWheelValue - oldMouseState.ScrollWheelValue : 0; }
} }
public static bool LeftButtonDown() public static bool LeftButtonDown()
{ {
return mouseState.LeftButton == ButtonState.Pressed; return GameMain.Instance.IsActive && mouseState.LeftButton == ButtonState.Pressed;
}
public static bool LeftButtonReleased()
{
return GameMain.Instance.IsActive && mouseState.LeftButton == ButtonState.Released;
} }
public static bool LeftButtonClicked() public static bool LeftButtonClicked()
{ {
return (oldMouseState.LeftButton == ButtonState.Pressed return (GameMain.Instance.IsActive &&
oldMouseState.LeftButton == ButtonState.Pressed
&& mouseState.LeftButton == ButtonState.Released); && mouseState.LeftButton == ButtonState.Released);
} }
public static bool RightButtonDown() public static bool RightButtonDown()
{ {
return mouseState.RightButton == ButtonState.Pressed; return GameMain.Instance.IsActive && mouseState.RightButton == ButtonState.Pressed;
} }
public static bool RightButtonClicked() public static bool RightButtonClicked()
{ {
return (oldMouseState.RightButton == ButtonState.Pressed return (GameMain.Instance.IsActive &&
oldMouseState.RightButton == ButtonState.Pressed
&& mouseState.RightButton == ButtonState.Released); && mouseState.RightButton == ButtonState.Released);
} }
public static bool DoubleClicked() public static bool DoubleClicked()
{ {
return doubleClicked; return GameMain.Instance.IsActive && doubleClicked;
} }
public static bool KeyHit(InputType inputType) public static bool KeyHit(InputType inputType)
{ {
return GameMain.Config.KeyBind(inputType).IsHit(); return GameMain.Instance.IsActive && GameMain.Config.KeyBind(inputType).IsHit();
} }
public static bool KeyDown(InputType inputType) public static bool KeyDown(InputType inputType)
{ {
return GameMain.Config.KeyBind(inputType).IsDown(); return GameMain.Instance.IsActive && GameMain.Config.KeyBind(inputType).IsDown();
}
public static bool KeyUp(InputType inputType)
{
return GameMain.Instance.IsActive && !GameMain.Config.KeyBind(inputType).IsDown();
} }
public static bool KeyHit(Keys button) public static bool KeyHit(Keys button)
{ {
return (oldKeyboardState.IsKeyDown(button) && keyboardState.IsKeyUp(button)); return (GameMain.Instance.IsActive && oldKeyboardState.IsKeyDown(button) && keyboardState.IsKeyUp(button));
} }
public static bool KeyDown(Keys button) public static bool KeyDown(Keys button)
{ {
return (keyboardState.IsKeyDown(button)); return (GameMain.Instance.IsActive && keyboardState.IsKeyDown(button));
} }
public static bool KeyUp(Keys button)
{
return GameMain.Instance.IsActive && keyboardState.IsKeyUp(button);
}
public static void Update(double deltaTime) public static void Update(double deltaTime)
{ {
timeSinceClick += deltaTime; timeSinceClick += deltaTime;
+1 -1
View File
@@ -202,7 +202,7 @@ namespace Barotrauma
GUI.Draw((float)deltaTime, spriteBatch, cam); GUI.Draw((float)deltaTime, spriteBatch, cam);
if (PlayerInput.GetMouseState.LeftButton != ButtonState.Pressed) Inventory.draggingItem = null; if (!PlayerInput.LeftButtonDown()) Inventory.draggingItem = null;
spriteBatch.End(); spriteBatch.End();
} }
+2
View File
@@ -525,6 +525,8 @@ namespace Barotrauma
private bool StartShift(GUIButton button, object selection) private bool StartShift(GUIButton button, object selection)
{ {
if (GameMain.GameSession.Map.SelectedConnection == null) return false;
GameMain.ShowLoading(ShiftLoading()); GameMain.ShowLoading(ShiftLoading());
//GameMain.GameSession.StartShift(selectedLevel, false); //GameMain.GameSession.StartShift(selectedLevel, false);
Binary file not shown.