mirror of
https://github.com/OMGeeky/ATCS.git
synced 2025-12-26 23:57:25 +01:00
extract TimedConditionsCellRenderer into CommonEditor
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -263,7 +263,7 @@ public class ItemEditor extends JSONElementEditor {
|
||||
BasicLambdaWithArg valueChanged = (selectedReply) -> {
|
||||
};
|
||||
BasicLambdaWithArg<JPanel> 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<Common.TimedActorConditionEffect> selectedSetKillSourceConditions = (value)->selectedKillEffectCondition = value;
|
||||
BasicLambdaWithReturn<Common.TimedActorConditionEffect> 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<Common.TimedActorConditionEffect> selectedSetHitReceivedSourceConditions = (value)->selectedHitReceivedEffectSourceCondition = value;
|
||||
BasicLambdaWithReturn<Common.TimedActorConditionEffect> 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<Common.TimedActorConditionEffect> selectedSetHitReceivedTargetConditions = (value)->selectedHitReceivedEffectTargetCondition = value;
|
||||
BasicLambdaWithReturn<Common.TimedActorConditionEffect> 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<Item.EquipEffect, Common.ActorConditionEffect> {
|
||||
public ConditionsListModel(Item.EquipEffect equipEffect) {
|
||||
super(equipEffect);
|
||||
|
||||
@@ -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<Common.TimedActorConditionEffect> selectedSetSource = (value)->selectedHitEffectSourceCondition = value;
|
||||
BasicLambdaWithReturn<Common.TimedActorConditionEffect> 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<Common.TimedActorConditionEffect> selectedSetTarget = (value)->selectedHitEffectTargetCondition = value;
|
||||
BasicLambdaWithReturn<Common.TimedActorConditionEffect> 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<Common.TimedActorConditionEffect> selectedSetReceivedSource = (value)->selectedHitReceivedEffectSourceCondition = value;
|
||||
BasicLambdaWithReturn<Common.TimedActorConditionEffect> 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<Common.TimedActorConditionEffect> selectedSetReceivedTarget = (value)->selectedHitReceivedEffectTargetCondition = value;
|
||||
BasicLambdaWithReturn<Common.TimedActorConditionEffect> 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<Common.TimedActorConditionEffect> selectedSetDeathSource = (value)->selectedDeathEffectSourceCondition = value;
|
||||
BasicLambdaWithReturn<Common.TimedActorConditionEffect> 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;
|
||||
|
||||
Reference in New Issue
Block a user