move some things around and make the code sturdier

This commit is contained in:
OMGeeky
2025-06-24 18:40:54 +02:00
parent 358d855eec
commit cd36813050

View File

@@ -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! /// 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; public EFFECT effect;
protected String applyToTargetHint; protected final String applyToTargetHint;
private JList hitTargetConditionsList; private JList hitTargetConditionsList;
private ConditionEffectEditorPane<LIST_MODEL_SOURCE, ELEMENT, MODEL> hitTargetConditionPane = new ConditionEffectEditorPane<>(); private final ConditionEffectEditorPane<LIST_MODEL_SOURCE, ELEMENT, MODEL> hitTargetConditionPane ;
/* /*
* create a new HitEffectPane with the selections (probably passed in from last time) * create a new HitEffectPane with the selections (probably passed in from last time)
*/ */
public HitEffectPane(String title, Supplier<ELEMENT> sourceNewSupplier, Editor editor, String applyToHint, String applyToTargetHint) { public HitEffectPane(String title, Supplier<ELEMENT> sourceNewSupplier, Editor editor, String applyToHint, String applyToTargetHint) {
super(title, sourceNewSupplier, editor, applyToHint); super(title, sourceNewSupplier, editor, applyToHint);
hitTargetConditionPane = new ConditionEffectEditorPane<>(editor);
if (applyToTargetHint == null || applyToTargetHint == "") { if (applyToTargetHint == null || applyToTargetHint == "") {
applyToTargetHint = ""; this.applyToTargetHint = "";
} else { } 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) { void createHitEffectPaneContent(FieldUpdateListener listener, boolean writable, EFFECT e, MODEL sourceConditionsModelInput, MODEL targetConditionsListModel) {
@@ -175,7 +175,7 @@ public class CommonEditor {
BasicLambdaWithReturn<ELEMENT> selectedGetTarget = () -> hitTargetConditionPane.selectedCondition; BasicLambdaWithReturn<ELEMENT> selectedGetTarget = () -> hitTargetConditionPane.selectedCondition;
BasicLambda selectedResetTarget = () -> hitTargetConditionPane.selectedCondition = null; BasicLambda selectedResetTarget = () -> hitTargetConditionPane.selectedCondition = null;
BasicLambdaWithArg<JPanel> updatePaneTarget = (editorPane) -> hitTargetConditionPane.updateEffectTimedConditionEditorPane( BasicLambdaWithArg<JPanel> updatePaneTarget = (editorPane) -> hitTargetConditionPane.updateEffectTimedConditionEditorPane(
editorPane, hitTargetConditionPane.selectedCondition, listener, editor); editorPane, hitTargetConditionPane.selectedCondition, listener);
var resultTarget = UiUtils.getCollapsibleItemList(listener, hitTargetConditionPane.conditionsModel, var resultTarget = UiUtils.getCollapsibleItemList(listener, hitTargetConditionPane.conditionsModel,
selectedResetTarget, selectedSetTarget, selectedGetTarget, selectedResetTarget, selectedSetTarget, selectedGetTarget,
@@ -206,10 +206,9 @@ public class CommonEditor {
} }
public static class DeathEffectPane<EFFECT extends Common.DeathEffect, LIST_MODEL_SOURCE, ELEMENT extends Common.TimedActorConditionEffect, MODEL extends OrderedListenerListModel<LIST_MODEL_SOURCE, ELEMENT>> { public static class DeathEffectPane<EFFECT extends Common.DeathEffect, LIST_MODEL_SOURCE, ELEMENT extends Common.TimedActorConditionEffect, MODEL extends OrderedListenerListModel<LIST_MODEL_SOURCE, ELEMENT>> {
protected Supplier<ELEMENT> conditionSupplier; protected final Supplier<ELEMENT> conditionSupplier;
protected String title; protected final String title;
protected Editor editor; protected final String applyToHint;
protected String applyToHint;
EFFECT effect; EFFECT effect;
@@ -220,7 +219,7 @@ public class CommonEditor {
private JSpinner effectAPMax; private JSpinner effectAPMax;
private JList<ELEMENT> sourceConditionsList; private JList<ELEMENT> sourceConditionsList;
private ConditionEffectEditorPane<LIST_MODEL_SOURCE, ELEMENT, MODEL> sourceConditionPane = new ConditionEffectEditorPane<>(); private final ConditionEffectEditorPane<LIST_MODEL_SOURCE, ELEMENT, MODEL> sourceConditionPane;
/* /*
@@ -229,19 +228,18 @@ public class CommonEditor {
public DeathEffectPane(String title, Supplier<ELEMENT> conditionSupplier, Editor editor, String applyToHint) { public DeathEffectPane(String title, Supplier<ELEMENT> conditionSupplier, Editor editor, String applyToHint) {
this.title = title; this.title = title;
this.conditionSupplier = conditionSupplier; this.conditionSupplier = conditionSupplier;
this.editor = editor; this.sourceConditionPane = new ConditionEffectEditorPane<>(editor);
this.applyToHint = applyToHint; if (applyToHint == null || applyToHint == "") {
this.applyToHint = "";
} else {
this.applyToHint = " (%s)".formatted(applyToHint);
}
} }
void createDeathEffectPaneContent(FieldUpdateListener listener, boolean writable, EFFECT e, MODEL sourceConditionsModel) { void createDeathEffectPaneContent(FieldUpdateListener listener, boolean writable, EFFECT e, MODEL sourceConditionsModel) {
effect = e; effect = e;
sourceConditionPane.conditionsModel = sourceConditionsModel; sourceConditionPane.conditionsModel = sourceConditionsModel;
if (applyToHint == null || applyToHint == "") {
applyToHint = "";
} else {
applyToHint = " (%s)".formatted(applyToHint);
}
effectPane = new CollapsiblePanel(title); effectPane = new CollapsiblePanel(title);
effectPane.setLayout(new JideBoxLayout(effectPane, JideBoxLayout.PAGE_AXIS)); effectPane.setLayout(new JideBoxLayout(effectPane, JideBoxLayout.PAGE_AXIS));
@@ -268,7 +266,7 @@ public class CommonEditor {
BasicLambdaWithReturn<ELEMENT> selectedGetSource = () -> sourceConditionPane.selectedCondition; BasicLambdaWithReturn<ELEMENT> selectedGetSource = () -> sourceConditionPane.selectedCondition;
BasicLambda selectedResetSource = () -> sourceConditionPane.selectedCondition = null; BasicLambda selectedResetSource = () -> sourceConditionPane.selectedCondition = null;
BasicLambdaWithArg<JPanel> updatePaneSource = (editorPane) -> sourceConditionPane.updateEffectTimedConditionEditorPane( BasicLambdaWithArg<JPanel> updatePaneSource = (editorPane) -> sourceConditionPane.updateEffectTimedConditionEditorPane(
editorPane, sourceConditionPane.selectedCondition, listener, editor); editorPane, sourceConditionPane.selectedCondition, listener);
var resultSource = UiUtils.getCollapsibleItemList(listener, sourceConditionPane.conditionsModel, selectedResetSource, var resultSource = UiUtils.getCollapsibleItemList(listener, sourceConditionPane.conditionsModel, selectedResetSource,
selectedSetSource, selectedGetSource, (x) -> { selectedSetSource, selectedGetSource, (x) -> {
@@ -305,6 +303,7 @@ public class CommonEditor {
} }
static class ConditionEffectEditorPane<LIST_MODEL_SOURCE, ELEMENT extends Common.TimedActorConditionEffect, MODEL extends OrderedListenerListModel<LIST_MODEL_SOURCE, ELEMENT>> { static class ConditionEffectEditorPane<LIST_MODEL_SOURCE, ELEMENT extends Common.TimedActorConditionEffect, MODEL extends OrderedListenerListModel<LIST_MODEL_SOURCE, ELEMENT>> {
private final Editor editor;
ELEMENT selectedCondition; ELEMENT selectedCondition;
MODEL conditionsModel; MODEL conditionsModel;
@@ -318,6 +317,10 @@ public class CommonEditor {
JRadioButton conditionForever; JRadioButton conditionForever;
JSpinner conditionDuration; JSpinner conditionDuration;
ConditionEffectEditorPane(Editor editor) {
this.editor = editor;
}
public void updateEffectTimedConditionWidgets(ELEMENT condition) { public void updateEffectTimedConditionWidgets(ELEMENT condition) {
boolean immunity = condition.isImmunity(); boolean immunity = condition.isImmunity();
boolean clear = condition.isClear(); boolean clear = condition.isClear();
@@ -334,16 +337,16 @@ public class CommonEditor {
conditionForever.setEnabled(!clear); 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(); pane.removeAll();
if (conditionBox != null) { if (conditionBox != null) {
e.removeElementListener(conditionBox); editor.removeElementListener(conditionBox);
} }
boolean writable = e.target.writable; boolean writable = editor.target.writable;
Project proj = e.target.getProject(); 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); listener);
conditionChance = Editor.addDoubleField(pane, "Chance: ", condition.chance, writable, listener); conditionChance = Editor.addDoubleField(pane, "Chance: ", condition.chance, writable, listener);