Skip to content

Commit

Permalink
No out-of-window keys capturing, AltGr ≠ Ctrl (continued) (#157)
Browse files Browse the repository at this point in the history
* AltGr no longer treated as Ctrl

But also LeftCtrl+AltGr doesn't make the CtrlDown variable true, as a side effect.

* No out-of-window keys capturing

* No out-of-window keys capturing

* No out-of-window keys capturing (mistake fix)

* No out-of-window keys capturing

* No out-of-window keys capturing

And a little cleanup of droping/deleting/selling items

* Keys capturing fixes and improvements

No out-of-window keys capturing
No game speed change while typing in a text box
0 key can pause game
Numpad keys can change game speed
  • Loading branch information
Cosmatevs authored and riperiperi committed Sep 27, 2019
1 parent 4d62cc0 commit 5502511
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 34 deletions.
30 changes: 15 additions & 15 deletions TSOClient/tso.client/UI/Panels/UILotControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -990,12 +990,10 @@ public override void Update(UpdateState state)
}
var nofocus = state.InputManager.GetFocus() == null;
var keyst = state.KeyboardState;
if (nofocus && (keyst.IsKeyDown(Keys.Up) || keyst.IsKeyDown(Keys.Left) || keyst.IsKeyDown(Keys.Down) || keyst.IsKeyDown(Keys.Right) ||
(keyst.IsKeyDown(Keys.W) || keyst.IsKeyDown(Keys.A) || keyst.IsKeyDown(Keys.S) || keyst.IsKeyDown(Keys.D))))
KBScroll = true;
else
KBScroll = false;
if (MouseIsOn)
KBScroll = state.WindowFocused && nofocus &&
(keyst.IsKeyDown(Keys.Up) || keyst.IsKeyDown(Keys.Left) || keyst.IsKeyDown(Keys.Down) || keyst.IsKeyDown(Keys.Right) ||
keyst.IsKeyDown(Keys.W) || keyst.IsKeyDown(Keys.A) || keyst.IsKeyDown(Keys.S) || keyst.IsKeyDown(Keys.D));
if (MouseIsOn)
{
if (state.MouseState.RightButton == ButtonState.Pressed)
{
Expand Down Expand Up @@ -1028,16 +1026,18 @@ public override void Update(UpdateState state)

//set cutaway around mouse
UpdateCutaway(state);

if (state.NewKeys.Contains(Keys.S) && state.KeyboardState.IsKeyDown(Keys.LeftControl))
{
//save lot
if (LotSaveDialog == null) SaveLot();
}
else if (state.NewKeys.Contains(Keys.F) && state.KeyboardState.IsKeyDown(Keys.LeftControl))
if(state.WindowFocused && nofocus)
{
//save facade
if (LotSaveDialog == null) SaveFacade(state.KeyboardState.IsKeyDown(Keys.LeftAlt));
if (state.NewKeys.Contains(Keys.S) && state.KeyboardState.IsKeyDown(Keys.LeftControl) && !state.KeyboardState.IsKeyDown(Keys.RightAlt))
{
//save lot
if (LotSaveDialog == null) SaveLot();
}
else if (state.NewKeys.Contains(Keys.F) && state.KeyboardState.IsKeyDown(Keys.LeftControl) && !state.KeyboardState.IsKeyDown(Keys.RightAlt))
{
//save facade
if (LotSaveDialog == null) SaveFacade(state.KeyboardState.IsKeyDown(Keys.LeftAlt));
}
}
}
}
Expand Down
20 changes: 9 additions & 11 deletions TSOClient/tso.client/UI/Panels/UIObjectHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,28 +472,26 @@ public void Update(UpdateState state, bool scrolled)
if (Locked) return;

CursorType cur = CursorType.SimsMove;
if (Holding != null)
if (Holding != null && state.WindowFocused)
{
if (Roommate) cur = CursorType.SimsPlace;
if (state.KeyboardState.IsKeyDown(Keys.Delete))
{
if (state.InputManager.GetFocus() == null)
{
SellBack(null);
}
} else if (state.KeyboardState.IsKeyDown(Keys.Escape))
if (state.KeyboardState.IsKeyDown(Keys.Escape))
{
OnDelete(Holding, null);
ClearSelected();
} else if (state.KeyboardState.IsKeyDown(Keys.I))
} else if (state.InputManager.GetFocus() == null)
{
if (state.InputManager.GetFocus() == null)
if (state.KeyboardState.IsKeyDown(Keys.I))
{
MoveToInventory(null);
} else if (state.KeyboardState.IsKeyDown(Keys.Delete))
{
SellBack(null);
}
}
}
if (Holding != null && Roommate)
{
cur = CursorType.SimsPlace;
{
if (MouseClicked) Holding.Clicked = true;
if (MouseIsDown && Holding.Clicked)
Expand Down
2 changes: 1 addition & 1 deletion TSOClient/tso.client/UI/Panels/UIUCP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ public override void Update(FSO.Common.Rendering.Framework.Model.UpdateState sta
var keys = state.NewKeys;
var nofocus = state.InputManager.GetFocus() == null;
base.Update(state);
if (Game.InLot)
if (Game.InLot && state.WindowFocused)
{
if (keys.Contains(Keys.F1) && !state.CtrlDown) SetPanel(1); // Live Mode Panel
if (keys.Contains(Keys.F2)) SetPanel(2); // Buy Mode Panel
Expand Down
16 changes: 10 additions & 6 deletions TSOClient/tso.client/UI/Screens/SandboxGameScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,18 @@ public override void Update(FSO.Common.Rendering.Framework.Model.UpdateState sta
Visible = World?.Visible == true && (World?.State as FSO.LotView.RC.WorldStateRC)?.CameraMode != true;
GameFacade.Game.IsMouseVisible = Visible;

if (state.NewKeys.Contains(Microsoft.Xna.Framework.Input.Keys.F1) && state.CtrlDown)
if (state.WindowFocused && state.NewKeys.Contains(Microsoft.Xna.Framework.Input.Keys.F1) && state.CtrlDown)
FSOFacade.Controller.ToggleDebugMenu();

base.Update(state);
if (state.NewKeys.Contains(Keys.D1)) ChangeSpeedTo(1);
if (state.NewKeys.Contains(Keys.D2)) ChangeSpeedTo(2);
if (state.NewKeys.Contains(Keys.D3)) ChangeSpeedTo(3);
if (state.NewKeys.Contains(Keys.P)) ChangeSpeedTo(0);

if (state.WindowFocused && state.InputManager.GetFocus() == null)
{
if (state.NewKeys.Contains(Keys.D1) || (state.KeyboardState.NumLock && state.NewKeys.Contains(Keys.NumPad1))) ChangeSpeedTo(1);
else if (state.NewKeys.Contains(Keys.D2) || (state.KeyboardState.NumLock && state.NewKeys.Contains(Keys.NumPad2))) ChangeSpeedTo(2);
else if (state.NewKeys.Contains(Keys.D3) || (state.KeyboardState.NumLock && state.NewKeys.Contains(Keys.NumPad3))) ChangeSpeedTo(3);
else if (state.NewKeys.Contains(Keys.P) || state.NewKeys.Contains(Keys.D0) || (state.KeyboardState.NumLock && state.NewKeys.Contains(Keys.NumPad0))) ChangeSpeedTo(0);
}

if (World != null)
{
Expand Down Expand Up @@ -675,4 +679,4 @@ private void SaveHouseButton_OnButtonClick(UIElement button)
if (vm.GlobalLink != null) ((VMTSOGlobalLinkStub)vm.GlobalLink).Database.Save();
}
}
}
}
2 changes: 2 additions & 0 deletions TSOClient/tso.common/rendering/framework/io/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public IFocusableUI GetFocus()
/// <param name="keys"></param>
public KeyboardInputResult ApplyKeyboardInput(StringBuilder m_SBuilder, UpdateState state, int cursorIndex, int cursorEndIndex, bool allowInput)
{
if (!state.WindowFocused) { return null; }

var PressedKeys = state.KeyboardState.GetPressedKeys();
int charCount = 0;
if (state.FrameTextInput == null) charCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ public bool ShiftDown
{
get { return KeyboardState.IsKeyDown(Keys.LeftShift) || KeyboardState.IsKeyDown(Keys.RightShift); }
}
/// <summary>
/// Right alt is treated as LeftCtrl+RightAlt so while right Alt is down, you cannot predict if left Ctrl is also down.
/// For that reason, this variable is false when left Ctrl and right Alt are down, and right Ctrl is not down.
/// </summary>
public bool CtrlDown
{
get { return KeyboardState.IsKeyDown(Keys.LeftControl) || KeyboardState.IsKeyDown(Keys.RightControl); }
get { return (KeyboardState.IsKeyDown(Keys.LeftControl) && !KeyboardState.IsKeyDown(Keys.RightAlt)) || KeyboardState.IsKeyDown(Keys.RightControl); }
}
public bool AltDown
{
Expand Down

0 comments on commit 5502511

Please sign in to comment.