implemented interactable gui, back/continue, new panels.

This commit is contained in:
Joshua-Ashton01
2022-11-10 10:50:59 -07:00
parent 582c6c41bc
commit 025550f4da
7 changed files with 209 additions and 11 deletions
+67 -11
View File
@@ -1,5 +1,6 @@
package GUI; package GUI;
import GUI.Panels.AbilityScorePanel;
import GUI.Panels.ChooseClassPanel; import GUI.Panels.ChooseClassPanel;
import GUI.Panels.ChooseRacePanel; import GUI.Panels.ChooseRacePanel;
import GUI.Panels.MainMenuPanel; import GUI.Panels.MainMenuPanel;
@@ -36,8 +37,11 @@ public class GUImanager extends JFrame {
public GUImanager (boolean returningUser) { public GUImanager (boolean returningUser) {
super("D&D Character Builder"); super("D&D Character Builder");
frameSetup(); frameSetup();
this.panels = new JPanel[]{new ChooseRacePanel(), new ChooseClassPanel()}; this.panels = new JPanel[]{new MainMenuPanel(), new ChooseRacePanel(), new ChooseClassPanel(), new AbilityScorePanel()};
this.lastPanel = 0;
this.currentPanel = 1;
this.nextPanel = 2;
/* if (returningUser) { /* if (returningUser) {
this.currentPanel = 0; this.currentPanel = 0;
@@ -48,11 +52,10 @@ public class GUImanager extends JFrame {
}*/ }*/
add(panels[currentPanel]); add(createMasterPanel());
} }
// TODO: Need to implement.
private void frameSetup() { private void frameSetup() {
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);
@@ -68,19 +71,72 @@ public class GUImanager extends JFrame {
} }
/* private JPanel createMasterPanel() {
NOTES: JPanel masterPanel = new JPanel();
I'm thinking of using CPU multi-threading to constantly check if a given creation panel's ableToContinue has become true, to update the GUI with a clickable "Continue" button. masterPanel.add(panels[currentPanel]);
Also. Continue button should be in GUI manager, otherwise the button's returned int of the next screen to display is obfuscated. JPanel navigationContainer = new JPanel(new GridLayout(1, 2, 10, 10));
navigationContainer.add(createBackButton());
navigationContainer.add(createContinueButton());
*/ masterPanel.add(navigationContainer);
private void clearAndReset(JPanel nextPanel) { return masterPanel;
removeAll(); }
add(nextPanel);
private JButton createBackButton() {
JButton button = new JButton("Back");
button.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lastPanel--;
currentPanel--;
nextPanel--;
clearAndReset();
}
}
);
return button;
}
private JButton createContinueButton() {
JButton button = new JButton("Continue");
button.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lastPanel++;
currentPanel++;
nextPanel++;
clearAndReset();
}
}
);
return button;
}
private void clearAndReset() {
getContentPane().removeAll();
add(createMasterPanel());
repaint(); repaint();
revalidate(); revalidate();
@@ -0,0 +1,122 @@
package GUI.Panels;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class AbilityScorePanel extends JPanel {
private JPanel[] statsPanels;
private int[] stats;
private String[] statNames;
private int currentIndex;
public AbilityScorePanel() {
super();
stats = new int[] {8,8,8,8,8,8};
statNames = new String[]{"Strength", "Dexterity", "Constitution", "Intelligence", "Wisdom", "Charisma"};
statsPanels = new JPanel[6];
for (int i = 0; i < statNames.length; i++) {
statsPanels[i] = createStatPanel(statNames[i], i);
}
createMasterPanel();
}
private void createMasterPanel() {
setLayout(new BorderLayout(0, 0));
JPanel masterPanel = new JPanel();
JLabel title = new JLabel("Step 3: Choose Ability Scores");
JPanel scoreHolder = new JPanel(new GridLayout(3, 2, 15, 15));
for (int i = 0; i < statNames.length; i++) {
scoreHolder.add(statsPanels[i]);
}
masterPanel.add(title);
masterPanel.add(scoreHolder);
add(masterPanel);
}
private JPanel createStatPanel(String statName, int currentIndex) {
JPanel container = new JPanel();
container.add(createMinusButton(currentIndex));
JPanel textHolder = new JPanel(new GridLayout(2, 1, 15, 15));
textHolder.add(new JLabel(statName));
textHolder.add(new JLabel(Integer.toString(stats[currentIndex])));
container.add(textHolder);
container.add(createPlusButton(currentIndex));
return container;
}
private void refreshStatPanel(int currentIndex) {
statsPanels[currentIndex].removeAll();
statsPanels[currentIndex] = createStatPanel(statNames[currentIndex], currentIndex);
revalidate();
repaint();
}
private JButton createMinusButton(int currentIndex) {
JButton button = new JButton("-");
button.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stats[currentIndex]--;
refreshStatPanel(currentIndex);
}
}
);
return button;
}
// TODO: Need to refactor into increment and decrement score methods, as the number of points required to purchase an increase rises.
private JButton createPlusButton(int currentIndex) {
JButton button = new JButton("+");
button.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stats[currentIndex]++;
refreshStatPanel(currentIndex);
}
}
);
return button;
}
}
@@ -0,0 +1,4 @@
package GUI.Panels;
public class DescriptionPanel {
}
@@ -0,0 +1,4 @@
package GUI.Panels;
public class EquipmentPanel {
}
@@ -0,0 +1,4 @@
package GUI.Panels;
public class FinalizePanel {
}
@@ -0,0 +1,4 @@
package GUI.Panels;
public class LoadCharacterPanel {
}
@@ -0,0 +1,4 @@
package GUI.Panels;
public class PreviewCharacterSheet {
}