4 * Copyright (C) 2006-2012 Matteo Nastasi
5 * mailto: nastasi@alternativeoutput.it
6 * matteo.nastasi@milug.org
7 * web: http://www.alternativeoutput.it
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details. You should have received a
18 * copy of the GNU General Public License along with this program; if
19 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
20 * Suite 330, Boston, MA 02111-1307, USA.
24 var mlang_briskin5 = { 'is_calling' : { 'it' : ' sta chiamando',
25 'en' : ' is calling' },
26 'deckreload' : { 'it' : '<br/>Per rendere visibile il nuovo mazzo di carte<br/><br/>occorre fare reload della pagina.',
27 'en' : '<br/>EN: Per rendere visibile il nuovo mazzo di carte<br/><br/>occorre fare reload della pagina.'},
28 'close_btn': { 'it' : 'Chiudi',
32 function Preferences(ring_endauct, deck, deck_old)
34 this.ring_endauct = ring_endauct;
36 this.deck_old = deck_old;
39 Preferences.prototype = {
45 function background_set()
47 $("bg").style.backgroundImage = 'url("img/brisk_table_sand'+table_pos+'.jpg")';
50 /* Stat: TABLE Subst: ASTA */
51 function act_asta(card,pnt)
53 send_mesg("asta|"+card+"|"+pnt);
56 var asta_xarr = new Array(0,66,132);
58 /* TODO: impostare gli onclick */
59 function dispose_asta(idx, pnt, nopoint)
63 var lng = langtolng(g_lang);
65 for (i = 0 ; i < 10 ; i++) {
68 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+lng+".png";
69 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
73 btn.src = "img/asta"+i+(pnt >= 0 ? "" : "_ro")+lng+".png";
74 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
78 btn.style.left = asta_xarr[i % 3];
80 btn.style.left = asta_xarr[(i+1) % 3];
82 btn.style.top = parseInt(i / 3) * 50 + (i == 9 ? 0 : 1);
85 eval("btn.onclick = function () { act_asta("+pass+",61); }");
86 btn.style.cursor = "pointer";
90 btn.style.cursor = "default";
96 btn.style.left = asta_xarr[i % 3];
97 btn.style.top = parseInt(i / 3) * 50 - 2;
98 // btn.style.visibility = "visible";
101 var rpnt = (pnt < 0 ? -pnt : pnt);
102 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
104 btn = $("astaptsub");
105 btn.style.left = asta_xarr[i % 3];
106 btn.style.top = 25 + parseInt(i / 3) * 50 - 1;
107 btn.src = "img/astaptsub"+(pnt >= 0 ? "" : "_ro")+lng+".png";
108 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
110 btn.onclick = function () { act_asta(9,$("astapt").value); };
111 btn.style.cursor = "pointer";
115 btn.style.cursor = "default";
120 btn = $("astapasso");
121 btn.style.left = asta_xarr[i % 3];
122 btn.style.top = parseInt(i / 3) * 50;
123 btn.src = "img/astapashalf"+(pnt >= 0 ? "" : "_ro")+lng+".png";
124 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
126 btn.onclick = function () { act_asta(-1,0); };
132 btn = $("astalascio");
133 btn.style.left = asta_xarr[i % 3];
134 btn.style.top = parseInt(i / 3) * 50 + 24;
135 btn.src = "img/astalascio"+lng+".png";
136 btn.style.visibility = "";
137 btn.onclick = function () { safelascio(); };
140 btn = $("astapasso");
141 btn.style.left = asta_xarr[i % 3];
142 btn.style.top = parseInt(i / 3) * 50;;
143 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+lng+".png";
144 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
146 btn.onclick = function () { act_asta(-1,0); };
152 btn = $("astalascio");
153 btn.style.visibility = "hidden";
156 // btn.style.visibility = "visible";
157 $("asta").style.visibility = "visible";
160 function asta_pnt_set(pnt)
163 var rpnt = (pnt < 0 ? -pnt : pnt);
164 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
169 $("asta").style.visibility = "hidden";
172 function choose_seed(card)
176 $("asta").style.visibility = "hidden";
177 $("astalascio").style.visibility = "hidden";
178 $("chooseed").style.visibility = "visible";
179 for (i = 0 ; i < 4 ; i++) {
180 $("seed"+i).setAttribute('data-card-id', '' + i + card);
182 eval("seed.onclick = function () { act_choose("+i+""+card+"); };");
186 var astat_suffix = new Array("","_ea","_ne","_nw","_we");
188 function show_astat(zer,uno,due,tre,qua)
190 var astat = new Array(zer,uno,due,tre,qua);
191 var lng = langtolng(g_lang);
193 for (i = 0 ; i < PLAYERS_N ; i++) {
194 idx = (PLAYERS_N + i - table_pos) % PLAYERS_N;
196 if (astat[i] == -2) {
197 $("public"+astat_suffix[idx]).style.visibility = "hidden";
199 else if (astat[i] == -1) {
200 $("public"+astat_suffix[idx]).style.visibility = "visible";
201 $("pubacard"+astat_suffix[idx]).src = "img/astapasso"+lng+".png";
202 $("pubapnt"+astat_suffix[idx]).innerHTML = "";
203 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
205 else if (astat[i] <= 10) {
206 $("public"+astat_suffix[idx]).style.visibility = "visible";
207 $("pubacard"+astat_suffix[idx]).src = "img/asta"+astat[i]+lng+".png";
208 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
210 else if (astat[i] <= 120) {
211 $("public"+astat_suffix[idx]).style.visibility = "visible";
212 $("pubacard"+astat_suffix[idx]).src = "img/asta9"+lng+".png";
213 $("pubapnt"+astat_suffix[idx]).style.visibility = "inherit"; // XXX VISIBLE
214 $("pubapnt"+astat_suffix[idx]).innerHTML = astat[i];
220 function table_init() {
221 var sux = new Array("", "_ea", "_ne", "_nw", "_we");
223 // console.log("table_init");
226 $("asta").style.visibility = "hidden";
227 $("caller").style.visibility = "hidden";
228 show_astat(-2,-2,-2,-2,-2);
231 for (i=0 ; i < CARD_HAND ; i++) {
232 Drag.init($("card" + i), card_mouseup_cb);
233 for (e = 0 ; e < PLAYERS_N ; e++)
234 $("card"+sux[e]+i).style.visibility = "hidden";
236 for (i=0 ; i < PLAYERS_N ; i++) {
237 // console.log("shut: "+"takes"+sux[i]);
238 $("takes"+sux[i]).style.visibility = "hidden";
241 for (i=0 ; i < CARD_HAND ; i++) {
251 function act_choose(card)
253 send_mesg("choose|"+card);
256 function act_play(card,x,y)
258 send_mesg("play|"+card+"|"+x+"|"+y);
261 function act_tableinfo()
263 send_mesg("tableinfo");
266 function act_exitlock()
268 send_mesg("exitlock");
271 function safelogout()
276 res = window.confirm("Sei sicuro di volere abbandonare la partita?\nATTENZIONE: se esci adesso senza il consenso degli altri giocatori non potrai sederti ai tavoli per "+(Math.floor(EXIT_BAN_TIME/60))+" minuti.");
278 res = window.confirm("Sei sicuro di volere abbandonare la partita?");
280 act_logout(g_exitlock);
283 function act_reload()
285 window.onunload = null;
286 window.onbeforeunload = null;
287 // alert(document.location.toString());
288 document.location.assign("index.php");
289 // document.location.reload();
292 function set_names(so,ea,ne,nw,we)
294 // alert("SET NAME");
295 $("name").innerHTML = user_decorator(so, false);
296 $("name").title = unescapeHTML(so[1]);
297 $("name_ea").innerHTML = user_decorator(ea, false);
298 $("name_ea").title = unescapeHTML(ea[1]);
299 $("name_ne").innerHTML = user_decorator(ne, false);
300 $("name_ne").title = unescapeHTML(ne[1]);
301 $("name_nw").innerHTML = user_decorator(nw, false);
302 $("name_nw").title = unescapeHTML(nw[1]);
303 $("name_we").innerHTML = user_decorator(we, false);
304 $("name_we").title = unescapeHTML(we[1]);
306 for (i = 0 ; i < PLAYERS_N ; i++)
307 $("name"+astat_suffix[i]).title_orig = $("name"+astat_suffix[i]).title;
312 function set_iscalling(idx)
316 for (i = 0 ; i < PLAYERS_N ; i++) {
317 $("name"+astat_suffix[i]).className = "pubinfo"+astat_suffix[i]+(i == idx ? "_iscalling" : "");
318 $("name"+astat_suffix[i]).title = $("name"+astat_suffix[i]).title_orig + (i == idx ? mlang_briskin5['is_calling'][g_lang] : "");
322 var preferences = new Preferences(true, 'xx', 'xx');
323 // FIXME move it in the html dynamic generation scope
324 var deck_list = { 'xx': 'Normal cards',
326 function preferences_init()
330 if ((rd = readCookie("CO_bin5_pref_ring_endauct")) != null) {
331 preferences.ring_endauct = $('pref_ring_endauct').checked = (rd == "true" ? true : false);
334 preferences.ring_endauct = $('pref_ring_endauct').checked = true;
337 if ((rd = readCookie("CO_bin5_pref_deck")) != null && rd in deck_list) {
338 $$('#pref_deck').val(rd);
339 preferences.deck = rd;
340 preferences.deck_old = rd;
344 $$('#pref_deck').val(rd);
345 preferences.deck = rd;
346 preferences.deck_old = rd;
350 function preferences_update()
353 createCookie("CO_bin5_pref_ring_endauct", (preferences.ring_endauct ? "true" : "false"), 24*3650, cookiepath);
354 createCookie("CO_bin5_pref_deck", preferences.deck, 24*3650, cookiepath);
355 ret = server_request('mesg', 'preferences_update');
358 function act_preferences_update()
360 preferences_update();
361 if (preferences.deck != preferences.deck_old) {
362 // FIXME: with dynamic text
363 x = new notify(gst, mlang_briskin5['deckreload'],
364 0, mlang_briskin5['close_btn'][g_lang], 400, 110);
366 preferences_showhide();
369 function pref_ring_endauct_set(obj)
371 preferences.ring_endauct = obj.checked;
374 function pref_deck_set(obj)
376 preferences.deck = $$(obj).val();
380 function preferences_show()
384 div_show($('preferences'));
387 function preferences_showhide()
389 if ($('preferences').style.visibility == 'hidden') {
392 $('preferences').style.top = parseInt((document.body.clientHeight -
393 parseInt(getStyle($('preferences'), "height","height"))
394 ) / 2) + document.body.scrollTop;
395 $('preferences').style.visibility = 'visible';
398 $('preferences').style.visibility = 'hidden';
401 function act_select_rules(rule_id)
403 send_mesg("chatt|/rules " + rule_id);
406 function act_select_deck(deck_id)
408 preferences.deck = deck_id;
411 function rules_set(id)
413 $('select_rules').value = id;