refactor: add option to enable up down buttons or not

This commit is contained in:
OMGeeky
2025-06-16 09:56:40 +02:00
parent 64ea5377bf
commit 92be506c11
2 changed files with 30 additions and 17 deletions

View File

@@ -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<Dialogue.Reply> 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) {

View File

@@ -23,6 +23,7 @@ public final class CommonEditor {
AtListModel<E, S> listModel,
boolean isCollapsed,
boolean writable,
boolean moveUpDownEnabled,
CallWithSingleArg<E> selectedValueSetter,
CallWithReturn<E> selectedValueGetter,
CallWithThreeArgs<JPanel, E, FieldUpdateListener> 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);
}