Skip to content

Commit

Permalink
wasd plugin: check chatbox input widget visibility to determine if a …
Browse files Browse the repository at this point in the history
…dialog is open

Fix using numbers to navigate dialog, and fix using wasd with dialog open
  • Loading branch information
Adam- committed Aug 16, 2018
1 parent f05df70 commit 4d6352d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,22 @@ class WASDCameraListener extends MouseListener implements KeyListener
@Override
public void keyTyped(KeyEvent e)
{
handleKey(e);
// allow if not typing in chatbox, or typing mode is enabled
if (client.getGameState() != GameState.LOGGED_IN
|| !plugin.chatboxFocused()
|| plugin.isTyping())
{
return;
}

// otherwise allow typing if a digit and this is a dialog
if (Character.isDigit(e.getKeyChar()) && plugin.chatboxDialog())
{
return;
}

// otherwise consume
e.consume();
}

@Override
Expand Down Expand Up @@ -84,6 +99,35 @@ else if (config.right().matches(e))
{
switch (e.getKeyCode())
{
case KeyEvent.VK_0:
case KeyEvent.VK_1:
case KeyEvent.VK_2:
case KeyEvent.VK_3:
case KeyEvent.VK_4:
case KeyEvent.VK_5:
case KeyEvent.VK_6:
case KeyEvent.VK_7:
case KeyEvent.VK_8:
case KeyEvent.VK_9:
case KeyEvent.VK_NUMPAD0:
case KeyEvent.VK_NUMPAD1:
case KeyEvent.VK_NUMPAD2:
case KeyEvent.VK_NUMPAD3:
case KeyEvent.VK_NUMPAD4:
case KeyEvent.VK_NUMPAD5:
case KeyEvent.VK_NUMPAD6:
case KeyEvent.VK_NUMPAD7:
case KeyEvent.VK_NUMPAD8:
case KeyEvent.VK_NUMPAD9:
case KeyEvent.VK_SPACE:
// numbers normally are consumed, unless a dialog box is open.
// most dialogs in the chatbox use the same chatbox input handler
// as normal chat
if (!plugin.chatboxDialog())
{
e.consume();
}
break;
case KeyEvent.VK_ENTER:
case KeyEvent.VK_SLASH:
// refocus chatbox
Expand Down Expand Up @@ -147,11 +191,6 @@ else if (config.right().matches(e))

@Override
public void keyReleased(KeyEvent e)
{
handleKey(e);
}

private void handleKey(KeyEvent e)
{
if (client.getGameState() != GameState.LOGGED_IN || !plugin.chatboxFocused())
{
Expand Down Expand Up @@ -180,6 +219,32 @@ else if (config.right().matches(e))
{
switch (e.getKeyCode())
{
case KeyEvent.VK_0:
case KeyEvent.VK_1:
case KeyEvent.VK_2:
case KeyEvent.VK_3:
case KeyEvent.VK_4:
case KeyEvent.VK_5:
case KeyEvent.VK_6:
case KeyEvent.VK_7:
case KeyEvent.VK_8:
case KeyEvent.VK_9:
case KeyEvent.VK_NUMPAD0:
case KeyEvent.VK_NUMPAD1:
case KeyEvent.VK_NUMPAD2:
case KeyEvent.VK_NUMPAD3:
case KeyEvent.VK_NUMPAD4:
case KeyEvent.VK_NUMPAD5:
case KeyEvent.VK_NUMPAD6:
case KeyEvent.VK_NUMPAD7:
case KeyEvent.VK_NUMPAD8:
case KeyEvent.VK_NUMPAD9:
case KeyEvent.VK_SPACE:
if (!plugin.chatboxDialog())
{
e.consume();
}
break;
case KeyEvent.VK_SLASH:
case KeyEvent.VK_F1:
case KeyEvent.VK_F2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,13 @@ WASDCameraConfig getConfig(ConfigManager configManager)
boolean chatboxFocused()
{
Widget chatboxParent = client.getWidget(WidgetInfo.CHATBOX_PARENT);
if (chatboxParent == null || chatboxParent.getOnKeyListener() == null)
{
return false;
}

// chat dialogs use the same key listener as chat
if (client.getWidget(WidgetInfo.DIALOG_NPC) != null
|| client.getWidget(WidgetInfo.DIALOG_SPRITE) != null
|| client.getWidget(WidgetInfo.DIALOG_OPTION) != null
|| client.getWidget(WidgetInfo.DIALOG_PLAYER) != null)
{
return false;
}
return chatboxParent != null && chatboxParent.getOnKeyListener() != null;
}

return true;
boolean chatboxDialog()
{
Widget chatboxInput = client.getWidget(WidgetInfo.CHATBOX_INPUT);
return chatboxInput == null || chatboxInput.isHidden();
}

@Subscribe
Expand Down

0 comments on commit 4d6352d

Please sign in to comment.