-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCharSelectionPanel.java
302 lines (259 loc) · 11.9 KB
/
CharSelectionPanel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.Font;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* The character selection screen of The Wellesley Trail. Allows for a user to
* to select an archetype to play as. Modifies a Person object with the
* archetype's sleep, smart, and social points.
*
* @author Zahra Thabet
* @author Nolen Belle Bryant
* @author Giulia Bronzi
*
* @version 12.17.18
*/
public class CharSelectionPanel extends JPanel
{
//creates panels to distinguish between the different parts of the
//character selection panel
private JPanel charPanel, instructRow, topRow, midRow, botRow;
private JPanel background, foreground;
private JLabel instruct1, instruct2, instruct3;
private JTextArea persStats; //displays the selected archetype's points
private JRadioButton athletic, hermit, horse, offCampus, society,wendy;
private JButton next;
private Person player; //Person object to be modified
private Boolean hasSelectedBefore; //tracks if next button should appear
private JLayeredPane content;//holds the background foreground displays
public CharSelectionPanel()
{
background = new JPanel();
background.setLayout(new BorderLayout());
foreground = new JPanel();
foreground.setLayout(new BorderLayout());
Font verand = new Font("Verdana", Font.BOLD, 20);
//next button shouldn't appear before an archetype has been selected
hasSelectedBefore=false;
instructRow = new JPanel();
//makes the background translucent
//instructRow.setBackground(new Color(0,0,0,0));
topRow = new JPanel ();
topRow.setBackground(new Color(0,0,0,0));
midRow = new JPanel();
midRow.setBackground(new Color(0,0,0,0));
botRow = new JPanel();
botRow.setBackground(new Color(0,0,0,0));
charPanel = new JPanel();
charPanel.setBackground(new Color(0,0,0,0));
//creates two rows of the character archetypes
charPanel.add(topRow);
charPanel.add(midRow);
//adds panels to the charSelect panel in the foreground of image
foreground.add(instructRow, BorderLayout.NORTH);
foreground.add(charPanel, BorderLayout.CENTER);
foreground.add(botRow,BorderLayout.SOUTH);
//testing for solving the bug
//botRow.setOpaque(true);
instruct1 = new JLabel("Select an archetype. Their sleep, smart and"
+ " social points will display below.");
instruct1.setFont(verand);
instruct2 = new JLabel("Each archetype comes with specialized points"+
" based on personality.");
instruct2.setFont(verand);
instruct3= new JLabel("When satsified with your choice, press the next"
+" button.");
instruct3.setFont(verand);
instructRow.add(instruct1,BorderLayout.NORTH);
instructRow.add(instruct2,BorderLayout.CENTER);
instructRow.add(instruct3,BorderLayout.SOUTH);
instructRow.setPreferredSize(new Dimension(1100,125));
//creates archetype radio buttons
athletic = new JRadioButton ("Athletic Alex");
athletic.setFont(verand);
hermit = new JRadioButton ("Hermit Harper");
hermit.setFont(verand);
horse = new JRadioButton ("Horse Girl Grace");
horse.setFont(verand);
offCampus = new JRadioButton ("Off Campus Ollie");
offCampus.setFont(verand);
society = new JRadioButton ("Society Skylar");
society.setFont(verand);
wendy = new JRadioButton ("Wendy Wellesley");
wendy.setFont(verand);
persStats = new JTextArea("");
persStats.setBackground(new Color(0,0,0,0));
persStats.setFont(verand);
ButtonGroup group = new ButtonGroup();
group.add (athletic);
group.add (hermit);
group.add (horse);
group.add(offCampus);
group.add(society);
group.add(wendy);
ButtonListener listener = new ButtonListener();
athletic.addActionListener (listener);
hermit.addActionListener (listener);
horse.addActionListener (listener);
offCampus.addActionListener (listener);
society.addActionListener (listener);
wendy.addActionListener (listener);
//adds half of the archetype images and radio buttons to the top panel
try{
ImageIcon image = new ImageIcon(ImageIO.read(
new File("images/AthleticAlex.png")));
Image pic = image.getImage(); // transform it
Image newimg = pic.getScaledInstance(
100, 200, java.awt.Image.SCALE_SMOOTH);
image = new ImageIcon(newimg); // transform it back
topRow.add(new JLabel(image));
} catch(IOException e){
System.out.println("Image not found in directory.");
}
topRow.add (athletic);
try{
ImageIcon image = new ImageIcon(ImageIO.read(
new File( "images/HermitHarper.png")));
Image pic = image.getImage(); // transform it
Image newimg = pic.getScaledInstance(
100, 200, java.awt.Image.SCALE_SMOOTH);
image = new ImageIcon(newimg); // transform it back
topRow.add(new JLabel(image));
} catch(IOException e){
System.out.println("Image not found in directory.");
}
topRow.add (hermit);
try{
ImageIcon image = new ImageIcon(ImageIO.read(
new File( "images/HorseGirlGrace.png")));
Image pic = image.getImage(); // transform it
Image newimg = pic.getScaledInstance(
100, 200, java.awt.Image.SCALE_SMOOTH);
image = new ImageIcon(newimg); // transform it back
topRow.add(new JLabel(image));
} catch(IOException e){
System.out.println("Image not found in directory.");
}
topRow.add (horse);
//adds the second half the arhcetypes' images and radio buttons to the
//midRow
try{
ImageIcon image = new ImageIcon(ImageIO.read(
new File("images/OffCampusOllie.png")));
Image pic = image.getImage(); // transform it
Image newimg = pic.getScaledInstance(
100, 200, java.awt.Image.SCALE_SMOOTH);
image = new ImageIcon(newimg); // transform it back
midRow.add(new JLabel(image));
} catch(IOException e){
System.out.println("Image not found in directory.");
}
midRow.add (offCampus);
try{
ImageIcon image = new ImageIcon(ImageIO.read(
new File("images/SocietySkylar.png")));
Image pic = image.getImage(); // transform it
Image newimg = pic.getScaledInstance(
100, 200, java.awt.Image.SCALE_SMOOTH);
image = new ImageIcon(newimg); // transform it back
midRow.add(new JLabel(image));
} catch(IOException e){
System.out.println("Image not found in directory.");
}
midRow.add (society);
try{
ImageIcon image = new ImageIcon(ImageIO.read(
new File("images/WendyWellesley.png")));
Image pic = image.getImage(); // transform it
Image newimg = pic.getScaledInstance(
100, 200, java.awt.Image.SCALE_SMOOTH);
image = new ImageIcon(newimg); // transform it back
midRow.add(new JLabel(image));
} catch(IOException e){
System.out.println("Image not found in directory.");
}
midRow.add (wendy);
//importing background image
try {
//scaling all input files to be the same size
ImageIcon image = new ImageIcon(ImageIO.read(
new File("images/CharScreen.jpg")));
Image pic = image.getImage(); // transform it
Image newimg = pic.getScaledInstance(
1200, 800, java.awt.Image.SCALE_SMOOTH);
image = new ImageIcon(newimg); // transform it back
background.add(new JLabel(image), BorderLayout.CENTER);
} catch (IOException e) {
e.printStackTrace();
}
//holds a background images and a panel on top
content = new JLayeredPane();
//add both back and foreground to the container
foreground.setBackground(new Color(0,0,0,0));
content.setBounds(0, 0, 1200, 800); //same as frame
content.setBackground(new Color(0,0,0,0));
foreground.setBounds(0, 00, 1200, 800);
background.setOpaque(true);
background.setBounds(0, 00, 1200, 800);
foreground.setOpaque(false);
content.add(background, new Integer(0), 0); //sets to the background
content.add(foreground, new Integer(1), 0);//sets to the foregound
setLayout(new BorderLayout());
botRow.add (persStats);//adds the person's scores to the bottom row
add(content, BorderLayout.CENTER);
add(botRow,BorderLayout.SOUTH);
}
/**
* Represents the listener for all buttons
*/
private class ButtonListener implements ActionListener
{
/**
* Sets the archetype of the Person depending on which radio button was
* pressed.
*
* @param event action event that triggers the action
*/
public void actionPerformed (ActionEvent event)
{
//if the source of the action is an archetype's radio button
if(!(event.getSource()==next)){
//if this is the first radio button pressed, display the next
//button
if (!hasSelectedBefore){
next = new JButton("next");
next.addActionListener(new ButtonListener());
next.setBackground(new Color(0,0,0,0));
botRow.add(next); //adds the next button to the bottom row
}
//the Person object gets the selected archetype's points
JRadioButton source = (JRadioButton)event.getSource();
String chosenName = source.getText();
player = new Person(chosenName);
persStats.setText(player.toString());
//reloads the screen which solves the problem of the text
//dublicating itself
revalidate();
repaint();
//signals that the next button doesn't need to be created again
hasSelectedBefore = true;
}else{
JPanel borderPanel = (JPanel)content.getParent();
JPanel cardLayoutPanel = (JPanel)borderPanel.getParent();
CardLayout layout = (CardLayout)cardLayoutPanel.getLayout();
//creates a new situation tree from a text file
TrailsBinaryTree tree = new TrailsBinaryTree("Situations.txt");
//creates a new SituationPanel from the player and the tree
SituationPanel nextPanel = new SituationPanel(player, tree);
//adds a new card to the CardLayout layout
cardLayoutPanel.add(nextPanel,"startSit");
//shows this new card
layout.show(cardLayoutPanel, "startSit");
}
}
}
}