From 92be506c118257878ee6010ccdefde28f5e9c452 Mon Sep 17 00:00:00 2001 From: OMGeeky <> Date: Mon, 16 Jun 2025 09:56:40 +0200 Subject: [PATCH] refactor: add option to enable up down buttons or not --- .../ui/gamedataeditors/DialogueEditor.java | 25 +++++++++++-------- .../ui/tools/CommonEditor.java | 22 +++++++++++----- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/DialogueEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/DialogueEditor.java index 3b73530..d512479 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/DialogueEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/DialogueEditor.java @@ -55,6 +55,7 @@ import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener; import com.gpl.rpg.atcontentstudio.ui.OverlayIcon; import com.gpl.rpg.atcontentstudio.ui.gamedataeditors.dialoguetree.DialogueGraphView; import com.gpl.rpg.atcontentstudio.ui.tools.CommonEditor; +import com.gpl.rpg.atcontentstudio.utils.lambda.CallWithSingleArg; import com.jidesoft.swing.JideBoxLayout; public class DialogueEditor extends JSONElementEditor { @@ -243,28 +244,30 @@ public class DialogueEditor extends JSONElementEditor { RepliesCellRenderer cellRenderer = new RepliesCellRenderer(); repliesListModel = new DialogueEditor.RepliesListModel(dialogue); + boolean isCollapsed = dialogue.replies == null || dialogue.replies.isEmpty(); + boolean moveUpDownEnabled = true; + CallWithSingleArg selectedReplyChanged = e -> { + selectedReply = e; + if (selectedReply != null && !Dialogue.Reply.GO_NEXT_TEXT.equals(selectedReply.text)) { + replyTextCache = selectedReply.text; + } else { + replyTextCache = null; + } + }; CollapsiblePanel replies = CommonEditor.createListPanel( title, cellRenderer, repliesListModel, - dialogue.replies == null || dialogue.replies.isEmpty(), + isCollapsed, dialogue.writable, - e -> { - selectedReply = e; - if (selectedReply != null && !Dialogue.Reply.GO_NEXT_TEXT.equals(selectedReply.text)) { - replyTextCache = selectedReply.text; - } else { - replyTextCache = null; - } - }, + moveUpDownEnabled, + selectedReplyChanged, ()->selectedReply, this::updateRepliesEditorPane, listener, Dialogue.Reply::new); pane.add(replies, JideBoxLayout.FIX); - - } public void updateRewardsEditorPane(final JPanel pane, final Dialogue.Reward reward, final FieldUpdateListener listener) { diff --git a/src/com/gpl/rpg/atcontentstudio/ui/tools/CommonEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/tools/CommonEditor.java index 01103ed..67947c8 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/tools/CommonEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/tools/CommonEditor.java @@ -23,6 +23,7 @@ public final class CommonEditor { AtListModel listModel, boolean isCollapsed, boolean writable, + boolean moveUpDownEnabled, CallWithSingleArg selectedValueSetter, CallWithReturn selectedValueGetter, CallWithThreeArgs updateRepliesEditorPane, @@ -47,12 +48,16 @@ public final class CommonEditor { selectedValueSetter.call(selectedReply); if (selectedReply != null) { deleteReply.setEnabled(true); - moveReplyUp.setEnabled(repliesList.getSelectedIndex() > 0); - moveReplyDown.setEnabled(repliesList.getSelectedIndex() < (listModel.getSize() - 1)); + if(moveUpDownEnabled){ + moveReplyUp.setEnabled(repliesList.getSelectedIndex() > 0); + moveReplyDown.setEnabled(repliesList.getSelectedIndex() < (listModel.getSize() - 1)); + } } else { deleteReply.setEnabled(false); - moveReplyUp.setEnabled(false); - moveReplyDown.setEnabled(false); + if(moveUpDownEnabled){ + moveReplyUp.setEnabled(false); + moveReplyDown.setEnabled(false); + } } updateRepliesEditorPane.call(repliesEditorPane, selectedReply, listener); }); @@ -75,6 +80,8 @@ public final class CommonEditor { listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff. } }); + if(moveUpDownEnabled){ + moveReplyUp.addActionListener(e -> { E selected = selectedValueGetter.call(); if (selected != null) { @@ -91,10 +98,13 @@ public final class CommonEditor { listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff. } }); + } listButtonsPane.add(createReply, JideBoxLayout.FIX); listButtonsPane.add(deleteReply, JideBoxLayout.FIX); - listButtonsPane.add(moveReplyUp, JideBoxLayout.FIX); - listButtonsPane.add(moveReplyDown, JideBoxLayout.FIX); + if(moveUpDownEnabled){ + listButtonsPane.add(moveReplyUp, JideBoxLayout.FIX); + listButtonsPane.add(moveReplyDown, JideBoxLayout.FIX); + } listButtonsPane.add(new JPanel(), JideBoxLayout.VARY); replies.add(listButtonsPane, JideBoxLayout.FIX); }