Skip to content

Commit

Permalink
Add alt+{num} keyboard shortcut to show/hide panels
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Apr 30, 2023
1 parent 98ed718 commit 207f0c3
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 7 deletions.
5 changes: 5 additions & 0 deletions EndlessClient/HUD/HudButtonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public HudButtonController(IHudStateActions hudStateActions,
_localizedStringFinder = localizedStringFinder;
}

public void ShowNews()
{
_hudStateActions.SwitchToState(InGameStates.News);
}

public void ClickInventory()
{
_hudStateActions.SwitchToState(InGameStates.Inventory);
Expand Down
4 changes: 3 additions & 1 deletion EndlessClient/HUD/HudStateActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public void SwitchToState(InGameStates newState)
if (!_hudControlProvider.IsInGame)
return;

_hudControlProvider.GetComponent<IHudPanel>(Controls.HudControlIdentifier.NewsPanel).Visible = false;
if (newState != InGameStates.News)
_hudControlProvider.GetComponent<IHudPanel>(Controls.HudControlIdentifier.NewsPanel).Visible = false;

var targetPanel = _hudControlProvider.HudPanels.Single(x => IsPanelForRequestedState(x, newState));
targetPanel.Visible = !targetPanel.Visible;
Expand Down Expand Up @@ -64,6 +65,7 @@ private bool IsPanelForRequestedState(IHudPanel hudPanel, InGameStates newState)
{
switch (newState)
{
case InGameStates.News: return hudPanel is NewsPanel;
case InGameStates.Inventory: return hudPanel is InventoryPanel;
case InGameStates.ActiveSpells: return hudPanel is ActiveSpellsPanel;
case InGameStates.PassiveSpells: return hudPanel is PassiveSpellsPanel;
Expand Down
2 changes: 2 additions & 0 deletions EndlessClient/HUD/IHudButtonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
public interface IHudButtonController
{
void ShowNews();

void ClickInventory();

void ClickViewMapToggle();
Expand Down
60 changes: 60 additions & 0 deletions EndlessClient/Input/PanelShortcutHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using EndlessClient.GameExecution;
using EndlessClient.HUD;
using EOLib.Domain.Map;
using Microsoft.Xna.Framework.Input;
using Optional;
using System.Linq;

namespace EndlessClient.Input
{
public class PanelShortcutHandler : InputHandlerBase
{
private readonly IHudButtonController _hudButtonController;

public PanelShortcutHandler(IEndlessGameProvider endlessGameProvider,
IUserInputProvider userInputProvider,
IUserInputTimeRepository userInputTimeRepository,
ICurrentMapStateRepository currentMapStateRepository,
IHudButtonController hudButtonController)
: base(endlessGameProvider, userInputProvider, userInputTimeRepository, currentMapStateRepository)
{
_hudButtonController = hudButtonController;
}

protected override Option<Keys> HandleInput()
{
if (!IsKeyHeld(Keys.LeftAlt) && !IsKeyHeld(Keys.RightAlt))
return Option.None<Keys>();

var keys = Enumerable.Range((int)Keys.D0, 10).Select(i => (Keys)i).Concat(new[] { Keys.OemTilde });

foreach (var key in keys)
{
if (IsKeyPressedOnce(key))
{
switch (key)
{
case Keys.OemTilde: _hudButtonController.ShowNews(); break;

case Keys.D1: _hudButtonController.ClickInventory(); break;
case Keys.D2: _hudButtonController.ClickViewMapToggle(); break;
case Keys.D3: _hudButtonController.ClickActiveSpells(); break;
case Keys.D4: _hudButtonController.ClickPassiveSpells(); break;
case Keys.D5: _hudButtonController.ClickChat(); break;
case Keys.D6: _hudButtonController.ClickStats(); break;

case Keys.D7: _hudButtonController.ClickOnlineList(); break;
case Keys.D8: _hudButtonController.ClickParty(); break;
// macro: intentionally not implemented
case Keys.D9: _hudButtonController.ClickSettings(); break;
case Keys.D0: _hudButtonController.ClickHelp(); break;
}

return Option.Some(key);
}
}

return Option.None<Keys>();
}
}
}
12 changes: 11 additions & 1 deletion EndlessClient/Input/UserInputHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using EndlessClient.Controllers;
using EndlessClient.Dialogs;
using EndlessClient.GameExecution;
using EndlessClient.HUD;
using EndlessClient.Rendering;
using EOLib.Domain.Map;
using Microsoft.Xna.Framework;
using System;
Expand All @@ -22,8 +24,10 @@ public UserInputHandler(IEndlessGameProvider endlessGameProvider,
IControlKeyController controlKeyController,
IFunctionKeyController functionKeyController,
INumPadController numPadController,
IHudButtonController hudButtonController,
ICurrentMapStateRepository currentMapStateRepository,
IActiveDialogProvider activeDialogProvider)
IActiveDialogProvider activeDialogProvider,
IClientWindowSizeProvider clientWindowSizeProvider)
{
_handlers = new List<IInputHandler>
{
Expand All @@ -48,6 +52,12 @@ public UserInputHandler(IEndlessGameProvider endlessGameProvider,
currentMapStateRepository,
numPadController),
};

if (clientWindowSizeProvider.Resizable)
{
_handlers.Add(new PanelShortcutHandler(endlessGameProvider, userInputProvider, userInputTimeRepository, currentMapStateRepository, hudButtonController));
}

_activeDialogProvider = activeDialogProvider;
}

Expand Down
14 changes: 12 additions & 2 deletions EndlessClient/Input/UserInputHandlerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using EndlessClient.Controllers;
using EndlessClient.Dialogs;
using EndlessClient.GameExecution;
using EndlessClient.HUD;
using EndlessClient.Rendering;
using EOLib.Domain.Map;

namespace EndlessClient.Input
Expand All @@ -16,8 +18,10 @@ public class UserInputHandlerFactory : IUserInputHandlerFactory
private readonly IControlKeyController _controlKeyController;
private readonly IFunctionKeyController _functionKeyController;
private readonly INumPadController _numPadController;
private readonly IHudButtonController _hudButtonController;
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly IActiveDialogProvider _activeDialogProvider;
private readonly IClientWindowSizeProvider _clientWindowSizeProvider;

public UserInputHandlerFactory(IEndlessGameProvider endlessGameProvider,
IUserInputProvider userInputProvider,
Expand All @@ -26,8 +30,10 @@ public UserInputHandlerFactory(IEndlessGameProvider endlessGameProvider,
IControlKeyController controlKeyController,
IFunctionKeyController functionKeyController,
INumPadController numPadController,
IHudButtonController hudButtonController,
ICurrentMapStateRepository currentMapStateRepository,
IActiveDialogProvider activeDialogProvider)
IActiveDialogProvider activeDialogProvider,
IClientWindowSizeProvider clientWindowSizeProvider)
{
_endlessGameProvider = endlessGameProvider;
_userInputProvider = userInputProvider;
Expand All @@ -36,8 +42,10 @@ public UserInputHandlerFactory(IEndlessGameProvider endlessGameProvider,
_controlKeyController = controlKeyController;
_functionKeyController = functionKeyController;
_numPadController = numPadController;
_hudButtonController = hudButtonController;
_currentMapStateRepository = currentMapStateRepository;
_activeDialogProvider = activeDialogProvider;
_clientWindowSizeProvider = clientWindowSizeProvider;
}

public IUserInputHandler CreateUserInputHandler()
Expand All @@ -49,8 +57,10 @@ public IUserInputHandler CreateUserInputHandler()
_controlKeyController,
_functionKeyController,
_numPadController,
_hudButtonController,
_currentMapStateRepository,
_activeDialogProvider);
_activeDialogProvider,
_clientWindowSizeProvider);
}
}

Expand Down
7 changes: 4 additions & 3 deletions EndlessClient/UIControls/ChatTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected override bool HandleTextInput(KeyboardEventArgs eventArgs)
if (_ignoreAllInput)
return false;

if (IsSpecialInput(eventArgs.Key))
if (IsSpecialInput(eventArgs.Key, eventArgs.Modifiers))
HandleSpecialInput(eventArgs.Key);
else
base.HandleTextInput(eventArgs);
Expand All @@ -128,10 +128,11 @@ private void HandleSpecialInput(Keys key)
Text = "";
}

private bool IsSpecialInput(Keys k)
private bool IsSpecialInput(Keys k, KeyboardModifiers modifiers)
{
return k == Keys.Escape || k == Keys.Decimal ||
(k >= Keys.NumPad0 && k <= Keys.NumPad9);
(k >= Keys.NumPad0 && k <= Keys.NumPad9) ||
modifiers == KeyboardModifiers.Alt;
}
}
}

0 comments on commit 207f0c3

Please sign in to comment.