From a7f214a1cb3aa68a6d962b217fdd33c3ca4caf68 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Mon, 23 Jun 2025 14:35:27 +0200 Subject: [PATCH] extract TimedConditionsCellRenderer into CommonEditor --- .../ui/gamedataeditors/CommonEditor.java | 46 +++++++++++++++++++ .../ui/gamedataeditors/ItemEditor.java | 42 ++--------------- .../ui/gamedataeditors/NPCEditor.java | 44 ++---------------- 3 files changed, 55 insertions(+), 77 deletions(-) create mode 100644 src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/CommonEditor.java diff --git a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/CommonEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/CommonEditor.java new file mode 100644 index 0000000..e968f9d --- /dev/null +++ b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/CommonEditor.java @@ -0,0 +1,46 @@ +package com.gpl.rpg.atcontentstudio.ui.gamedataeditors; + +import com.gpl.rpg.atcontentstudio.model.gamedata.ActorCondition; +import com.gpl.rpg.atcontentstudio.model.gamedata.Common; +import com.gpl.rpg.atcontentstudio.ui.DefaultIcons; +import com.gpl.rpg.atcontentstudio.ui.OverlayIcon; + +import javax.swing.*; +import java.awt.*; + +public class CommonEditor { + + public static class TimedConditionsCellRenderer extends DefaultListCellRenderer { + private static final long serialVersionUID = 7987880146189575234L; + + @Override + public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") 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); + Common.TimedActorConditionEffect effect = (Common.TimedActorConditionEffect) value; + + if (effect.condition != null) { + + boolean immunity = (effect.magnitude == null || effect.magnitude == ActorCondition.MAGNITUDE_CLEAR) && (effect.duration != null && effect.duration > ActorCondition.DURATION_NONE); + boolean clear = (effect.magnitude == null || effect.magnitude == ActorCondition.MAGNITUDE_CLEAR) && (effect.duration == null || effect.duration == ActorCondition.DURATION_NONE); + boolean forever = effect.duration != null && effect.duration == ActorCondition.DURATION_FOREVER; + + if (clear) { + label.setIcon(new ImageIcon(effect.condition.getIcon())); + label.setText(effect.chance + "% chances to clear actor condition " + effect.condition.getDesc()); + } else if (immunity) { + label.setIcon(new OverlayIcon(effect.condition.getIcon(), DefaultIcons.getImmunityIcon())); + label.setText(effect.chance + "% chances to give immunity to " + effect.condition.getDesc() + (forever ? " forever" : " for " + effect.duration + " rounds")); + } else { + label.setIcon(new ImageIcon(effect.condition.getIcon())); + label.setText(effect.chance + "% chances to give actor condition " + effect.condition.getDesc() + " x" + effect.magnitude + (forever ? " forever" : " for " + effect.duration + " rounds")); + } + } else { + label.setText("New, undefined actor condition effect."); + } + } + return c; + } + } +} diff --git a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/ItemEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/ItemEditor.java index 7845d7e..2e2cfd6 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/ItemEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/ItemEditor.java @@ -263,7 +263,7 @@ public class ItemEditor extends JSONElementEditor { BasicLambdaWithArg valueChanged = (selectedReply) -> { }; BasicLambdaWithArg updateEditorPane = (editorPane) -> updateHitSourceTimedConditionEditorPane(editorPane, selectedHitEffectSourceCondition, listener); - TimedConditionsCellRenderer cellRenderer = new TimedConditionsCellRenderer(); + CommonEditor.TimedConditionsCellRenderer cellRenderer = new CommonEditor.TimedConditionsCellRenderer(); String title = "Actor Conditions applied to the source: "; var collapsibleItemList = UiUtils.getCollapsibleItemList( listener, @@ -330,7 +330,7 @@ public class ItemEditor extends JSONElementEditor { String titleKillSourceConditions = "Actor Conditions applied to the source: "; killSourceConditionsModel = new SourceTimedConditionsListModel(killEffect); - TimedConditionsCellRenderer cellRendererKillSourceConditions = new TimedConditionsCellRenderer(); + CommonEditor.TimedConditionsCellRenderer cellRendererKillSourceConditions = new CommonEditor.TimedConditionsCellRenderer(); BasicLambdaWithArg selectedSetKillSourceConditions = (value)->selectedKillEffectCondition = value; BasicLambdaWithReturn selectedGetKillSourceConditions = ()->selectedKillEffectCondition ; BasicLambda selectedResetKillSourceConditions = ()->selectedKillEffectCondition = null; @@ -379,7 +379,7 @@ public class ItemEditor extends JSONElementEditor { String titleHitReceivedSourceConditions = "Actor Conditions applied to the player: "; hitReceivedSourceConditionsModel = new SourceTimedConditionsListModel(killEffect); - TimedConditionsCellRenderer cellRendererHitReceivedSourceConditions = new TimedConditionsCellRenderer(); + CommonEditor.TimedConditionsCellRenderer cellRendererHitReceivedSourceConditions = new CommonEditor.TimedConditionsCellRenderer(); BasicLambdaWithArg selectedSetHitReceivedSourceConditions = (value)->selectedHitReceivedEffectSourceCondition = value; BasicLambdaWithReturn selectedGetHitReceivedSourceConditions = ()->selectedHitReceivedEffectSourceCondition ; BasicLambda selectedResetHitReceivedSourceConditions = ()->selectedHitReceivedEffectSourceCondition = null; @@ -405,7 +405,7 @@ public class ItemEditor extends JSONElementEditor { String titleHitReceivedTargetConditions = "Actor Conditions applied to the attacker: "; hitReceivedTargetConditionsModel = new TargetTimedConditionsListModel(hitReceivedEffect); - TimedConditionsCellRenderer cellRendererHitReceivedTargetConditions = new TimedConditionsCellRenderer(); + CommonEditor.TimedConditionsCellRenderer cellRendererHitReceivedTargetConditions = new CommonEditor.TimedConditionsCellRenderer(); BasicLambdaWithArg selectedSetHitReceivedTargetConditions = (value)->selectedHitReceivedEffectTargetCondition = value; BasicLambdaWithReturn selectedGetHitReceivedTargetConditions = ()->selectedHitReceivedEffectTargetCondition ; BasicLambda selectedResetHitReceivedTargetConditions = ()->selectedHitReceivedEffectTargetCondition = null; @@ -1018,40 +1018,6 @@ public class ItemEditor extends JSONElementEditor { } } - public static class TimedConditionsCellRenderer extends DefaultListCellRenderer { - private static final long serialVersionUID = 7987880146189575234L; - - @Override - public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") 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); - Common.TimedActorConditionEffect effect = (Common.TimedActorConditionEffect) value; - - if (effect.condition != null) { - - boolean immunity = (effect.magnitude == null || effect.magnitude == ActorCondition.MAGNITUDE_CLEAR) && (effect.duration != null && effect.duration > ActorCondition.DURATION_NONE); - boolean clear = (effect.magnitude == null || effect.magnitude == ActorCondition.MAGNITUDE_CLEAR) && (effect.duration == null || effect.duration == ActorCondition.DURATION_NONE); - boolean forever = effect.duration != null && effect.duration == ActorCondition.DURATION_FOREVER; - - if (clear) { - label.setIcon(new ImageIcon(effect.condition.getIcon())); - label.setText(effect.chance + "% chances to clear actor condition " + effect.condition.getDesc()); - } else if (immunity) { - label.setIcon(new OverlayIcon(effect.condition.getIcon(), DefaultIcons.getImmunityIcon())); - label.setText(effect.chance + "% chances to give immunity to " + effect.condition.getDesc() + (forever ? " forever" : " for " + effect.duration + " rounds")); - } else { - label.setIcon(new ImageIcon(effect.condition.getIcon())); - label.setText(effect.chance + "% chances to give actor condition " + effect.condition.getDesc() + " x" + effect.magnitude + (forever ? " forever" : " for " + effect.duration + " rounds")); - } - } else { - label.setText("New, undefined actor condition effect."); - } - } - return c; - } - } - public static class ConditionsListModel extends OrderedListenerListModel { public ConditionsListModel(Item.EquipEffect equipEffect) { super(equipEffect); diff --git a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/NPCEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/NPCEditor.java index 6e251b1..32dada8 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/NPCEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/NPCEditor.java @@ -251,7 +251,7 @@ public class NPCEditor extends JSONElementEditor { String titleSource = "Actor Conditions applied to the source: "; hitSourceConditionsListModel = new SourceTimedConditionsListModel(hitEffect); - TimedConditionsCellRenderer cellRendererSource = new TimedConditionsCellRenderer(); + CommonEditor.TimedConditionsCellRenderer cellRendererSource = new CommonEditor.TimedConditionsCellRenderer(); BasicLambdaWithArg selectedSetSource = (value)->selectedHitEffectSourceCondition = value; BasicLambdaWithReturn selectedGetSource = ()->selectedHitEffectSourceCondition ; BasicLambda selectedResetSource = ()->selectedHitEffectSourceCondition = null; @@ -278,7 +278,7 @@ public class NPCEditor extends JSONElementEditor { String titleTarget = "Actor Conditions applied to the target: "; hitTargetConditionsListModel = new TargetTimedConditionsListModel(hitEffect); - TimedConditionsCellRenderer cellRendererTarget = new TimedConditionsCellRenderer(); + CommonEditor.TimedConditionsCellRenderer cellRendererTarget = new CommonEditor.TimedConditionsCellRenderer(); BasicLambdaWithArg selectedSetTarget = (value)->selectedHitEffectTargetCondition = value; BasicLambdaWithReturn selectedGetTarget = ()->selectedHitEffectTargetCondition ; BasicLambda selectedResetTarget = ()->selectedHitEffectTargetCondition = null; @@ -320,7 +320,7 @@ public class NPCEditor extends JSONElementEditor { String titleReceivedSource = "Actor Conditions applied to this NPC: "; hitReceivedSourceConditionsListModel = new SourceTimedConditionsListModel(hitReceivedEffect); - TimedConditionsCellRenderer cellRendererReceivedSource = new TimedConditionsCellRenderer(); + CommonEditor.TimedConditionsCellRenderer cellRendererReceivedSource = new CommonEditor.TimedConditionsCellRenderer(); BasicLambdaWithArg selectedSetReceivedSource = (value)->selectedHitReceivedEffectSourceCondition = value; BasicLambdaWithReturn selectedGetReceivedSource = ()->selectedHitReceivedEffectSourceCondition ; BasicLambda selectedResetReceivedSource = ()->selectedHitReceivedEffectSourceCondition = null; @@ -346,7 +346,7 @@ public class NPCEditor extends JSONElementEditor { String titleReceivedTarget = "Actor Conditions applied to the attacker: "; hitReceivedTargetConditionsListModel = new TargetTimedConditionsListModel(hitReceivedEffect); - TimedConditionsCellRenderer cellRendererReceivedTarget = new TimedConditionsCellRenderer(); + CommonEditor.TimedConditionsCellRenderer cellRendererReceivedTarget = new CommonEditor.TimedConditionsCellRenderer(); BasicLambdaWithArg selectedSetReceivedTarget = (value)->selectedHitReceivedEffectTargetCondition = value; BasicLambdaWithReturn selectedGetReceivedTarget = ()->selectedHitReceivedEffectTargetCondition ; BasicLambda selectedResetReceivedTarget = ()->selectedHitReceivedEffectTargetCondition = null; @@ -384,7 +384,7 @@ public class NPCEditor extends JSONElementEditor { String titleDeathSource = "Actor Conditions applied to the killer: "; deathSourceConditionsListModel = new SourceTimedConditionsListModel(deathEffect); - TimedConditionsCellRenderer cellRendererDeathSource = new TimedConditionsCellRenderer(); + CommonEditor.TimedConditionsCellRenderer cellRendererDeathSource = new CommonEditor.TimedConditionsCellRenderer(); BasicLambdaWithArg selectedSetDeathSource = (value)->selectedDeathEffectSourceCondition = value; BasicLambdaWithReturn selectedGetDeathSource = ()->selectedDeathEffectSourceCondition ; BasicLambda selectedResetDeathSource = ()->selectedDeathEffectSourceCondition = null; @@ -896,40 +896,6 @@ public class NPCEditor extends JSONElementEditor { } } - public static class TimedConditionsCellRenderer extends DefaultListCellRenderer { - private static final long serialVersionUID = 7987880146189575234L; - - @Override - public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") 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); - Common.TimedActorConditionEffect effect = (Common.TimedActorConditionEffect) value; - - if (effect.condition != null) { - - boolean immunity = (effect.magnitude == null || effect.magnitude == ActorCondition.MAGNITUDE_CLEAR) && (effect.duration != null && effect.duration > ActorCondition.DURATION_NONE); - boolean clear = (effect.magnitude == null || effect.magnitude == ActorCondition.MAGNITUDE_CLEAR) && (effect.duration == null || effect.duration == ActorCondition.DURATION_NONE); - boolean forever = effect.duration != null && effect.duration == ActorCondition.DURATION_FOREVER; - - if (clear) { - label.setIcon(new ImageIcon(effect.condition.getIcon())); - label.setText(effect.chance + "% chances to clear actor condition " + effect.condition.getDesc()); - } else if (immunity) { - label.setIcon(new OverlayIcon(effect.condition.getIcon(), DefaultIcons.getImmunityIcon())); - label.setText(effect.chance + "% chances to give immunity to " + effect.condition.getDesc() + (forever ? " forever" : " for " + effect.duration + " rounds")); - } else { - label.setIcon(new ImageIcon(effect.condition.getIcon())); - label.setText(effect.chance + "% chances to give actor condition " + effect.condition.getDesc() + " x" + effect.magnitude + (forever ? " forever" : " for " + effect.duration + " rounds")); - } - } else { - label.setText("New, undefined actor condition effect."); - } - } - return c; - } - } - public static boolean isNull(Common.HitEffect effect) { if (effect.ap_boost_min != null) return false; if (effect.ap_boost_max != null) return false;