66import net .runelite .api .gameval .InterfaceID ;
77import net .runelite .api .gameval .VarClientID ;
88import net .runelite .api .widgets .Widget ;
9- import net .runelite .client .config .ConfigManager ;
9+ import net .runelite .client .input .KeyManager ;
10+ import net .runelite .client .input .KeyListener ;
1011import net .runelite .client .ui .overlay .Overlay ;
1112import net .runelite .client .ui .overlay .OverlayLayer ;
1213import net .runelite .client .ui .overlay .OverlayPosition ;
1516import javax .inject .Inject ;
1617import java .awt .*;
1718import java .awt .event .KeyEvent ;
18- import java .awt .event .KeyListener ;
1919
2020@ Slf4j
2121public class IrcOverlay extends Overlay implements KeyListener {
2222 private final Client client ;
2323 private final IrcPanel panel ;
24- @ Inject
25- private ConfigManager configManager ;
2624
2725 final int tabHeight = 12 ;
2826 final int tabSpacing = 2 ; // space between tabs
2927 final int padding = 8 ;
3028
3129 @ Setter
3230 private boolean enabled ;
33- private boolean overlayDynamic ;
34- private IrcConfig config ;
31+ private final IrcConfig config ;
32+ private final KeyManager keyManager ;
3533
3634 @ Inject
37- public IrcOverlay (Client client , IrcPanel panel , IrcConfig config ) {
35+ public IrcOverlay (Client client , IrcPanel panel , IrcConfig config , KeyManager keyManager ) {
3836 this .client = client ;
3937 this .panel = panel ;
4038 this .config = config ;
4139 this .enabled = config .overlayEnabled ();
40+ this .keyManager = keyManager ;
4241
4342 updatePosition ();
4443
45- this . client . getCanvas (). addKeyListener (this );
44+ keyManager . registerKeyListener (this );
4645 }
4746
48- public void subscribeEvents () {
49- KeyboardFocusManager .getCurrentKeyboardFocusManager ().addKeyEventDispatcher (e -> {
50- if (panel == null ) return false ;
51-
52- if (e .getID () == KeyEvent .KEY_PRESSED ) {
53- if (e .getKeyCode () == KeyEvent .VK_PAGE_UP && this .config .pageUpDownNavigation ()) {
54- panel .cycleChannelBackwards ();
55- e .consume ();
56- return true ;
57- } else if (e .getKeyCode () == KeyEvent .VK_PAGE_DOWN && this .config .pageUpDownNavigation ()) {
58- panel .cycleChannel ();
59- e .consume ();
60- return true ;
61- }
62-
63- Component focusOwner = KeyboardFocusManager
64- .getCurrentKeyboardFocusManager ()
65- .getFocusOwner ();
66-
67- // Only process if NOT inside the text input
68- if (!focusOwner .equals (panel .inputField ) && chatboxFocused () && this .config .backTickNavigation ()) {
69- if (e .getKeyCode () == KeyEvent .VK_BACK_QUOTE && (e .getModifiersEx () & KeyEvent .SHIFT_DOWN_MASK ) != 0 ) {
70- e .consume ();
71- panel .cycleChannelBackwards ();
72- return true ;
73- } else if (e .getKeyCode () == KeyEvent .VK_BACK_QUOTE ) {
74- e .consume ();
75- panel .cycleChannel ();
76- return true ;
77- }
78- }
79-
80- }
81-
82- return false ;
83- });
47+ public void shutdown () {
48+ keyManager .unregisterKeyListener (this );
8449 }
8550
8651 private boolean isHidden (int component ) {
@@ -102,28 +67,6 @@ boolean isOptionsDialogOpen() {
10267 return client .getWidget (InterfaceID .Chatmenu .OPTIONS ) != null ;
10368 }
10469
105- boolean chatboxFocused () {
106- Widget chatboxParent = client .getWidget (InterfaceID .Chatbox .UNIVERSE );
107- if (chatboxParent == null || chatboxParent .getOnKeyListener () == null ) {
108- return false ;
109- }
110-
111- // If the search box on the world map is open and focused, ~keypress_permit blocks the keypress
112- Widget worldMapSearch = client .getWidget (InterfaceID .Worldmap .MAPLIST_DISPLAY );
113- if (worldMapSearch != null && client .getVarcIntValue (VarClientID .WORLDMAP_SEARCHING ) == 1 ) {
114- return false ;
115- }
116-
117- // The report interface blocks input due to 162:54 being hidden, however player/npc dialog and
118- // options do this too, and so we can't disable remapping just due to 162:54 being hidden.
119- Widget report = client .getWidget (InterfaceID .Reportabuse .UNIVERSE );
120- if (report != null ) {
121- return false ;
122- }
123-
124- return true ;
125- }
126-
12770 private static final int CHATBOX_GROUP = 162 ;
12871 private static final int CHATBOX_MESSAGES_CHILD = 0 ;
12972 private static final int CHATAREA = InterfaceID .Chatbox .CHATAREA ;
@@ -203,29 +146,19 @@ public Dimension render(Graphics2D graphics) {
203146
204147 @ Override
205148 public void keyPressed (KeyEvent e ) {
206- if (panel == null ) return ;
149+ if (panel == null || panel . getChannelPanes () == null ) return ;
207150
208151 if (e .getKeyCode () == KeyEvent .VK_PAGE_UP && this .config .pageUpDownNavigation ()) {
209152 panel .cycleChannelBackwards ();
210153 e .consume ();
211- return ;
212154 } else if (e .getKeyCode () == KeyEvent .VK_PAGE_DOWN && this .config .pageUpDownNavigation ()) {
213155 panel .cycleChannel ();
214156 e .consume ();
215- return ;
216- }
217-
218- Component focusOwner = KeyboardFocusManager
219- .getCurrentKeyboardFocusManager ()
220- .getFocusOwner ();
221-
222- // Only process if NOT inside the text input
223- if (!focusOwner .equals (panel .inputField ) && chatboxFocused () && this .config .backTickNavigation ()) {
157+ } else if (this .config .backTickNavigation ()) {
224158 if (e .getKeyCode () == KeyEvent .VK_BACK_QUOTE && (e .getModifiersEx () & KeyEvent .SHIFT_DOWN_MASK ) != 0 ) {
225159 panel .cycleChannelBackwards ();
226160 e .consume ();
227161 } else if (e .getKeyCode () == KeyEvent .VK_BACK_QUOTE ) {
228- log .debug ("f" );
229162 panel .cycleChannel ();
230163 e .consume ();
231164 }
@@ -241,4 +174,11 @@ public void keyTyped(KeyEvent e) {
241174 public void keyReleased (KeyEvent e ) {
242175 // Unnecessary
243176 }
177+
178+ @ Override
179+ public boolean isEnabledOnLoginScreen ()
180+ {
181+ return true ;
182+ }
183+
244184}
0 commit comments