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

View File

@@ -183,7 +183,7 @@ namespace Barotrauma
}
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);

View File

@@ -70,18 +70,18 @@ namespace Barotrauma
}
}
//try
//{
try
{
Coroutines[i].MoveNext();
// }
}
// catch (Exception e)
// {
//#if DEBUG
// DebugConsole.ThrowError("Coroutine " + Coroutines[i] + " threw an exception: " + e.Message);
//#endif
// Coroutines.RemoveAt(i);
// }
catch (Exception e)
{
#if DEBUG
DebugConsole.ThrowError("Coroutine " + Coroutines[i] + " threw an exception: " + e.Message);
#endif
Coroutines.RemoveAt(i);
}
}
}

View File

@@ -99,7 +99,7 @@ namespace Barotrauma
//textBox.Update(deltaTime);
if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.Enter) && textBox.Text != "")
if (PlayerInput.KeyDown(Keys.Enter) && textBox.Text != "")
{
NewMessage(textBox.Text, Color.White);
ExecuteCommand(textBox.Text, game);

View File

@@ -300,7 +300,7 @@ namespace Barotrauma
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);

View File

@@ -152,7 +152,7 @@ namespace Barotrauma
if (rect.Contains(PlayerInput.MousePosition) && CanBeSelected && Enabled && (MouseOn == null || MouseOn == this || IsParentOf(MouseOn)))
{
state = ComponentState.Hover;
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed)
if (PlayerInput.LeftButtonDown())
{
if (OnPressed != null)
{

View File

@@ -152,7 +152,7 @@ namespace Barotrauma
if (style != null) style.Apply(textBlock, this);
textBlock.Padding = new Vector4(3.0f, 0.0f, 3.0f, 0.0f);
previousMouse = PlayerInput.GetMouseState;
//previousMouse = PlayerInput.GetMouseState;
CaretEnabled = true;
//SetTextPos();
@@ -171,7 +171,7 @@ namespace Barotrauma
if (keyboardDispatcher.Subscriber == this) keyboardDispatcher.Subscriber = null;
}
MouseState previousMouse;
//MouseState previousMouse;
public override void Update(float deltaTime)
{
if (!Visible) return;

View File

@@ -61,7 +61,7 @@ namespace Barotrauma
box.State = ComponentState.Hover;
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed)
if (PlayerInput.LeftButtonDown())
{
box.State = ComponentState.Selected;
}

View File

@@ -326,10 +326,10 @@ namespace Barotrauma
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.Y = PlayerInput.GetMouseState.Y - slotRect.Height / 2;
slotRect.X = (int)PlayerInput.MousePosition.X - slotRect.Width / 2;
slotRect.Y = (int)PlayerInput.MousePosition.Y - slotRect.Height / 2;
DrawSlot(spriteBatch, slotRect, draggingItem, false, false);
}

View File

@@ -136,7 +136,7 @@ namespace Barotrauma.Items.Components
ignoredBodies.Add(limb.body.FarseerBody);
}
Vector2 rayStart = item.WorldPosition + TransformedBarrelPos;
Vector2 rayStart = item.WorldPosition;
Vector2 rayEnd = targetPosition;
Body targetBody = Submarine.PickBody(

View File

@@ -351,7 +351,7 @@ namespace Barotrauma.Items.Components
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.SelectEntity(item);

View File

@@ -205,10 +205,10 @@ namespace Barotrauma
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.Y = PlayerInput.GetMouseState.Y - slotRect.Height / 2;
slotRect.X = (int)PlayerInput.MousePosition.X - slotRect.Width / 2;
slotRect.Y = (int)PlayerInput.MousePosition.Y - slotRect.Height / 2;
//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);
@@ -261,12 +261,12 @@ namespace Barotrauma
{
if (draggingItem == null)
{
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed)
if (PlayerInput.LeftButtonDown())
{
draggingItem = item;
}
}
else if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released)
else if (PlayerInput.LeftButtonReleased())
{
if (PlayerInput.DoubleClicked())
{

View File

@@ -114,8 +114,7 @@ namespace Barotrauma
if (placePosition == Vector2.Zero)
{
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed)
placePosition = position;
if (PlayerInput.LeftButtonDown()) placePosition = position;
}
else
{
@@ -124,7 +123,7 @@ namespace Barotrauma
if (resizeVertical)
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);
placePosition = Vector2.Zero;

View File

@@ -253,7 +253,7 @@ namespace Barotrauma
return;
}
if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.Delete))
if (PlayerInput.KeyDown(Keys.Delete))
{
foreach (MapEntity e in selectedList) e.Remove();
selectedList.Clear();
@@ -283,7 +283,7 @@ namespace Barotrauma
//started moving selected entities
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
@@ -320,10 +320,10 @@ namespace Barotrauma
e.isHighlighted = true;
}
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released)
if (PlayerInput.LeftButtonReleased())
{
if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.LeftControl) ||
PlayerInput.GetKeyboardState.IsKeyDown(Keys.RightControl))
if (PlayerInput.KeyDown(Keys.LeftControl) ||
PlayerInput.KeyDown(Keys.RightControl))
{
foreach (MapEntity e in newSelection)
{
@@ -353,8 +353,8 @@ namespace Barotrauma
else
{
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed &&
PlayerInput.GetKeyboardState.IsKeyUp(Keys.Space))
if (PlayerInput.LeftButtonDown() &&
PlayerInput.KeyUp(Keys.Space))
{
//if clicking a selected entity, start moving it
foreach (MapEntity e in selectedList)
@@ -377,7 +377,7 @@ namespace Barotrauma
{
if (GUIComponent.MouseOn != null) return;
Vector2 position = new Vector2(PlayerInput.GetMouseState.X, PlayerInput.GetMouseState.Y);
Vector2 position = PlayerInput.MousePosition;
position = cam.ScreenToWorld(position);
if (startMovingPos != Vector2.Zero)

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);
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed) placePosition = position;
if (PlayerInput.LeftButtonDown()) placePosition = position;
}
else
{
@@ -152,7 +152,7 @@ namespace Barotrauma
newRect.Location -= Submarine.Loaded.Position.ToPoint();
}
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released)
if (PlayerInput.LeftButtonReleased())
{
object[] lobject = new object[] { this, newRect };
constructor.Invoke(lobject);
@@ -164,7 +164,7 @@ namespace Barotrauma
GUI.DrawRectangle(spriteBatch, newRect, Color.DarkBlue);
}
if (PlayerInput.GetMouseState.RightButton == ButtonState.Pressed)
if (PlayerInput.RightButtonDown())
{
placePosition = Vector2.Zero;
selected = null;

View File

@@ -283,11 +283,11 @@ namespace Barotrauma
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
{
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;
}
}
}

View File

@@ -124,7 +124,7 @@ namespace Barotrauma
if (placePosition == Vector2.Zero)
{
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed)
if (PlayerInput.LeftButtonDown())
placePosition = Submarine.MouseToWorldGrid(cam);
newRect.X = (int)position.X;
@@ -140,7 +140,7 @@ namespace Barotrauma
newRect = Submarine.AbsRect(placePosition, placeSize);
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released)
if (PlayerInput.LeftButtonReleased())
{
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, -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;
}
}
}

View File

@@ -258,7 +258,7 @@ namespace Barotrauma
public static Vector2 MouseToWorldGrid(Camera cam)
{
Vector2 position = new Vector2(PlayerInput.GetMouseState.X, PlayerInput.GetMouseState.Y);
Vector2 position = PlayerInput.MousePosition;
position = cam.ScreenToWorld(position);
return VectorToWorldGrid(position);

View File

@@ -214,14 +214,14 @@ namespace Barotrauma
get { return new Vector2(mouseState.Position.X, mouseState.Position.Y); }
}
public static MouseState GetMouseState
{
get { return mouseState; }
}
public static MouseState GetOldMouseState
{
get { return oldMouseState; }
}
//public static MouseState GetMouseState
//{
// get { return mouseState; }
//}
//public static MouseState GetOldMouseState
//{
// get { return oldMouseState; }
//}
public static bool MouseInsideWindow
{
@@ -231,74 +231,91 @@ namespace Barotrauma
public static Vector2 MouseSpeed
{
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
{
get { return keyboardState; }
}
public static KeyboardState GetKeyboardState
{
get { return keyboardState; }
}
public static KeyboardState GetOldKeyboardState
{
get { return oldKeyboardState; }
}
public static KeyboardState GetOldKeyboardState
{
get { return oldKeyboardState; }
}
public static int ScrollWheelSpeed
{
get { return mouseState.ScrollWheelValue - oldMouseState.ScrollWheelValue; }
get { return GameMain.Instance.IsActive ? mouseState.ScrollWheelValue - oldMouseState.ScrollWheelValue : 0; }
}
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()
{
return (oldMouseState.LeftButton == ButtonState.Pressed
return (GameMain.Instance.IsActive &&
oldMouseState.LeftButton == ButtonState.Pressed
&& mouseState.LeftButton == ButtonState.Released);
}
public static bool RightButtonDown()
{
return mouseState.RightButton == ButtonState.Pressed;
return GameMain.Instance.IsActive && mouseState.RightButton == ButtonState.Pressed;
}
public static bool RightButtonClicked()
{
return (oldMouseState.RightButton == ButtonState.Pressed
return (GameMain.Instance.IsActive &&
oldMouseState.RightButton == ButtonState.Pressed
&& mouseState.RightButton == ButtonState.Released);
}
public static bool DoubleClicked()
{
return doubleClicked;
return GameMain.Instance.IsActive && doubleClicked;
}
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)
{
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)
{
return (oldKeyboardState.IsKeyDown(button) && keyboardState.IsKeyUp(button));
return (GameMain.Instance.IsActive && oldKeyboardState.IsKeyDown(button) && keyboardState.IsKeyUp(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)
{
timeSinceClick += deltaTime;

View File

@@ -202,7 +202,7 @@ namespace Barotrauma
GUI.Draw((float)deltaTime, spriteBatch, cam);
if (PlayerInput.GetMouseState.LeftButton != ButtonState.Pressed) Inventory.draggingItem = null;
if (!PlayerInput.LeftButtonDown()) Inventory.draggingItem = null;
spriteBatch.End();
}

View File

@@ -525,6 +525,8 @@ namespace Barotrauma
private bool StartShift(GUIButton button, object selection)
{
if (GameMain.GameSession.Map.SelectedConnection == null) return false;
GameMain.ShowLoading(ShiftLoading());
//GameMain.GameSession.StartShift(selectedLevel, false);

Binary file not shown.