|
|
@@ -9,8 +9,6 @@ import org.leumasjaffe.charsheet.model.observable.IntValue;
|
|
|
import org.leumasjaffe.charsheet.model.skill.DDSkill;
|
|
|
import org.leumasjaffe.charsheet.util.StringHelper;
|
|
|
import org.leumasjaffe.observer.IndirectObservableListener;
|
|
|
-import org.leumasjaffe.observer.Observable;
|
|
|
-import org.leumasjaffe.observer.ObservableListener;
|
|
|
import org.leumasjaffe.observer.ObserverDispatch;
|
|
|
|
|
|
import lombok.AccessLevel;
|
|
|
@@ -21,6 +19,7 @@ import javax.swing.JCheckBox;
|
|
|
import java.awt.GridBagConstraints;
|
|
|
import javax.swing.JLabel;
|
|
|
import java.awt.Insets;
|
|
|
+import java.util.function.IntFunction;
|
|
|
import java.awt.Dimension;
|
|
|
import javax.swing.JTextField;
|
|
|
import java.awt.Color;
|
|
|
@@ -37,13 +36,17 @@ public class SkillLevelUpLine extends JPanel {
|
|
|
*
|
|
|
*/
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
- ObservableListener<JTextField, IntValue> modifierListener;
|
|
|
+ boolean isClassSkill;
|
|
|
+ DDSkill skill;
|
|
|
+ IntValue current;
|
|
|
IndirectObservableListener<JTextField, DDCharacter> totalListener;
|
|
|
-
|
|
|
+
|
|
|
public SkillLevelUpLine(final DDCharacter chara, final DDCharacterClass cclass, final DDSkill skill, IntValue pointsAvaliable) {
|
|
|
- final IntValue current = new IntValue(0);
|
|
|
- final int pointsPerRank = cclass.isClassSkill(skill.getName()) ? 1 : 2;
|
|
|
- final int startingRanks = skill.getRanks();
|
|
|
+ isClassSkill = cclass.isClassSkill(skill.getName());
|
|
|
+ this.skill = skill;
|
|
|
+ current = new IntValue(0);
|
|
|
+ final int pointsPerRank = isClassSkill ? 1 : 2;
|
|
|
+ final int maxPoints = (chara.getLevel() + 3) / pointsPerRank - skill.getRanks().value();
|
|
|
|
|
|
setBorder(new MatteBorder(0, 0, 1, 0, (Color) new Color(0, 0, 0)));
|
|
|
setPreferredSize(new Dimension(475, 22));
|
|
|
@@ -186,50 +189,46 @@ public class SkillLevelUpLine extends JPanel {
|
|
|
add(points, gbc_points);
|
|
|
points.setColumns(10);
|
|
|
|
|
|
+ IntFunction<Void> lambda = (value) -> {
|
|
|
+ pointsAvaliable.value(pointsAvaliable.value() - (value * pointsPerRank));
|
|
|
+ current.value(current.value() + value);
|
|
|
+ points.setText(Integer.toString(current.value()));
|
|
|
+ ObserverDispatch.notifySubscribers(pointsAvaliable, this);
|
|
|
+ ObserverDispatch.notifySubscribers(current, this);
|
|
|
+ return null;
|
|
|
+ };
|
|
|
+
|
|
|
plus.addActionListener((e) -> {
|
|
|
- if (pointsAvaliable.value() >= pointsPerRank) {
|
|
|
- pointsAvaliable.value(pointsAvaliable.value() - pointsPerRank);
|
|
|
- current.value(current.value() + 1);
|
|
|
- points.setText(Integer.toString(current.value()));
|
|
|
- ObserverDispatch.notifySubscribers(pointsAvaliable, this);
|
|
|
- } else {
|
|
|
- // TODO warning
|
|
|
- }
|
|
|
+ if (pointsAvaliable.value() >= pointsPerRank && current.value() < maxPoints) { lambda.apply(1); }
|
|
|
});
|
|
|
minus.addActionListener((e) -> {
|
|
|
- if (current.value() > 0) {
|
|
|
- pointsAvaliable.value(pointsAvaliable.value() + pointsPerRank);
|
|
|
- current.value(current.value() - 1);
|
|
|
- points.setText(Integer.toString(current.value()));
|
|
|
- ObserverDispatch.notifySubscribers(pointsAvaliable, this);
|
|
|
- } else {
|
|
|
- // TODO warning
|
|
|
- }
|
|
|
+ if (current.value() > 0) { lambda.apply(-1); }
|
|
|
});
|
|
|
|
|
|
if ( skill.getAbility().isEmpty() ) {
|
|
|
totalListener = new IndirectObservableListener<>(total,
|
|
|
(c, v) -> {
|
|
|
- c.setText(StringHelper.toString(skill.getRanks()));
|
|
|
+ c.setText(StringHelper.toString(skill.getRanks().value() + current.value()));
|
|
|
});
|
|
|
- modifierListener = null;
|
|
|
- totalListener.setObserved(chara, new Observable());
|
|
|
+ totalListener.setObserved(chara, current);
|
|
|
} else {
|
|
|
totalListener = new IndirectObservableListener<>(total,
|
|
|
(c, v) -> {
|
|
|
- final float skillRanks = skill.getRanks();
|
|
|
+ final int skillRanks = skill.getRanks().value();
|
|
|
final int mod = Ability.modifier(Ability.fields.get(skill.getAbility())
|
|
|
.apply(chara.getAbilities().getBase()).value());
|
|
|
- c.setText(StringHelper.toString(skillRanks + mod));
|
|
|
+ c.setText(StringHelper.toString(skillRanks + mod + current.value()));
|
|
|
});
|
|
|
- modifierListener = new ObservableListener<>(modifier,
|
|
|
- ( c, v ) -> c.setText(StringHelper.toString(Ability.modifier(v.value()))));
|
|
|
|
|
|
final IntValue abilScore = Ability.fields.get(skill.getAbility())
|
|
|
.apply(chara.getAbilities().getBase());
|
|
|
- totalListener.setObserved(chara, abilScore);
|
|
|
- modifierListener.setObserved(abilScore);
|
|
|
+ modifier.setText(StringHelper.toString(Ability.modifier(abilScore.value())));
|
|
|
+ totalListener.setObserved(chara, current);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ void applyChange() {
|
|
|
+ skill.spendPoints(current.value(), !isClassSkill);
|
|
|
+ ObserverDispatch.notifySubscribers(skill.getRanks(), this);
|
|
|
+ }
|
|
|
}
|