-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHelp.java
More file actions
122 lines (110 loc) · 4.19 KB
/
Help.java
File metadata and controls
122 lines (110 loc) · 4.19 KB
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
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.ArrayList;
import java.awt.image.BufferedImage;
//this class implements the help screen
public class Help extends MouseAdapter {
//PROPERTIES
//int value that represents the current help screen
private int intHelpScreen;
private HelpPanel helpPanel;
private Timer helpTimer = new Timer(1000/60, event -> helpPanel.repaint());
//image for the current help screen being displayed
private BufferedImage currentHelpImage;
//list of areas to be clicked, used to change the help screen
private ArrayList<ClickableArea> clickAreaList = new ArrayList<>();
//list of images for the help screens
private ArrayList<BufferedImage> helpImageList = new ArrayList<>();
//METHODS
@Override
public void mouseClicked(MouseEvent evt) {
//iterate through areas to see if one was clicked
for(ClickableArea area : clickAreaList) {
if(area.clickedArea(evt)) {
//set the current image to the chosen one
currentHelpImage = helpImageList.get(area.intNumber - 1);
//save the current screen number
intHelpScreen = area.intNumber;
break;
}
}
}
//add all the clickable areas to the lists
private void initializeClickAreas() {
for(int i = 0; i < 9; i++) {
clickAreaList.add(new ClickableArea(382 + (i*60), 652, (i+1)));
}
}
//load all the help images
private void initImages() {
for(int i = 0; i < 9; i++) {
//load the dark or white version depending on settings
helpImageList.add(Utility.loadImage("Assets/" + (Settings.isDark()?"Dark":"White") + "_Help/help_" + (i+1) + ".png", this.getClass()));
}
currentHelpImage = helpImageList.get(0);
}
public JPanel getHelpPanel() {
return helpPanel;
}
//standard CONSTRUCTOR
public Help() {
helpPanel = new HelpPanel();
helpPanel.setPreferredSize(Utility.panelDimensions);
helpPanel.addMouseListener(this);
initializeClickAreas();
initImages();
helpTimer.start();
}
//CONSTRUCTOR to launch the help panel at a particular screen
public Help(int intScreenNum) {
helpPanel = new HelpPanel();
helpPanel.setPreferredSize(Utility.panelDimensions);
helpPanel.addMouseListener(this);
initializeClickAreas();
initImages();
helpTimer.start();
currentHelpImage = helpImageList.get(intScreenNum-1<0?0:intScreenNum-1);
}
//class that implements the ui for the help screen
private class HelpPanel extends JPanel {
//PROPERTIES
private JButton backButton = new JButton("BACK");
private JButton tutorialButton = new JButton("TUTORIAL");
//CONSTRUCTOR, initalize ui elements
HelpPanel() {
super(null);
backButton.setSize(116, 45);
backButton.setLocation(30, 28);
backButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
helpTimer.stop();
Utility.changePanel(new MainMenu().getMenuPanel());
}
});
Utility.setButtonStyle(backButton, 12);
tutorialButton.setSize(150, 45);
tutorialButton.setLocation(1100, 28);
tutorialButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
helpTimer.stop();
Utility.changePanel(new TutorialMode(intHelpScreen).getTutorialPanel());
}
});
Utility.setButtonStyle(tutorialButton, 12);
add(backButton);
add(tutorialButton);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if(currentHelpImage != null) {
//draw the current help image to the screen
g.drawImage(currentHelpImage, 0, 0, null);
}
}
}
}