|
@@ -5,12 +5,16 @@ import static org.leumasjaffe.charsheet.view.level.LevelUpSpellPanel.SpellPickTy
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
+import java.util.Set;
|
|
|
import java.util.function.Consumer;
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
|
|
import org.jdesktop.swingx.VerticalLayout;
|
|
import org.jdesktop.swingx.VerticalLayout;
|
|
|
|
|
+import org.leumasjaffe.charsheet.model.DDCharacterClass;
|
|
|
import org.leumasjaffe.charsheet.model.magic.DDSpell;
|
|
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.BoolGate;
|
|
|
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.magic.SelectSpellsPanel.Info;
|
|
@@ -36,18 +40,22 @@ import javax.swing.JLabel;
|
|
|
@SuppressWarnings("serial")
|
|
@SuppressWarnings("serial")
|
|
|
@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
|
|
@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
|
|
|
class UpdateClassWithLevelPanel extends JPanel {
|
|
class UpdateClassWithLevelPanel extends JPanel {
|
|
|
- static int CHOOSE_SKILL_INDEX = 0;
|
|
|
|
|
- static int LEARN_SPELL_INDEX = 1;
|
|
|
|
|
- static int PREPARE_SPELL_INDEX = 2;
|
|
|
|
|
|
|
+ static int CHOOSE_SKILL_INDEX = 0, LEARN_SPELL_INDEX = 1, PREPARE_SPELL_INDEX = 2;
|
|
|
|
|
|
|
|
|
|
+ LevelUpClassInfo levelUpInfo;
|
|
|
|
|
+ JTabbedPane tabbedPane;
|
|
|
|
|
+
|
|
|
|
|
+ SkillLevelUpPanel skills;
|
|
|
|
|
+ @NonFinal Optional<LevelUpSpellPanel> learnSpells = Optional.empty();
|
|
|
|
|
+ @NonFinal Optional<LevelUpSpellPanel> prepSpells = Optional.empty();
|
|
|
|
|
+
|
|
|
BoolGate readyCount = new BoolGate(3);
|
|
BoolGate readyCount = new BoolGate(3);
|
|
|
ObservableListener<Consumer<Boolean>, BoolGate> listener;
|
|
ObservableListener<Consumer<Boolean>, BoolGate> listener;
|
|
|
- JTabbedPane tabbedPane;
|
|
|
|
|
- @NonFinal LevelUpSpellPanel learnSpells = null;
|
|
|
|
|
@NonFinal ObservableListener<UpdateClassWithLevelPanel, BoolGate> learnAndPrepareListener = null;
|
|
@NonFinal ObservableListener<UpdateClassWithLevelPanel, BoolGate> learnAndPrepareListener = null;
|
|
|
|
|
|
|
|
public UpdateClassWithLevelPanel(LevelUpClassInfo info, VoidVoidFunction back,
|
|
public UpdateClassWithLevelPanel(LevelUpClassInfo info, VoidVoidFunction back,
|
|
|
Consumer<Boolean> setReady) {
|
|
Consumer<Boolean> setReady) {
|
|
|
|
|
+ this.levelUpInfo = info;
|
|
|
info.ddClass.getLevel().value(info.toLevel);
|
|
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};
|
|
@@ -70,7 +78,7 @@ class UpdateClassWithLevelPanel extends JPanel {
|
|
|
});
|
|
});
|
|
|
tabbedPane.addTab("Features", null, features, null);
|
|
tabbedPane.addTab("Features", null, features, null);
|
|
|
|
|
|
|
|
- JPanel skills = new SkillLevelUpPanel(info.ddCharacter, info.ddClass) {
|
|
|
|
|
|
|
+ skills = new SkillLevelUpPanel(info.ddCharacter, info.ddClass) {
|
|
|
@Override public void setIsReady(boolean b) {
|
|
@Override public void setIsReady(boolean b) {
|
|
|
readyCount.set(CHOOSE_SKILL_INDEX, b);
|
|
readyCount.set(CHOOSE_SKILL_INDEX, b);
|
|
|
ObserverDispatch.notifySubscribers(readyCount, null);
|
|
ObserverDispatch.notifySubscribers(readyCount, null);
|
|
@@ -79,30 +87,12 @@ 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.set(1, !sb.learnsSpells());
|
|
|
|
|
- readyCount.set(2, !sb.preparesSpells());
|
|
|
|
|
|
|
+ readyCount.set(LEARN_SPELL_INDEX, !sb.learnsSpells());
|
|
|
|
|
+ readyCount.set(PREPARE_SPELL_INDEX, !sb.preparesSpells());
|
|
|
if (sb.learnsSpells()) {
|
|
if (sb.learnsSpells()) {
|
|
|
- LevelUpSpellPanel spells = new LevelUpSpellPanel(LEARN,
|
|
|
|
|
- new SelectSpellsPanel.Info(info.ddCharacter, info.ddClass),
|
|
|
|
|
- readyCount.handle(LEARN_SPELL_INDEX));
|
|
|
|
|
- tabbedPane.addTab("Learn Spells", null, spells, null);
|
|
|
|
|
- if (sb.preparesSpells()) {
|
|
|
|
|
- learnAndPrepareListener = new ObservableListener<>(this, (c, v) -> {
|
|
|
|
|
- if (v.get(LEARN_SPELL_INDEX)) {
|
|
|
|
|
- c.createPrepareLearnedSpellPanel(info, spells);
|
|
|
|
|
- } else {
|
|
|
|
|
- c.tabbedPane.remove(learnSpells);
|
|
|
|
|
- c.learnSpells = null;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- learnAndPrepareListener.setObserved(readyCount);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (sb.preparesSpells()) {
|
|
|
|
|
- LevelUpSpellPanel spells = new LevelUpSpellPanel(PREPARE,
|
|
|
|
|
- new SelectSpellsPanel.Info(info.ddCharacter, info.ddClass),
|
|
|
|
|
- readyCount.handle(PREPARE_SPELL_INDEX));
|
|
|
|
|
- tabbedPane.addTab("Prepare Spells", null, spells, null);
|
|
|
|
|
|
|
+ createPanelsForLearnSpell(sb);
|
|
|
|
|
+ } else if (sb.preparesSpells()) {
|
|
|
|
|
+ createPanelForPrepareSpells();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -139,7 +129,32 @@ class UpdateClassWithLevelPanel extends JPanel {
|
|
|
listener.setObserved(readyCount);
|
|
listener.setObserved(readyCount);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void createPrepareLearnedSpellPanel(LevelUpClassInfo info, LevelUpSpellPanel spells) {
|
|
|
|
|
|
|
+ private void createPanelForPrepareSpells() {
|
|
|
|
|
+ LevelUpSpellPanel spells = new LevelUpSpellPanel(PREPARE,
|
|
|
|
|
+ new SelectSpellsPanel.Info(levelUpInfo.ddCharacter, levelUpInfo.ddClass),
|
|
|
|
|
+ readyCount.handle(PREPARE_SPELL_INDEX));
|
|
|
|
|
+ tabbedPane.addTab("Prepare Spells", null, spells, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void createPanelsForLearnSpell(DDSpellbook sb) {
|
|
|
|
|
+ learnSpells = Optional.of(new LevelUpSpellPanel(LEARN,
|
|
|
|
|
+ new SelectSpellsPanel.Info(levelUpInfo.ddCharacter, levelUpInfo.ddClass),
|
|
|
|
|
+ readyCount.handle(LEARN_SPELL_INDEX)));
|
|
|
|
|
+ tabbedPane.addTab("Learn Spells", null, learnSpells.get(), null);
|
|
|
|
|
+ if (sb.preparesSpells()) {
|
|
|
|
|
+ learnAndPrepareListener = new ObservableListener<>(this, (c, v) -> {
|
|
|
|
|
+ if (v.get(LEARN_SPELL_INDEX)) {
|
|
|
|
|
+ c.createPrepareLearnedSpellPanel(learnSpells.get());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ c.tabbedPane.remove(prepSpells.get());
|
|
|
|
|
+ c.prepSpells = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ learnAndPrepareListener.setObserved(readyCount);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void createPrepareLearnedSpellPanel(LevelUpSpellPanel spells) {
|
|
|
LevelUpSpellPanel.SpellPicker pick = new LevelUpSpellPanel.SpellPicker() {
|
|
LevelUpSpellPanel.SpellPicker pick = new LevelUpSpellPanel.SpellPicker() {
|
|
|
@Override
|
|
@Override
|
|
|
public List<List<Integer>> getSpellCounts(Info info) {
|
|
public List<List<Integer>> getSpellCounts(Info info) {
|
|
@@ -156,10 +171,10 @@ class UpdateClassWithLevelPanel extends JPanel {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- learnSpells = new LevelUpSpellPanel(pick,
|
|
|
|
|
- new SelectSpellsPanel.Info(info.ddCharacter, info.ddClass),
|
|
|
|
|
- readyCount.handle(PREPARE_SPELL_INDEX));
|
|
|
|
|
- tabbedPane.addTab("Prepare Spells", null, learnSpells, null);
|
|
|
|
|
|
|
+ prepSpells = Optional.of(new LevelUpSpellPanel(pick,
|
|
|
|
|
+ new SelectSpellsPanel.Info(levelUpInfo.ddCharacter, levelUpInfo.ddClass),
|
|
|
|
|
+ readyCount.handle(PREPARE_SPELL_INDEX)));
|
|
|
|
|
+ tabbedPane.addTab("Prepare Spells", null, prepSpells.get(), null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -168,4 +183,20 @@ class UpdateClassWithLevelPanel extends JPanel {
|
|
|
ObserverDispatch.unsubscribeAll(listener);
|
|
ObserverDispatch.unsubscribeAll(listener);
|
|
|
ObserverDispatch.unsubscribeAll(learnAndPrepareListener);
|
|
ObserverDispatch.unsubscribeAll(learnAndPrepareListener);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public void commitAllChanges() {
|
|
|
|
|
+ final String className = levelUpInfo.ddClass.getName();
|
|
|
|
|
+ skills.commitAllChanges();
|
|
|
|
|
+ learnSpells.ifPresent(pan -> {});
|
|
|
|
|
+ prepSpells.ifPresent(pan -> {});
|
|
|
|
|
+ final Set<DDCharacterClass> classes = levelUpInfo.ddCharacter.getClasses();
|
|
|
|
|
+ if (classes.stream().map(DDCharacterClass::getName).anyMatch(className::equals)) {
|
|
|
|
|
+ // Update class to new data
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // New class
|
|
|
|
|
+ }
|
|
|
|
|
+ // TODO: Acquire features
|
|
|
|
|
+ // TODO: Update spellbook
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|