ソースを参照

Add a button for creating a new skill from a wildcard skill.
Adjust GUI elements for SkilLevelUpLine components.
Use the isWildcardSkill() function instead of doing a manual check.

Sam Jaffe 8 年 前
コミット
7d84c4b9dc

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

@@ -55,7 +55,7 @@ class NormalSkillLevelUpLine extends SkillLevelUpLine {
 		final int pointsPerRank = isClassSkill ? 1 : 2;
 		final int maxPoints = (chara.getLevel() + 3) - skill.getRanks().value();
 		
-		setBorder(new MatteBorder(0, 0, 1, 0, (Color) new Color(0, 0, 0)));
+		setBorder(new MatteBorder(0, 0, 1, 0, new Color(0, 0, 0)));
 		setPreferredSize(new Dimension(480, 22));
 		GridBagLayout gridBagLayout = new GridBagLayout();
 		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
@@ -157,12 +157,11 @@ class NormalSkillLevelUpLine extends SkillLevelUpLine {
 		add(ranks, gbc_ranks);
 		ranks.setColumns(10);
 		
-		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);
+		Component horizontalStrut = Box.createHorizontalStrut(10);
+		GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();
+		gbc_horizontalStrut.gridx = 8;
+		gbc_horizontalStrut.gridy = 0;
+		add(horizontalStrut, gbc_horizontalStrut);
 		
 		JButton plus = new JButton("+");
 		plus.setMargin(new Insets(2, 2, 2, 2));
@@ -197,6 +196,12 @@ class NormalSkillLevelUpLine extends SkillLevelUpLine {
 		add(points, gbc_points);
 		points.setColumns(10);
 		
+		Component horizontalStrut_1 = Box.createHorizontalStrut(5);
+		GridBagConstraints gbc_horizontalStrut_1 = new GridBagConstraints();
+		gbc_horizontalStrut_1.gridx = 12;
+		gbc_horizontalStrut_1.gridy = 0;
+		add(horizontalStrut_1, gbc_horizontalStrut_1);
+
 		IntFunction<Void> lambda = (value) -> {
 			pointsAvaliable.value(pointsAvaliable.value() - (value * pointsPerRank));
 			current.value(current.value() + value);
@@ -218,12 +223,6 @@ class NormalSkillLevelUpLine extends SkillLevelUpLine {
 			final int mod = p.ability.map(v -> v.baseModifier()).orElse(0);
 			c.setText(StringHelper.toString(skillRanks + mod + p.points.value()));
 		});
-
-		Component horizontalStrut_1 = Box.createHorizontalStrut(5);
-		GridBagConstraints gbc_horizontalStrut_1 = new GridBagConstraints();
-		gbc_horizontalStrut_1.gridx = 12;
-		gbc_horizontalStrut_1.gridy = 0;
-		add(horizontalStrut_1, gbc_horizontalStrut_1);
 		final Optional<Ability.Scores> ability = getAbility(chara, skill);
 		ability.ifPresent(v -> modifier.setText(StringHelper.toString(v.baseModifier())));
 		totalListener.setObserved(new TotalPacket(ability, skill, current), current, skill);

+ 0 - 3
src/main/lombok/org/leumasjaffe/charsheet/view/skills/SkillLevelUpLine.java

@@ -2,10 +2,7 @@ package org.leumasjaffe.charsheet.view.skills;
 
 import javax.swing.JPanel;
 
-import org.leumasjaffe.charsheet.model.skill.DDSkill;
-
 @SuppressWarnings("serial")
 abstract class SkillLevelUpLine extends JPanel {
-	abstract DDSkill getSkill(); // TODO: ?
 	abstract void applyChange();
 }

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

@@ -91,8 +91,8 @@ public abstract class SkillLevelUpPanel extends JPanel {
 		lines = new ArrayList<>();
 		final DDSkills skills = chara.getSkills();
 		skills.getSkills().stream().forEach(skill -> {
-			SkillLevelUpLine line = skill.getName().contains("(*)")
-					? new WildcardSkillLevelUpLine(chara, cclass, skill)
+			SkillLevelUpLine line = skill.isWildcardSkill()
+					? new WildcardSkillLevelUpLine(chara, cclass, skills, skill)
 					: new NormalSkillLevelUpLine(chara, cclass, skill, pointsAvailable);
 			skillPanel.add(line);
 			lines.add(line);

+ 44 - 11
src/main/lombok/org/leumasjaffe/charsheet/view/skills/WildcardSkillLevelUpLine.java

@@ -5,31 +5,37 @@ import org.leumasjaffe.charsheet.model.DDCharacter;
 import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.observable.IntValue;
 import org.leumasjaffe.charsheet.model.skill.DDSkill;
+import org.leumasjaffe.charsheet.model.skill.DDSkills;
 import org.leumasjaffe.charsheet.util.AbilityHelper;
+import org.leumasjaffe.observer.ObserverDispatch;
 
 import lombok.AccessLevel;
-import lombok.Getter;
 import lombok.Value;
 import lombok.experimental.FieldDefaults;
 
 import java.awt.GridBagLayout;
+
+import javax.swing.Box;
+import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import java.awt.GridBagConstraints;
 import javax.swing.JLabel;
 import java.awt.Insets;
 import java.util.Optional;
 import java.awt.Dimension;
+import java.awt.Font;
+
 import javax.swing.JTextField;
 import java.awt.Color;
+import java.awt.Component;
+
 import javax.swing.border.MatteBorder;
 import javax.swing.SwingConstants;
 import javax.swing.JPanel;
 
 @SuppressWarnings("serial")
 @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
-class WildcardSkillLevelUpLine extends SkillLevelUpLine {
-	@Getter DDSkill skill;
-	
+class WildcardSkillLevelUpLine extends SkillLevelUpLine {	
 	@Value
 	private static final class TotalPacket {
 		Optional<Ability.Scores> ability;
@@ -38,15 +44,14 @@ class WildcardSkillLevelUpLine extends SkillLevelUpLine {
 	}
 	
 	public WildcardSkillLevelUpLine(final DDCharacter chara, final DDCharacterClass cclass, 
-			final DDSkill skill) {
-		this.skill = skill;
+			final DDSkills skillList, final DDSkill skill) {
 		
 		setBorder(new MatteBorder(0, 0, 1, 0, (Color) new Color(0, 0, 0)));
 		setPreferredSize(new Dimension(480, 22));
 		GridBagLayout gridBagLayout = new GridBagLayout();
-		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
+		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 		gridBagLayout.rowHeights = new int[]{0, 0};
-		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
+		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
 		gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
 		setLayout(gridBagLayout);
 		
@@ -77,7 +82,8 @@ class WildcardSkillLevelUpLine extends SkillLevelUpLine {
 		gbl_panel.rowWeights = new double[]{0.0, Double.MIN_VALUE};
 		panel.setLayout(gbl_panel);
 				
-		JLabel lblName = new JLabel(skill.getName().replaceAll("\\(.*", "("));
+		final String skillLead = skill.getName().replaceAll("\\(.*", "(");
+		JLabel lblName = new JLabel(skillLead);
 		GridBagConstraints gbc_lblName = new GridBagConstraints();
 		gbc_lblName.anchor = GridBagConstraints.EAST;
 		gbc_lblName.gridx = 0;
@@ -166,12 +172,39 @@ class WildcardSkillLevelUpLine extends SkillLevelUpLine {
 		ranks.setMaximumSize(new Dimension(30, 20));
 		ranks.setPreferredSize(new Dimension(30, 20));
 		GridBagConstraints gbc_ranks = new GridBagConstraints();
-		gbc_ranks.insets = new Insets(1, 0, 0, 0);
+		gbc_ranks.insets = new Insets(1, 0, 0, 5);
 		gbc_ranks.fill = GridBagConstraints.HORIZONTAL;
 		gbc_ranks.gridx = 7;
 		gbc_ranks.gridy = 0;
 		add(ranks, gbc_ranks);
-		ranks.setColumns(10);				
+		ranks.setColumns(10);
+		
+		Component horizontalStrut = Box.createHorizontalStrut(10);
+		GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();
+		gbc_horizontalStrut.gridx = 8;
+		gbc_horizontalStrut.gridy = 0;
+		add(horizontalStrut, gbc_horizontalStrut);
+		
+		JButton addSkill = new JButton("Add Skill");
+		addSkill.setMargin(new Insets(2, 2, 2, 2));
+		addSkill.setFont(new Font("Tahoma", Font.PLAIN, 8));
+		addSkill.setPreferredSize(new Dimension(55, 19));
+		addSkill.setMinimumSize(new Dimension(55, 19));
+		GridBagConstraints gbc_plus = new GridBagConstraints();
+		gbc_plus.insets = new Insets(1, 0, 0, 5);
+		gbc_plus.gridx = 9;
+		gbc_plus.gridy = 0;
+		add(addSkill, gbc_plus);
+		
+		addSkill.addActionListener(e -> {
+			final String input = textField.getText();
+			if (input.isEmpty()) { return; }
+			textField.setText("");
+			DDSkill newSkill = skillList.getSkill(skillLead + input + ")");
+			if (newSkill.getPointsSpent() == 0) { // Don't notify if I typed a skill I already know
+				ObserverDispatch.notifySubscribers(skillList);
+			}
+		});
 	}
 
 	private Optional<Ability.Scores> getAbility(final DDCharacter chara, final DDSkill skill) {