From cd368130507b8300999b6b032d9290b7204a82fb Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Tue, 24 Jun 2025 18:40:54 +0200 Subject: [PATCH] move some things around and make the code sturdier --- .../ui/gamedataeditors/CommonEditor.java | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/CommonEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/CommonEditor.java index aae9341..f44c671 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/CommonEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/CommonEditor.java @@ -141,22 +141,22 @@ public class CommonEditor { /// this should just be a convenience field, to access it, without casting. DO NOT SET WITHOUT ALSO SETTING THE FIELD IN THE SUPER-CLASS! public EFFECT effect; - protected String applyToTargetHint; + protected final String applyToTargetHint; private JList hitTargetConditionsList; - private ConditionEffectEditorPane hitTargetConditionPane = new ConditionEffectEditorPane<>(); + private final ConditionEffectEditorPane hitTargetConditionPane ; /* * create a new HitEffectPane with the selections (probably passed in from last time) */ public HitEffectPane(String title, Supplier sourceNewSupplier, Editor editor, String applyToHint, String applyToTargetHint) { super(title, sourceNewSupplier, editor, applyToHint); + hitTargetConditionPane = new ConditionEffectEditorPane<>(editor); if (applyToTargetHint == null || applyToTargetHint == "") { - applyToTargetHint = ""; + this.applyToTargetHint = ""; } else { - applyToTargetHint = " (%s)".formatted(applyToTargetHint); + this.applyToTargetHint = " (%s)".formatted(applyToTargetHint); } - this.applyToTargetHint = applyToTargetHint; } void createHitEffectPaneContent(FieldUpdateListener listener, boolean writable, EFFECT e, MODEL sourceConditionsModelInput, MODEL targetConditionsListModel) { @@ -175,7 +175,7 @@ public class CommonEditor { BasicLambdaWithReturn selectedGetTarget = () -> hitTargetConditionPane.selectedCondition; BasicLambda selectedResetTarget = () -> hitTargetConditionPane.selectedCondition = null; BasicLambdaWithArg updatePaneTarget = (editorPane) -> hitTargetConditionPane.updateEffectTimedConditionEditorPane( - editorPane, hitTargetConditionPane.selectedCondition, listener, editor); + editorPane, hitTargetConditionPane.selectedCondition, listener); var resultTarget = UiUtils.getCollapsibleItemList(listener, hitTargetConditionPane.conditionsModel, selectedResetTarget, selectedSetTarget, selectedGetTarget, @@ -206,10 +206,9 @@ public class CommonEditor { } public static class DeathEffectPane> { - protected Supplier conditionSupplier; - protected String title; - protected Editor editor; - protected String applyToHint; + protected final Supplier conditionSupplier; + protected final String title; + protected final String applyToHint; EFFECT effect; @@ -220,7 +219,7 @@ public class CommonEditor { private JSpinner effectAPMax; private JList sourceConditionsList; - private ConditionEffectEditorPane sourceConditionPane = new ConditionEffectEditorPane<>(); + private final ConditionEffectEditorPane sourceConditionPane; /* @@ -229,19 +228,18 @@ public class CommonEditor { public DeathEffectPane(String title, Supplier conditionSupplier, Editor editor, String applyToHint) { this.title = title; this.conditionSupplier = conditionSupplier; - this.editor = editor; - this.applyToHint = applyToHint; + this.sourceConditionPane = new ConditionEffectEditorPane<>(editor); + if (applyToHint == null || applyToHint == "") { + this.applyToHint = ""; + } else { + this.applyToHint = " (%s)".formatted(applyToHint); + } } void createDeathEffectPaneContent(FieldUpdateListener listener, boolean writable, EFFECT e, MODEL sourceConditionsModel) { effect = e; sourceConditionPane.conditionsModel = sourceConditionsModel; - if (applyToHint == null || applyToHint == "") { - applyToHint = ""; - } else { - applyToHint = " (%s)".formatted(applyToHint); - } effectPane = new CollapsiblePanel(title); effectPane.setLayout(new JideBoxLayout(effectPane, JideBoxLayout.PAGE_AXIS)); @@ -268,7 +266,7 @@ public class CommonEditor { BasicLambdaWithReturn selectedGetSource = () -> sourceConditionPane.selectedCondition; BasicLambda selectedResetSource = () -> sourceConditionPane.selectedCondition = null; BasicLambdaWithArg updatePaneSource = (editorPane) -> sourceConditionPane.updateEffectTimedConditionEditorPane( - editorPane, sourceConditionPane.selectedCondition, listener, editor); + editorPane, sourceConditionPane.selectedCondition, listener); var resultSource = UiUtils.getCollapsibleItemList(listener, sourceConditionPane.conditionsModel, selectedResetSource, selectedSetSource, selectedGetSource, (x) -> { @@ -305,6 +303,7 @@ public class CommonEditor { } static class ConditionEffectEditorPane> { + private final Editor editor; ELEMENT selectedCondition; MODEL conditionsModel; @@ -318,6 +317,10 @@ public class CommonEditor { JRadioButton conditionForever; JSpinner conditionDuration; + ConditionEffectEditorPane(Editor editor) { + this.editor = editor; + } + public void updateEffectTimedConditionWidgets(ELEMENT condition) { boolean immunity = condition.isImmunity(); boolean clear = condition.isClear(); @@ -334,16 +337,16 @@ public class CommonEditor { conditionForever.setEnabled(!clear); } - public void updateEffectTimedConditionEditorPane(JPanel pane, ELEMENT condition, final FieldUpdateListener listener, Editor e) { + public void updateEffectTimedConditionEditorPane(JPanel pane, ELEMENT condition, final FieldUpdateListener listener) { pane.removeAll(); if (conditionBox != null) { - e.removeElementListener(conditionBox); + editor.removeElementListener(conditionBox); } - boolean writable = e.target.writable; - Project proj = e.target.getProject(); + boolean writable = editor.target.writable; + Project proj = editor.target.getProject(); - conditionBox = e.addActorConditionBox(pane, proj, "Actor Condition: ", condition.condition, writable, + conditionBox = editor.addActorConditionBox(pane, proj, "Actor Condition: ", condition.condition, writable, listener); conditionChance = Editor.addDoubleField(pane, "Chance: ", condition.chance, writable, listener);