-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.java
168 lines (141 loc) · 4.68 KB
/
Settings.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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class Settings extends JPanel {
JButton exitButton;
boolean isOpen = false, isClick = false, isHover = false;
JPanel musicVolumeDisplay = new JPanel(), sfxVolumeDisplay = new JPanel();
JSlider musicVolume, sfxVolume;
JLabel musicLevel = new JLabel("50"), sfxLevel = new JLabel("50"), music = new JLabel("Music Volume"), sfx = new JLabel("SFX Volume");
int musicVolumeLevel = Bson.getMusicVolume(), sfxVolumeLevel = Bson.getSFXVolume();
public Settings() {
super();
exitButton = new JButton("Exit");
exitButton.setBounds(10, 10, 80, 40);
exitButton.setFocusable(true);
exitButton.addActionListener((e) -> {
if (GameFrame.isGame) GameFrame.board.setVisible(true);
// else if (GameFrame.isEdit) GameFrame.editor.setVisible(true);
else GameFrame.levelSelect.setVisible(true);
this.setVisible(false);
Sound.playSfx(0);
});
this.setBounds(0, 0, 800, 500);
this.setLayout(null);
this.setVisible(false);
this.setFocusable(true);
this.requestFocus();
// add more stuff later
music.setBounds(100, 200, 100, 40);
music.setVisible(true);
this.add(music);
musicVolume = new JSlider();
musicVolume.setBounds(100, 240, 600, 20);
musicVolume.setPaintTicks(true);
musicVolume.setMajorTickSpacing(10);
this.add(musicVolume);
musicVolume.setVisible(true);
musicVolume.setValue(musicVolumeLevel);
musicVolume.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
musicVolumeLevel = musicVolume.getValue();
displayMusicVolume(musicVolumeLevel);
Sound.setMusicVolume(musicVolumeLevel);
Bson.updateMusic(musicVolumeLevel);
}
});
musicVolume.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
isClick = true;
}
public void mouseReleased(MouseEvent e) {
isClick = false;
if (!isHover) musicVolumeDisplay.setVisible(false);
}
public void mouseEntered(MouseEvent e) {
isHover = true;
musicVolumeLevel = musicVolume.getValue();
displayMusicVolume(musicVolumeLevel);
}
public void mouseExited(MouseEvent e) {
isHover = false;
if (!isClick) musicVolumeDisplay.setVisible(false);
}
});
musicVolumeDisplay.setVisible(false);
musicVolumeDisplay.setBackground(Color.white);
musicVolumeDisplay.add(musicLevel);
this.add(musicVolumeDisplay);
//sfx
sfx.setBounds(100, 270, 100, 40);
sfx.setVisible(true);
this.add(sfx);
sfxVolume = new JSlider();
sfxVolume.setBounds(100, 310, 600, 20);
sfxVolume.setPaintTicks(true);
sfxVolume.setMajorTickSpacing(10);
this.add(sfxVolume);
sfxVolume.setVisible(true);
sfxVolume.setValue(sfxVolumeLevel);
sfxVolume.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
sfxVolumeLevel = sfxVolume.getValue();
displaySfxVolume(sfxVolumeLevel);
Sound.setSfxVolume(sfxVolumeLevel);
Bson.updateSFX(sfxVolumeLevel);
}
});
sfxVolume.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
isClick = true;
}
public void mouseReleased(MouseEvent e) {
isClick = false;
if (!isHover) sfxVolumeDisplay.setVisible(false);
}
public void mouseEntered(MouseEvent e) {
isHover = true;
sfxVolumeLevel = sfxVolume.getValue();
displaySfxVolume(sfxVolumeLevel);
}
public void mouseExited(MouseEvent e) {
isHover = false;
if (!isClick) sfxVolumeDisplay.setVisible(false);
}
});
sfxVolumeDisplay.setVisible(false);
sfxVolumeDisplay.setBackground(Color.white);
sfxVolumeDisplay.add(sfxLevel);
this.add(sfxVolumeDisplay);
this.add(exitButton);
}
/**
* displays the music volume tag
*
* @param i provides the mouse's x position
*/
public void displayMusicVolume(int i) {
musicLevel.setText(String.valueOf(i));
//starts at 98
//ends at 682
musicVolumeDisplay.setBounds(98 + (int)Math.round(5.84 * i), 220, 20, 20);
musicVolumeDisplay.setVisible(true);
}
/**
* displays the sound effect's volume tag
*
* @param i provides the mouse's x position
*/
public void displaySfxVolume(int i) {
sfxLevel.setText(String.valueOf(i));
//starts at 98
//ends at 682
sfxVolumeDisplay.setBounds(98 + (int)Math.round(5.84 * i), 290, 20, 20);
sfxVolumeDisplay.setVisible(true);
}
}