Selaa lähdekoodia

Put 'all' skills into DDSkills object.
TODO: Handle '(*)' skills

Sam Jaffe 8 vuotta sitten
vanhempi
commit
caf334d8fd

+ 6 - 3
src/main/lombok/org/leumasjaffe/charsheet/model/skill/DDSkillPrototype.java

@@ -18,13 +18,12 @@ import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.experimental.FieldDefaults;
 
-@AllArgsConstructor
-@Data
+@AllArgsConstructor @Data
 @FieldDefaults(level=AccessLevel.PRIVATE)
 public class DDSkillPrototype {
 	final String name;
 	final boolean requiresTraining;
-	String ability;
+	String ability = "";
 	
 	private static final Map<String, DDSkillPrototype> prototypes;
 	
@@ -58,6 +57,10 @@ public class DDSkillPrototype {
 			return Optional.ofNullable(prototypes.get(name));
 		}
 	}
+	
+	public static Stream<DDSkillPrototype> all() {
+		return prototypes.values().stream();
+	}
 
 	public static Stream<DDSkillPrototype> untrained() {
 		return prototypes.values().stream().filter(p -> !p.requiresTraining && !p.getName().contains("(*)"));

+ 2 - 1
src/main/lombok/org/leumasjaffe/charsheet/model/skill/DDSkills.java

@@ -21,7 +21,7 @@ public class DDSkills extends Observable.Instance {
 	
 	@JsonCreator
 	public DDSkills(Collection<DDSkill> in) {
-		skills.putAll(DDSkillPrototype.untrained().collect(Collectors.toMap(t -> t.getName(), t -> new DDSkill(t))));
+		skills.putAll(DDSkillPrototype.all().collect(Collectors.toMap(t -> t.getName(), t -> new DDSkill(t))));
 		skills.putAll(in.stream().collect(Collectors.toMap(t -> t.getName(), t -> t)));
 	}
 	
@@ -35,6 +35,7 @@ public class DDSkills extends Observable.Instance {
 	}
 
 	public Optional<DDSkill> getSkill(String name) {
+		// TODO: Put if absent?
 		return Optional.ofNullable(skills.get(name));
 	}
 }

+ 2 - 1
src/main/lombok/org/leumasjaffe/charsheet/view/SkillTab.java

@@ -129,7 +129,8 @@ public class SkillTab extends JPanel {
 		skillPanel.removeAll();
 		int[] totalPoints = {0};
 		final DDSkills skills = model.getSkills();
-		skills.getSkills().stream().forEach( skill -> {
+		skills.getSkills().stream().filter(sk -> sk.getPointsSpent() > 0 || !sk.isRequiresTraining())
+		.forEach( skill -> {
 			skillPanel.add(new SkillLine(model, skill));
 			totalPoints[0] += skill.getPointsSpent();
 		});

+ 13 - 12
src/main/lombok/org/leumasjaffe/charsheet/view/skills/SkillLevelUpLine.java

@@ -52,7 +52,8 @@ class SkillLevelUpLine extends JPanel {
 		IntValue points;
 	}
 	
-	public SkillLevelUpLine(final DDCharacter chara, final DDCharacterClass cclass, final DDSkill skill, IntValue pointsAvaliable) {
+	public SkillLevelUpLine(final DDCharacter chara, final DDCharacterClass cclass, 
+			final DDSkill skill, IntValue pointsAvaliable) {
 		isClassSkill = cclass.isClassSkill(skill.getName());
 		this.skill = skill;
 		current = new IntValue(0);
@@ -161,18 +162,18 @@ class SkillLevelUpLine extends JPanel {
 		add(ranks, gbc_ranks);
 		ranks.setColumns(10);
 		
-		Component horizontalStrut = Box.createHorizontalStrut(20);
-		GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();
-		gbc_horizontalStrut.insets = new Insets(0, 0, 0, 5);
-		gbc_horizontalStrut.gridx = 8;
-		gbc_horizontalStrut.gridy = 0;
-		add(horizontalStrut, gbc_horizontalStrut);
+		Component horizontalGlue = Box.createHorizontalGlue();
+		GridBagConstraints gbc_horizontalGlue = new GridBagConstraints();
+		gbc_horizontalGlue.insets = new Insets(0, 0, 0, 5);
+		gbc_horizontalGlue.gridx = 8;
+		gbc_horizontalGlue.gridy = 0;
+		add(horizontalGlue, gbc_horizontalGlue);
 		
 		JButton plus = new JButton("+");
 		plus.setMargin(new Insets(2, 2, 2, 2));
 		plus.setFont(new Font("Tahoma", Font.PLAIN, 8));
-		plus.setPreferredSize(new Dimension(30, 19));
-		plus.setMinimumSize(new Dimension(30, 19));
+		plus.setPreferredSize(new Dimension(25, 19));
+		plus.setMinimumSize(new Dimension(25, 19));
 		GridBagConstraints gbc_plus = new GridBagConstraints();
 		gbc_plus.insets = new Insets(0, 0, 1, 5);
 		gbc_plus.gridx = 9;
@@ -182,8 +183,8 @@ class SkillLevelUpLine extends JPanel {
 		JButton minus = new JButton("-");
 		minus.setMargin(new Insets(2, 2, 2, 2));
 		minus.setFont(new Font("Tahoma", Font.PLAIN, 8));
-		minus.setMinimumSize(new Dimension(30, 19));
-		minus.setPreferredSize(new Dimension(30, 19));
+		minus.setMinimumSize(new Dimension(25, 19));
+		minus.setPreferredSize(new Dimension(25, 19));
 		GridBagConstraints gbc_minus = new GridBagConstraints();
 		gbc_minus.insets = new Insets(0, 0, 1, 5);
 		gbc_minus.gridx = 10;
@@ -234,7 +235,7 @@ class SkillLevelUpLine extends JPanel {
 	}
 
 	private Optional<Ability.Scores> getAbility(final DDCharacter chara, final DDSkill skill) {
-		if (skill.getAbility().isEmpty()) { return Optional.empty(); }
+		if (skill.getAbility() == null || skill.getAbility().isEmpty()) { return Optional.empty(); }
 		else { return Optional.of(AbilityHelper.get(chara, skill)); }
 	}
 

+ 4 - 2
src/main/lombok/org/leumasjaffe/charsheet/view/skills/SkillLevelUpPanel.java

@@ -23,6 +23,7 @@ import org.leumasjaffe.observer.ObserverDispatch;
 import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.experimental.FieldDefaults;
+import javax.swing.ScrollPaneConstants;
 
 @SuppressWarnings("serial")
 @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
@@ -75,6 +76,7 @@ public abstract class SkillLevelUpPanel extends JPanel {
 		pointsRemaining.setColumns(10);
 		
 		JScrollPane scrollPane = new JScrollPane();
+		scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
 		GridBagConstraints gbc_scrollPane = new GridBagConstraints();
 		gbc_scrollPane.fill = GridBagConstraints.BOTH;
 		gbc_scrollPane.gridx = 0;
@@ -82,13 +84,13 @@ public abstract class SkillLevelUpPanel extends JPanel {
 		add(scrollPane, gbc_scrollPane);
 		
 		JPanel skillPanel = new JPanel();
-		skillPanel.setMinimumSize(new Dimension(300, 200));
+		scrollPane.setPreferredSize(new Dimension(480, 300));
 		scrollPane.setViewportView(skillPanel);
 		skillPanel.setLayout(new VerticalLayout());
 				
 		lines = new ArrayList<>();
 		final DDSkills skills = chara.getSkills();
-		skills.getSkills().stream().forEach( skill -> {
+		skills.getSkills().stream().forEach(skill -> {
 			SkillLevelUpLine line = new SkillLevelUpLine(chara, cclass, skill, pointsAvaliable);
 			skillPanel.add(line);
 			lines.add(line);