|
@@ -1,12 +1,19 @@
|
|
|
package org.leumasjaffe.charsheet.view.level;
|
|
package org.leumasjaffe.charsheet.view.level;
|
|
|
|
|
|
|
|
|
|
+import static org.leumasjaffe.charsheet.view.level.LevelUpSpellPanel.SpellPickType.*;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Collection;
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.function.Consumer;
|
|
import java.util.function.Consumer;
|
|
|
import java.util.stream.IntStream;
|
|
import java.util.stream.IntStream;
|
|
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
|
|
import org.jdesktop.swingx.VerticalLayout;
|
|
import org.jdesktop.swingx.VerticalLayout;
|
|
|
|
|
+import org.leumasjaffe.charsheet.model.magic.DDSpell;
|
|
|
import org.leumasjaffe.charsheet.view.magic.SelectSpellsPanel;
|
|
import org.leumasjaffe.charsheet.view.magic.SelectSpellsPanel;
|
|
|
|
|
+import org.leumasjaffe.charsheet.view.magic.SelectSpellsPanel.Info;
|
|
|
import org.leumasjaffe.charsheet.view.skills.SkillLevelUpPanel;
|
|
import org.leumasjaffe.charsheet.view.skills.SkillLevelUpPanel;
|
|
|
import org.leumasjaffe.function.VoidVoidFunction;
|
|
import org.leumasjaffe.function.VoidVoidFunction;
|
|
|
import org.leumasjaffe.observer.Observable;
|
|
import org.leumasjaffe.observer.Observable;
|
|
@@ -15,6 +22,7 @@ import org.leumasjaffe.observer.ObserverDispatch;
|
|
|
|
|
|
|
|
import lombok.AccessLevel;
|
|
import lombok.AccessLevel;
|
|
|
import lombok.experimental.FieldDefaults;
|
|
import lombok.experimental.FieldDefaults;
|
|
|
|
|
+import lombok.experimental.NonFinal;
|
|
|
|
|
|
|
|
import java.awt.GridBagLayout;
|
|
import java.awt.GridBagLayout;
|
|
|
import javax.swing.JTabbedPane;
|
|
import javax.swing.JTabbedPane;
|
|
@@ -31,33 +39,37 @@ import javax.swing.JLabel;
|
|
|
class UpdateClassWithLevelPanel extends JPanel {
|
|
class UpdateClassWithLevelPanel extends JPanel {
|
|
|
@FieldDefaults(level=AccessLevel.PUBLIC, makeFinal=true)
|
|
@FieldDefaults(level=AccessLevel.PUBLIC, makeFinal=true)
|
|
|
public class BoolArray extends Observable {
|
|
public class BoolArray extends Observable {
|
|
|
- boolean data[] = new boolean[] {false, false};
|
|
|
|
|
|
|
+ boolean data[] = new boolean[] {false, false, false};
|
|
|
}
|
|
}
|
|
|
BoolArray readyCount = new BoolArray();
|
|
BoolArray readyCount = new BoolArray();
|
|
|
ObservableListener<Consumer<Boolean>, BoolArray> listener;
|
|
ObservableListener<Consumer<Boolean>, BoolArray> listener;
|
|
|
|
|
+ JTabbedPane tabbedPane;
|
|
|
|
|
+ @NonFinal LevelUpSpellPanel learnSpells = null;
|
|
|
|
|
+
|
|
|
public UpdateClassWithLevelPanel(LevelUpClassInfo info, VoidVoidFunction back,
|
|
public UpdateClassWithLevelPanel(LevelUpClassInfo info, VoidVoidFunction back,
|
|
|
Consumer<Boolean> setReady) {
|
|
Consumer<Boolean> setReady) {
|
|
|
|
|
+ info.ddClass.getLevel().value(info.toLevel);
|
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
gridBagLayout.columnWidths = new int[]{0, 0};
|
|
gridBagLayout.columnWidths = new int[]{0, 0};
|
|
|
gridBagLayout.rowHeights = new int[]{0, 0, 0};
|
|
gridBagLayout.rowHeights = new int[]{0, 0, 0};
|
|
|
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
|
gridBagLayout.rowWeights = new double[]{1.0, 0.0, Double.MIN_VALUE};
|
|
gridBagLayout.rowWeights = new double[]{1.0, 0.0, Double.MIN_VALUE};
|
|
|
setLayout(gridBagLayout);
|
|
setLayout(gridBagLayout);
|
|
|
-
|
|
|
|
|
- JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
|
|
GridBagConstraints gbc_tabbedPane = new GridBagConstraints();
|
|
GridBagConstraints gbc_tabbedPane = new GridBagConstraints();
|
|
|
gbc_tabbedPane.insets = new Insets(0, 0, 5, 0);
|
|
gbc_tabbedPane.insets = new Insets(0, 0, 5, 0);
|
|
|
gbc_tabbedPane.fill = GridBagConstraints.BOTH;
|
|
gbc_tabbedPane.fill = GridBagConstraints.BOTH;
|
|
|
gbc_tabbedPane.gridx = 0;
|
|
gbc_tabbedPane.gridx = 0;
|
|
|
gbc_tabbedPane.gridy = 0;
|
|
gbc_tabbedPane.gridy = 0;
|
|
|
add(tabbedPane, gbc_tabbedPane);
|
|
add(tabbedPane, gbc_tabbedPane);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
JPanel features = new JPanel(new VerticalLayout(2));
|
|
JPanel features = new JPanel(new VerticalLayout(2));
|
|
|
info.ddClass.getBase().getFeatures(info.toLevel).forEach(prop -> {
|
|
info.ddClass.getBase().getFeatures(info.toLevel).forEach(prop -> {
|
|
|
features.add(new JLabel(prop.getName()));
|
|
features.add(new JLabel(prop.getName()));
|
|
|
});
|
|
});
|
|
|
tabbedPane.addTab("Features", null, features, null);
|
|
tabbedPane.addTab("Features", null, features, null);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
JPanel skills = new SkillLevelUpPanel(info.ddCharacter, info.ddClass) {
|
|
JPanel skills = new SkillLevelUpPanel(info.ddCharacter, info.ddClass) {
|
|
|
@Override public void setIsReady(boolean b) {
|
|
@Override public void setIsReady(boolean b) {
|
|
|
readyCount.data[0] = b;
|
|
readyCount.data[0] = b;
|
|
@@ -65,23 +77,35 @@ class UpdateClassWithLevelPanel extends JPanel {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
tabbedPane.addTab("Skills", null, skills, null);
|
|
tabbedPane.addTab("Skills", null, skills, null);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
info.ddClass.getSpellBook().ifPresent(sb -> {
|
|
info.ddClass.getSpellBook().ifPresent(sb -> {
|
|
|
|
|
+ readyCount.data[1] = !sb.learnsSpells();
|
|
|
|
|
+ readyCount.data[2] = !sb.preparesSpells();
|
|
|
if (sb.learnsSpells()) {
|
|
if (sb.learnsSpells()) {
|
|
|
- JPanel spells = new LevelUpSpellPanel(LevelUpSpellPanel.SpellPickType.LEARN,
|
|
|
|
|
|
|
+ LevelUpSpellPanel spells = new LevelUpSpellPanel(LEARN,
|
|
|
new SelectSpellsPanel.Info(info.ddCharacter, info.ddClass),
|
|
new SelectSpellsPanel.Info(info.ddCharacter, info.ddClass),
|
|
|
- info.toLevel, readyCount);
|
|
|
|
|
|
|
+ readyCount, 1);
|
|
|
tabbedPane.addTab("Learn Spells", null, spells, null);
|
|
tabbedPane.addTab("Learn Spells", null, spells, null);
|
|
|
|
|
+ if (sb.preparesSpells()) {
|
|
|
|
|
+ // TODO: use Observable?
|
|
|
|
|
+ spells.addPropertyChangeListener(SelectSpellsPanel.READY, e -> {
|
|
|
|
|
+ if ((Boolean) e.getNewValue()) {
|
|
|
|
|
+ createPrepareLearnedSpellPanel(info, spells);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ tabbedPane.remove(learnSpells);
|
|
|
|
|
+ learnSpells = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- // FIXME: needs to get the newly learned spells
|
|
|
|
|
- if (sb.preparesSpells()) {
|
|
|
|
|
- JPanel spells = new LevelUpSpellPanel(LevelUpSpellPanel.SpellPickType.PREPARE,
|
|
|
|
|
|
|
+ else if (sb.preparesSpells()) {
|
|
|
|
|
+ LevelUpSpellPanel spells = new LevelUpSpellPanel(PREPARE,
|
|
|
new SelectSpellsPanel.Info(info.ddCharacter, info.ddClass),
|
|
new SelectSpellsPanel.Info(info.ddCharacter, info.ddClass),
|
|
|
- info.toLevel, readyCount);
|
|
|
|
|
|
|
+ readyCount, 2);
|
|
|
tabbedPane.addTab("Prepare Spells", null, spells, null);
|
|
tabbedPane.addTab("Prepare Spells", null, spells, null);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
JPanel panel = new JPanel();
|
|
JPanel panel = new JPanel();
|
|
|
GridBagConstraints gbc_panel = new GridBagConstraints();
|
|
GridBagConstraints gbc_panel = new GridBagConstraints();
|
|
|
gbc_panel.fill = GridBagConstraints.BOTH;
|
|
gbc_panel.fill = GridBagConstraints.BOTH;
|
|
@@ -94,7 +118,7 @@ class UpdateClassWithLevelPanel extends JPanel {
|
|
|
gbl_panel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
|
gbl_panel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
|
|
gbl_panel.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
gbl_panel.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
|
panel.setLayout(gbl_panel);
|
|
panel.setLayout(gbl_panel);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
JButton btnBack = new JButton("Back");
|
|
JButton btnBack = new JButton("Back");
|
|
|
GridBagConstraints gbc_btnBack = new GridBagConstraints();
|
|
GridBagConstraints gbc_btnBack = new GridBagConstraints();
|
|
|
gbc_btnBack.insets = new Insets(0, 0, 0, 5);
|
|
gbc_btnBack.insets = new Insets(0, 0, 0, 5);
|
|
@@ -102,17 +126,40 @@ class UpdateClassWithLevelPanel extends JPanel {
|
|
|
gbc_btnBack.gridy = 0;
|
|
gbc_btnBack.gridy = 0;
|
|
|
panel.add(btnBack, gbc_btnBack);
|
|
panel.add(btnBack, gbc_btnBack);
|
|
|
btnBack.addActionListener(e -> back.apply());
|
|
btnBack.addActionListener(e -> back.apply());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Component horizontalGlue = Box.createHorizontalGlue();
|
|
Component horizontalGlue = Box.createHorizontalGlue();
|
|
|
GridBagConstraints gbc_horizontalGlue = new GridBagConstraints();
|
|
GridBagConstraints gbc_horizontalGlue = new GridBagConstraints();
|
|
|
gbc_horizontalGlue.gridx = 1;
|
|
gbc_horizontalGlue.gridx = 1;
|
|
|
gbc_horizontalGlue.gridy = 0;
|
|
gbc_horizontalGlue.gridy = 0;
|
|
|
panel.add(horizontalGlue, gbc_horizontalGlue);
|
|
panel.add(horizontalGlue, gbc_horizontalGlue);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
listener = new ObservableListener<>(setReady, (c, v) -> {
|
|
listener = new ObservableListener<>(setReady, (c, v) -> {
|
|
|
c.accept(IntStream.range(0, v.data.length)
|
|
c.accept(IntStream.range(0, v.data.length)
|
|
|
.mapToObj(i -> v.data[i]).allMatch(b -> b));
|
|
.mapToObj(i -> v.data[i]).allMatch(b -> b));
|
|
|
});
|
|
});
|
|
|
listener.setObserved(readyCount);
|
|
listener.setObserved(readyCount);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private void createPrepareLearnedSpellPanel(LevelUpClassInfo info, LevelUpSpellPanel spells) {
|
|
|
|
|
+ LevelUpSpellPanel.SpellPicker pick = new LevelUpSpellPanel.SpellPicker() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<List<Integer>> getSpellCounts(Info info) {
|
|
|
|
|
+ return PREPARE.getSpellCounts(info);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Collection<DDSpell> getAvailableSpells(Info info, int i) {
|
|
|
|
|
+ final Collection<DDSpell> start = new ArrayList<>(PREPARE.getAvailableSpells(info, i));
|
|
|
|
|
+ if (spells.getPanels().get(i) != null) {
|
|
|
|
|
+ start.addAll(spells.getPanels().get(i).getPrepared());
|
|
|
|
|
+ }
|
|
|
|
|
+ return start;
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ learnSpells = new LevelUpSpellPanel(pick,
|
|
|
|
|
+ new SelectSpellsPanel.Info(info.ddCharacter, info.ddClass),
|
|
|
|
|
+ readyCount, 2);
|
|
|
|
|
+ tabbedPane.addTab("Prepare Spells", null, learnSpells, null);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|