improve EffectPane generics and usage & fix hitReceivedEffect

This commit is contained in:
OMGeeky
2025-09-23 18:33:53 +02:00
parent ef9a2a628d
commit 29241f18b8
3 changed files with 56 additions and 73 deletions

View File

@@ -26,7 +26,7 @@ public class CommonEditor {
private static final long serialVersionUID = 7987880146189575234L;
@Override
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
JLabel label = (JLabel) c;
@@ -68,7 +68,7 @@ public class CommonEditor {
private static final long serialVersionUID = 7987880146189575234L;
@Override
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
JLabel label = (JLabel) c;
@@ -90,7 +90,7 @@ public class CommonEditor {
}
}
public static class HitRecievedEffectPane<EFFECT extends Common.HitReceivedEffect, LIST_MODEL_SOURCE, ELEMENT extends Common.TimedActorConditionEffect, MODEL extends OrderedListenerListModel<LIST_MODEL_SOURCE, ELEMENT>> extends HitEffectPane<EFFECT, LIST_MODEL_SOURCE, ELEMENT, MODEL> {
public static class HitReceivedEffectPane<EFFECT extends Common.HitReceivedEffect> extends HitEffectPane<EFFECT> {
/// this should just be a convenience field, to access it, without casting. DO NOT SET WITHOUT ALSO SETTING THE FIELD IN THE SUPER-CLASS!
EFFECT effect;
private JSpinner hitReceivedEffectHPMinTarget;
@@ -98,13 +98,13 @@ public class CommonEditor {
private JSpinner hitReceivedEffectAPMinTarget;
private JSpinner hitReceivedEffectAPMaxTarget;
public HitRecievedEffectPane(String title, Supplier<ELEMENT> sourceNewSupplier, Editor editor, String applyToHint, String applyToTargetHint) {
super(title, sourceNewSupplier, editor, applyToHint, applyToTargetHint);
public HitReceivedEffectPane(String title, Editor editor, String applyToHint, String applyToTargetHint) {
super(title, editor, applyToHint, applyToTargetHint);
}
void createHitReceivedEffectPaneContent(FieldUpdateListener listener, boolean writable, EFFECT e, MODEL sourceConditionsModelInput, MODEL targetConditionsModelInput) {
void createHitReceivedEffectPaneContent(FieldUpdateListener listener, boolean writable, EFFECT e) {
effect = e;
createHitEffectPaneContent(listener, writable, e, sourceConditionsModelInput, targetConditionsModelInput);
createHitEffectPaneContent(listener, writable, e);
}
@Override
@@ -144,32 +144,34 @@ public class CommonEditor {
}
}
public static class HitEffectPane<EFFECT extends Common.HitEffect, LIST_MODEL_SOURCE, ELEMENT extends Common.TimedActorConditionEffect, MODEL extends OrderedListenerListModel<LIST_MODEL_SOURCE, ELEMENT>> extends DeathEffectPane<EFFECT, LIST_MODEL_SOURCE, ELEMENT, MODEL> {
public static class HitEffectPane<EFFECT extends Common.HitEffect>
extends DeathEffectPane<EFFECT> {
/// 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 final String applyToTargetHint;
private JList hitTargetConditionsList;
private final ConditionEffectEditorPane<LIST_MODEL_SOURCE, ELEMENT, MODEL> hitTargetConditionPane;
private JList<Common.TimedActorConditionEffect> hitTargetConditionsList;
private final ConditionEffectEditorPane<Common.HitEffect, TargetTimedConditionsListModel> hitTargetConditionPane;
/*
* 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) {
super(title, sourceNewSupplier, editor, applyToHint);
public HitEffectPane(String title, Editor editor, String applyToHint, String applyToTargetHint) {
super(title, editor, applyToHint);
hitTargetConditionPane = new ConditionEffectEditorPane<>(editor);
if (applyToTargetHint == null || applyToTargetHint == "") {
if (applyToTargetHint == null || applyToTargetHint.isEmpty()) {
this.applyToTargetHint = "";
} else {
this.applyToTargetHint = String.format(" (%s)", applyToTargetHint);
}
}
void createHitEffectPaneContent(FieldUpdateListener listener, boolean writable, EFFECT e, MODEL sourceConditionsModelInput, MODEL targetConditionsListModel) {
void createHitEffectPaneContent(FieldUpdateListener listener, boolean writable, EFFECT e) {
effect = e;
hitTargetConditionPane.conditionsModel = targetConditionsListModel;
createDeathEffectPaneContent(listener, writable, e, sourceConditionsModelInput);
hitTargetConditionPane.conditionsModel = new TargetTimedConditionsListModel(e);
createDeathEffectPaneContent(listener, writable, e);
}
@Override
@@ -178,8 +180,8 @@ public class CommonEditor {
String titleTarget = String.format("Actor Conditions applied to the target%s: ", applyToTargetHint);
CommonEditor.TimedConditionsCellRenderer cellRendererTarget = new CommonEditor.TimedConditionsCellRenderer();
BasicLambdaWithArg<ELEMENT> selectedSetTarget = (value) -> hitTargetConditionPane.selectedCondition = value;
BasicLambdaWithReturn<ELEMENT> selectedGetTarget = () -> hitTargetConditionPane.selectedCondition;
BasicLambdaWithArg<Common.TimedActorConditionEffect> selectedSetTarget = (value) -> hitTargetConditionPane.selectedCondition = value;
BasicLambdaWithReturn<Common.TimedActorConditionEffect> selectedGetTarget = () -> hitTargetConditionPane.selectedCondition;
BasicLambda selectedResetTarget = () -> hitTargetConditionPane.selectedCondition = null;
BasicLambdaWithArg<JPanel> updatePaneTarget = (editorPane) -> hitTargetConditionPane.updateEffectTimedConditionEditorPane(
editorPane, hitTargetConditionPane.selectedCondition, listener);
@@ -212,8 +214,8 @@ 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>> {
protected final Supplier<ELEMENT> conditionSupplier;
public static class DeathEffectPane<EFFECT extends Common.DeathEffect> {
protected final Supplier<Common.TimedActorConditionEffect> conditionSupplier;
protected final String title;
protected final String applyToHint;
@@ -224,28 +226,28 @@ public class CommonEditor {
private JSpinner effectHPMax;
private JSpinner effectAPMin;
private JSpinner effectAPMax;
private JList<ELEMENT> sourceConditionsList;
private JList<Common.TimedActorConditionEffect> sourceConditionsList;
private final ConditionEffectEditorPane<LIST_MODEL_SOURCE, ELEMENT, MODEL> sourceConditionPane;
private final ConditionEffectEditorPane<Common.DeathEffect, SourceTimedConditionsListModel> sourceConditionPane;
/*
* create a new DeatchEffectPane with the selections (probably passed in from last time)
*/
public DeathEffectPane(String title, Supplier<ELEMENT> conditionSupplier, Editor editor, String applyToHint) {
public DeathEffectPane(String title, Editor editor, String applyToHint) {
this.title = title;
this.conditionSupplier = conditionSupplier;
this.conditionSupplier = Common.TimedActorConditionEffect::new;
this.sourceConditionPane = new ConditionEffectEditorPane<>(editor);
if (applyToHint == null || applyToHint == "") {
if (applyToHint == null || applyToHint.isEmpty()) {
this.applyToHint = "";
} else {
this.applyToHint = String.format(" (%s)", applyToHint);
}
}
void createDeathEffectPaneContent(FieldUpdateListener listener, boolean writable, EFFECT e, MODEL sourceConditionsModel) {
void createDeathEffectPaneContent(FieldUpdateListener listener, boolean writable, EFFECT e) {
effect = e;
sourceConditionPane.conditionsModel = sourceConditionsModel;
sourceConditionPane.conditionsModel = new SourceTimedConditionsListModel(e);
effectPane = new CollapsiblePanel(title);
effectPane.setLayout(new JideBoxLayout(effectPane, JideBoxLayout.PAGE_AXIS));
@@ -269,8 +271,8 @@ public class CommonEditor {
protected void addLists(FieldUpdateListener listener, boolean writable) {
String titleSource = String.format("Actor Conditions applied to the source%s: ", applyToHint);
TimedConditionsCellRenderer cellRendererSource = new TimedConditionsCellRenderer();
BasicLambdaWithArg<ELEMENT> selectedSetSource = (value) -> sourceConditionPane.selectedCondition = value;
BasicLambdaWithReturn<ELEMENT> selectedGetSource = () -> sourceConditionPane.selectedCondition;
BasicLambdaWithArg<Common.TimedActorConditionEffect> selectedSetSource = (value) -> sourceConditionPane.selectedCondition = value;
BasicLambdaWithReturn<Common.TimedActorConditionEffect> selectedGetSource = () -> sourceConditionPane.selectedCondition;
BasicLambda selectedResetSource = () -> sourceConditionPane.selectedCondition = null;
BasicLambdaWithArg<JPanel> updatePaneSource = (editorPane) -> sourceConditionPane.updateEffectTimedConditionEditorPane(
editorPane, sourceConditionPane.selectedCondition, listener);
@@ -309,9 +311,9 @@ 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, MODEL extends OrderedListenerListModel<LIST_MODEL_SOURCE, Common.TimedActorConditionEffect> > {
private final Editor editor;
ELEMENT selectedCondition;
Common.TimedActorConditionEffect selectedCondition;
MODEL conditionsModel;
Editor.MyComboBox conditionBox;
@@ -328,7 +330,7 @@ public class CommonEditor {
this.editor = editor;
}
public void updateEffectTimedConditionWidgets(ELEMENT condition) {
public void updateEffectTimedConditionWidgets(Common.TimedActorConditionEffect condition) {
boolean writable = editor.target.writable;
boolean immunity = condition.isImmunity();
@@ -352,7 +354,7 @@ public class CommonEditor {
conditionForever.setEnabled(!clear && writable);
}
public void updateEffectTimedConditionEditorPane(JPanel pane, ELEMENT condition, final FieldUpdateListener listener) {
public void updateEffectTimedConditionEditorPane(JPanel pane, Common.TimedActorConditionEffect condition, final FieldUpdateListener listener) {
pane.removeAll();
if (conditionBox != null) {
editor.removeElementListener(conditionBox);
@@ -495,7 +497,7 @@ public class CommonEditor {
}
private void setDurationToDefaultIfNone() {
if (selectedCondition.duration == null || selectedCondition.duration == ActorCondition.DURATION_NONE) {
if (selectedCondition.duration == null || selectedCondition.duration.equals(ActorCondition.DURATION_NONE)) {
selectedCondition.duration = 1;
}
}

View File

@@ -76,9 +76,9 @@ public class ItemEditor extends JSONElementEditor {
private JRadioButton equipConditionImmunity;
private JSpinner equipConditionMagnitude;
private CommonEditor.HitEffectPane hitEffectPane = new CommonEditor.HitEffectPane("Effect on every hit: ", TimedActorConditionEffect::new, this, null, null);
private CommonEditor.DeathEffectPane killEffectPane = new CommonEditor.DeathEffectPane(killLabel, TimedActorConditionEffect::new, this, null);
private CommonEditor.HitRecievedEffectPane hitReceivedEffectPane = new CommonEditor.HitRecievedEffectPane("Effect on every hit received: ", TimedActorConditionEffect::new, this, null, null);
private final CommonEditor.HitEffectPane<HitEffect> hitEffectPane = new CommonEditor.HitEffectPane<>("Effect on every hit: ", this, null, "npc");
private final CommonEditor.DeathEffectPane<DeathEffect> killEffectPane = new CommonEditor.DeathEffectPane<>(killLabel, this, null);
private final CommonEditor.HitReceivedEffectPane<HitReceivedEffect> hitReceivedEffectPane = new CommonEditor.HitReceivedEffectPane<>("Effect on every hit received: ", this, "player", "npc");
public ItemEditor(Item item) {
super(item, item.getDesc(), item.getIcon());
@@ -86,7 +86,6 @@ public class ItemEditor extends JSONElementEditor {
addEditorTab(json_view_id, getJSONView());
}
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void insertFormViewDataField(JPanel pane) {
@@ -111,11 +110,7 @@ public class ItemEditor extends JSONElementEditor {
equipEffectPane = new CollapsiblePanel("Effect when equipped: ");
equipEffectPane.setLayout(new JideBoxLayout(equipEffectPane, JideBoxLayout.PAGE_AXIS));
if (item.equip_effect == null) {
equipEffect = new Item.EquipEffect();
} else {
equipEffect = item.equip_effect;
}
equipEffect = Objects.requireNonNullElseGet(item.equip_effect, Item.EquipEffect::new);
equipDmgMin = addIntegerField(equipEffectPane, "Attack Damage min: ", equipEffect.damage_boost_min, true, item.writable, listener);
equipDmgMax = addIntegerField(equipEffectPane, "Attack Damage max: ", equipEffect.damage_boost_max, true, item.writable, listener);
equipSetDM = addIntegerField(equipEffectPane, "Damage modifier %: ", equipEffect.damage_modifier, 100, false, item.writable, listener);
@@ -164,33 +159,27 @@ public class ItemEditor extends JSONElementEditor {
}
HitEffect hitEffect = Objects.requireNonNullElseGet(item.hit_effect, HitEffect::new);
hitEffectPane.createHitEffectPaneContent(listener, item.writable, hitEffect,
new CommonEditor.SourceTimedConditionsListModel(hitEffect),
new CommonEditor.TargetTimedConditionsListModel(hitEffect));
hitEffectPane.createHitEffectPaneContent(listener, item.writable, hitEffect);
pane.add(hitEffectPane.effectPane, JideBoxLayout.FIX);
DeathEffect killEffect = Objects.requireNonNullElseGet(item.kill_effect, DeathEffect::new);
killEffectPane.createDeathEffectPaneContent(listener, item.writable, killEffect,
new CommonEditor.SourceTimedConditionsListModel(killEffect));
killEffectPane.createDeathEffectPaneContent(listener, item.writable, killEffect);
pane.add(killEffectPane.effectPane, JideBoxLayout.FIX);
HitReceivedEffect hitReceivedEffect = Objects.requireNonNullElseGet(item.hit_received_effect,
HitReceivedEffect::new);
hitReceivedEffectPane.createHitReceivedEffectPaneContent(listener, item.writable, hitReceivedEffect,
new CommonEditor.SourceTimedConditionsListModel(
hitReceivedEffect),
new CommonEditor.TargetTimedConditionsListModel(
hitReceivedEffect));
pane.add(killEffectPane.effectPane, JideBoxLayout.FIX);
HitReceivedEffect hitReceivedEffect = Objects.requireNonNullElseGet(item.hit_received_effect, HitReceivedEffect::new);
hitReceivedEffectPane.createHitReceivedEffectPaneContent(listener, item.writable, hitReceivedEffect);
pane.add(hitReceivedEffectPane.effectPane, JideBoxLayout.FIX);
if (item.category == null || item.category.action_type == null || item.category.action_type == ItemCategory.ActionType.none) {
equipEffectPane.setVisible(false);
hitEffectPane.effectPane.setVisible(false);
hitReceivedEffectPane.effectPane.setVisible(false);
killEffectPane.effectPane.setVisible(false);
} else if (item.category.action_type == ItemCategory.ActionType.use) {
equipEffectPane.setVisible(false);
hitEffectPane.effectPane.setVisible(false);
hitReceivedEffectPane.effectPane.setVisible(false);
killEffectPane.effectPane.setVisible(true);
killEffectPane.effectPane.setTitle(useLabel);
killEffectPane.effectPane.revalidate();
@@ -198,6 +187,7 @@ public class ItemEditor extends JSONElementEditor {
} else if (item.category.action_type == ItemCategory.ActionType.equip) {
equipEffectPane.setVisible(true);
hitEffectPane.effectPane.setVisible(true);
hitReceivedEffectPane.effectPane.setVisible(true);
killEffectPane.effectPane.setVisible(true);
killEffectPane.effectPane.setTitle(killLabel);
killEffectPane.effectPane.revalidate();

View File

@@ -59,10 +59,10 @@ public class NPCEditor extends JSONElementEditor {
private JSpinner blockChance;
private JSpinner dmgRes;
private CommonEditor.HitEffectPane hitEffectPane = new CommonEditor.HitEffectPane("Effect on every hit: ", TimedActorConditionEffect::new, this, null, null);
private CommonEditor.HitRecievedEffectPane hitReceivedEffectPane = new CommonEditor.HitRecievedEffectPane("Effect on every hit received: ", TimedActorConditionEffect::new, this, "NPC",
"Attacker");
private CommonEditor.DeathEffectPane deathEffectPane = new CommonEditor.DeathEffectPane("Effect when killed: ", TimedActorConditionEffect::new, this, "Killer");
private final CommonEditor.HitEffectPane<HitEffect> hitEffectPane = new CommonEditor.HitEffectPane<>("Effect on every hit: ", this, null, null);
private final CommonEditor.HitReceivedEffectPane<HitReceivedEffect> hitReceivedEffectPane = new CommonEditor.HitReceivedEffectPane<>("Effect on every hit received: ", this, "attacked",
"attacker");
private final CommonEditor.DeathEffectPane<DeathEffect> deathEffectPane = new CommonEditor.DeathEffectPane<>("Effect when killed: ", this, "attacker");
private JPanel dialogueGraphPane;
private DialogueGraphView dialogueGraphView;
@@ -117,7 +117,6 @@ public class NPCEditor extends JSONElementEditor {
}
}
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void insertFormViewDataField(JPanel pane) {
final NPC npc = (NPC) target;
@@ -151,23 +150,15 @@ public class NPCEditor extends JSONElementEditor {
dmgRes = addIntegerField(combatTraitPane, "Damage resistance: ", npc.damage_resistance, false, npc.writable, listener);
HitEffect hitEffect = Objects.requireNonNullElseGet(npc.hit_effect, HitEffect::new);
hitEffectPane.createHitEffectPaneContent(listener, npc.writable, hitEffect,
new CommonEditor.SourceTimedConditionsListModel(hitEffect),
new CommonEditor.TargetTimedConditionsListModel(hitEffect));
hitEffectPane.createHitEffectPaneContent(listener, npc.writable, hitEffect);
combatTraitPane.add(hitEffectPane.effectPane, JideBoxLayout.FIX);
HitReceivedEffect hitReceivedEffect = Objects.requireNonNullElseGet(npc.hit_received_effect,
HitReceivedEffect::new);
hitReceivedEffectPane.createHitReceivedEffectPaneContent(listener, npc.writable, hitReceivedEffect,
new CommonEditor.SourceTimedConditionsListModel(
hitReceivedEffect),
new CommonEditor.TargetTimedConditionsListModel(
hitReceivedEffect));
HitReceivedEffect hitReceivedEffect = Objects.requireNonNullElseGet(npc.hit_received_effect, HitReceivedEffect::new);
hitReceivedEffectPane.createHitReceivedEffectPaneContent(listener, npc.writable, hitReceivedEffect);
combatTraitPane.add(hitReceivedEffectPane.effectPane, JideBoxLayout.FIX);
DeathEffect deathEffect = Objects.requireNonNullElseGet(npc.death_effect, DeathEffect::new);
deathEffectPane.createDeathEffectPaneContent(listener, npc.writable, deathEffect,
new CommonEditor.SourceTimedConditionsListModel(deathEffect));
deathEffectPane.createDeathEffectPaneContent(listener, npc.writable, deathEffect);
combatTraitPane.add(deathEffectPane.effectPane, JideBoxLayout.FIX);
pane.add(combatTraitPane, JideBoxLayout.FIX);