Merge pull request #4 from joshashton-code/refactorFileIO

Refactor file io
This commit is contained in:
Josh Ashton
2022-11-30 15:14:01 -07:00
committed by GitHub
117 changed files with 632 additions and 641 deletions
+58
View File
@@ -1,2 +1,60 @@
# Application
CSIS 1410 - Group Project
CURRENT TODO ITEMS:
**************** CONTENT ****************
- All PHB classes should be included.
**************** GUI ********************
- Finish GUI panels
PANELS:
- Race
Upload custom profile picture button.
- Description (needs positioning)
- Spells & Equipment
- Preview
- Load Character/View character
- Save as PDF / Print
DESCRIPTIONS:
- Class action scene pictures.
- Ability Scores description text.
- Class descriptions.
- Race descriptions.
*************** FILES ******************
NOTE: user.dir = /home/joshuaashton/Development/misc/dndApp/src
user.home = /home/joshuaashton
NOTE: user.dir is changed to exe directory by application launch4j. This creates an exe file from .jar.
see Inno Setup Compiler to package .exe and the JRE into a singular installer.
- Upload custom profile picture.
- Character sheet from selections.
- Load existing characters to edit.
- Save new characters.
- File directory based upon OS used.
- Export to PDF.
- Print
************** FINAL TOUCHES **********
- Generate a random character.
- Character levels.
- Spells.
- Dice roller.
+3 -2
View File
@@ -1,10 +1,11 @@
package src;
public class App {
public static void main(String[] args) {
FileManager data = new FileManager();
GUImanager gui = new GUImanager();
GUImanager gui = new GUImanager(data.isReturninguser());
gui.setVisible(true);
}
-28
View File
@@ -1,28 +0,0 @@
import java.awt.*;
public interface AppTheme {
public Color lightAccent = Color.decode("#EAF0CE");
public Color lightBrown = Color.decode("#EBBE9B");
public Color medBrown = Color.decode("#E4A677");
public Color darkBrown = Color.decode("#502419");
public Color darkestBrown = Color.decode("#1F0E0A");
public Color black = Color.BLACK;
public Color confirmationBlue = Color.decode("#296EB4");
public Color rejectionRed = Color.decode("#A23E48");
public Font headerFont = new Font("SanSalvi", Font.BOLD, 45);
public Font subHeaderFont = new Font("SanSalvi", Font.PLAIN, 35);
public Font paragraphFont = new Font("SanSalvi", Font.PLAIN, 20);
public Font userTextFont = new Font("SanSalvi", Font.PLAIN, 15);
public Font buttonFont = new Font("SanSalvi", Font.PLAIN, 15);
public String OS = System.getProperty("os.name");
}
+2
View File
@@ -1,3 +1,5 @@
package src;
public class Background {
int backgroundIndex;
+20 -3
View File
@@ -1,9 +1,13 @@
package src;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import java.awt.*;
public class BasicNavPanel extends JPanel implements AppTheme {
import static src.AppConstants.*;
public class BasicNavPanel extends JPanel {
private DefaultButton backButton;
private DefaultButton continueButton;
@@ -13,7 +17,16 @@ public class BasicNavPanel extends JPanel implements AppTheme {
super(new GridLayout(1, 2, 30, 0));
this.backButton = backButton;
this.continueButton = continueButton;
if(continueButton == null) {
this.continueButton = null;
} else {
this.continueButton = continueButton;
}
this.continueRequirement = continueRequirement;
createNavPanel();
@@ -56,7 +69,11 @@ public class BasicNavPanel extends JPanel implements AppTheme {
if (continueRequirement == 0) {
add(continueButton);
if(continueButton != null) {
add(continueButton);
}
} else {
+48 -5
View File
@@ -1,13 +1,20 @@
package src;
import javax.swing.*;
import java.awt.*;
public class BasicPanel extends JPanel implements AppTheme {
import static src.AppConstants.*;
import static src.ImageManager.*;
public class BasicPanel extends JPanel {
private DefaultButton[] optionButtons;
private String[] options;
private ImageInfoPanel infoPanel;
private InfoPanel infoPanel;
private int choiceIndex;
private String panelTitle;
private ImageManager images;
private int currentPanel;
public BasicPanel(JPanel navPanel, String[] options, String[] descriptions, String panelTitle) {
@@ -24,8 +31,13 @@ public class BasicPanel extends JPanel implements AppTheme {
};
this.infoPanel = new ImageInfoPanel(options, descriptions, basicBounds, Integer.parseInt(Character.toString(panelTitle.charAt(5))));
infoPanel.updateInfo(0); // Default start with 0th element.
images = new ImageManager();
infoPanel = new InfoPanel(options, descriptions, basicBounds, images);
currentPanel = Integer.parseInt(Character.toString(panelTitle.charAt(5)));
infoPanel.updateInfo(0, getNextPortrait(0));
choiceIndex = 0;
@@ -35,6 +47,28 @@ public class BasicPanel extends JPanel implements AppTheme {
}
private JLabel getNextPortrait(int index) {
JLabel nextPortrait;
if(currentPanel == 1) {
nextPortrait = images.getRacePortrait(index);
} else if(currentPanel == 2) {
nextPortrait = images.getClassPortrait(index);
} else {
nextPortrait = null;
}
return nextPortrait;
}
private void panelSetup() {
setBackground(lightBrown);
@@ -108,7 +142,16 @@ public class BasicPanel extends JPanel implements AppTheme {
optionButtons[newIndex].select();
choiceIndex = newIndex;
infoPanel.updateInfo(choiceIndex);
if(currentPanel == 1 || currentPanel == 2) {
infoPanel.updateInfo(choiceIndex, getNextPortrait(choiceIndex));
} else {
infoPanel.updateInfo(choiceIndex);
}
}
+78 -59
View File
@@ -1,3 +1,5 @@
package src;
import java.io.Serializable;
public class CharacterSheet implements Serializable {
@@ -6,97 +8,113 @@ public class CharacterSheet implements Serializable {
private int heightFeet;
private int heightInch;
private int weight;
private String eye;
private String hair;
private String eyeColor;
private String hairColor;
private Race race;
private ClassTemplate chClass;
private String[] spells;
private String[] equipment;
private String alignment;
private String background;
private CharacterStats stats;
/**
* @param name
* @param age
* @param heightFeet
* @param heightInch
* @param weight
* @param eye
* @param hair
/*
* TODO: Need to add the following variables:
*
* - CharacterClass x1 var
* - ChosenSpells xN vars
* - Equipment xN vars
* - Description x3 vars
*
* TOTAL: Minimum 12, + N spells and N equipment
*
*/
public CharacterSheet(String name, int age,
int heightFeet, int heightInch,
int weight, String eye, String hair,
Race race, CharacterStats stats) {
public CharacterSheet(
String name,
int age,
int heightFeet,
int heightInch,
int weight,
String eyeColor,
String hairColor,
Race race,
ClassTemplate chClass,
String alignment,
String background,
CharacterStats stats
) {
this.name = name;
this.age = age;
this.heightFeet = heightFeet;
this.heightInch = heightInch;
this.weight = weight;
this.eye = eye;
this.hair = hair;
this.eyeColor = eyeColor;
this.hairColor = hairColor;
this.race = race;
this.chClass = chClass;
this.alignment = alignment;
this.background = background;
this.stats = stats;
}
/**
* Default constructor
*/
public CharacterSheet() {
this.name = "null";
this.age = 0;
this.heightFeet = 0;
this.heightInch = 0;
this.weight = 0;
this.eye = "null";
this.hair = "null";
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @return the heightFeet
*/
public int getHeightFeet() {
return heightFeet;
}
/**
* @return the heightInch
*/
public int getHeightInch() {
return heightInch;
}
/**
* @return the weigth
*/
public int getWeight() {
return weight;
}
/**
* @return the eye
*/
public String getEye() {
return eye;
public String getEyeColor() {
return eyeColor;
}
/**
* @return the hair
*/
public String getHair() {
return hair;
public String getHairColor() {
return hairColor;
}
public Race getRace() {
return race;
}
public ClassTemplate getCharacterClass() {
return chClass;
}
public CharacterStats getStats() {
@@ -107,10 +125,11 @@ public class CharacterSheet implements Serializable {
@Override
public String toString() {
return "name: " + name + " | age: " + age + " | height: "
+ heightFeet + "\'" + heightInch + "\" | weight: "
+ weight + " | eye: " + eye + " | hair: " + hair
+ " | race: " + race.toString() + " | stats: " + stats.toString();
String output = "Character name: " + name + "\nAge: " + age + "\nHeight: " + heightFeet + "\'" + heightInch + "\"" + "\nWeight: " + weight + "\nEye Color: " + eyeColor + "\nHair Color: " + hairColor + "\nRace: " + race.toString() + "\nClass: " + chClass.toString() + "\nStats: " + stats.toString();
return output;
}
}
+5 -1
View File
@@ -1,4 +1,8 @@
public class CharacterStats {
package src;
import java.io.Serializable;
public class CharacterStats implements Serializable {
private Stats[] stats;
+5 -1
View File
@@ -1,4 +1,8 @@
public class Charisma extends Stats {
package src;
import java.io.Serializable;
public class Charisma extends Stats implements Serializable {
private int abilityScore;
private int abilityScoreModifier;
+9 -5
View File
@@ -1,8 +1,12 @@
package src;
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.*;
public class ChooseAbilityScoresPanel extends JPanel implements AppTheme {
import static src.AppConstants.*;
public class ChooseAbilityScoresPanel extends JPanel {
private DefaultButton[] statInfoButtons;
private JLabel[] statLabels;
@@ -30,7 +34,7 @@ public class ChooseAbilityScoresPanel extends JPanel implements AppTheme {
};
infoPanel = new InfoPanel(statOptions, statDescriptions, abilityScoreBounds, 3);
infoPanel = new InfoPanel(statOptions, statDescriptions, abilityScoreBounds);
infoPanel.updateInfo(0); // Default start with 0th element.
createMasterPanel(panelTitle);
@@ -82,13 +86,13 @@ public class ChooseAbilityScoresPanel extends JPanel implements AppTheme {
private JPanel createAbilityPanel(String ability, int statIndex) {
JPanel panel = new JPanel();
panel.setFont(paragraphFont);
panel.setFont(paragraphText);
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.setFont(paragraphText);
tmpButton.setHorizontalAlignment(SwingConstants.CENTER);
tmpButton.addActionListener(e -> updateButtons(statIndex));
@@ -107,7 +111,7 @@ public class ChooseAbilityScoresPanel extends JPanel implements AppTheme {
JPanel subPanel = new JPanel();
JLabel scoreLabel = new JLabel("" + selectedStats[statIndex]);
scoreLabel.setFont(paragraphFont);
scoreLabel.setFont(paragraphText);
scoreLabel.setHorizontalAlignment(SwingConstants.CENTER);
statLabels[statIndex] = scoreLabel;
+2
View File
@@ -1,3 +1,5 @@
package src;
public interface ClassTemplate {
abstract String getDescription();
+2
View File
@@ -1,3 +1,5 @@
package src;
public class Cleric implements ClassTemplate {
private int HP;
+5 -1
View File
@@ -1,4 +1,8 @@
public class Constitution extends Stats {
package src;
import java.io.Serializable;
public class Constitution extends Stats implements Serializable {
private int abilityScore;
private int abilityScoreModifier;
-12
View File
@@ -1,12 +0,0 @@
import java.awt.*;
public interface CustomTheme {
public Color background = null;
public Color foreground = null;
Color getBackground();
Color getForeground();
}
+5 -1
View File
@@ -1,9 +1,13 @@
package src;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class DefaultButton extends JButton implements AppTheme {
import static src.AppConstants.*;
public class DefaultButton extends JButton {
private boolean selected;
+9 -5
View File
@@ -1,9 +1,13 @@
package src;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import java.awt.*;
public class DescriptionPanel extends JPanel implements AppTheme {
import static src.AppConstants.*;
public class DescriptionPanel extends JPanel {
private BasicNavPanel nav;
private String[] characteristics;
@@ -137,12 +141,12 @@ public class DescriptionPanel extends JPanel implements AppTheme {
panel.setOpaque(false);
JLabel label = new JLabel(characteristicsHolder[index]);
label.setFont(paragraphFont);
label.setFont(paragraphText);
label.setOpaque(false);
label.setForeground(darkestBrown);
JTextField field = new JTextField(10);
field.setFont(paragraphFont);
field.setFont(paragraphText);
field.setBackground(lightBrown);
field.setBorder(null);
@@ -219,13 +223,13 @@ public class DescriptionPanel extends JPanel implements AppTheme {
panel.setOpaque(false);
JLabel label = new JLabel("Enter a Description");
label.setFont(paragraphFont);
label.setFont(paragraphText);
label.setOpaque(false);
label.setForeground(darkestBrown);
JTextArea textArea = new JTextArea();
textArea.setForeground(darkestBrown);
textArea.setFont(userTextFont);
textArea.setFont(userText);
textArea.setOpaque(false);
textArea.setBorder(new LineBorder(darkestBrown, 3));
+5 -1
View File
@@ -1,4 +1,8 @@
public class Dexterity extends Stats {
package src;
import java.io.Serializable;
public class Dexterity extends Stats implements Serializable {
private int abilityScore;
private int abilityScoreModifier;
+2
View File
@@ -1,3 +1,5 @@
package src;
public class Dragonborn implements Race {
private final int speed = 30;
private final int maxAge = 80;
+2
View File
@@ -1,3 +1,5 @@
package src;
public class Dwarf implements Race {
private final int speed = 25;
private final int maxAge = 350;
+22 -10
View File
@@ -1,4 +1,8 @@
public class Elf implements Race {
package src;
import java.io.Serializable;
public class Elf implements Race, Serializable {
private final int speed = 30;
private final int maxAge = 750;
private String[] traits;
@@ -14,57 +18,65 @@ public class Elf implements Race {
@Override
public String getRace() {
// TODO Auto-generated method stub
return this.getClass().getSimpleName();
}
@Override
public int maxAge() {
// TODO Auto-generated method stub
return maxAge;
}
@Override
public int getSpeed() {
// TODO Auto-generated method stub
return speed;
}
@Override
public String[] getTraits() {
// TODO Auto-generated method stub
return traits;
}
@Override
public String[] getSkills() {
// TODO Auto-generated method stub
return skills;
}
@Override
public String[] getLanguages() {
// TODO Auto-generated method stub
return languages;
}
@Override
public String[] getProficiencies() {
// TODO Auto-generated method stub
return proficiencies;
}
@Override
public int[] getASI() {
// TODO Auto-generated method stub
return new int[]{1, 1};
}
@Override
public String toString() {
// TODO Auto-generated method stub
return this.getClass().getSimpleName();
}
}
-8
View File
@@ -1,8 +0,0 @@
public class ExportPDF {
public ExportPDF() {
}
}
+13 -2
View File
@@ -1,4 +1,8 @@
public class Fighter implements ClassTemplate {
package src;
import java.io.Serializable;
public class Fighter implements ClassTemplate, Serializable {
private int HP;
@@ -7,7 +11,7 @@ public class Fighter implements ClassTemplate {
// TODO: This should be the type of die.
private int hitDie;
public Fighter(Stats[] stats, int level) {
public Fighter() {
}
@@ -85,4 +89,11 @@ public class Fighter implements ClassTemplate {
return null;
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
}
+104 -60
View File
@@ -1,115 +1,159 @@
package src;
import java.awt.*;
import java.io.*;
import java.util.*;
import static src.AppConstants.*;
public class FileManager {
private File[] savedCharacters;
private String filepath;
private boolean returningUser;
private ArrayList<File> saveFiles;
private ArrayList<CharacterSheet> saves;
public FileManager() {
findSavedCharacters();
saveFiles = new ArrayList<>();
loadFonts();
setSaveFiles();
loadFont();
}
private void loadFonts() {
public int getNumSaves() {
try {
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("SanSalvi.ttf")));
} catch (IOException | FontFormatException e) {
//Handle exception
System.out.println("Error finding font.");
}
return saveFiles.size();
}
public boolean isReturninguser() {
public boolean isReturningUser() {
if (savedCharacters == null) {
return returningUser;
return false;
}
}
public CharacterSheet readSavedCharacter(int index) {
return savedCharacters.length > 0;
return readCharacter(saveFiles.get(index));
}
}
public CharacterSheet readCharacter(int index) {
public void saveCharacter(CharacterSheet completedCharacter) {
CharacterSheet sheet = null;
writeCharacter(completedCharacter);
try {
}
FileInputStream fileIn = new FileInputStream("/dndBuilder/" + savedCharacters[index].getPath() + ".dnd");
ObjectInputStream in = new ObjectInputStream(fileIn);
sheet = (CharacterSheet) in.readObject();
in.close();
fileIn.close();
public ArrayList<CharacterSheet> getSaves() {
} catch (IOException i) {
return saves;
i.printStackTrace();
}
} catch (ClassNotFoundException c) {
// TODO: Need to implement.
public void deleteCharacter() {
System.out.println("Saved characters not found");
c.printStackTrace();
}
}
private void loadFont() {
return sheet;
try {
}
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
public void saveCharacter(CharacterSheet completedCharacter) {
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontFilepath)));
try {
} catch(IOException | FontFormatException e) {
FileOutputStream fileOut =
new FileOutputStream("/dndBuilder/" + completedCharacter.getName().hashCode() + ".dnd");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(completedCharacter);
out.close();
fileOut.close();
System.out.println("Filepath of font not found: " + fontFilepath + " does not exist.");
} catch (IOException i) {
}
i.printStackTrace();
}
}
private void setSaveFiles() {
findSavedCharacters();
File[] tmp = new File(savesFilepath).listFiles();
}
if(tmp != null) {
public void deleteCharacter(int index) {
for(int i = 0; i < tmp.length; i++) {
File[] tmp = new File[savedCharacters.length - 1];
saveFiles.add(tmp[i]);
for (int i = 0; i < savedCharacters.length; i++) {
}
if (i != index) {
returningUser = true;
tmp[i] = savedCharacters[i];
} else {
}
returningUser = false;
}
}
savedCharacters = tmp;
saves = new ArrayList<>();
findSavedCharacters();
for(File file : saveFiles) {
}
saves.add(readCharacter(file));
private void findSavedCharacters() {
}
savedCharacters = new File("/dndBuilder").listFiles();
}
}
private CharacterSheet readCharacter(File file) {
CharacterSheet sheet = null;
try {
FileInputStream fileIn = new FileInputStream(file.getPath());
ObjectInputStream in = new ObjectInputStream(fileIn);
sheet = (CharacterSheet) in.readObject();
in.close();
fileIn.close();
} catch (IOException | ClassNotFoundException e) {
System.out.println("No saved characters were found");
}
return sheet;
}
private void writeCharacter(CharacterSheet sheet) {
try(
FileOutputStream fileOut = new FileOutputStream(savesFilepath + sheet.getName() + ".dnd");
ObjectOutputStream objOut = new ObjectOutputStream(fileOut);
) {
objOut.writeObject(sheet);
setSaveFiles();
} catch (IOException e) {
System.out.println("ERROR: ");
e.printStackTrace();
System.out.println("\nERROR: Unable to write character sheet object to \n" + filepath + "/.savedSheets");
}
}
}
+104 -11
View File
@@ -1,8 +1,17 @@
package src;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import src.AppConstants.*;
public class GUImanager extends JFrame {
private FileManager fileManager;
private ArrayList<CharacterSheet> saves;
private ArrayList<DefaultButton> savesButtons;
private static JPanel[] panels;
private int lastPanel;
private int currentPanel;
@@ -25,24 +34,23 @@ public class GUImanager extends JFrame {
private String[] backgroundDescriptions;
private int[] selectedStats;
public GUImanager(boolean returningUser) {
public GUImanager() {
super("D&D Character Builder");
fileManager = new FileManager();
frameSetup();
setupPanelInfo();
this.panels = new JPanel[]{
new MainMenuPanel(createNewCharacterButton(), createRandomCharacterButton(), createLoadButton()),
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(1), statOptions, statDescriptions, selectedStats, "Step 3: Choose Your Ability Scores"),
new DescriptionPanel(createNavPanel(), characteristics, alignmentOptions, alignmentDescriptions, backgroundOptions, backgroundDescriptions, "Step 4: Describe your character")
new DescriptionPanel(createNavPanel(), characteristics, alignmentOptions, alignmentDescriptions, backgroundOptions, backgroundDescriptions, "Step 4: Describe your character"),
new LoadCharacterPanel(createBackPanel(), loadableCharacters()),
new ViewCharacterPanel(createBackPanel(), new CharacterSheet("Josh", 21, 5, 8, 180, "Brown", "Dark Brown", new Elf(), new Fighter(), "Neutral", "Nomad", new CharacterStats(9, 15, 12, 10, 13, 10)))
};
/*
this.currentPanel = 0;
this.lastPanel = currentPanel - 1;
this.nextPanel = currentPanel + 1;*/
if (returningUser) {
if (fileManager.isReturningUser()) {
this.currentPanel = 0;
@@ -52,6 +60,9 @@ public class GUImanager extends JFrame {
}
this.lastPanel = currentPanel - 1;
this.nextPanel = currentPanel + 1;
add(panels[currentPanel]);
}
@@ -62,7 +73,7 @@ public class GUImanager extends JFrame {
setLayout(new BorderLayout());
setPreferredSize(new Dimension(750, 550));
setSize(getPreferredSize());
// setResizable(false);
setResizable(false);
setLocationRelativeTo(null);
try {
@@ -260,6 +271,12 @@ public class GUImanager extends JFrame {
}
private BasicNavPanel createBackPanel() {
return new BasicNavPanel(createBackButton(0), null, 0);
}
private DefaultButton createBackButton() {
DefaultButton button = new DefaultButton("Back");
@@ -280,6 +297,25 @@ public class GUImanager extends JFrame {
}
private DefaultButton createBackButton(int manualBackPoint) {
DefaultButton button = new DefaultButton("Back");
button.addActionListener(
e -> {
lastPanel = currentPanel;
currentPanel = manualBackPoint;
nextPanel = 0;
clearAndReset();
}
);
return button;
}
private DefaultButton createContinueButton() {
DefaultButton button = new DefaultButton("Continue");
@@ -305,6 +341,19 @@ public class GUImanager extends JFrame {
DefaultButton button = createContinueButton();
button.setText("Create New Character");
button.addActionListener(
e -> {
lastPanel = currentPanel;
currentPanel = 1;
nextPanel = 2;
clearAndReset();
}
);
return button;
}
@@ -361,8 +410,7 @@ public class GUImanager extends JFrame {
e -> {
lastPanel = currentPanel;
currentPanel = 3;
nextPanel = currentPanel + 1;
currentPanel = 5;
clearAndReset();
}
@@ -373,6 +421,50 @@ public class GUImanager extends JFrame {
}
private ArrayList<DefaultButton> loadableCharacters() {
System.out.println("Loading characters...");
saves = fileManager.getSaves();
savesButtons = new ArrayList<>();
for(int i = 0; i < saves.size(); i++) {
savesButtons.add(createLoadNCharacterButton(i));
}
for(int i = 0; i < saves.size(); i++) {
System.out.println(saves.get(i).toString());
}
return savesButtons;
}
private DefaultButton createLoadNCharacterButton(int index) {
DefaultButton button = new DefaultButton(saves.get(index).getName());
button.addActionListener(
e -> {
lastPanel = currentPanel;
panels[5] = new ViewCharacterPanel(createBackPanel(), saves.get(index));
currentPanel = 5;
clearAndReset();
}
);
return button;
}
// TODO: Need to implement random character creation.
private void createRandomCharacter() {
@@ -392,4 +484,5 @@ public class GUImanager extends JFrame {
}
}
+2
View File
@@ -1,3 +1,5 @@
package src;
public class Gnome implements Race {
private final int speed = 25;
private final int maxAge = 500;
+2
View File
@@ -1,3 +1,5 @@
package src;
public class HalfElf implements Race {
private final int speed = 30;
private final int maxAge = 180;
+2
View File
@@ -1,3 +1,5 @@
package src;
public class HalfOrc implements Race {
private final int speed = 30;
private final int maxAge = 75;
+2
View File
@@ -1,3 +1,5 @@
package src;
public class Halfling implements Race {
private final int speed = 30;
private final int maxAge = 750;
+2
View File
@@ -1,3 +1,5 @@
package src;
public class Human implements Race {
private final int speed = 30;
-136
View File
@@ -1,136 +0,0 @@
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("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;
}
}
+21 -5
View File
@@ -1,22 +1,38 @@
package src;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
public class InfoPanel extends JPanel implements AppTheme {
import static src.AppConstants.*;
public class InfoPanel extends JPanel {
protected JTextArea[] descriptions;
protected Rectangle[] bounds;
protected String[] holderDescriptions;
protected String[] categoryHolder;
protected int panelIndex;
protected ImageManager images;
public InfoPanel(String[] categoryHolder, String[] holderDescriptions, Rectangle[] bounds, int panelIndex) {
public InfoPanel(String[] categoryHolder, String[] holderDescriptions, Rectangle[] bounds) {
super();
this.categoryHolder = categoryHolder;
this.holderDescriptions = holderDescriptions;
this.bounds = bounds;
this.panelIndex = panelIndex;
panelSetup();
createDescriptions();
}
public InfoPanel(String[] categoryHolder, String[] holderDescriptions, Rectangle[] bounds, ImageManager images) {
super();
this.categoryHolder = categoryHolder;
this.holderDescriptions = holderDescriptions;
this.bounds = bounds;
panelSetup();
@@ -76,7 +92,7 @@ public class InfoPanel extends JPanel implements AppTheme {
tmpDesc.setOpaque(true);
tmpDesc.setEditable(false);
tmpDesc.setFocusable(false);
tmpDesc.setFont(paragraphFont);
tmpDesc.setFont(paragraphText);
tmpDesc.setBounds(bounds[2]);
tmpDesc.setBorder(new EmptyBorder(5, 5, 5, 5));
tmpDesc.setBackground(medBrown);
+5 -1
View File
@@ -1,4 +1,8 @@
public class Intelligence extends Stats {
package src;
import java.io.Serializable;
public class Intelligence extends Stats implements Serializable {
private int abilityScore;
private int abilityScoreModifier;
+67 -1
View File
@@ -1,2 +1,68 @@
public class LoadCharacterPanel {
package src;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import static src.AppConstants.*;
public class LoadCharacterPanel extends JPanel {
private ArrayList<DefaultButton> savedCharacters;
public LoadCharacterPanel(JPanel nav, ArrayList<DefaultButton> savedCharacters) {
super();
panelSetup();
this.savedCharacters = savedCharacters;
createMasterPanel();
add(nav, BorderLayout.SOUTH);
}
private void panelSetup() {
setBackground(lightBrown);
setLayout(new BorderLayout(0, 0));
}
private void createMasterPanel() {
JLabel title = new JLabel("Load a Character");
title.setHorizontalAlignment(SwingConstants.CENTER);
title.setFont(headerFont);
title.setForeground(darkestBrown);
JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setLayout(null);
//panel.add(buttonPanel());
// TODO: Need to implement.
//panel.add(portraitPanel());
add(buttonPanel(), BorderLayout.NORTH);
}
private JPanel buttonPanel() {
JPanel panel = new JPanel(new GridLayout(savedCharacters.size(), 1, 0, 0));
panel.setOpaque(false);
panel.setBackground(lightBrown);
for(int i = 0; i < savedCharacters.size(); i++) {
panel.add(savedCharacters.get(i));
}
return panel;
}
}
+5 -1
View File
@@ -1,3 +1,5 @@
package src;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
@@ -5,7 +7,9 @@ import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MainMenuPanel extends JPanel implements AppTheme {
import static src.AppConstants.*;
public class MainMenuPanel extends JPanel {
private DefaultButton newCharacter;
private DefaultButton randomCharacter;
-2
View File
@@ -1,2 +0,0 @@
public class PreviewCharacterSheet {
}
+2
View File
@@ -1,3 +1,5 @@
package src;
public interface Race {
String getRace();
+2
View File
@@ -1,3 +1,5 @@
package src;
/**
* Object stores information about a character's skills arrays. Firstly, the name of each skill, and secondly the value of each skill. When constructed, a private method is called
* which adds any proficiency bonus to each skill and then adds the ability score modifier to each skill.
+2
View File
@@ -1,3 +1,5 @@
package src;
public abstract class Stats {
public int calcSavingThrow(int abilityScore) {
+5 -1
View File
@@ -1,4 +1,8 @@
public class Strength extends Stats {
package src;
import java.io.Serializable;
public class Strength extends Stats implements Serializable {
private int abilityScore;
private int abilityScoreModifier;
+2
View File
@@ -1,3 +1,5 @@
package src;
public class Tiefling implements Race {
private final int speed = 30;
private final int maxAge = 85;
+5 -1
View File
@@ -1,4 +1,8 @@
public class Wisdom extends Stats {
package src;
import java.io.Serializable;
public class Wisdom extends Stats implements Serializable {
private int abilityScore;
private int abilityScoreModifier;
+2
View File
@@ -1,3 +1,5 @@
package src;
public class Wizard implements ClassTemplate {
private int HP;
-277
View File
@@ -1,277 +0,0 @@
import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class step4 extends JPanel implements AppTheme {
private JTextField nameTxtField;
private JTextField ageTextField;
private JTextField heightTxtField;
private JTextField weightTxtField;
private JTextField skinTxtField;
private JTextField eyesTxtField;
private JTextField hairTxtField;
/**
* Create the panel.
*/
public step4() {
createEntirePanel();
}
private void createEntirePanel() {
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));
setLayout(new BorderLayout(0, 0));
JLabel lblNewLabel = createLbl();
add(lblNewLabel, BorderLayout.NORTH);
//Creates back and continue panel
JPanel backContPanel = createBackContinuePanel();
add(backContPanel, BorderLayout.SOUTH);
JPanel innerPanel = new JPanel();
innerPanel.setToolTipText("");
innerPanel.setOpaque(false);
add(innerPanel, BorderLayout.CENTER);
innerPanel.setLayout(null);
JPanel nameAndAlignment = new JPanel();
nameAndAlignment.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
nameAndAlignment.setBackground(new Color(210, 105, 30));
nameAndAlignment.setBounds(6, 6, 306, 114);
innerPanel.add(nameAndAlignment);
nameAndAlignment.setLayout(null);
JLabel nameLbl = new JLabel("Character Name: ");
nameLbl.setBounds(6, 6, 108, 16);
nameAndAlignment.add(nameLbl);
nameTxtField = new JTextField();
nameTxtField.setBounds(121, 1, 173, 26);
nameAndAlignment.add(nameTxtField);
nameTxtField.setColumns(10);
JLabel ageLbl = new JLabel("Age: ");
ageLbl.setBounds(6, 34, 32, 16);
nameAndAlignment.add(ageLbl);
ageTextField = new JTextField();
ageTextField.setBounds(61, 34, 64, 21);
nameAndAlignment.add(ageTextField);
ageTextField.setColumns(10);
JLabel heightLbl = new JLabel("Height: ");
heightLbl.setBounds(6, 62, 55, 16);
nameAndAlignment.add(heightLbl);
heightTxtField = new JTextField();
heightTxtField.setBounds(61, 57, 64, 26);
nameAndAlignment.add(heightTxtField);
heightTxtField.setColumns(10);
JLabel weightLbl = new JLabel("Weight:");
weightLbl.setBounds(6, 90, 61, 16);
nameAndAlignment.add(weightLbl);
weightTxtField = new JTextField();
weightTxtField.setBounds(61, 85, 64, 26);
nameAndAlignment.add(weightTxtField);
weightTxtField.setColumns(10);
JLabel skinLbl = new JLabel("Skin: ");
skinLbl.setBounds(131, 34, 35, 16);
nameAndAlignment.add(skinLbl);
skinTxtField = new JTextField();
skinTxtField.setBounds(165, 29, 130, 26);
nameAndAlignment.add(skinTxtField);
skinTxtField.setColumns(10);
JLabel eyesLbl = new JLabel("Eyes: ");
eyesLbl.setBounds(130, 62, 42, 16);
nameAndAlignment.add(eyesLbl);
eyesTxtField = new JTextField();
eyesTxtField.setBounds(164, 57, 130, 26);
nameAndAlignment.add(eyesTxtField);
eyesTxtField.setColumns(10);
JLabel hairLbl = new JLabel("Hair: ");
hairLbl.setBounds(127, 90, 39, 16);
nameAndAlignment.add(hairLbl);
hairTxtField = new JTextField();
hairTxtField.setBounds(164, 85, 130, 26);
nameAndAlignment.add(hairTxtField);
hairTxtField.setColumns(10);
JPanel alignmentPanel = new JPanel();
alignmentPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
alignmentPanel.setBackground(new Color(205, 133, 63));
alignmentPanel.setBounds(324, 6, 396, 114);
innerPanel.add(alignmentPanel);
alignmentPanel.setLayout(new BorderLayout(0, 0));
JLabel alignmentLbl = new JLabel("Alignment");
alignmentLbl.setFont(new Font("Lucida Grande", Font.PLAIN, 19));
alignmentLbl.setHorizontalAlignment(SwingConstants.CENTER);
alignmentPanel.add(alignmentLbl, BorderLayout.NORTH);
JPanel alignmentInnerPanel = new JPanel();
alignmentInnerPanel.setOpaque(false);
alignmentPanel.add(alignmentInnerPanel, BorderLayout.CENTER);
alignmentInnerPanel.setLayout(new GridLayout(3, 3, 0, 0));
JButton btnLawfulGood = new JButton("Lawful Good");
alignmentInnerPanel.add(btnLawfulGood);
JButton btnNuetralGood = new JButton("Neutral Good");
alignmentInnerPanel.add(btnNuetralGood);
JButton btnChaoticGood = new JButton("Chaotic Good");
alignmentInnerPanel.add(btnChaoticGood);
JButton btnLawfulNeutral = new JButton("Lawful Neutral");
alignmentInnerPanel.add(btnLawfulNeutral);
JButton btnTrueNeutral = new JButton("True Neutral");
alignmentInnerPanel.add(btnTrueNeutral);
JButton btnChaoticNeutral = new JButton("Chaotic Neutral");
alignmentInnerPanel.add(btnChaoticNeutral);
JButton btnLawfulEvil = new JButton("Lawful Evil");
alignmentInnerPanel.add(btnLawfulEvil);
JButton btnNeutralEvil = new JButton("Neutral Evil");
alignmentInnerPanel.add(btnNeutralEvil);
JButton btnChaoticEvil = new JButton("Chaotic Evil");
alignmentInnerPanel.add(btnChaoticEvil);
JPanel backgroundPanel = new JPanel();
backgroundPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
backgroundPanel.setBackground(new Color(210, 105, 30));
backgroundPanel.setBounds(6, 132, 306, 264);
innerPanel.add(backgroundPanel);
backgroundPanel.setLayout(new BorderLayout(0, 0));
JLabel backgroundLbl = new JLabel("Background");
backgroundLbl.setFont(new Font("Dialog", Font.PLAIN, 20));
backgroundLbl.setHorizontalAlignment(SwingConstants.CENTER);
backgroundPanel.add(backgroundLbl, BorderLayout.NORTH);
JPanel backgroundInnerPanel = new JPanel();
backgroundInnerPanel.setOpaque(false);
backgroundPanel.add(backgroundInnerPanel, BorderLayout.CENTER);
backgroundInnerPanel.setLayout(new GridLayout(9, 2, 0, 0));
JButton btnAcolyte = new JButton("Acolyte");
backgroundInnerPanel.add(btnAcolyte);
JButton btnCharlatan = new JButton("Charlatan");
backgroundInnerPanel.add(btnCharlatan);
JButton btnCriminal = new JButton("Criminal");
backgroundInnerPanel.add(btnCriminal);
JButton btnEntertainer = new JButton("Entertainer");
backgroundInnerPanel.add(btnEntertainer);
JButton btnFolkHero = new JButton("Folk Hero");
backgroundInnerPanel.add(btnFolkHero);
JButton btnGladiator = new JButton("Gladiator");
backgroundInnerPanel.add(btnGladiator);
JButton btnGuildArtisan = new JButton("Guild Artisan");
backgroundInnerPanel.add(btnGuildArtisan);
JButton btnGuildMerchant = new JButton("Guild Merchant");
backgroundInnerPanel.add(btnGuildMerchant);
JButton btnHermit = new JButton("Hermit");
backgroundInnerPanel.add(btnHermit);
JButton btnKnight = new JButton("Knight");
backgroundInnerPanel.add(btnKnight);
JButton btnNoble = new JButton("Noble");
backgroundInnerPanel.add(btnNoble);
JButton btnOutlander = new JButton("Outlander");
backgroundInnerPanel.add(btnOutlander);
JButton btnPirate = new JButton("Pirate");
backgroundInnerPanel.add(btnPirate);
JButton btnSage = new JButton("Sage");
backgroundInnerPanel.add(btnSage);
JButton btnSailor = new JButton("Sailor");
backgroundInnerPanel.add(btnSailor);
JButton btnSoldier = new JButton("Soldier");
backgroundInnerPanel.add(btnSoldier);
JButton btnSpy = new JButton("Spy");
backgroundInnerPanel.add(btnSpy);
JButton btnUrchin = new JButton("Urchin");
backgroundInnerPanel.add(btnUrchin);
JPanel panel = new JPanel();
panel.setBackground(new Color(205, 133, 63));
panel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
panel.setBounds(324, 132, 396, 264);
panel.setLayout(new BorderLayout(0, 0));
JLabel lblDescription = new JLabel("Description");
lblDescription.setFont(new Font("Lucida Grande", Font.PLAIN, 20));
lblDescription.setHorizontalAlignment(SwingConstants.CENTER);
JTextArea textArea = new JTextArea();
textArea.setBackground(new Color(238, 232, 170));
panel.add(lblDescription, BorderLayout.NORTH);
panel.add(textArea, BorderLayout.CENTER);
innerPanel.add(panel);
}
private JPanel createBackContinuePanel() {
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) {
}
});
backContPanel.add(backBtn);
JButton continueBtn = new JButton("Continue --->");
continueBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
backContPanel.add(continueBtn);
return backContPanel;
}
/**
* @return
*/
private JLabel createLbl() {
JLabel titleLbl = new JLabel("Step 4: Description");
titleLbl.setHorizontalAlignment(SwingConstants.CENTER);
titleLbl.setFont(new Font("Bodoni 72 Oldstyle", Font.PLAIN, 33));
return titleLbl;
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 351 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 233 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 247 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 324 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 267 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 374 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 268 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 305 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 477 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 258 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

Some files were not shown because too many files have changed in this diff Show More