From 23f2922b2e1e91aca7fc40f510e254881db0b89f Mon Sep 17 00:00:00 2001 From: ix0rai Date: Fri, 29 Sep 2023 23:41:05 -0500 Subject: [PATCH] add keybinds and remove background for navigator panel --- .../enigma/gui/config/keybind/KeyBinds.java | 3 ++ .../enigma/gui/elements/EditorTabbedPane.java | 4 ++ .../enigma/gui/elements/NavigatorPanel.java | 52 +++++++++++-------- enigma/src/main/resources/lang/en_us.json | 2 + 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/config/keybind/KeyBinds.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/config/keybind/KeyBinds.java index 52d54be4f..53bd7a6ed 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/config/keybind/KeyBinds.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/config/keybind/KeyBinds.java @@ -45,6 +45,9 @@ public final class KeyBinds { public static final KeyBind EDITOR_RELOAD_CLASS = KeyBind.builder("reload_class", EDITOR_CATEGORY).mod(InputEvent.CTRL_DOWN_MASK).key(KeyEvent.VK_F5).build(); public static final KeyBind EDITOR_QUICK_FIND = KeyBind.builder("quick_find", EDITOR_CATEGORY).mod(InputEvent.CTRL_DOWN_MASK).key(KeyEvent.VK_F).build(); + public static final KeyBind ENTRY_NAVIGATOR_NEXT = KeyBind.builder("navigate_next", EDITOR_CATEGORY).mod(InputEvent.CTRL_DOWN_MASK).key(KeyEvent.VK_DOWN).build(); + public static final KeyBind ENTRY_NAVIGATOR_LAST = KeyBind.builder("navigate_last", EDITOR_CATEGORY).mod(InputEvent.CTRL_DOWN_MASK).key(KeyEvent.VK_UP).build(); + public static final KeyBind SAVE_MAPPINGS = KeyBind.builder("save", MENU_CATEGORY).mod(InputEvent.CTRL_DOWN_MASK).key(KeyEvent.VK_S).build(); public static final KeyBind DROP_MAPPINGS = KeyBind.builder("drop_mappings", MENU_CATEGORY).build(); public static final KeyBind RELOAD_MAPPINGS = KeyBind.builder("reload_mappings", MENU_CATEGORY).build(); diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorTabbedPane.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorTabbedPane.java index e6349cf2c..dd33f4e60 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorTabbedPane.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorTabbedPane.java @@ -74,6 +74,10 @@ public void onTitleChanged(EditorPanel editor, String title) { ed.getEditor().addKeyListener(GuiUtil.onKeyPress(keyEvent -> { if (KeyBinds.EDITOR_CLOSE_TAB.matches(keyEvent)) { this.closeEditor(ed); + } else if (KeyBinds.ENTRY_NAVIGATOR_NEXT.matches(keyEvent)) { + this.navigator.navigateDown(); + } else if (KeyBinds.ENTRY_NAVIGATOR_LAST.matches(keyEvent)) { + this.navigator.navigateUp(); } })); diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/NavigatorPanel.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/NavigatorPanel.java index 81b75171c..86515dd30 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/NavigatorPanel.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/NavigatorPanel.java @@ -10,7 +10,6 @@ import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.border.LineBorder; import java.awt.Color; import java.awt.event.ItemEvent; import java.util.ArrayList; @@ -55,32 +54,43 @@ public NavigatorPanel(Gui gui) { } JButton up = new JButton("⋀"); - up.addActionListener(event -> { - List> currentEntrySet = this.entries.get(this.selectedType); - if (!currentEntrySet.isEmpty()) { - this.currentIndex--; - this.wrapIndex(); - - this.tryNavigate(); - } - }); - + up.addActionListener(event -> this.navigateUp()); JButton down = new JButton("⋁"); - down.addActionListener(event -> { - List> currentEntrySet = this.entries.get(this.selectedType); - if (!currentEntrySet.isEmpty()) { - this.currentIndex++; - this.wrapIndex(); - - this.tryNavigate(); - } - }); + down.addActionListener(event -> this.navigateDown()); this.add(typeSelector); this.add(up); this.add(down); this.add(this.statsLabel); - this.setBorder(new LineBorder(Color.BLACK)); + + // transparent background + this.setBackground(new Color(0, 0, 0, 0)); + } + + /** + * Navigates to the next entry matching the current filter. + */ + public void navigateDown() { + List> currentEntrySet = this.entries.get(this.selectedType); + if (!currentEntrySet.isEmpty()) { + this.currentIndex++; + this.wrapIndex(); + + this.tryNavigate(); + } + } + + /** + * Navigates to the last entry matching the current filter. + */ + public void navigateUp() { + List> currentEntrySet = this.entries.get(this.selectedType); + if (!currentEntrySet.isEmpty()) { + this.currentIndex--; + this.wrapIndex(); + + this.tryNavigate(); + } } private void onTypeChange() { diff --git a/enigma/src/main/resources/lang/en_us.json b/enigma/src/main/resources/lang/en_us.json index c446823c7..b4cc3a786 100644 --- a/enigma/src/main/resources/lang/en_us.json +++ b/enigma/src/main/resources/lang/en_us.json @@ -295,6 +295,8 @@ "keybind.editor.zoom_out": "Zoom in", "keybind.editor.close_tab": "Close editor tab", "keybind.editor.reload_class": "Reload open class", + "keybind.editor.navigate_next": "Navigate to next entry", + "keybind.editor.navigate_last": "Navigate to last entry", "keybind.menu.search": "Search", "keybind.menu.search_all": "Search for anything", "keybind.menu.search_class": "Search for class",