|
|
@@ -14,10 +14,12 @@ import org.leumasjaffe.charsheet.model.DDCharacter;
|
|
|
import org.leumasjaffe.charsheet.model.DDCharacterClass;
|
|
|
import org.leumasjaffe.charsheet.model.magic.DDSpell;
|
|
|
import org.leumasjaffe.charsheet.model.magic.DDSpellbook;
|
|
|
+import org.leumasjaffe.charsheet.model.observable.BoolGate;
|
|
|
import org.leumasjaffe.charsheet.model.observable.IntValue;
|
|
|
import org.leumasjaffe.charsheet.util.AbilityHelper;
|
|
|
import org.leumasjaffe.event.SelectTableRowPopupMenuListener;
|
|
|
import org.leumasjaffe.format.StringHelper;
|
|
|
+import org.leumasjaffe.observer.ObserverDispatch;
|
|
|
|
|
|
import lombok.AccessLevel;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -89,17 +91,11 @@ public class SelectSpellsPanel extends JPanel {
|
|
|
IntValue sharedValue;
|
|
|
SelectSpellModel modelPrepared, modelKnown;
|
|
|
|
|
|
- public SelectSpellsPanel(Info info, int level, Collection<DDSpell> prepared, int toPrepare,
|
|
|
- Collection<DDSpell> avail, boolean allowsDuplicates, IntValue val) {
|
|
|
- this(info.chara, level, info.dclass, prepared, toPrepare, avail, allowsDuplicates, val);
|
|
|
- }
|
|
|
-
|
|
|
- public SelectSpellsPanel(DDCharacter chara, int level,
|
|
|
- DDCharacterClass dclass, Collection<DDSpell> prepared, int toPrepare,
|
|
|
+ public SelectSpellsPanel(Info info, BoolGate gate, int level, Collection<DDSpell> prepared, int toPrepare,
|
|
|
Collection<DDSpell> avail, boolean allowsDuplicates, IntValue sharedValue) {
|
|
|
this.allowsDuplicates = allowsDuplicates;
|
|
|
this.sharedValue = sharedValue;
|
|
|
- final DDSpellbook spellBook = dclass.getSpellBook().get();
|
|
|
+ final DDSpellbook spellBook = info.dclass.getSpellBook().get();
|
|
|
this.prepared = new ArrayList<>(prepared);
|
|
|
final List<DDSpell> known = new ArrayList<>(avail);
|
|
|
this.modelPrepared = new SelectSpellModel(createPrepareModel(prepared, toPrepare));
|
|
|
@@ -114,7 +110,7 @@ public class SelectSpellsPanel extends JPanel {
|
|
|
gridBagLayout.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
|
|
setLayout(gridBagLayout);
|
|
|
|
|
|
- JPanel panel = new ChooseSpellsPerDayHeader(level, spellBook, AbilityHelper.get(chara, dclass));
|
|
|
+ JPanel panel = new ChooseSpellsPerDayHeader(level, spellBook, AbilityHelper.get(info.chara, info.dclass));
|
|
|
GridBagConstraints gbc_panel = new GridBagConstraints();
|
|
|
gbc_panel.gridwidth = 3;
|
|
|
gbc_panel.insets = new Insets(0, 0, 5, 5);
|
|
|
@@ -172,8 +168,8 @@ public class SelectSpellsPanel extends JPanel {
|
|
|
JMenuItem mntmInfo = new JMenuItem("Info");
|
|
|
mntmInfo.addActionListener( e -> {
|
|
|
DDSpell spell = known.get(tableKnown.getSelectedRow());
|
|
|
- JFrame frame = new JFrame(spell.getName() + " (" + dclass.getName() + " " + level + ")");
|
|
|
- frame.add(new SpellInfoPanel(chara, dclass, spell));
|
|
|
+ JFrame frame = new JFrame(spell.getName() + " (" + info.dclass.getName() + " " + level + ")");
|
|
|
+ frame.add(new SpellInfoPanel(info.chara, info.dclass, spell));
|
|
|
frame.pack();
|
|
|
frame.setVisible(true);
|
|
|
});
|
|
|
@@ -223,7 +219,8 @@ public class SelectSpellsPanel extends JPanel {
|
|
|
} else if (orows.length == 0 && countNone() >= rows.length) {
|
|
|
replace(rows);
|
|
|
} else {
|
|
|
- final String message = StringHelper.format("Unable to assign new spells, more spells were selected ({}) than were avaliable ({})",
|
|
|
+ final String message = StringHelper.format(
|
|
|
+ "Unable to assign new spells, more spells were selected ({}) than were avaliable ({})",
|
|
|
rows.length, orows.length == 0 ? countNone() : orows.length);
|
|
|
JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
|
|
|
}
|
|
|
@@ -231,19 +228,20 @@ public class SelectSpellsPanel extends JPanel {
|
|
|
tablePrepared.getSelectionModel().clearSelection();
|
|
|
tablePrepared.repaint();
|
|
|
|
|
|
- if (!(Boolean) getClientProperty(READY) && !Arrays.asList(modelPrepared.data).contains(NONE)) {
|
|
|
+ if (!gate.get(level) && !Arrays.asList(modelPrepared.data).contains(NONE)) {
|
|
|
this.prepared.clear();
|
|
|
for (Object o : modelPrepared.data) {
|
|
|
this.prepared.add(DDSpell.fromString((String) o)); // TODO
|
|
|
}
|
|
|
- putClientProperty(READY, true);
|
|
|
+ gate.set(level, true);
|
|
|
+ ObserverDispatch.notifySubscribers(gate, this);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- public SelectSpellsPanel(DDCharacter chara, int level, DDCharacterClass dclass,
|
|
|
+ public SelectSpellsPanel(Info info, BoolGate gate, int level,
|
|
|
Collection<DDSpell> prepared, Collection<DDSpell> avail) {
|
|
|
- this(chara, level, dclass, prepared, 0, avail, true, new IntValue(-1));
|
|
|
+ this(info, gate, level, prepared, 0, avail, true, new IntValue(-1));
|
|
|
}
|
|
|
|
|
|
private boolean wouldHaveIllegalDuplicate(int row) {
|