From 5ce84dc1b1615efa37c2d271df059a6a7d46a544 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Mon, 23 Jun 2025 13:02:03 +0200 Subject: [PATCH] extract some CollapsibleItemLists (in ItemEditor) --- .../ui/gamedataeditors/ItemEditor.java | 220 +++++------------- 1 file changed, 64 insertions(+), 156 deletions(-) diff --git a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/ItemEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/ItemEditor.java index bad3fa5..c8d3a1a 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/ItemEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/ItemEditor.java @@ -210,63 +210,33 @@ 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)); - 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. - } - } - }); - 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); + String titleEquipConditions = "Actor Conditions applied when equipped: "; + equipConditionsModel = new ConditionsListModel(equipEffect); + ConditionsCellRenderer cellRendererEquipConditions = new ConditionsCellRenderer(); + BasicLambdaWithArg selectedSetEquipConditions = (value)->selectedEquipEffectCondition = value; + BasicLambdaWithReturn selectedGetEquipConditions = ()->selectedEquipEffectCondition ; + BasicLambda selectedResetEquipConditions = ()->selectedEquipEffectCondition = null; + BasicLambdaWithArg updatePaneEquipConditions = (editorPane) -> updateEquipConditionEditorPane(editorPane, selectedEquipEffectCondition, listener); + var resultEquipConditions = UiUtils.getCollapsibleItemList(listener, + equipConditionsModel, + selectedResetEquipConditions, + selectedSetEquipConditions, + selectedGetEquipConditions, + (x) -> {}, + updatePaneEquipConditions, + item.writable, + Common.ConditionEffect::new, + cellRendererEquipConditions, + titleEquipConditions, + (x) -> null); + equipConditionsList = resultEquipConditions.list; + CollapsiblePanel equipConditionsPane = resultEquipConditions.collapsiblePanel; if (item.equip_effect == null || item.equip_effect.conditions == null || item.equip_effect.conditions.isEmpty()) { equipConditionsPane.collapse(); } equipEffectPane.add(equipConditionsPane, JideBoxLayout.FIX); + pane.add(equipEffectPane, JideBoxLayout.FIX); if (item.equip_effect == null) { equipEffectPane.collapse(); @@ -317,59 +287,27 @@ public class ItemEditor extends JSONElementEditor { 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 titleHitTargetConditions = "Actor Conditions applied to the target: "; 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. - } - } - }); - - 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); + ConditionsCellRenderer cellRendererHitTargetConditions = new ConditionsCellRenderer(); + BasicLambdaWithArg selectedSetHitTargetConditions = (value)->selectedHitEffectTargetCondition = value; + BasicLambdaWithReturn selectedGetHitTargetConditions = ()->selectedHitEffectTargetCondition ; + BasicLambda selectedResetHitTargetConditions = ()->selectedHitEffectTargetCondition = null; + BasicLambdaWithArg updatePaneHitTargetConditions = (editorPane) -> updateHitTargetTimedConditionEditorPane(editorPane, selectedHitEffectTargetCondition, listener); + var resultHitTargetConditions = UiUtils.getCollapsibleItemList(listener, + hitTargetConditionsModel, + selectedResetHitTargetConditions, + selectedSetHitTargetConditions, + selectedGetHitTargetConditions, + (x) -> {}, + updatePaneHitTargetConditions, + item.writable, + Common.TimedConditionEffect::new, + cellRendererHitTargetConditions, + titleHitTargetConditions, + (x) -> null); + hitTargetConditionsList = resultHitTargetConditions.list; + CollapsiblePanel hitTargetConditionsPane = resultHitTargetConditions.collapsiblePanel; if (item.hit_effect == null || item.hit_effect.conditions_target == null || item.hit_effect.conditions_target.isEmpty()) { hitTargetConditionsPane.collapse(); } @@ -391,63 +329,33 @@ 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)); - 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. - } - } - }); - 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); + String titleKillSourceConditions = "Actor Conditions applied to the source: "; + killSourceConditionsModel = new SourceTimedConditionsListModel(killEffect); + TimedConditionsCellRenderer cellRendererKillSourceConditions = new TimedConditionsCellRenderer(); + BasicLambdaWithArg selectedSetKillSourceConditions = (value)->selectedKillEffectCondition = value; + BasicLambdaWithReturn selectedGetKillSourceConditions = ()->selectedKillEffectCondition ; + BasicLambda selectedResetKillSourceConditions = ()->selectedKillEffectCondition = null; + BasicLambdaWithArg updatePaneKillSourceConditions = (editorPane) -> updateKillSourceTimedConditionEditorPane(editorPane, selectedKillEffectCondition, listener); + var resultKillSourceConditions = UiUtils.getCollapsibleItemList(listener, + killSourceConditionsModel, + selectedResetKillSourceConditions, + selectedSetKillSourceConditions, + selectedGetKillSourceConditions, + (x) -> {}, + updatePaneKillSourceConditions, + item.writable, + Common.TimedConditionEffect::new, + cellRendererKillSourceConditions, + titleKillSourceConditions, + (x) -> null); + killSourceConditionsList = resultKillSourceConditions.list; + CollapsiblePanel killSourceConditionsPane = resultKillSourceConditions.collapsiblePanel; if (item.kill_effect == null || item.kill_effect.conditions_source == null || item.kill_effect.conditions_source.isEmpty()) { killSourceConditionsPane.collapse(); } killEffectPane.add(killSourceConditionsPane, JideBoxLayout.FIX); + if (item.kill_effect == null) { killEffectPane.collapse(); }