-
Notifications
You must be signed in to change notification settings - Fork 0
/
IceTimer.pde
206 lines (180 loc) · 5.61 KB
/
IceTimer.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
//
// IceTimer - Graphical timer and match scheduler for pick-up ice hockey
// Copyright (C) 2014–15 Joe Cridge
//
// This file is part of IceTimer.
//
// IceTimer is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// IceTimer is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with IceTimer. If not, see <http://www.gnu.org/licenses/>.
//
// Joe Cridge, February 2015.
// <[email protected]>
//
import java.util.Calendar;
import javax.swing.ImageIcon;
final color TIMER_GREY = color(60);
final color TIMER_GREEN = color(0, 175, 0);
final color TIMER_AMBER = color(220, 130, 0);
final color TIMER_RED = color(195, 0, 0);
boolean inSession, fullScreen;
color highlight;
ControlPanel controlPanel;
SessionBar sessionBar;
MatchList matchList;
void setup() {
// Initialise global variables
inSession = false;
highlight = TIMER_GREEN;
// Load preferences
Table prefs = loadTable("prefs.csv");
int halfIceThresh = prefs.getInt(1, 1);
int thirdIceThresh = prefs.getInt(2, 1);
int endHour = prefs.getInt(3, dayNumber());
int endMin = prefs.getInt(4, dayNumber());
int nTeams = prefs.getInt(5, 1);
int matchLength = prefs.getInt(6, 1);
int nSim;
if (nTeams < halfIceThresh) {
nSim = 1;
} else if (nTeams < thirdIceThresh) {
nSim = 2;
} else {
nSim = 3;
}
fullScreen = boolean(prefs.getString(7, 1));
// Initialise frame
if (fullScreen) {
size(displayWidth, displayHeight);
} else {
size(1000, 700);
}
background(highlight);
noStroke();
smooth();
// Create interface components
String clubName = prefs.getString(0, 1);
PImage clubLogo = loadImage("images/logo.png");
String panelTitle = dayName() + " " + clubName;
controlPanel = new ControlPanel(panelTitle, clubLogo, endHour, endMin, nTeams, nSim, halfIceThresh, thirdIceThresh);
sessionBar = new SessionBar();
matchList = new MatchList(nSim, matchLength);
// Set window properties
ImageIcon titlebaricon = new ImageIcon(loadBytes("images/icon_16.gif"));
frame.setIconImage(titlebaricon.getImage());
frame.setTitle(panelTitle + " | IceTimer 1.2");
}
void draw() {
// Update highlight colour if necessary
if (sessionBar.hasChangedColour) {
color newColour = sessionBar.getHighlightColour();
highlight = newColour;
controlPanel.setHighlightColour(newColour);
sessionBar.hasChangedColour = false;
}
// Texture background
background(highlight);
fill(lerpColor(highlight, TIMER_GREY, 0.1));
for (int i = 0; i < height; i++) {
if (int(i/3.0) % 2 == 1) {
rect(0, i, width, 1);
}
}
// Refresh timers
matchList.update();
sessionBar.update();
// Display interface components
matchList.display();
controlPanel.display();
sessionBar.display();
}
void keyPressed() {
if (key == ' ') {
matchList.playPause();
} else if (key == '+') {
matchList.advanceGame(1);
} else if (key == '_') {
matchList.advanceGame(-1);
} else if (key == 'C') {
matchList.toggleMiniButtons();
} else if (key == 'F') {
toggleFullScreen();
}
}
void mousePressed() {
if (mouseY <= 150) {
// Get control panel to respond to mouse press
controlPanel.respond(mouseX, mouseY);
// Start or stop session if necessary
boolean newInSession = !controlPanel.isActive;
if (inSession != newInSession) {
inSession = newInSession;
if (inSession) {
startSession();
} else {
endSession();
}
}
} else {
// Get match list to respond to mouse press
matchList.respond(mouseX, mouseY);
}
}
String dayName() {
// Returns full name of week day
Calendar c = Calendar.getInstance();
int day = c.get(Calendar.DAY_OF_WEEK);
String names[] = {
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
};
return names[day-1];
}
int dayNumber() {
// Returns weekday index, 1 for Sunday through 7 for Saturday
Calendar c = Calendar.getInstance();
int weekday = c.get(Calendar.DAY_OF_WEEK);
return weekday;
}
void endSession() {
// Trigger session end
sessionBar.deactivate();
matchList.deactivate();
}
void startSession() {
// Get final parameters from control panel
int endHour = controlPanel.getEndHour();
int endMin = controlPanel.getEndMin();
int nTeams = controlPanel.getNTeams();
int nSim = controlPanel.getNSim();
// Initiate session
sessionBar.activate(endHour, endMin);
matchList.activate(nSim);
matchList.reloadMatches(nTeams, nSim);
}
boolean sketchFullScreen() {
// Decide whether to enter full screen using prefs.csv
Table prefs = loadTable("prefs.csv");
boolean fullScreen = boolean(prefs.getString(7, 1));
return fullScreen;
}
void toggleFullScreen() {
// Changes the saved preference for full screen or windowed mode
fullScreen = !fullScreen;
String[] prefStrings = loadStrings("prefs.csv");
prefStrings[7] = "fullScreen," + str(fullScreen);
// Use first path for OSX, second for Windows
//saveStrings("IceTimer.app/Contents/Java/data/prefs.csv", prefStrings);
saveStrings("data/prefs.csv", prefStrings);
// Show that the change has been made
String newTitle = fullScreen ? "Full screen on restart" : "Windowed on restart";
controlPanel.setTitle(newTitle);
}