-
Notifications
You must be signed in to change notification settings - Fork 2
/
EventWindow.pde
205 lines (171 loc) · 5.99 KB
/
EventWindow.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
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
import org.gicentre.utils.stat.*;
public class EventWindow implements Window {
private ControlP5 control;
private Button playPause;
private Button stop;
private Slider timeFrame;
private WindowHeader header;
private GameEvent gameEvent;
private BasketballCourt b;
private ArrayList<GameEventFrame> events;
private float currentEvent = 0;
private boolean playing;
String[] labelsDistHome;
float[] valuesDistHome;
String[] labelsDistVisitor;
float[] valuesDistVisitor;
BarChart chartDistancesHome;
BarChart chartDistancesVisitor;
public EventWindow(GameEvent gameEvent) {
this.header = new WindowHeader("Event: " + gameEvent.getHomeDescription() + gameEvent.getVisitorDescription());
this.gameEvent = gameEvent;
this.playing = false;
}
public void setup() {
this.b = new BasketballCourt(650, 400, this.gameEvent);
this.b.setup();
events = this.gameEvent.getEventFrames();
control = new ControlP5(WINDOW_APPLET);
timeFrame = control.addSlider("events", "", "")
.setPosition(120, 70)
.setSize(450,25)
.setValue(0)
.setRange(0, events.size() - 1);
playPause = control.addButton("playback", "", "play")
.setValue(0)
.setPosition(20, 70)
.setSize(40, 25);
stop = control.addButton("stop", "", "stop")
.setValue(0)
.setPosition(70, 70)
.setSize(40, 25);
HashMap<String, Float> distancesHome = gameEvent.getDistanceTraveledHomeTeam();
labelsDistHome = new String[distancesHome.size()];
valuesDistHome = new float[distancesHome.size()];
int pIdx = 0;
for(String player : distancesHome.keySet()) {
labelsDistHome[pIdx] = player;
valuesDistHome[pIdx] = distancesHome.get(player);
pIdx++;
}
HashMap<String, Float> distancesVisitor = gameEvent.getDistanceTraveledVisitorTeam();
labelsDistVisitor = new String[distancesVisitor.size()];
valuesDistVisitor = new float[distancesVisitor.size()];
pIdx = 0;
for(String player : distancesVisitor.keySet()) {
labelsDistVisitor[pIdx] = player;
valuesDistVisitor[pIdx] = distancesVisitor.get(player);
pIdx++;
}
this.setupDistanceGraphs();
}
public void draw() {
background(COLOR_BACKGROUND);
GameEventFrame ge = events.get((int)currentEvent);
control.draw();
fill(COLOR_GRAY1);
textAlign(LEFT);
textFont(FONT_BOLD_14);
text(gameEvent.getGame().getHomeTeam().getAbbreviation(), 610, 87);
text(gameEvent.getGame().getVisitorTeam().getAbbreviation(), 675, 87);
fill(COLOR_HOME_TEAM);
ellipse(595, 82, 20, 20);
fill(COLOR_VISITOR_TEAM);
ellipse(660, 82, 20, 20);
pushMatrix();
translate(20, 105);
fill(COLOR_BEIGE2);
rect(0, 0, b.getWidth() + 40, b.getHeight() + 40);
translate(20, 20);
b.draw();
b.drawPlayersAndBall(ge.getHomeTeam(), ge.getVisitorTeam(), ge.getBall());
translate(-20, b.getHeight() + 35);
fill(COLOR_BEIGE2);
rect(0, 0, b.getWidth() + 40, 170);
translate(20, 20);
fill(COLOR_GRAY1);
textAlign(LEFT);
textFont(FONT_BOLD_14);
text("Game Clock: " + ge.getGameClock() + " sec", 0, 10);
text("Shot Clock: " + ge.getShotClock() + " sec", 0, 35);
text("Ball Height: " + ge.getBall()[2] + " ft", 0, 60);
popMatrix();
textAlign(CENTER);
pushMatrix();
translate(730, 70);
fill(COLOR_BEIGE2);
rect(0, 0, 355, 295);
textFont(FONT_12);
chartDistancesHome.draw(17, 50, 320, 235);
textFont(FONT_BOLD_16);
fill(COLOR_GRAY1);
text("Distance Traveled (" + gameEvent.getGame().getHomeTeam().getAbbreviation() + ")", 355/2, 30);
translate(0, 310);
fill(COLOR_BEIGE2);
rect(0, 0, 355, 295);
textFont(FONT_12);
chartDistancesVisitor.draw(17, 50, 320, 235);
textFont(FONT_BOLD_16);
fill(COLOR_GRAY1);
text("Distance Traveled (" + gameEvent.getGame().getVisitorTeam().getAbbreviation() + ")", 355/2, 30);
popMatrix();
// If play is on, move to next frame
if(playing) {
timeFrame.setValue((currentEvent+1)%events.size());
}
header.draw();
}
private void setupDistanceGraphs() {
// Distances Home Team
chartDistancesHome = new BarChart(WINDOW_APPLET);
chartDistancesHome.setData(valuesDistHome);
chartDistancesHome.setMinValue(0);
chartDistancesHome.setMaxValue(max(valuesDistHome));
// Appearance
fill(255);
textFont(FONT_12);
chartDistancesHome.setBarColour(COLOR_HOME_TEAM);
chartDistancesHome.setBarGap(10);
chartDistancesHome.showValueAxis(true);
chartDistancesHome.setValueFormat("# ft");
chartDistancesHome.setBarLabels(labelsDistHome);
chartDistancesHome.showCategoryAxis(true);
chartDistancesHome.transposeAxes(true);
// Distances Visitor Team
chartDistancesVisitor = new BarChart(WINDOW_APPLET);
chartDistancesVisitor.setData(valuesDistVisitor);
chartDistancesVisitor.setMinValue(0);
chartDistancesVisitor.setMaxValue(max(valuesDistVisitor));
// Appearance
fill(255);
textFont(FONT_12);
chartDistancesVisitor.setBarColour(COLOR_VISITOR_TEAM);
chartDistancesVisitor.setBarGap(10);
chartDistancesVisitor.showValueAxis(true);
chartDistancesVisitor.setValueFormat("# ft");
chartDistancesVisitor.setBarLabels(labelsDistVisitor);
chartDistancesVisitor.showCategoryAxis(true);
chartDistancesVisitor.transposeAxes(true);
}
public void mouseEvent(int eventType) {
b.mouseEvent(eventType);
header.mouseEvent(eventType);
}
public void event(ControlEvent event) {
if(event.isFrom(timeFrame)) {
currentEvent = timeFrame.getValue();
} else if(event.isFrom(playPause)) {
playing = !playing;
if(playing)
playPause.setLabel("pause");
else
playPause.setLabel("play");
} else if(event.isFrom(stop)) {
playing = false;
timeFrame.setValue(0);
}
}
public void clearControls() {
control.dispose();
}
}