forked from AliceDevine/clegg-fortunes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.html
310 lines (257 loc) · 8.46 KB
/
popup.html
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<!DOCTYPE html>
<html>
<!--
Copyright 2011 Daniel Seither ([email protected]), Cornelius Flöter ([email protected])
This file is part of Clan Contest.
Clan Contest 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.
Clan Contest 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 Clan Contest. If not, see http://www.gnu.org/licenses/.
-->
<head>
<title>Clan Contest</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="style/popup.css">
<script src="lib/jquery-1.6.1.js"></script>
<script src="questions.js"></script>
<script type="text/javascript">
// maximum number of answers per question
var max_answers = 0;
// tasks to be run after DOM is fully loaded
$(document).ready(function() {
// calculate maximum number of answers per round
$.each(answers_rounds, function(idx_round, answers) {
if (answers.length > max_answers)
max_answers = answers.length;
});
// initialize answer table for rounds
var tbl_rounds_answers = $('#tbl_rounds_answers');
for (var i = 0; i < max_answers; i++) {
tbl_rounds_answers.append(
'<tr id="answer_row'+i+'">' +
'<td class="answer_priority">'+(i+1)+'.</td>' +
'<td class="answer"><span id="answer'+i+'" class="answer_span"> </span></td>' +
'<td class="answer_points" id="points'+i+'"></td>' +
'</tr>'
);
}
// initialize answer table for finals
var tbl_finals_answers = $('#tbl_finals_answers');
for (var i = 0; i < answers_finals.length; i++) {
tbl_finals_answers.append(
'<tr>' +
'<td class="answer"><span id="finals_answer'+i+'-0"></span><span id="finals_answer'+i+'-0-empty"> </span></td>' +
'<td class="answer_points"><span id="finals_points'+i+'-0"></span><span id="finals_points'+i+'-0-empty"> </span></td>' +
'<td class="answer_points"><span id="finals_points'+i+'-1"></span><span id="finals_points'+i+'-1-empty"> </span></td>' +
'<td class="answer"><span id="finals_answer'+i+'-1"></span><span id="finals_answer'+i+'-1-empty"> </span></td>' +
'</tr>'
);
}
// notify control window
window.opener.game_window_init_done();
});
// tasks to be run when window is closed
window.onbeforeunload = function (e) {
// notify control window
window.opener.game_window_closed();
};
// contains change handlers for the game window
var state_changer = new Object();
// handle teams.* settings
state_changer.teams = function(args, value) {
var team = args.shift();
var setting = args.shift();
switch (setting) {
case 'name':
// set team name
$('#name_t'+team).text(value);
break;
case 'points':
// set team points
$('#team'+team+'_points').text(value);
break;
case 'misses':
// set team misses
for (var i = 0; i < 3; i++) {
var text = (i < value) ? 'X' : ' ';
$('#x_t'+team+'_'+ i).html(text);
}
break;
}
}
// handle screen.* settings
state_changer.screen = function(args, value) {
var screen = args.shift();
// switch to screen
$('.screen').hide();
$('#view_'+value).show();
}
// handle round.* settings
state_changer.round = function(args, value) {
var setting = args.shift();
switch (setting) {
case 'id':
// switch to round
$('#round_display').text(value+1);
// update multiplicator
if (multiplicator[value] > 1)
$('#multiplicator_display').text('('+multiplicator[value]+'x)')
else
$('#multiplicator_display').empty();
// set length of answers table
$('#tbl_rounds_answers').find('td').addClass('invisible');
for (var a = 0; a < answers_rounds[value].length; a++) {
$('#answer_row'+a).find('td').removeClass('invisible');
}
break;
case 'points':
// set round points
$('#round_points').text(value);
break;
case 'answers_shown':
var idx_answer = args.shift();
// show/hide answer
var text;
var points;
if (value >= 0) {
var answer = answers_rounds[value][idx_answer];
text = answer[0];
points = answer[1];
} else {
text = ' ';
points = ' ';
}
//rollin effect
answer = $('#answer'+idx_answer);
answer.css("width", "0%");
answer.html(text);
answer.animate({width: '100%'}, 500);
$('#points'+idx_answer).html(points);
break;
}
}
// handle finals.* settings
state_changer.finals = function(args, value) {
var setting = args.shift();
switch (setting) {
case 'points':
// set points
$('#finals_points').text(value);
break;
case 'answers':
// configure answers display
var player = args.shift();
var idx_question = args.shift();
var setting2 = args.shift();
switch (setting2) {
case 'id':
// set answer text and points
var text;
var points;
// wrong answer (given as string)
if (typeof(value) == 'string') {
text = value;
points = '--';
// no answer given (yet)
} else if (value < 0) {
text = '';
points = '';
// correct answer given (as index)
} else {
var answer = answers_finals[idx_question][value];
text = answer[0];
points = answer[1];
}
$('#finals_answer'+idx_question+'-'+player).text(text);
$('#finals_points'+idx_question+'-'+player).text(points);
break;
case 'answer_shown':
// show/hide answer
$('#finals_answer'+idx_question+'-'+player).toggle(value);
$('#finals_answer'+idx_question+'-'+player+'-empty').toggle(!value);
break;
case 'points_shown':
// show/hide points
$('#finals_points'+idx_question+'-'+player).toggle(value);
$('#finals_points'+idx_question+'-'+player+'-empty').toggle(!value);
break;
}
break;
}
}
// ##### start of API (to be called from control window) #####
// apply changes to game window
function apply_changes(changes) {
$.each(changes, function(setting, value) {
var args = setting.split('.');
var toplevel = args.shift();
state_changer[toplevel](args, value);
});
}
// set timer value
function set_timer(timeleft) {
$('#timeleft').text(timeleft);
}
// ##### end of API (to be called from control window) #####
</script>
</head>
<body>
<div id="container">
<!-- splash -->
<div class="screen" id="view_splash">
<img src="gfx/logo.png" />
</div>
<!-- round 1 to 4 -->
<div class="screen" id="view_rounds">
<h1>Round <span id="round_display"></span> <span id="multiplicator_display"></span></h1>
<table class="answerstable" id="tbl_rounds_answers"><!-- placeholder for answers, filled using JS --></table>
<table class="pointstable">
<tr>
<td id="name_t0" class="points_left"></td>
<td class="points_center"></td>
<td id="name_t1" class="points_right"></td>
</tr>
<tr class="points_row">
<td id="team0_points" class="points_left"></td>
<td id="round_points" class="points_center"></td>
<td id="team1_points" class="points_right"></td>
</tr>
<tr>
<td class="points_left">
<span id="x_t0_0"> </span>
<span id="x_t0_1"> </span>
<span id="x_t0_2"> </span>
</td>
<td></td>
<td class="points_right">
<span id="x_t1_2"> </span>
<span id="x_t1_1"> </span>
<span id="x_t1_0"> </span>
</td>
</tr>
</table>
</div>
<!-- finals -->
<div class="screen" id="view_finals">
<h1>Finals</h1>
<table class="answerstable" id="tbl_finals_answers"><!-- placeholder for answers, filled using JS --></table>
<table class="pointstable">
<tr>
<td class="points_left">Time left: <span id="timeleft"></span> s</td>
<td class="points_right">Σ <span id="finals_points"></span></td>
</tr>
</table>
</div>
<!-- end -->
<div class="screen" id="view_end">
<img src="gfx/logo.png" />
</div>
</div>
</body>
</html>