refactor: streamline list panel creation in DroplistEditor & ItemEditor

This commit is contained in:
OMGeeky
2025-06-16 11:16:12 +02:00
parent ee6907efdd
commit 63d6397da5
2 changed files with 131 additions and 439 deletions

View File

@@ -1,28 +1,17 @@
package com.gpl.rpg.atcontentstudio.ui.gamedataeditors;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
@@ -34,103 +23,67 @@ import com.gpl.rpg.atcontentstudio.model.gamedata.Item;
import com.gpl.rpg.atcontentstudio.ui.CollapsiblePanel;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener;
import com.gpl.rpg.atcontentstudio.ui.tools.CommonEditor;
import com.jidesoft.swing.JideBoxLayout;
public class DroplistEditor extends JSONElementEditor {
private static final long serialVersionUID = 1139455254096811058L;
private static final String form_view_id = "Form";
private static final String json_view_id = "JSON";
private Droplist.DroppedItem selectedItem;
private JTextField idField;
private MyComboBox itemCombo;
private DroppedItemsListModel droppedItemsListModel;
private JSpinner qtyMinField;
private JSpinner qtyMaxField;
private JComponent chanceField;
public DroplistEditor(Droplist droplist) {
super(droplist, droplist.getDesc(), droplist.getIcon());
addEditorTab(form_view_id, getFormView());
addEditorTab(json_view_id, getJSONView());
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void insertFormViewDataField(JPanel pane) {
final Droplist droplist = (Droplist)target;
final FieldUpdateListener listener = new DroplistFieldUpdater();
createButtonPane(pane, droplist.getProject(), droplist, Droplist.class, Droplist.getImage(), null, listener);
idField = addTextField(pane, "Droplist ID: ", droplist.id, droplist.writable, listener);
CollapsiblePanel itemsPane = new CollapsiblePanel("Items in this droplist: ");
itemsPane.setLayout(new JideBoxLayout(itemsPane, JideBoxLayout.PAGE_AXIS));
String title = "Items in this droplist: ";
DroppedItemsCellRenderer cellRenderer = new DroppedItemsCellRenderer();
droppedItemsListModel = new DroppedItemsListModel(droplist);
final JList itemsList = new JList(droppedItemsListModel);
itemsList.setCellRenderer(new DroppedItemsCellRenderer());
itemsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
itemsPane.add(new JScrollPane(itemsList), JideBoxLayout.FIX);
final JPanel droppedItemsEditorPane = new JPanel();
final JButton createDroppedItem = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
final JButton deleteDroppedItem = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
deleteDroppedItem.setEnabled(false);
itemsList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
selectedItem = (Droplist.DroppedItem) itemsList.getSelectedValue();
if (selectedItem == null) {
deleteDroppedItem.setEnabled(false);
} else {
deleteDroppedItem.setEnabled(true);
}
updateDroppedItemsEditorPane(droppedItemsEditorPane, selectedItem, listener);
}
});
if (droplist.writable) {
JPanel listButtonsPane = new JPanel();
listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
createDroppedItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Droplist.DroppedItem tempItem = new Droplist.DroppedItem();
droppedItemsListModel.addItem(tempItem);
itemsList.setSelectedValue(tempItem, true);
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
deleteDroppedItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedItem != null) {
droppedItemsListModel.removeItem(selectedItem);
selectedItem = null;
itemsList.clearSelection();
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
listButtonsPane.add(createDroppedItem, JideBoxLayout.FIX);
listButtonsPane.add(deleteDroppedItem, JideBoxLayout.FIX);
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
itemsPane.add(listButtonsPane, JideBoxLayout.FIX);
}
droppedItemsEditorPane.setLayout(new JideBoxLayout(droppedItemsEditorPane, JideBoxLayout.PAGE_AXIS));
itemsPane.add(droppedItemsEditorPane, JideBoxLayout.FIX);
final boolean moveUpDownEnabled = false;
CollapsiblePanel itemsPane = CommonEditor.createListPanel(
title,
cellRenderer,
droppedItemsListModel,
droplist.writable,
moveUpDownEnabled,
(e) -> selectedItem = e,
() -> selectedItem,
this::updateDroppedItemsEditorPane,
listener,
Droplist.DroppedItem::new);
if (droplist.dropped_items == null || droplist.dropped_items.isEmpty()) {
itemsPane.collapse();
}
pane.add(itemsPane, JideBoxLayout.FIX);
}
public void updateDroppedItemsEditorPane(JPanel pane, DroppedItem di, FieldUpdateListener listener) {
boolean writable = ((Droplist)target).writable;
Project proj = ((Droplist)target).getProject();
@@ -147,69 +100,24 @@ public class DroplistEditor extends JSONElementEditor {
pane.revalidate();
pane.repaint();
}
public class DroppedItemsListModel implements ListModel<Droplist.DroppedItem> {
Droplist source;
public static class DroppedItemsListModel extends CommonEditor.AtListModel<Droplist.DroppedItem, Droplist> {
public DroppedItemsListModel(Droplist droplist) {
this.source = droplist;
super(droplist);
}
@Override
public int getSize() {
if (source.dropped_items == null) return 0;
return source.dropped_items.size();
}
@Override
public Droplist.DroppedItem getElementAt(int index) {
if (source.dropped_items == null) return null;
return source.dropped_items.get(index);
}
public void addItem(Droplist.DroppedItem item) {
if (source.dropped_items == null) {
source.dropped_items = new ArrayList<Droplist.DroppedItem>();
}
source.dropped_items.add(item);
int index = source.dropped_items.indexOf(item);
for (ListDataListener l : listeners) {
l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index));
}
}
public void removeItem(Droplist.DroppedItem item) {
int index = source.dropped_items.indexOf(item);
source.dropped_items.remove(item);
if (source.dropped_items.isEmpty()) {
source.dropped_items = null;
}
for (ListDataListener l : listeners) {
l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index));
}
protected List<Droplist.DroppedItem> getInner() {
return source.dropped_items;
}
public void itemChanged(Droplist.DroppedItem item) {
int index = source.dropped_items.indexOf(item);
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index));
}
}
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
listeners.add(l);
}
@Override
public void removeListDataListener(ListDataListener l) {
listeners.remove(l);
protected void setInner(List<Droplist.DroppedItem> value) {
source.dropped_items = value;
}
}
public static class DroppedItemsCellRenderer extends DefaultListCellRenderer {
private static final long serialVersionUID = 7987880146189575234L;
@@ -230,7 +138,7 @@ public class DroplistEditor extends JSONElementEditor {
}
return c;
}
public boolean isNull(Droplist.DroppedItem item) {
return ((item == null) || (
item.item == null &&
@@ -241,8 +149,8 @@ public class DroplistEditor extends JSONElementEditor {
));
}
}
public class DroplistFieldUpdater implements FieldUpdateListener {
@Override
public void valueChanged(JComponent source, Object value) {
@@ -254,7 +162,7 @@ public class DroplistEditor extends JSONElementEditor {
return;
}
if (target.id.equals((String) value)) return;
if (idChanging()) {
droplist.id = (String) value;
DroplistEditor.this.name = droplist.getDesc();

View File

@@ -232,59 +232,23 @@ public class ItemEditor extends JSONElementEditor {
equipIncUseCost = addIntegerField(equipEffectPane, "Increase item use cost: ", equipEffect.increase_use_item_cost, true, item.writable, listener);
equipIncReequipCost = addIntegerField(equipEffectPane, "Increase reequip cost: ", equipEffect.increase_reequip_cost, true, item.writable, listener);
equipIncAttackCost = addIntegerField(equipEffectPane, "Increase attack cost: ", equipEffect.increase_attack_cost, true, item.writable, listener);
CollapsiblePanel equipConditionsPane = new CollapsiblePanel("Actor Conditions applied when equipped: ");
equipConditionsPane.setLayout(new JideBoxLayout(equipConditionsPane, JideBoxLayout.PAGE_AXIS));
String title = "Actor Conditions applied when equipped: ";
ConditionsCellRenderer cellRenderer = new ConditionsCellRenderer();
equipConditionsModel = new ConditionsListModel(equipEffect);
equipConditionsList = new JList(equipConditionsModel);
equipConditionsList.setCellRenderer(new ConditionsCellRenderer());
equipConditionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
equipConditionsPane.add(new JScrollPane(equipConditionsList), JideBoxLayout.FIX);
final JPanel equipConditionsEditorPane = new JPanel();
final JButton createEquipCondition = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
final JButton deleteEquipCondition = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
equipConditionsList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
selectedEquipEffectCondition = (Common.ConditionEffect) equipConditionsList.getSelectedValue();
if (selectedEquipEffectCondition == null) {
deleteEquipCondition.setEnabled(false);
} else {
deleteEquipCondition.setEnabled(true);
}
updateEquipConditionEditorPane(equipConditionsEditorPane, selectedEquipEffectCondition, listener);
}
});
if (item.writable) {
JPanel listButtonsPane = new JPanel();
listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
createEquipCondition.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Common.ConditionEffect condition = new Common.ConditionEffect();
equipConditionsModel.addItem(condition);
equipConditionsList.setSelectedValue(condition, true);
listener.valueChanged(equipConditionsList, null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
deleteEquipCondition.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedEquipEffectCondition != null) {
equipConditionsModel.removeItem(selectedEquipEffectCondition);
selectedEquipEffectCondition = null;
equipConditionsList.clearSelection();
listener.valueChanged(equipConditionsList, null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
final boolean moveUpDownEnabled = false;
CollapsiblePanel equipConditionsPane = CommonEditor.createListPanel(
title,
cellRenderer,
equipConditionsModel,
item.writable,
moveUpDownEnabled,
(e) -> selectedEquipEffectCondition = e,
() -> selectedEquipEffectCondition,
this::updateEquipConditionEditorPane,
listener,
Common.ConditionEffect::new);
listButtonsPane.add(createEquipCondition, JideBoxLayout.FIX);
listButtonsPane.add(deleteEquipCondition, JideBoxLayout.FIX);
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
equipConditionsPane.add(listButtonsPane, JideBoxLayout.FIX);
}
equipConditionsEditorPane.setLayout(new JideBoxLayout(equipConditionsEditorPane, JideBoxLayout.PAGE_AXIS));
equipConditionsPane.add(equipConditionsEditorPane, JideBoxLayout.FIX);
if (item.equip_effect == null || item.equip_effect.conditions == null || item.equip_effect.conditions.isEmpty()) {
equipConditionsPane.collapse();
}
@@ -305,116 +269,44 @@ public class ItemEditor extends JSONElementEditor {
hitHPMax = addIntegerField(hitEffectPane, "HP bonus max: ", hitEffect.hp_boost_max, true, item.writable, listener);
hitAPMin = addIntegerField(hitEffectPane, "AP bonus min: ", hitEffect.ap_boost_min, true, item.writable, listener);
hitAPMax = addIntegerField(hitEffectPane, "AP bonus max: ", hitEffect.ap_boost_max, true, item.writable, listener);
final CollapsiblePanel hitSourceConditionsPane = new CollapsiblePanel("Actor Conditions applied to the source: ");
hitSourceConditionsPane.setLayout(new JideBoxLayout(hitSourceConditionsPane, JideBoxLayout.PAGE_AXIS));
String hitSourceTitle = "Actor Conditions applied to the source: ";
TimedConditionsCellRenderer hitSourceCellRenderer = new TimedConditionsCellRenderer();
hitSourceConditionsModel = new SourceTimedConditionsListModel(hitEffect);
hitSourceConditionsList = new JList(hitSourceConditionsModel);
hitSourceConditionsList.setCellRenderer(new TimedConditionsCellRenderer());
hitSourceConditionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
hitSourceConditionsPane.add(new JScrollPane(hitSourceConditionsList), JideBoxLayout.FIX);
final JPanel sourceTimedConditionsEditorPane = new JPanel();
final JButton createHitSourceCondition = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
final JButton deleteHitSourceCondition = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
hitSourceConditionsList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
selectedHitEffectSourceCondition = (Common.TimedConditionEffect) hitSourceConditionsList.getSelectedValue();
updateHitSourceTimedConditionEditorPane(sourceTimedConditionsEditorPane, selectedHitEffectSourceCondition, listener);
if (selectedHitEffectSourceCondition == null) {
deleteHitSourceCondition.setEnabled(false);
} else {
deleteHitSourceCondition.setEnabled(true);
}
}
});
if (item.writable) {
JPanel listButtonsPane = new JPanel();
listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
createHitSourceCondition.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Common.TimedConditionEffect condition = new Common.TimedConditionEffect();
hitSourceConditionsModel.addItem(condition);
hitSourceConditionsList.setSelectedValue(condition, true);
listener.valueChanged(hitSourceConditionsList, null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
deleteHitSourceCondition.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedHitEffectSourceCondition != null) {
hitSourceConditionsModel.removeItem(selectedHitEffectSourceCondition);
selectedHitEffectSourceCondition = null;
hitSourceConditionsList.clearSelection();
listener.valueChanged(hitSourceConditionsList, null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
final boolean hitSourceMoveUpDownEnabled = false;
final CollapsiblePanel hitSourceConditionsPane = CommonEditor.createListPanel(
hitSourceTitle,
hitSourceCellRenderer,
hitSourceConditionsModel,
item.writable,
hitSourceMoveUpDownEnabled,
(e) -> selectedHitEffectSourceCondition = e,
() -> selectedHitEffectSourceCondition,
this::updateHitSourceTimedConditionEditorPane,
listener,
Common.TimedConditionEffect::new);
listButtonsPane.add(createHitSourceCondition, JideBoxLayout.FIX);
listButtonsPane.add(deleteHitSourceCondition, JideBoxLayout.FIX);
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
hitSourceConditionsPane.add(listButtonsPane, JideBoxLayout.FIX);
}
sourceTimedConditionsEditorPane.setLayout(new JideBoxLayout(sourceTimedConditionsEditorPane, JideBoxLayout.PAGE_AXIS));
hitSourceConditionsPane.add(sourceTimedConditionsEditorPane, JideBoxLayout.FIX);
if (item.hit_effect == null || item.hit_effect.conditions_source == null || item.hit_effect.conditions_source.isEmpty()) {
hitSourceConditionsPane.collapse();
}
hitEffectPane.add(hitSourceConditionsPane, JideBoxLayout.FIX);
final CollapsiblePanel hitTargetConditionsPane = new CollapsiblePanel("Actor Conditions applied to the target: ");
hitTargetConditionsPane.setLayout(new JideBoxLayout(hitTargetConditionsPane, JideBoxLayout.PAGE_AXIS));
String hitTargetTitle = "Actor Conditions applied to the target: ";
TimedConditionsCellRenderer hitTargetCellRenderer = new TimedConditionsCellRenderer();
hitTargetConditionsModel = new TargetTimedConditionsListModel(hitEffect);
hitTargetConditionsList = new JList(hitTargetConditionsModel);
hitTargetConditionsList.setCellRenderer(new TimedConditionsCellRenderer());
hitTargetConditionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
hitTargetConditionsPane.add(new JScrollPane(hitTargetConditionsList), JideBoxLayout.FIX);
final JPanel targetTimedConditionsEditorPane = new JPanel();
final JButton createHitTargetCondition = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
final JButton deleteHitTargetCondition = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
hitTargetConditionsList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
selectedHitEffectTargetCondition = (Common.TimedConditionEffect) hitTargetConditionsList.getSelectedValue();
updateHitTargetTimedConditionEditorPane(targetTimedConditionsEditorPane, selectedHitEffectTargetCondition, listener);
if (selectedHitEffectTargetCondition == null) {
deleteHitTargetCondition.setEnabled(false);
} else {
deleteHitTargetCondition.setEnabled(true);
}
}
});
if (item.writable) {
JPanel listButtonsPane = new JPanel();
listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
createHitTargetCondition.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Common.TimedConditionEffect condition = new Common.TimedConditionEffect();
hitTargetConditionsModel.addItem(condition);
hitTargetConditionsList.setSelectedValue(condition, true);
listener.valueChanged(hitTargetConditionsList, null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
deleteHitTargetCondition.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedHitEffectTargetCondition != null) {
hitTargetConditionsModel.removeItem(selectedHitEffectTargetCondition);
selectedHitEffectTargetCondition = null;
hitTargetConditionsList.clearSelection();
listener.valueChanged(hitTargetConditionsList, null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
final boolean hitTargetMoveUpDownEnabled = false;
final CollapsiblePanel hitTargetConditionsPane = CommonEditor.createListPanel(
hitTargetTitle,
hitTargetCellRenderer,
hitTargetConditionsModel,
item.writable,
hitTargetMoveUpDownEnabled,
(e) -> selectedHitEffectTargetCondition = e,
() -> selectedHitEffectTargetCondition,
this::updateHitTargetTimedConditionEditorPane,
listener,
Common.TimedConditionEffect::new);
listButtonsPane.add(createHitTargetCondition, JideBoxLayout.FIX);
listButtonsPane.add(deleteHitTargetCondition, JideBoxLayout.FIX);
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
hitTargetConditionsPane.add(listButtonsPane, JideBoxLayout.FIX);
}
targetTimedConditionsEditorPane.setLayout(new JideBoxLayout(targetTimedConditionsEditorPane, JideBoxLayout.PAGE_AXIS));
hitTargetConditionsPane.add(targetTimedConditionsEditorPane, JideBoxLayout.FIX);
if (item.hit_effect == null || item.hit_effect.conditions_target == null || item.hit_effect.conditions_target.isEmpty()) {
hitTargetConditionsPane.collapse();
}
@@ -437,59 +329,23 @@ public class ItemEditor extends JSONElementEditor {
killHPMax = addIntegerField(killEffectPane, "HP bonus max: ", killEffect.hp_boost_max, true, item.writable, listener);
killAPMin = addIntegerField(killEffectPane, "AP bonus min: ", killEffect.ap_boost_min, true, item.writable, listener);
killAPMax = addIntegerField(killEffectPane, "AP bonus max: ", killEffect.ap_boost_max, true, item.writable, listener);
final CollapsiblePanel killSourceConditionsPane = new CollapsiblePanel("Actor Conditions applied to the source: ");
killSourceConditionsPane.setLayout(new JideBoxLayout(killSourceConditionsPane, JideBoxLayout.PAGE_AXIS));
String killSourceTitle = "Actor Conditions applied to the source: ";
TimedConditionsCellRenderer killSourceCellRenderer = new TimedConditionsCellRenderer();
killSourceConditionsModel = new SourceTimedConditionsListModel(killEffect);
killSourceConditionsList = new JList(killSourceConditionsModel);
killSourceConditionsList.setCellRenderer(new TimedConditionsCellRenderer());
killSourceConditionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
killSourceConditionsPane.add(new JScrollPane(killSourceConditionsList), JideBoxLayout.FIX);
final JPanel killSourceTimedConditionsEditorPane = new JPanel();
final JButton createKillSourceCondition = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
final JButton deleteKillSourceCondition = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
killSourceConditionsList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
selectedKillEffectCondition = (Common.TimedConditionEffect) killSourceConditionsList.getSelectedValue();
updateKillSourceTimedConditionEditorPane(killSourceTimedConditionsEditorPane, selectedKillEffectCondition, listener);
if (selectedKillEffectCondition == null) {
deleteKillSourceCondition.setEnabled(false);
} else {
deleteKillSourceCondition.setEnabled(true);
}
}
});
if (item.writable) {
JPanel listButtonsPane = new JPanel();
listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
createKillSourceCondition.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Common.TimedConditionEffect condition = new Common.TimedConditionEffect();
killSourceConditionsModel.addItem(condition);
killSourceConditionsList.setSelectedValue(condition, true);
listener.valueChanged(killSourceConditionsList, null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
deleteKillSourceCondition.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedKillEffectCondition != null) {
killSourceConditionsModel.removeItem(selectedKillEffectCondition);
selectedKillEffectCondition = null;
killSourceConditionsList.clearSelection();
listener.valueChanged(killSourceConditionsList, null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
final boolean killSourceMoveUpDownEnabled = false;
final CollapsiblePanel killSourceConditionsPane = CommonEditor.createListPanel(
killSourceTitle,
killSourceCellRenderer,
killSourceConditionsModel,
item.writable,
killSourceMoveUpDownEnabled,
(e) -> selectedKillEffectCondition = e,
() -> selectedKillEffectCondition,
this::updateKillSourceTimedConditionEditorPane,
listener,
Common.TimedConditionEffect::new);
listButtonsPane.add(createKillSourceCondition, JideBoxLayout.FIX);
listButtonsPane.add(deleteKillSourceCondition, JideBoxLayout.FIX);
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
killSourceConditionsPane.add(listButtonsPane, JideBoxLayout.FIX);
}
killSourceTimedConditionsEditorPane.setLayout(new JideBoxLayout(killSourceTimedConditionsEditorPane, JideBoxLayout.PAGE_AXIS));
killSourceConditionsPane.add(killSourceTimedConditionsEditorPane, JideBoxLayout.FIX);
if (item.kill_effect == null || item.kill_effect.conditions_source == null || item.kill_effect.conditions_source.isEmpty()) {
killSourceConditionsPane.collapse();
}
@@ -515,116 +371,44 @@ public class ItemEditor extends JSONElementEditor {
hitReceivedHPMaxTarget = addIntegerField(hitReceivedEffectPane, "Attacker HP bonus max: ", hitReceivedEffect.hp_boost_max_target, true, item.writable, listener);
hitReceivedAPMinTarget = addIntegerField(hitReceivedEffectPane, "Attacker AP bonus min: ", hitReceivedEffect.ap_boost_min_target, true, item.writable, listener);
hitReceivedAPMaxTarget = addIntegerField(hitReceivedEffectPane, "Attacker AP bonus max: ", hitReceivedEffect.ap_boost_max_target, true, item.writable, listener);
final CollapsiblePanel hitReceivedSourceConditionsPane = new CollapsiblePanel("Actor Conditions applied to the player: ");
hitReceivedSourceConditionsPane.setLayout(new JideBoxLayout(hitReceivedSourceConditionsPane, JideBoxLayout.PAGE_AXIS));
String hitReceivedSourceTitle = "Actor Conditions applied to the player: ";
TimedConditionsCellRenderer hitReceivedSourceCellRenderer = new TimedConditionsCellRenderer();
hitReceivedSourceConditionsModel = new SourceTimedConditionsListModel(hitReceivedEffect);
hitReceivedSourceConditionsList = new JList(hitReceivedSourceConditionsModel);
hitReceivedSourceConditionsList.setCellRenderer(new TimedConditionsCellRenderer());
hitReceivedSourceConditionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
hitReceivedSourceConditionsPane.add(new JScrollPane(hitReceivedSourceConditionsList), JideBoxLayout.FIX);
final JPanel hitReceivedSourceTimedConditionsEditorPane = new JPanel();
final JButton createHitReceivedSourceCondition = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
final JButton deleteHitReceivedSourceCondition = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
hitReceivedSourceConditionsList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
selectedHitReceivedEffectSourceCondition = (Common.TimedConditionEffect) hitReceivedSourceConditionsList.getSelectedValue();
updateHitReceivedSourceTimedConditionEditorPane(hitReceivedSourceTimedConditionsEditorPane, selectedHitReceivedEffectSourceCondition, listener);
if (selectedHitReceivedEffectSourceCondition == null) {
deleteHitReceivedSourceCondition.setEnabled(false);
} else {
deleteHitReceivedSourceCondition.setEnabled(true);
}
}
});
if (item.writable) {
JPanel listButtonsPane = new JPanel();
listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
createHitReceivedSourceCondition.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Common.TimedConditionEffect condition = new Common.TimedConditionEffect();
hitReceivedSourceConditionsModel.addItem(condition);
hitReceivedSourceConditionsList.setSelectedValue(condition, true);
listener.valueChanged(hitReceivedSourceConditionsList, null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
deleteHitReceivedSourceCondition.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedHitReceivedEffectSourceCondition != null) {
hitReceivedSourceConditionsModel.removeItem(selectedHitReceivedEffectSourceCondition);
selectedHitReceivedEffectSourceCondition = null;
hitReceivedSourceConditionsList.clearSelection();
listener.valueChanged(hitReceivedSourceConditionsList, null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
final boolean hitReceivedSourceMoveUpDownEnabled = false;
final CollapsiblePanel hitReceivedSourceConditionsPane = CommonEditor.createListPanel(
hitReceivedSourceTitle,
hitReceivedSourceCellRenderer,
hitReceivedSourceConditionsModel,
item.writable,
hitReceivedSourceMoveUpDownEnabled,
(e) -> selectedHitReceivedEffectSourceCondition = e,
() -> selectedHitReceivedEffectSourceCondition,
this::updateHitReceivedSourceTimedConditionEditorPane,
listener,
Common.TimedConditionEffect::new);
listButtonsPane.add(createHitReceivedSourceCondition, JideBoxLayout.FIX);
listButtonsPane.add(deleteHitReceivedSourceCondition, JideBoxLayout.FIX);
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
hitReceivedSourceConditionsPane.add(listButtonsPane, JideBoxLayout.FIX);
}
hitReceivedSourceTimedConditionsEditorPane.setLayout(new JideBoxLayout(hitReceivedSourceTimedConditionsEditorPane, JideBoxLayout.PAGE_AXIS));
hitReceivedSourceConditionsPane.add(hitReceivedSourceTimedConditionsEditorPane, JideBoxLayout.FIX);
if (item.hit_received_effect == null || item.hit_received_effect.conditions_source == null || item.hit_received_effect.conditions_source.isEmpty()) {
hitReceivedSourceConditionsPane.collapse();
}
hitReceivedEffectPane.add(hitReceivedSourceConditionsPane, JideBoxLayout.FIX);
final CollapsiblePanel hitReceivedTargetConditionsPane = new CollapsiblePanel("Actor Conditions applied to the attacker: ");
hitReceivedTargetConditionsPane.setLayout(new JideBoxLayout(hitReceivedTargetConditionsPane, JideBoxLayout.PAGE_AXIS));
String hitReceivedTargetTitle = "Actor Conditions applied to the attacker: ";
TimedConditionsCellRenderer hitReceivedTargetCellRenderer = new TimedConditionsCellRenderer();
hitReceivedTargetConditionsModel = new TargetTimedConditionsListModel(hitReceivedEffect);
hitReceivedTargetConditionsList = new JList(hitReceivedTargetConditionsModel);
hitReceivedTargetConditionsList.setCellRenderer(new TimedConditionsCellRenderer());
hitReceivedTargetConditionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
hitReceivedTargetConditionsPane.add(new JScrollPane(hitReceivedTargetConditionsList), JideBoxLayout.FIX);
final JPanel hitReceivedTargetTimedConditionsEditorPane = new JPanel();
final JButton createHitReceivedTargetCondition = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
final JButton deleteHitReceivedTargetCondition = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
hitReceivedTargetConditionsList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
selectedHitReceivedEffectTargetCondition = (Common.TimedConditionEffect) hitReceivedTargetConditionsList.getSelectedValue();
updateHitReceivedTargetTimedConditionEditorPane(hitReceivedTargetTimedConditionsEditorPane, selectedHitReceivedEffectTargetCondition, listener);
if (selectedHitReceivedEffectTargetCondition == null) {
deleteHitReceivedTargetCondition.setEnabled(false);
} else {
deleteHitReceivedTargetCondition.setEnabled(true);
}
}
});
if (item.writable) {
JPanel listButtonsPane = new JPanel();
listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
createHitReceivedTargetCondition.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Common.TimedConditionEffect condition = new Common.TimedConditionEffect();
hitReceivedTargetConditionsModel.addItem(condition);
hitReceivedTargetConditionsList.setSelectedValue(condition, true);
listener.valueChanged(hitReceivedTargetConditionsList, null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
deleteHitReceivedTargetCondition.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedHitReceivedEffectTargetCondition != null) {
hitReceivedTargetConditionsModel.removeItem(selectedHitReceivedEffectTargetCondition);
selectedHitReceivedEffectTargetCondition = null;
hitReceivedTargetConditionsList.clearSelection();
listener.valueChanged(hitReceivedTargetConditionsList, null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
final boolean hitReceivedTargetMoveUpDownEnabled = false;
final CollapsiblePanel hitReceivedTargetConditionsPane = CommonEditor.createListPanel(
hitReceivedTargetTitle,
hitReceivedTargetCellRenderer,
hitReceivedTargetConditionsModel,
item.writable,
hitReceivedTargetMoveUpDownEnabled,
(e) -> selectedHitReceivedEffectTargetCondition = e,
() -> selectedHitReceivedEffectTargetCondition,
this::updateHitReceivedTargetTimedConditionEditorPane,
listener,
Common.TimedConditionEffect::new);
listButtonsPane.add(createHitReceivedTargetCondition, JideBoxLayout.FIX);
listButtonsPane.add(deleteHitReceivedTargetCondition, JideBoxLayout.FIX);
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
hitReceivedTargetConditionsPane.add(listButtonsPane, JideBoxLayout.FIX);
}
hitReceivedTargetTimedConditionsEditorPane.setLayout(new JideBoxLayout(hitReceivedTargetTimedConditionsEditorPane, JideBoxLayout.PAGE_AXIS));
hitReceivedTargetConditionsPane.add(hitReceivedTargetTimedConditionsEditorPane, JideBoxLayout.FIX);
if (item.hit_received_effect == null || item.hit_received_effect.conditions_target == null || item.hit_received_effect.conditions_target.isEmpty()) {
hitReceivedTargetConditionsPane.collapse();
}