|
|
@@ -0,0 +1,244 @@
|
|
|
+package org.leumasjaffe.charsheet.view.level;
|
|
|
+
|
|
|
+import javax.swing.JPanel;
|
|
|
+
|
|
|
+import org.leumasjaffe.charsheet.model.HitPoints;
|
|
|
+import org.leumasjaffe.charsheet.model.observable.BoolGate;
|
|
|
+import org.leumasjaffe.event.AnyActionDocumentListener;
|
|
|
+import org.leumasjaffe.observer.ObserverDispatch;
|
|
|
+
|
|
|
+import lombok.AccessLevel;
|
|
|
+import lombok.experimental.FieldDefaults;
|
|
|
+import java.awt.GridBagLayout;
|
|
|
+import javax.swing.JLabel;
|
|
|
+import java.awt.GridBagConstraints;
|
|
|
+import java.awt.Color;
|
|
|
+import javax.swing.border.LineBorder;
|
|
|
+
|
|
|
+import java.awt.Font;
|
|
|
+import javax.swing.SwingConstants;
|
|
|
+import java.awt.Dimension;
|
|
|
+import java.awt.Insets;
|
|
|
+import java.security.SecureRandom;
|
|
|
+
|
|
|
+import javax.swing.JTextField;
|
|
|
+import javax.swing.JButton;
|
|
|
+
|
|
|
+@SuppressWarnings("serial")
|
|
|
+@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
|
|
|
+public class LU_HitDicePanel extends JPanel {
|
|
|
+ JTextField txtInput;
|
|
|
+ JButton btnRoll;
|
|
|
+
|
|
|
+ public LU_HitDicePanel(LevelUpClassInfo info, BoolGate.Handle handle) {
|
|
|
+ final int maxHealth = info.ddClass.getProto().getHitDice();
|
|
|
+ GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
+ gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0};
|
|
|
+ gridBagLayout.rowHeights = new int[]{0, 0, 0};
|
|
|
+ gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
|
|
+ gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0};
|
|
|
+ setLayout(gridBagLayout);
|
|
|
+
|
|
|
+ JLabel lblRollHealthIncrease = new JLabel("Roll Health Increase");
|
|
|
+ lblRollHealthIncrease.setPreferredSize(new Dimension(60, 22));
|
|
|
+ lblRollHealthIncrease.setOpaque(true);
|
|
|
+ lblRollHealthIncrease.setMinimumSize(new Dimension(50, 25));
|
|
|
+ lblRollHealthIncrease.setMaximumSize(new Dimension(50, 25));
|
|
|
+ lblRollHealthIncrease.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ lblRollHealthIncrease.setForeground(Color.WHITE);
|
|
|
+ lblRollHealthIncrease.setFont(new Font("Tahoma", Font.BOLD, 14));
|
|
|
+ lblRollHealthIncrease.setBorder(new LineBorder(new Color(255, 255, 255), 0));
|
|
|
+ lblRollHealthIncrease.setBackground(Color.BLACK);
|
|
|
+ GridBagConstraints gbc_lblRollHealthIncrease = new GridBagConstraints();
|
|
|
+ gbc_lblRollHealthIncrease.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ gbc_lblRollHealthIncrease.gridwidth = 4;
|
|
|
+ gbc_lblRollHealthIncrease.insets = new Insets(0, 0, 2, 0);
|
|
|
+ gbc_lblRollHealthIncrease.gridx = 0;
|
|
|
+ gbc_lblRollHealthIncrease.gridy = 0;
|
|
|
+ add(lblRollHealthIncrease, gbc_lblRollHealthIncrease);
|
|
|
+
|
|
|
+ JPanel panel = new JPanel();
|
|
|
+ GridBagConstraints gbc_panel = new GridBagConstraints();
|
|
|
+ gbc_panel.insets = new Insets(0, 0, 2, 5);
|
|
|
+ gbc_panel.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ gbc_panel.gridx = 0;
|
|
|
+ gbc_panel.gridy = 1;
|
|
|
+ add(panel, gbc_panel);
|
|
|
+ GridBagLayout gbl_panel = new GridBagLayout();
|
|
|
+ gbl_panel.columnWidths = new int[]{0};
|
|
|
+ gbl_panel.rowHeights = new int[]{0, 0};
|
|
|
+ gbl_panel.columnWeights = new double[]{Double.MIN_VALUE};
|
|
|
+ gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
|
+ panel.setLayout(gbl_panel);
|
|
|
+
|
|
|
+ JLabel lblCurrent = new JLabel("Current");
|
|
|
+ lblCurrent.setPreferredSize(new Dimension(50, 11));
|
|
|
+ lblCurrent.setOpaque(true);
|
|
|
+ lblCurrent.setMinimumSize(new Dimension(50, 25));
|
|
|
+ lblCurrent.setMaximumSize(new Dimension(50, 25));
|
|
|
+ lblCurrent.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ lblCurrent.setForeground(Color.WHITE);
|
|
|
+ lblCurrent.setFont(new Font("Tahoma", Font.BOLD, 10));
|
|
|
+ lblCurrent.setBorder(new LineBorder(new Color(255, 255, 255), 0));
|
|
|
+ lblCurrent.setBackground(Color.BLACK);
|
|
|
+ GridBagConstraints gbc_lblCurrent = new GridBagConstraints();
|
|
|
+ gbc_lblCurrent.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ gbc_lblCurrent.gridx = 0;
|
|
|
+ gbc_lblCurrent.gridy = 0;
|
|
|
+ panel.add(lblCurrent, gbc_lblCurrent);
|
|
|
+
|
|
|
+ JLabel lblHealth = new JLabel("Health");
|
|
|
+ lblHealth.setPreferredSize(new Dimension(50, 11));
|
|
|
+ lblHealth.setOpaque(true);
|
|
|
+ lblHealth.setMinimumSize(new Dimension(50, 25));
|
|
|
+ lblHealth.setMaximumSize(new Dimension(50, 25));
|
|
|
+ lblHealth.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ lblHealth.setForeground(Color.WHITE);
|
|
|
+ lblHealth.setFont(new Font("Tahoma", Font.BOLD, 10));
|
|
|
+ lblHealth.setBorder(new LineBorder(new Color(255, 255, 255), 0));
|
|
|
+ lblHealth.setBackground(Color.BLACK);
|
|
|
+ GridBagConstraints gbc_lblHealth = new GridBagConstraints();
|
|
|
+ gbc_lblHealth.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ gbc_lblHealth.gridx = 0;
|
|
|
+ gbc_lblHealth.gridy = 1;
|
|
|
+ panel.add(lblHealth, gbc_lblHealth);
|
|
|
+
|
|
|
+ JTextField txtCurrenthealth = new JTextField(Integer.toString(info.ddCharacter.getHealth().getTotal().value()));
|
|
|
+ txtCurrenthealth.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ txtCurrenthealth.setEditable(false);
|
|
|
+ txtCurrenthealth.setColumns(3);
|
|
|
+ txtCurrenthealth.setMinimumSize(new Dimension(30, 20));
|
|
|
+ txtCurrenthealth.setMaximumSize(new Dimension(30, 20));
|
|
|
+ txtCurrenthealth.setPreferredSize(new Dimension(30, 20));
|
|
|
+ txtCurrenthealth.setBorder(new LineBorder(Color.BLACK));
|
|
|
+ GridBagConstraints gbc_txtCurrenthealth = new GridBagConstraints();
|
|
|
+ gbc_txtCurrenthealth.insets = new Insets(0, 0, 2, 5);
|
|
|
+ gbc_txtCurrenthealth.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ gbc_txtCurrenthealth.gridx = 1;
|
|
|
+ gbc_txtCurrenthealth.gridy = 1;
|
|
|
+ add(txtCurrenthealth, gbc_txtCurrenthealth);
|
|
|
+
|
|
|
+ JLabel lblHitDice = new JLabel("Hit Dice");
|
|
|
+ lblHitDice.setPreferredSize(new Dimension(60, 22));
|
|
|
+ lblHitDice.setOpaque(true);
|
|
|
+ lblHitDice.setMinimumSize(new Dimension(50, 25));
|
|
|
+ lblHitDice.setMaximumSize(new Dimension(50, 25));
|
|
|
+ lblHitDice.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ lblHitDice.setForeground(Color.WHITE);
|
|
|
+ lblHitDice.setFont(new Font("Tahoma", Font.BOLD, 14));
|
|
|
+ lblHitDice.setBorder(new LineBorder(new Color(255, 255, 255), 0));
|
|
|
+ lblHitDice.setBackground(Color.BLACK);
|
|
|
+ GridBagConstraints gbc_lblHitDice = new GridBagConstraints();
|
|
|
+ gbc_lblHitDice.anchor = GridBagConstraints.EAST;
|
|
|
+ gbc_lblHitDice.insets = new Insets(0, 0, 2, 5);
|
|
|
+ gbc_lblHitDice.gridx = 2;
|
|
|
+ gbc_lblHitDice.gridy = 1;
|
|
|
+ add(lblHitDice, gbc_lblHitDice);
|
|
|
+
|
|
|
+ JTextField textHitDie = new JTextField("d" + Integer.toString(maxHealth));
|
|
|
+ textHitDie.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ textHitDie.setEditable(false);
|
|
|
+ textHitDie.setColumns(2);
|
|
|
+ textHitDie.setMinimumSize(new Dimension(30, 20));
|
|
|
+ textHitDie.setMaximumSize(new Dimension(30, 20));
|
|
|
+ textHitDie.setPreferredSize(new Dimension(30, 20));
|
|
|
+ textHitDie.setBorder(new LineBorder(Color.BLACK));
|
|
|
+ GridBagConstraints gbc_textHitDie = new GridBagConstraints();
|
|
|
+ gbc_textHitDie.insets = new Insets(0, 0, 2, 0);
|
|
|
+ gbc_textHitDie.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ gbc_textHitDie.gridx = 3;
|
|
|
+ gbc_textHitDie.gridy = 1;
|
|
|
+ add(textHitDie, gbc_textHitDie);
|
|
|
+
|
|
|
+ JLabel lblRoll = new JLabel("Roll");
|
|
|
+ lblRoll.setPreferredSize(new Dimension(60, 22));
|
|
|
+ lblRoll.setOpaque(true);
|
|
|
+ lblRoll.setMinimumSize(new Dimension(50, 25));
|
|
|
+ lblRoll.setMaximumSize(new Dimension(50, 25));
|
|
|
+ lblRoll.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ lblRoll.setForeground(Color.WHITE);
|
|
|
+ lblRoll.setFont(new Font("Tahoma", Font.BOLD, 14));
|
|
|
+ lblRoll.setBorder(new LineBorder(new Color(255, 255, 255), 0));
|
|
|
+ lblRoll.setBackground(Color.BLACK);
|
|
|
+ GridBagConstraints gbc_lblRoll = new GridBagConstraints();
|
|
|
+ gbc_lblRoll.anchor = GridBagConstraints.EAST;
|
|
|
+ gbc_lblRoll.insets = new Insets(0, 0, 0, 5);
|
|
|
+ gbc_lblRoll.gridx = 0;
|
|
|
+ gbc_lblRoll.gridy = 2;
|
|
|
+ add(lblRoll, gbc_lblRoll);
|
|
|
+
|
|
|
+ txtInput = new JTextField();
|
|
|
+ txtInput.setPreferredSize(new Dimension(30, 20));
|
|
|
+ txtInput.setMinimumSize(new Dimension(30, 20));
|
|
|
+ txtInput.setMaximumSize(new Dimension(30, 20));
|
|
|
+ txtInput.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ txtInput.setColumns(3);
|
|
|
+ txtInput.setBorder(new LineBorder(Color.BLACK));
|
|
|
+ GridBagConstraints gbc_txtInput = new GridBagConstraints();
|
|
|
+ gbc_txtInput.insets = new Insets(0, 0, 0, 5);
|
|
|
+ gbc_txtInput.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ gbc_txtInput.gridx = 1;
|
|
|
+ gbc_txtInput.gridy = 2;
|
|
|
+ add(txtInput, gbc_txtInput);
|
|
|
+ AnyActionDocumentListener.emptyOrText(txtInput,
|
|
|
+ evt -> txtInput.setBackground(Color.WHITE),
|
|
|
+ evt -> {
|
|
|
+ final int value = getRoll();
|
|
|
+ final boolean good = value > 0 && value <= maxHealth;
|
|
|
+ txtInput.setBackground(good ? new Color(198,239,206) : new Color(255,199,206));
|
|
|
+ handle.set(good);
|
|
|
+ });
|
|
|
+
|
|
|
+ JPanel panel_1 = new JPanel();
|
|
|
+ GridBagConstraints gbc_panel_1 = new GridBagConstraints();
|
|
|
+ gbc_panel_1.gridwidth = 2;
|
|
|
+ gbc_panel_1.fill = GridBagConstraints.BOTH;
|
|
|
+ gbc_panel_1.gridx = 2;
|
|
|
+ gbc_panel_1.gridy = 2;
|
|
|
+ add(panel_1, gbc_panel_1);
|
|
|
+ GridBagLayout gbl_panel_1 = new GridBagLayout();
|
|
|
+ gbl_panel_1.columnWidths = new int[]{0, 0};
|
|
|
+ gbl_panel_1.rowHeights = new int[]{0, 0};
|
|
|
+ gbl_panel_1.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
|
+ gbl_panel_1.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
|
+ panel_1.setLayout(gbl_panel_1);
|
|
|
+
|
|
|
+ btnRoll = new JButton("Roll");
|
|
|
+ btnRoll.setPreferredSize(new Dimension(75, 24));
|
|
|
+ GridBagConstraints gbc_btnRoll = new GridBagConstraints();
|
|
|
+ gbc_btnRoll.gridx = 0;
|
|
|
+ gbc_btnRoll.gridy = 0;
|
|
|
+ panel_1.add(btnRoll, gbc_btnRoll);
|
|
|
+ btnRoll.addActionListener(e -> {
|
|
|
+ final int result = new SecureRandom().nextInt(maxHealth) + 1;
|
|
|
+ setRoll(result);
|
|
|
+ handle.set(true);
|
|
|
+ });
|
|
|
+
|
|
|
+ if (info.toLevel == 1 && info.ddCharacter.getLevel() == 0) {
|
|
|
+ setRoll(maxHealth);
|
|
|
+ handle.set(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void commitChange(HitPoints hp) {
|
|
|
+ final int roll = getRoll();
|
|
|
+ hp.getRolled().value(hp.getRolled().value() + roll);
|
|
|
+ hp.getCurrent().value(hp.getCurrent().value() + roll);
|
|
|
+ hp.getTotal().value(hp.getTotal().value() + roll);
|
|
|
+ ObserverDispatch.notifySubscribers(hp.getRolled());
|
|
|
+ ObserverDispatch.notifySubscribers(hp.getCurrent());
|
|
|
+ ObserverDispatch.notifySubscribers(hp.getTotal());
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getRoll() {
|
|
|
+ if (!txtInput.getText().matches("^\\d+$")) return -1;
|
|
|
+ return Integer.parseInt(txtInput.getText());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setRoll(final int result) {
|
|
|
+ txtInput.setText(Integer.toString(result));
|
|
|
+ txtInput.setEditable(false);
|
|
|
+ btnRoll.setEnabled(false);
|
|
|
+ }
|
|
|
+}
|