From cf8c0497bc83e577f11a30331438fd7dab68989f Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Sun, 1 Jun 2025 22:51:15 +0200 Subject: [PATCH] add navigation to getCollapsibleItemList --- .../ui/gamedataeditors/DialogueEditor.java | 7 ++- .../ui/gamedataeditors/DroplistEditor.java | 1 + .../utils/BasicLambdaWithArgAndReturn.java | 5 ++ .../rpg/atcontentstudio/utils/UiUtils.java | 55 +++++++++++-------- 4 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 src/com/gpl/rpg/atcontentstudio/utils/BasicLambdaWithArgAndReturn.java diff --git a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/DialogueEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/DialogueEditor.java index df317db..3480137 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/DialogueEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/DialogueEditor.java @@ -243,6 +243,7 @@ public class DialogueEditor extends JSONElementEditor { Dialogue.Reward::new, cellRendererRewards, titleRewards, + (x)->null, false ).collapsiblePanel; if (dialogue.rewards == null || dialogue.rewards.isEmpty()) { @@ -355,8 +356,9 @@ public class DialogueEditor extends JSONElementEditor { dialogue.writable, Dialogue.Reply::new, cellRendererReplies, - titleReplies - , true + titleReplies, + (x)->null, + true ).collapsiblePanel; if (dialogue.replies == null || dialogue.replies.isEmpty()) { replies.collapse(); @@ -706,6 +708,7 @@ public class DialogueEditor extends JSONElementEditor { Requirement::new, cellRendererRequirements, titleRequirements, + (x)-> x.required_obj, false ); CollapsiblePanel requirementsPane = itemsPane.collapsiblePanel; diff --git a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/DroplistEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/DroplistEditor.java index d70f744..6e5fefe 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/DroplistEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/DroplistEditor.java @@ -73,6 +73,7 @@ public class DroplistEditor extends JSONElementEditor { DroppedItem::new, new DroppedItemsCellRenderer(), "Items in this droplist: ", + (x)-> x.item, false ).collapsiblePanel; if (droplist.dropped_items == null || droplist.dropped_items.isEmpty()) { diff --git a/src/com/gpl/rpg/atcontentstudio/utils/BasicLambdaWithArgAndReturn.java b/src/com/gpl/rpg/atcontentstudio/utils/BasicLambdaWithArgAndReturn.java new file mode 100644 index 0000000..69b2d2c --- /dev/null +++ b/src/com/gpl/rpg/atcontentstudio/utils/BasicLambdaWithArgAndReturn.java @@ -0,0 +1,5 @@ +package com.gpl.rpg.atcontentstudio.utils; + +public interface BasicLambdaWithArgAndReturn { + public R doIt(T arg); +} diff --git a/src/com/gpl/rpg/atcontentstudio/utils/UiUtils.java b/src/com/gpl/rpg/atcontentstudio/utils/UiUtils.java index 0ce7573..08f8b6f 100644 --- a/src/com/gpl/rpg/atcontentstudio/utils/UiUtils.java +++ b/src/com/gpl/rpg/atcontentstudio/utils/UiUtils.java @@ -29,6 +29,7 @@ public class UiUtils { Supplier tempSupplier, DefaultListCellRenderer cellRenderer, String title, + BasicLambdaWithArgAndReturn getReferencedObj, boolean withMoveButtons) { CollapsiblePanel itemsPane = new CollapsiblePanel(title); itemsPane.setLayout(new JideBoxLayout(itemsPane, JideBoxLayout.PAGE_AXIS)); @@ -109,28 +110,8 @@ public class UiUtils { listButtonsPane.add(new JPanel(), JideBoxLayout.VARY); itemsPane.add(listButtonsPane, JideBoxLayout.FIX); } - //TODO: add double click to navigate to the item in the editor pane. - // TODO: figure out what ID is needed here -// itemsList.addMouseListener(new MouseAdapter() { -// @Override -// public void mouseClicked(MouseEvent e) { -// if (e.getClickCount() == 2) { -// if (itemsList.getSelectedValue() != null && ((E)itemsList.getSelectedValue()).required_obj != null) { -// ATContentStudio.frame.openEditor(((E)itemsList.getSelectedValue()).required_obj); -// ATContentStudio.frame.selectInTree(((E)itemsList.getSelectedValue()).required_obj); -// } -// } -// } -// }); -// itemsList.addKeyListener(new KeyAdapter() { -// @Override -// public void keyReleased(KeyEvent e) { -// if (e.getKeyCode() == KeyEvent.VK_ENTER) { -// ATContentStudio.frame.openEditor(((E)itemsList.getSelectedValue()).required_obj); -// ATContentStudio.frame.selectInTree(((E)itemsList.getSelectedValue()).required_obj); -// } -// } -// }); + + addNavigationListeners(getReferencedObj, itemsList); editorPane.setLayout(new JideBoxLayout(editorPane, JideBoxLayout.PAGE_AXIS)); itemsPane.add(editorPane, JideBoxLayout.FIX); @@ -142,4 +123,34 @@ public class UiUtils { }; } + private static void addNavigationListeners(BasicLambdaWithArgAndReturn getReferencedObj, JList itemsList) { + // Add listeners to the list for double-click and Enter key to open the editor + itemsList.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + E selectedValue = itemsList.getSelectedValue(); + if (selectedValue == null) return; + GameDataElement referencedObj = getReferencedObj.doIt(selectedValue); + if (referencedObj != null) { + ATContentStudio.frame.openEditor(referencedObj); + ATContentStudio.frame.selectInTree( referencedObj); + } + } + } + }); + itemsList.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + E selectedValue = itemsList.getSelectedValue(); + if (selectedValue == null) return; + GameDataElement referencedObj = getReferencedObj.doIt(selectedValue); + ATContentStudio.frame.openEditor(referencedObj); + ATContentStudio.frame.selectInTree(referencedObj); + } + } + }); + } + } \ No newline at end of file