-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToggleButton.java
More file actions
86 lines (70 loc) · 1.63 KB
/
ToggleButton.java
File metadata and controls
86 lines (70 loc) · 1.63 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
/**
* this is an extension of the button class to allow the button to have states,
* an example would be the top button in the option screen,
* it swaps between two states > keyboard and mouse
* @author elan
*
*/
public class ToggleButton extends Button
{
private String[] states;
private String mainText;
private int currentState = 0;
public ToggleButton(double x, double y, double w, double h, String t)
{
super(x, y, w, h, t);
mainText = t;
text = mainText + ": " + states[currentState];
}
public ToggleButton(Button button)
{
super(button.x, button.y, button.width, button.height, button.text);
}
public ToggleButton(double x, double y, double w, double h, String t, String[] states)
{
super(x, y, w, h, t);
this.states = new String[states.length];
for (int i = 0; i < states.length; i++)
this.states[i] = states[i];
mainText = t;
setText();
}
public void addStates(String[] states)
{
this.states = new String[states.length];
for (int i = 0; i < states.length; i++)
this.states[i] = states[i];
mainText = text;
setText();
}
private void toggle()
{
currentState++;
if(currentState >= states.length)
currentState = 0;
text = mainText + ": " + states[currentState];
}
public void clicked()
{
toggle();
if(mainText.equals("Controls"))
{
States.controlsKeyboard = !States.controlsKeyboard;
}
}
public void checkStates()
{
if(mainText.equals("Controls"))
{
if(!States.controlsKeyboard && currentState != 1)
{
currentState = 1;
setText();
}
}
}
private void setText()
{
text = mainText + ": " + states[currentState];
}
}