From b7e9bf0582ec937824595478de492e433c0fdec1 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Tue, 24 Jun 2025 16:07:50 +0200 Subject: [PATCH] move ListModels to CommonEditor for re-use --- .../ui/gamedataeditors/CommonEditor.java | 38 +++++++++++++++++++ .../ui/gamedataeditors/NPCEditor.java | 37 ++---------------- 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/CommonEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/CommonEditor.java index 1d81c9a..19b8498 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/CommonEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/CommonEditor.java @@ -15,6 +15,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.List; import java.util.function.Supplier; import static com.gpl.rpg.atcontentstudio.ui.Editor.addIntegerField; @@ -617,4 +618,41 @@ public class CommonEditor { return updateHit; } } + + + //region list-models + + public static class TargetTimedConditionsListModel extends OrderedListenerListModel { + public TargetTimedConditionsListModel(Common.HitEffect effect) { + super(effect); + } + + @Override + protected java.util.List getItems() { + return source.conditions_target; + } + + @Override + protected void setItems(java.util.List items) { + source.conditions_target = items; + } + } + + public static class SourceTimedConditionsListModel extends OrderedListenerListModel { + public SourceTimedConditionsListModel(Common.DeathEffect effect) { + super(effect); + } + + @Override + protected java.util.List getItems() { + return source.conditions_source; + } + + @Override + protected void setItems(List items) { + source.conditions_source = items; + } + } + + //endregion } diff --git a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/NPCEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/NPCEditor.java index 30aa4ab..32fe94b 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/NPCEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/NPCEditor.java @@ -151,7 +151,7 @@ public class NPCEditor extends JSONElementEditor { } if (hitEffectPane == null) hitEffectPane = new CommonEditor.HitEffectPane("Effect on every hit: ", Common.TimedActorConditionEffect::new, this, null, null); - hitEffectPane.createHitEffectPaneContent(listener, npc.writable, hitEffect, new SourceTimedConditionsListModel(hitEffect), new TargetTimedConditionsListModel(hitEffect)); + hitEffectPane.createHitEffectPaneContent(listener, npc.writable, hitEffect, new CommonEditor.SourceTimedConditionsListModel(hitEffect), new CommonEditor.TargetTimedConditionsListModel(hitEffect)); combatTraitPane.add(hitEffectPane.effectPane, JideBoxLayout.FIX); Common.HitReceivedEffect hitReceivedEffect; @@ -162,7 +162,7 @@ public class NPCEditor extends JSONElementEditor { } if (hitReceivedEffectPane == null) hitReceivedEffectPane = new CommonEditor.HitRecievedEffectPane("Effect on every hit received: ", Common.TimedActorConditionEffect::new, this, "NPC", "Attacker"); - hitReceivedEffectPane.createHitReceivedEffectPaneContent(listener, npc.writable, hitReceivedEffect, new SourceTimedConditionsListModel(hitReceivedEffect), new TargetTimedConditionsListModel(hitReceivedEffect)); + hitReceivedEffectPane.createHitReceivedEffectPaneContent(listener, npc.writable, hitReceivedEffect, new CommonEditor.SourceTimedConditionsListModel(hitReceivedEffect), new CommonEditor.TargetTimedConditionsListModel(hitReceivedEffect)); combatTraitPane.add(hitReceivedEffectPane.effectPane, JideBoxLayout.FIX); Common.DeathEffect deathEffect; @@ -173,44 +173,13 @@ public class NPCEditor extends JSONElementEditor { } if (deathEffectPane == null) deathEffectPane = new CommonEditor.DeathEffectPane("Effect when killed: ", Common.TimedActorConditionEffect::new, this, "Killer"); - deathEffectPane.createDeathEffectPaneContent(listener, npc.writable, deathEffect, new SourceTimedConditionsListModel(deathEffect) + deathEffectPane.createDeathEffectPaneContent(listener, npc.writable, deathEffect, new CommonEditor.SourceTimedConditionsListModel(deathEffect) ); combatTraitPane.add(deathEffectPane.effectPane, JideBoxLayout.FIX); pane.add(combatTraitPane, JideBoxLayout.FIX); } - public static class TargetTimedConditionsListModel extends OrderedListenerListModel { - public TargetTimedConditionsListModel(Common.HitEffect effect) { - super(effect); - } - - @Override - protected List getItems() { - return source.conditions_target; - } - - @Override - protected void setItems(List items) { - source.conditions_target = items; - } - } - - public static class SourceTimedConditionsListModel extends OrderedListenerListModel { - public SourceTimedConditionsListModel(Common.DeathEffect effect) { - super(effect); - } - - @Override - protected List getItems() { - return source.conditions_source; - } - - @Override - protected void setItems(List items) { - source.conditions_source = items; - } - } public class NPCFieldUpdater implements FieldUpdateListener {