-
Notifications
You must be signed in to change notification settings - Fork 0
/
panel.pde
77 lines (65 loc) · 2.37 KB
/
panel.pde
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
final int TARGET_SIZE = 40;
class Panel {
float x, y, width; // positional values
boolean isVisible;
ArrayList<ATarget> targets;
int[] c = new int[3];
PImage img;
Panel(float x, float y, float width, ArrayList<ATarget> targets, int r, int g, int b, PImage img) {
this.x = x;
this.y = y;
this.width = width;
this.isVisible = false;
this.targets = targets;
this.c = new int[] { r, g, b };
this.img = img;
}
void draw() {
float posX = x - boardMap.xo;
float posY = y - boardMap.yo;
if (isVisible) {
fill(255, 255, 255);
rect(posX, posY, width, 200);
fill(255, 0, 0);
for (int i = 0; i < targets.size(); i += 2) {
text(targets.get(i).getName(), posX + 10 + i * 60, posY + 30);
rect(posX+10+i*60,posY+30, TARGET_SIZE, TARGET_SIZE);
}
for (int i = 1; i < targets.size(); i+= 2) {
text(targets.get(i).getName(), posX + 10 + (i - 1) * 60, posY + 100);
rect(posX + 10 + (i - 1) * 60, posY + 100, TARGET_SIZE, TARGET_SIZE);
}
}
fill(this.c[0], this.c[1], this.c[2]);
rect(this.x - boardMap.xo, boardMap.numCols * boardMap.gridsize - 20 - boardMap.yo, 20, 20);
image(this.img, this.x - boardMap.xo, boardMap.numCols * boardMap.gridsize - 20 - boardMap.yo);
}
void click() {
float posX = x - boardMap.xo;
float posY = y + boardMap.yo;
if (isVisible) {
for (int i = 0; i < targets.size(); i += 2) {
if (posX + 10 + i * 60 < mouseX - boardMap.xo && mouseX- boardMap.xo < posX + 70 + i * 60 && posY + 30 < mouseY + boardMap.yo && mouseY + boardMap.yo < posY + 30 + TARGET_SIZE) {
targets.get(i).clicked();
}
}
for (int i = 1; i < targets.size(); i += 2) {
if (posX + 10 + (i - 1) * 60 < mouseX - boardMap.xo && mouseX- boardMap.xo < posX + 70 + (i - 1) * 60 && posY + 100 < mouseY + boardMap.yo && mouseY + boardMap.yo < posY + 100 + TARGET_SIZE) {
targets.get(i).clicked();
}
}
}
}
boolean inPanelToggle(int x, int y) {
return (this.x < mouseX && this.x + 20 > mouseX && boardMap.numCols * boardMap.gridsize - 20 < mouseY &&
boardMap.numCols * boardMap.gridsize > mouseY);
}
void toggleVisible() {
for (Panel panel : userInterface.panels) {
if (panel != this) {
panel.isVisible = false;
}
}
this.isVisible = !this.isVisible;
}
}