diff --git a/dndBuilder/src/GUI/GUImanager.java b/dndBuilder/src/GUI/GUImanager.java index 4a47c45..fd6f636 100644 --- a/dndBuilder/src/GUI/GUImanager.java +++ b/dndBuilder/src/GUI/GUImanager.java @@ -1,6 +1,7 @@ package GUI; import GUI.Panels.*; +import GUI.Panels.SubPanels.NavPanel; import Resources.CustomAssets.DefaultButton; import javax.swing.*; @@ -22,23 +23,30 @@ public class GUImanager extends JFrame { private int raceChoice; private int classChoice; + private String[] statOptions; + private String[] statDescriptions; + private int[] selectedStats; + public GUImanager (boolean returningUser) { super("D&D Character Builder"); frameSetup(); - setupRaceAndClass(); + setupPanelInfo(); this.panels = new JPanel[]{ new MainMenuPanel(), - new BasicPanel(createBackButton(), createContinueButton(), raceOptions, raceDescriptions, "Step 1: Choose Your Race"), // To choose Race. - new BasicPanel(createBackButton(), createContinueButton(), classOptions, classDescriptions, "Step 2: Choose Your Class"), // To choose Class. - new ChooseAbilityScoresPanel(createBackButton(), createContinueButton()) + new BasicPanel(createNavPanel(), raceOptions, raceDescriptions, "Step 1: Choose Your Race"), // To choose Race. + new BasicPanel(createNavPanel(), classOptions, classDescriptions, "Step 2: Choose Your Class"), // To choose Class. + new ChooseAbilityScoresPanel(createNavPanel(27), statOptions, statDescriptions, selectedStats, "Step 3: Choose Your Ability Scores") }; - - this.lastPanel = 0; this.currentPanel = 1; - this.nextPanel = 2; + this.lastPanel = currentPanel - 1; + this.nextPanel = currentPanel + 1; + +/* this.lastPanel = 0; + this.currentPanel = 1; + this.nextPanel = 2;*/ /* if (returningUser) { @@ -72,7 +80,7 @@ public class GUImanager extends JFrame { } - private void setupRaceAndClass() { + private void setupPanelInfo() { raceOptions = new String[]{ "Dragonborn", @@ -136,6 +144,42 @@ public class GUImanager extends JFrame { }; + statOptions = new String[] { + + "Strength", + "Dexterity", + "Constitution", + "Intelligence", + "Wisdom", + "Charisma" + + }; + + statDescriptions = new String[] { + + "Strength is a thing.", + "Dexterity is a thing", + "Constitution is a thing", + "Intelligence is a thing", + "Wisdom is a thing", + "Charisma is a thing" + + }; + + selectedStats = new int[] {8, 8, 8, 8, 8, 8}; + + } + + private NavPanel createNavPanel() { + + return new NavPanel(createBackButton(), createContinueButton(), 0); + + } + + private NavPanel createNavPanel(int continueRequirement) { + + return new NavPanel(createBackButton(), createContinueButton(), continueRequirement); + } private DefaultButton createBackButton() { diff --git a/dndBuilder/src/GUI/Panels/BasicPanel.java b/dndBuilder/src/GUI/Panels/BasicPanel.java index d3d95d0..1563bad 100644 --- a/dndBuilder/src/GUI/Panels/BasicPanel.java +++ b/dndBuilder/src/GUI/Panels/BasicPanel.java @@ -13,29 +13,40 @@ public class BasicPanel extends JPanel implements AppTheme { private DefaultButton[] optionButtons; private String[] options; - private String[] descriptions; - private InfoPanel infoPanel; - private DefaultButton backButton; - private DefaultButton continueButton; + private ImageInfoPanel infoPanel; private int choiceIndex; private String panelTitle; - - - public BasicPanel(DefaultButton backButton, DefaultButton continueButton, String[] options, String[] descriptions, String panelTitle) { + public BasicPanel(JPanel navPanel, String[] options, String[] descriptions, String panelTitle) { super(); - this.backButton = backButton; - this.continueButton = continueButton; this.options = options; - this.descriptions = descriptions; this.panelTitle = panelTitle; - this.infoPanel = new InfoPanel(options, descriptions); - choiceIndex = 0; + Rectangle[] basicBounds = new Rectangle[]{ + + new Rectangle(5, 5, 600, 400), // ImageInfo panel + new Rectangle(275, 10, 300, 35), // ImageInfo subheader + new Rectangle(275, 45, 300, 355), // ImageInfo text + new Rectangle(10, 45, 250, 355) + + }; + + this.infoPanel = new ImageInfoPanel(options, descriptions, basicBounds, Integer.parseInt(Character.toString(panelTitle.charAt(5)))); + infoPanel.updateInfo(0); // Default start with 0th element. + + choiceIndex = 0; panelSetup(); createMasterPanel(); + add(navPanel, BorderLayout.SOUTH); + + } + + private void panelSetup() { + + setBackground(lightBrown); + setLayout(new BorderLayout(0, 0)); } @@ -47,14 +58,13 @@ public class BasicPanel extends JPanel implements AppTheme { title.setForeground(darkestBrown); add(title, BorderLayout.NORTH); - JPanel racePanel = new JPanel(); - racePanel.setOpaque(false); - racePanel.setLayout(null); - racePanel.add(infoPanel); - racePanel.add(createButtonPanel()); + JPanel panel = new JPanel(); + panel.setOpaque(false); + panel.setLayout(null); + panel.add(infoPanel); + panel.add(createButtonPanel()); - add(racePanel); - add(createNavPanel(), BorderLayout.SOUTH); + add(panel); } @@ -91,37 +101,18 @@ public class BasicPanel extends JPanel implements AppTheme { } - private void panelSetup() { + private DefaultButton createButton(String holderName, int index) { - setBackground(lightBrown); - setLayout(new BorderLayout(0, 0)); - - } - - private JPanel createNavPanel() { - - JPanel panel = new JPanel(new GridLayout(1, 2, 30, 0)); - panel.setBackground(darkestBrown); - panel.setBorder(new EmptyBorder(15, 150, 15, 150)); - panel.add(backButton); - panel.add(continueButton); - - return panel; - - } - - private DefaultButton createButton(String raceName, int index) { - - DefaultButton button = new DefaultButton(raceName); - button.addActionListener(e -> updateButtons(choiceIndex, index)); + DefaultButton button = new DefaultButton(holderName); + button.addActionListener(e -> updateButtons(index)); return button; } - private void updateButtons(int lastIndex, int newIndex) { + private void updateButtons(int newIndex) { - optionButtons[lastIndex].deSelect(); + optionButtons[choiceIndex].deSelect(); optionButtons[newIndex].select(); choiceIndex = newIndex; diff --git a/dndBuilder/src/GUI/Panels/ChooseAbilityScoresPanel.java b/dndBuilder/src/GUI/Panels/ChooseAbilityScoresPanel.java index dd3b2f5..6ac239e 100644 --- a/dndBuilder/src/GUI/Panels/ChooseAbilityScoresPanel.java +++ b/dndBuilder/src/GUI/Panels/ChooseAbilityScoresPanel.java @@ -1,243 +1,244 @@ package GUI.Panels; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; +import GUI.AppTheme; +import GUI.Panels.SubPanels.InfoPanel; +import GUI.Panels.SubPanels.NavPanel; +import Resources.CustomAssets.DefaultButton; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.SwingConstants; -import javax.swing.border.BevelBorder; -import javax.swing.JTextPane; -import java.awt.GridLayout; +import javax.swing.*; +import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; +import java.awt.*; -public class ChooseAbilityScoresPanel extends JPanel { +public class ChooseAbilityScoresPanel extends JPanel implements AppTheme { - /** - * Create the panel. - */ - public ChooseAbilityScoresPanel(JButton backButton, JButton continueButton) { - createEntirePanel(backButton, continueButton); + private DefaultButton[] statInfoButtons; + private JLabel[] statLabels; + private String[] statOptions; + + private InfoPanel infoPanel; + private NavPanel navPanel; + + private int[] selectedStats; + private int selectedStatIndex; + + public ChooseAbilityScoresPanel(NavPanel navPanel, String[] statOptions, String[] statDescriptions, int[] selectedStats, String panelTitle) { + + super(); + panelSetup(); + this.statOptions = statOptions; + this.selectedStats = selectedStats; + this.statInfoButtons = new DefaultButton[statOptions.length]; + statLabels = new JLabel[statOptions.length]; + this.navPanel = navPanel; + + Rectangle[] abilityScoreBounds = { + + new Rectangle(520, 5, 200, 400), // ImageInfo panel + new Rectangle(5, 10, 200, 35), // ImageInfo subheader + new Rectangle(5, 45, 200, 355) // ImageInfo text + + }; + + infoPanel = new InfoPanel(statOptions, statDescriptions, abilityScoreBounds, 3); + infoPanel.updateInfo(0); // Default start with 0th element. + + createMasterPanel(panelTitle); + add(navPanel, BorderLayout.SOUTH); } - /** - * - */ - private void createEntirePanel(JButton backButton, JButton continueButton) { - setBackground(new Color(222, 184, 135)); - setBorder(new BevelBorder(BevelBorder.RAISED, new Color(160, 82, 45), new Color(165, 42, 42), new Color(0, 0, 0), null)); + private void panelSetup() { + + setBackground(lightBrown); setLayout(new BorderLayout(0, 0)); - - JLabel lblNewLabel = createLbl(); - add(lblNewLabel, BorderLayout.NORTH); - //Creates back and continue panel - JPanel backContPanel = createBackContinuePanel(backButton, continueButton); - add(backContPanel, BorderLayout.SOUTH); - - JPanel innerPanel = createInnerPanel(); - add(innerPanel, BorderLayout.CENTER); + } - /** - * @return - */ - private JPanel createInnerPanel() { - JPanel innerPanel = new JPanel(); - innerPanel.setOpaque(false); - innerPanel.setLayout(null); - - createInfoPanel(innerPanel); - - JPanel mainAbilityPanel = new JPanel(); - mainAbilityPanel.setOpaque(false); - mainAbilityPanel.setBounds(6, 6, 505, 405); - innerPanel.add(mainAbilityPanel); - mainAbilityPanel.setLayout(new GridLayout(2, 3, 10, 10)); - - JPanel strengthPanel = createAbilityPanel("Strength"); - mainAbilityPanel.add(strengthPanel); - - JPanel dexterityPanel = createAbilityPanel("Dexterity"); - mainAbilityPanel.add(dexterityPanel); - - JPanel constitutionPanel = createAbilityPanel("Constitution"); - mainAbilityPanel.add(constitutionPanel); - - JPanel intelligencePanel = createAbilityPanel("Intelligence"); - mainAbilityPanel.add(intelligencePanel); - - JPanel wisdomPanel = createAbilityPanel("Wisdom"); - mainAbilityPanel.add(wisdomPanel); - - JPanel charismaPanel = createAbilityPanel("Charisma"); - mainAbilityPanel.add(charismaPanel); - - return innerPanel; - } + private void createMasterPanel(String panelTitle) { + + JLabel title = new JLabel(panelTitle); + title.setHorizontalAlignment(SwingConstants.CENTER); + title.setFont(headerFont); + title.setForeground(darkestBrown); + add(title, BorderLayout.NORTH); - /** - * @return - */ - private JPanel createAbilityPanel(String str) { - JPanel abilityPanel = new JPanel(); - abilityPanel.setFont(new Font("Lucida Grande", Font.PLAIN, 20)); - abilityPanel.setBackground(new Color(205, 133, 63)); - abilityPanel.setBorder(new LineBorder(new Color(165, 42, 42), 6, true)); - abilityPanel.setLayout(new BorderLayout(0, 0)); - - JLabel abilityLbl = new JLabel(str); - abilityLbl.setFont(new Font("Lucida Grande", Font.PLAIN, 19)); - abilityLbl.setHorizontalAlignment(SwingConstants.CENTER); - abilityPanel.add(abilityLbl, BorderLayout.NORTH); - - JButton btnNewButton = new JButton("Information"); - btnNewButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - } - }); - btnNewButton.setName("infoBtn"); - abilityPanel.add(btnNewButton, BorderLayout.SOUTH); - JPanel panel = new JPanel(); - panel.setOpaque(false); - abilityPanel.add(panel, BorderLayout.CENTER); - panel.setLayout(null); - - JLabel scoreLbl = new JLabel("1"); - scoreLbl.setFont(new Font("Lucida Grande", Font.PLAIN, 24)); - scoreLbl.setHorizontalAlignment(SwingConstants.CENTER); - scoreLbl.setBounds(56, 50, 30, 30); - panel.add(scoreLbl); - - JButton btnNewButton_1 = new JButton("+"); - btnNewButton_1.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null)); - btnNewButton_1.setFont(new Font("Lucida Grande", Font.PLAIN, 24)); - btnNewButton_1.setBounds(90, 50, 30, 30); - panel.add(btnNewButton_1); - - JButton decreaseBtn = new JButton("-"); - decreaseBtn.setFont(new Font("Lucida Grande", Font.PLAIN, 24)); - decreaseBtn.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null)); - decreaseBtn.setBounds(21, 50, 30, 30); - panel.add(decreaseBtn); - return abilityPanel; + panel.setOpaque(false); + panel.setLayout(null); + panel.add(createAbilityScorePanels()); + panel.add(infoPanel); + + add(panel); + } - /** - * @param innerPanel - */ - private void createInfoPanel(JPanel innerPanel) { - JPanel infoPanel = new JPanel(); - infoPanel.setOpaque(false); - infoPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null)); - infoPanel.setBounds(508, 6, 212, 405); - innerPanel.add(infoPanel); - infoPanel.setLayout(null); - - JLabel infoLbl = new JLabel("Information"); - infoLbl.setHorizontalAlignment(SwingConstants.CENTER); - infoLbl.setFont(new Font("Bodoni 72 Oldstyle", Font.PLAIN, 24)); - infoLbl.setBounds(6, 6, 200, 23); - infoPanel.add(infoLbl); - - JTextPane textPane = new JTextPane(); - textPane.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null)); - textPane.setBackground(new Color(205, 133, 63)); - textPane.setBounds(6, 28, 200, 240); - infoPanel.add(textPane); - - JPanel diceRollerPanel = new JPanel(); - diceRollerPanel.setBackground(new Color(160, 82, 45)); - diceRollerPanel.setBounds(6, 269, 200, 130); - infoPanel.add(diceRollerPanel); - diceRollerPanel.setLayout(null); - - JLabel diceRollLbl = new JLabel("4 X D6 Dice Roll"); - diceRollLbl.setHorizontalAlignment(SwingConstants.CENTER); - diceRollLbl.setFont(new Font("Bodoni 72", Font.PLAIN, 16)); - diceRollLbl.setBounds(6, 0, 194, 22); - diceRollerPanel.add(diceRollLbl); - - JButton diceRollBtn = new JButton("Roll"); - diceRollBtn.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { + private JPanel createAbilityScorePanels() { + + JPanel mainAbilityPanel = new JPanel(); + mainAbilityPanel.setBounds(5, 5, 505, 405); + mainAbilityPanel.setLayout(new GridLayout(2, 3, 10, 10)); + mainAbilityPanel.setBackground(lightBrown); + + for (int i = 0; i < statOptions.length; i++) { + + mainAbilityPanel.add(createAbilityPanel(statOptions[i], i)); + } - }); - diceRollBtn.setBounds(45, 95, 117, 29); - diceRollerPanel.add(diceRollBtn); - - JLabel d6Lbl1 = new JLabel("1"); - d6Lbl1.setFont(new Font("Lucida Grande", Font.PLAIN, 20)); - d6Lbl1.setHorizontalAlignment(SwingConstants.CENTER); - d6Lbl1.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null)); - d6Lbl1.setOpaque(true); - d6Lbl1.setBackground(new Color(255, 215, 0)); - d6Lbl1.setBounds(26, 50, 30, 30); - diceRollerPanel.add(d6Lbl1); - - JLabel d6Lbl2 = new JLabel("1"); - d6Lbl2.setFont(new Font("Lucida Grande", Font.PLAIN, 20)); - d6Lbl2.setHorizontalAlignment(SwingConstants.CENTER); - d6Lbl2.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null)); - d6Lbl2.setOpaque(true); - d6Lbl2.setBackground(new Color(255, 215, 0)); - d6Lbl2.setBounds(68, 50, 30, 30); - diceRollerPanel.add(d6Lbl2); - - JLabel d6Lbl3 = new JLabel("1"); - d6Lbl3.setFont(new Font("Lucida Grande", Font.PLAIN, 20)); - d6Lbl3.setHorizontalAlignment(SwingConstants.CENTER); - d6Lbl3.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null)); - d6Lbl3.setOpaque(true); - d6Lbl3.setBackground(new Color(255, 215, 0)); - d6Lbl3.setBounds(110, 50, 30, 30); - diceRollerPanel.add(d6Lbl3); - - JLabel d6lbl4 = new JLabel("1"); - d6lbl4.setFont(new Font("Lucida Grande", Font.PLAIN, 20)); - d6lbl4.setHorizontalAlignment(SwingConstants.CENTER); - d6lbl4.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null)); - d6lbl4.setOpaque(true); - d6lbl4.setBackground(new Color(255, 215, 0)); - d6lbl4.setBounds(152, 50, 30, 30); - diceRollerPanel.add(d6lbl4); + + return mainAbilityPanel; + } - - private JPanel createBackContinuePanel(JButton backButton, JButton continueButton) { - JPanel backContPanel = new JPanel(); - backContPanel.setBackground(new Color(205, 133, 63)); - - -/* JButton backBtn = new JButton("<--- Back "); - backBtn.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { + + private JPanel createAbilityPanel(String ability, int statIndex) { + JPanel panel = new JPanel(); + panel.setFont(paragraphFont); + panel.setBackground(medBrown); + panel.setBorder(new LineBorder(darkestBrown, 4, true)); + panel.setLayout(new BorderLayout(0, 0)); + + DefaultButton tmpButton = new DefaultButton(ability); + tmpButton.setFont(paragraphFont); + tmpButton.setHorizontalAlignment(SwingConstants.CENTER); + tmpButton.addActionListener(e -> updateButtons(statIndex)); + + statInfoButtons[statIndex] = tmpButton; + + panel.add(statInfoButtons[statIndex], BorderLayout.NORTH); + + panel.add(createScorePanel(statIndex)); + + return panel; + + } + + private JPanel createScorePanel(int statIndex) { + + JPanel subPanel = new JPanel(); + + JLabel scoreLabel = new JLabel("" + selectedStats[statIndex]); + scoreLabel.setFont(paragraphFont); + scoreLabel.setHorizontalAlignment(SwingConstants.CENTER); + scoreLabel.setBounds(56, 50, 30, 30); + + statLabels[statIndex] = scoreLabel; + + + DefaultButton increaseButton = new DefaultButton("+"); + increaseButton.setBounds(90, 50, 30, 30); + increaseButton.addActionListener(e -> increase(statIndex)); + + DefaultButton decreaseButton = new DefaultButton("-"); + decreaseButton.setBounds(21, 50, 30, 30); + decreaseButton.addActionListener(e -> decrease(statIndex)); + + subPanel.add(decreaseButton); + subPanel.add(scoreLabel); + subPanel.add(increaseButton); + + subPanel.setBackground(lightBrown); + + return subPanel; + + } + + private int statCostCalculator(int statIndex, boolean isDecreasing) { + + int cost = 0; + + int currentStatValue = selectedStats[statIndex]; + + if (isDecreasing) { + + if(currentStatValue <= 8) { + System.out.println("registered invalid decrease"); + + return -1; + } - }); - backContPanel.add(backBtn);*/ - backContPanel.add(backButton); - -/* JButton continueBtn = new JButton("Continue --->"); - continueBtn.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { + + if(currentStatValue < 14) { + + cost = 1; + + } else if (currentStatValue == 14 || currentStatValue == 15) { + + cost = 2; + } - }); - backContPanel.add(continueBtn);*/ - backContPanel.add(continueButton); - return backContPanel; + + } else { + + if(currentStatValue < 13) { + + cost = 1; + + } else if (currentStatValue == 13 || currentStatValue == 14) { + + cost = 2; + + } else { + System.out.println("registered invalid increase"); + return -1; + + } + + } + + return cost; + } - - /** - * @return - */ - private JLabel createLbl() { - JLabel titleLbl = new JLabel("Step 3: Ability Scores"); - titleLbl.setHorizontalAlignment(SwingConstants.CENTER); - titleLbl.setFont(new Font("Bodoni 72 Oldstyle", Font.PLAIN, 33)); - return titleLbl; + + private void increase(int statIndex) { + + int value = statCostCalculator(statIndex, false); + + if(value == -1) { + + return; + + } + + if(navPanel.getContinueRequirement() - value >= 0) { + + selectedStats[statIndex]++; + statLabels[statIndex].setText("" + selectedStats[statIndex]); + + navPanel.decreaseContinueRequirement(value); + + } + } -} + + private void decrease(int statIndex) { + + int value = statCostCalculator(statIndex, true); + + if(value == -1) { + + return; + + } + + if(navPanel.getContinueRequirement() + value <= 27) { + + selectedStats[statIndex]--; + statLabels[statIndex].setText("" + selectedStats[statIndex]); + + navPanel.increaseContinueRequirement(value); + + } + + } + + private void updateButtons(int newIndex) { + + statInfoButtons[selectedStatIndex].deSelect(); + statInfoButtons[newIndex].select(); + + selectedStatIndex = newIndex; + infoPanel.updateInfo(selectedStatIndex); + + } + +} \ No newline at end of file diff --git a/dndBuilder/src/GUI/Panels/SubPanels/ImageInfoPanel.java b/dndBuilder/src/GUI/Panels/SubPanels/ImageInfoPanel.java new file mode 100644 index 0000000..cbff3c2 --- /dev/null +++ b/dndBuilder/src/GUI/Panels/SubPanels/ImageInfoPanel.java @@ -0,0 +1,143 @@ +package GUI.Panels.SubPanels; + +import GUI.AppTheme; +import org.w3c.dom.css.Rect; + +import javax.imageio.ImageIO; +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.util.Objects; +import java.util.Random; + +public class ImageInfoPanel extends InfoPanel implements AppTheme { + + private JLabel[][] portraits; + private int lastIndex; + + public ImageInfoPanel(String[] categoryHolder, String[] holderDescriptions, Rectangle[] bounds, int panelIndex) { + + super(categoryHolder, holderDescriptions, bounds, panelIndex); + + createPortraits(); + + } + + @Override + public void updateInfo(int holderIndex) { + + super.updateInfo(holderIndex, portraits[holderIndex][getNextPortrait(holderIndex)]); + + } + + private int getNextPortrait(int holderIndex) { + + Random ran = new Random(); + int bound = portraits[holderIndex].length; + int newIndex = ran.nextInt(bound); + +/* while(newIndex == lastIndex) { + + newIndex = ran.nextInt(bound); + + }*/ + + lastIndex = newIndex; + + return newIndex; + + } + + private void createPortraits() { + + String category = ""; + + if(panelIndex == 1) { + + category = "Races"; + + } else if (panelIndex == 2) { + + category = "Classes"; + + } + + portraits = new JLabel[categoryHolder.length][]; + + for (int i = 0; i < categoryHolder.length; i++) { + + File imagesDir; + + if(OS.startsWith("Windows")) { + + imagesDir = new File("dndBuilder\\src\\Resources\\Img\\" + category + "\\" + categoryHolder[i].toLowerCase() + "\\"); + + } else if (OS.startsWith("Mac")) { + + imagesDir = new File("dndBuilder/src/Resources/Img/" + category + "/" + categoryHolder[i].toLowerCase() + "/"); + + } else if (OS.startsWith("Linux")) { + + imagesDir = new File("dndBuilder/src/Resources/Img/" + category + "/" + categoryHolder[i].toLowerCase() + "/"); + + } else { + + System.out.println("Unable to detect operating system."); + return; + + } + + File[] dir = imagesDir.listFiles(); + portraits[i] = new JLabel[dir.length]; + int index = 0; + + for (File file : dir) { + portraits[i][index] = image(file); + portraits[i][index].setOpaque(true); + portraits[i][index].setBackground(lightBrown); + portraits[i][index].setBounds(bounds[3]); + + index++; + } + + + } + + + } + + private JLabel image(File file) { + + BufferedImage img; + Image finalImg; + JLabel picture; + + try { + + img = ImageIO.read(file); + finalImg = img.getScaledInstance(250, 375, Image.SCALE_SMOOTH); + + } catch (Exception e) { + + System.out.println("Error reading file."); + img = null; + finalImg = null; + + } + + if(Objects.isNull(finalImg)) { + + picture = new JLabel("ERROR: Image not found."); + + } else { + + picture = new JLabel(new ImageIcon(finalImg)); + + } + + return picture; + + } + +} diff --git a/dndBuilder/src/GUI/Panels/SubPanels/InfoPanel.java b/dndBuilder/src/GUI/Panels/SubPanels/InfoPanel.java index 3586e30..71f1031 100644 --- a/dndBuilder/src/GUI/Panels/SubPanels/InfoPanel.java +++ b/dndBuilder/src/GUI/Panels/SubPanels/InfoPanel.java @@ -13,75 +13,59 @@ import java.util.Random; public class InfoPanel extends JPanel implements AppTheme { - private JTextArea[] descriptions; - private String[] holderDescriptions; - private JLabel[][] portraits; - private String[] categoryHolder; - private static int numInfoPanelObjects = 0; - private int lastIndex; + protected JTextArea[] descriptions; + protected Rectangle[] bounds; + protected String[] holderDescriptions; + protected String[] categoryHolder; + protected int panelIndex; - public InfoPanel(String[] categoryHolder, String[] holderDescriptions) { + public InfoPanel(String[] categoryHolder, String[] holderDescriptions, Rectangle[] bounds, int panelIndex) { super(); - numInfoPanelObjects++; this.categoryHolder = categoryHolder; this.holderDescriptions = holderDescriptions; + this.bounds = bounds; + this.panelIndex = panelIndex; panelSetup(); createDescriptions(); - createPortraits(); - - updateInfo(0); // Default selection of the 0th elements. } public void updateInfo(int holderIndex) { - removeAll(); + panelSetup(); - - panelSetup(); add(descriptions[holderIndex]); - System.out.println(); - - add(portraits[holderIndex][getNextPortrait(holderIndex)]); - repaint(); revalidate(); } + protected void updateInfo(int holderIndex, JLabel portrait) { + removeAll(); + panelSetup(); - private int getNextPortrait(int holderIndex) { + add(descriptions[holderIndex]); + add(portrait); - Random ran = new Random(); - int bound = portraits[holderIndex].length; - int newIndex = ran.nextInt(bound); - -/* while(newIndex == lastIndex) { - - newIndex = ran.nextInt(bound); - - }*/ - - lastIndex = newIndex; - - return newIndex; + repaint(); + revalidate(); } private void panelSetup() { setOpaque(false); - setBounds(5, 5, 600, 400); + setBounds(bounds[0]); setLayout(null); JLabel subHeader = new JLabel("Description"); subHeader.setFont(subHeaderFont); subHeader.setHorizontalAlignment(SwingConstants.LEFT); - subHeader.setBounds(275, 10, 300, 35); + subHeader.setBounds(bounds[1]); subHeader.setForeground(darkestBrown); add(subHeader); @@ -98,12 +82,13 @@ public class InfoPanel extends JPanel implements AppTheme { tmpDesc.setText(holderDescriptions[i]); tmpDesc.setWrapStyleWord(true); tmpDesc.setLineWrap(true); - tmpDesc.setOpaque(false); + tmpDesc.setOpaque(true); tmpDesc.setEditable(false); tmpDesc.setFocusable(false); tmpDesc.setFont(paragraphFont); - tmpDesc.setBounds(275, 45, 300, 355); + tmpDesc.setBounds(bounds[2]); tmpDesc.setBorder(new EmptyBorder(5, 5, 5, 5)); + tmpDesc.setBackground(medBrown); tmpDesc.setForeground(darkestBrown); descriptions[i] = tmpDesc; @@ -112,96 +97,4 @@ public class InfoPanel extends JPanel implements AppTheme { } - private void createPortraits() { - - String category = ""; - - if(numInfoPanelObjects == 1) { - - category = "Races"; - - } else if (numInfoPanelObjects == 2) { - - category = "Classes"; - - } - - portraits = new JLabel[categoryHolder.length][]; - - for (int i = 0; i < categoryHolder.length; i++) { - - File imagesDir; - - if(OS.startsWith("Windows")) { - - imagesDir = new File("dndBuilder\\src\\Resources\\Img\\" + category + "\\" + categoryHolder[i].toLowerCase() + "\\"); - - } else if (OS.startsWith("Mac")) { - - imagesDir = new File("dndBuilder/src/Resources/Img/" + category + "/" + categoryHolder[i].toLowerCase() + "/"); - - } else if (OS.startsWith("Linux")) { - - imagesDir = new File("dndBuilder/src/Resources/Img/" + category + "/" + categoryHolder[i].toLowerCase() + "/"); - - } else { - - System.out.println("Unable to detect operating system."); - return; - - } - - File[] dir = imagesDir.listFiles(); - portraits[i] = new JLabel[dir.length]; - int index = 0; - - for (File file : dir) { - portraits[i][index] = image(file); - portraits[i][index].setOpaque(true); - portraits[i][index].setBackground(lightBrown); - portraits[i][index].setBounds(10, 45, 250, 355); - - index++; - - } - - - } - - - } - - private JLabel image(File file) { - - BufferedImage img; - Image finalImg; - JLabel picture; - - try { - - img = ImageIO.read(file); - finalImg = img.getScaledInstance(250, 375, Image.SCALE_SMOOTH); - - } catch (Exception e) { - - System.out.println("Error reading file."); - img = null; - finalImg = null; - - } - - if(Objects.isNull(finalImg)) { - - picture = new JLabel("ERROR: Image not found."); - - } else { - - picture = new JLabel(new ImageIcon(finalImg)); - - } - - return picture; - - } - } diff --git a/dndBuilder/src/GUI/Panels/SubPanels/NavPanel.java b/dndBuilder/src/GUI/Panels/SubPanels/NavPanel.java new file mode 100644 index 0000000..7798f9c --- /dev/null +++ b/dndBuilder/src/GUI/Panels/SubPanels/NavPanel.java @@ -0,0 +1,80 @@ +package GUI.Panels.SubPanels; + +import GUI.AppTheme; +import Resources.CustomAssets.DefaultButton; + +import javax.sound.sampled.Line; +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import javax.swing.border.LineBorder; +import java.awt.*; + +public class NavPanel extends JPanel implements AppTheme { + + private DefaultButton backButton; + private DefaultButton continueButton; + private int continueRequirement; + + public NavPanel(DefaultButton backButton, DefaultButton continueButton, int continueRequirement) { + + super(new GridLayout(1, 2, 30, 0)); + this.backButton = backButton; + this.continueButton = continueButton; + + this.continueRequirement = continueRequirement; + createNavPanel(); + + } + + public int getContinueRequirement() { + + return continueRequirement; + + } + + public void decreaseContinueRequirement(int value) { + + continueRequirement -= value; + updateContinueRequirement(); + + } + + public void increaseContinueRequirement(int value) { + + continueRequirement += value; + updateContinueRequirement(); + + } + + private void updateContinueRequirement() { + + removeAll(); + + createNavPanel(); + + } + + private void createNavPanel() { + + setBackground(darkestBrown); + setBorder(new EmptyBorder(15, 150, 15, 150)); + add(backButton); + + if(continueRequirement == 0) { + + add(continueButton); + + } else { + + DefaultButton requiredStepsNeeds = new DefaultButton(Integer.toString(continueRequirement) + " Points Left"); + requiredStepsNeeds.select(); + requiredStepsNeeds.setBorder(new LineBorder(lightAccent, 1)); + requiredStepsNeeds.setBorderPainted(true); + requiredStepsNeeds.setEnabled(false); + add(requiredStepsNeeds); + + } + + } + +}