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' } }
27 function Preferences(ring_endauct, deck, deck_old)
29 this.ring_endauct = ring_endauct;
31 this.deck_old = deck_old;
34 Preferences.prototype = {
40 function background_set()
42 $("bg").style.backgroundImage = 'url("img/brisk_table_sand'+table_pos+'.jpg")';
45 /* Stat: TABLE Subst: ASTA */
46 function act_asta(card,pnt)
48 send_mesg("asta|"+card+"|"+pnt);
51 var asta_xarr = new Array(0,66,132);
53 /* TODO: impostare gli onclick */
54 function dispose_asta(idx, pnt, nopoint)
58 var lng = langtolng(g_lang);
60 for (i = 0 ; i < 10 ; i++) {
63 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+lng+".png";
64 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
68 btn.src = "img/asta"+i+(pnt >= 0 ? "" : "_ro")+lng+".png";
69 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
73 btn.style.left = asta_xarr[i % 3];
75 btn.style.left = asta_xarr[(i+1) % 3];
77 btn.style.top = parseInt(i / 3) * 50 + (i == 9 ? 0 : 1);
80 eval("btn.onclick = function () { act_asta("+pass+",61); }");
81 btn.style.cursor = "pointer";
85 btn.style.cursor = "default";
91 btn.style.left = asta_xarr[i % 3];
92 btn.style.top = parseInt(i / 3) * 50 - 2;
93 // btn.style.visibility = "visible";
96 var rpnt = (pnt < 0 ? -pnt : pnt);
97 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
100 btn.style.left = asta_xarr[i % 3];
101 btn.style.top = 25 + parseInt(i / 3) * 50 - 1;
102 btn.src = "img/astaptsub"+(pnt >= 0 ? "" : "_ro")+lng+".png";
103 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
105 btn.onclick = function () { act_asta(9,$("astapt").value); };
106 btn.style.cursor = "pointer";
110 btn.style.cursor = "default";
115 btn = $("astapasso");
116 btn.style.left = asta_xarr[i % 3];
117 btn.style.top = parseInt(i / 3) * 50;
118 btn.src = "img/astapashalf"+(pnt >= 0 ? "" : "_ro")+lng+".png";
119 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
121 btn.onclick = function () { act_asta(-1,0); };
127 btn = $("astalascio");
128 btn.style.left = asta_xarr[i % 3];
129 btn.style.top = parseInt(i / 3) * 50 + 24;
130 btn.src = "img/astalascio"+lng+".png";
131 btn.style.visibility = "";
132 btn.onclick = function () { safelascio(); };
135 btn = $("astapasso");
136 btn.style.left = asta_xarr[i % 3];
137 btn.style.top = parseInt(i / 3) * 50;;
138 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+lng+".png";
139 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
141 btn.onclick = function () { act_asta(-1,0); };
147 btn = $("astalascio");
148 btn.style.visibility = "hidden";
151 // btn.style.visibility = "visible";
152 $("asta").style.visibility = "visible";
155 function asta_pnt_set(pnt)
158 var rpnt = (pnt < 0 ? -pnt : pnt);
159 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
164 $("asta").style.visibility = "hidden";
167 function choose_seed(card)
171 $("asta").style.visibility = "hidden";
172 $("astalascio").style.visibility = "hidden";
173 $("chooseed").style.visibility = "visible";
174 for (i = 0 ; i < 4 ; i++) {
175 $("seed"+i).src = "img/"+i+""+card+".png";
177 eval("seed.onclick = function () { act_choose("+i+""+card+"); };");
181 var astat_suffix = new Array("","_ea","_ne","_nw","_we");
183 function show_astat(zer,uno,due,tre,qua)
185 var astat = new Array(zer,uno,due,tre,qua);
186 var lng = langtolng(g_lang);
188 for (i = 0 ; i < PLAYERS_N ; i++) {
189 idx = (PLAYERS_N + i - table_pos) % PLAYERS_N;
191 if (astat[i] == -2) {
192 $("public"+astat_suffix[idx]).style.visibility = "hidden";
194 else if (astat[i] == -1) {
195 $("public"+astat_suffix[idx]).style.visibility = "visible";
196 $("pubacard"+astat_suffix[idx]).src = "img/astapasso"+lng+".png";
197 $("pubapnt"+astat_suffix[idx]).innerHTML = "";
198 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
200 else if (astat[i] <= 10) {
201 $("public"+astat_suffix[idx]).style.visibility = "visible";
202 $("pubacard"+astat_suffix[idx]).src = "img/asta"+astat[i]+lng+".png";
203 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
205 else if (astat[i] <= 120) {
206 $("public"+astat_suffix[idx]).style.visibility = "visible";
207 $("pubacard"+astat_suffix[idx]).src = "img/asta9"+lng+".png";
208 $("pubapnt"+astat_suffix[idx]).style.visibility = "inherit"; // XXX VISIBLE
209 $("pubapnt"+astat_suffix[idx]).innerHTML = astat[i];
215 function table_init() {
216 var sux = new Array("", "_ea", "_ne", "_nw", "_we");
218 // console.log("table_init");
221 $("asta").style.visibility = "hidden";
222 $("caller").style.visibility = "hidden";
223 show_astat(-2,-2,-2,-2,-2);
226 for (i=0 ; i < CARD_HAND ; i++) {
227 Drag.init($("card" + i), card_mouseup_cb);
228 for (e = 0 ; e < PLAYERS_N ; e++)
229 $("card"+sux[e]+i).style.visibility = "hidden";
231 for (i=0 ; i < PLAYERS_N ; i++) {
232 // console.log("shut: "+"takes"+sux[i]);
233 $("takes"+sux[i]).style.visibility = "hidden";
236 for (i=0 ; i < CARD_HAND ; i++) {
246 function act_choose(card)
248 send_mesg("choose|"+card);
251 function act_play(card,x,y)
253 send_mesg("play|"+card+"|"+x+"|"+y);
256 function act_tableinfo()
258 send_mesg("tableinfo");
261 function act_exitlock()
263 send_mesg("exitlock");
266 function safelogout()
271 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.");
273 res = window.confirm("Sei sicuro di volere abbandonare la partita?");
275 act_logout(g_exitlock);
278 function act_reload()
280 window.onunload = null;
281 window.onbeforeunload = null;
282 // alert(document.location.toString());
283 document.location.assign("index.php");
284 // document.location.reload();
287 function set_names(so,ea,ne,nw,we)
289 // alert("SET NAME");
290 $("name").innerHTML = user_decorator(so, false);
291 $("name").title = unescapeHTML(so[1]);
292 $("name_ea").innerHTML = user_decorator(ea, false);
293 $("name_ea").title = unescapeHTML(ea[1]);
294 $("name_ne").innerHTML = user_decorator(ne, false);
295 $("name_ne").title = unescapeHTML(ne[1]);
296 $("name_nw").innerHTML = user_decorator(nw, false);
297 $("name_nw").title = unescapeHTML(nw[1]);
298 $("name_we").innerHTML = user_decorator(we, false);
299 $("name_we").title = unescapeHTML(we[1]);
301 for (i = 0 ; i < PLAYERS_N ; i++)
302 $("name"+astat_suffix[i]).title_orig = $("name"+astat_suffix[i]).title;
307 function set_iscalling(idx)
311 for (i = 0 ; i < PLAYERS_N ; i++) {
312 $("name"+astat_suffix[i]).className = "pubinfo"+astat_suffix[i]+(i == idx ? "_iscalling" : "");
313 $("name"+astat_suffix[i]).title = $("name"+astat_suffix[i]).title_orig + (i == idx ? mlang_briskin5['is_calling'][g_lang] : "");
317 var preferences = new Preferences(true, 'xx', 'xx');
318 // FIXME move it in the html dynamic generation scope
319 var deck_list = { 'xx': 'Normal cards',
321 function preferences_init()
325 if ((rd = readCookie("CO_bin5_pref_ring_endauct")) != null) {
326 preferences.ring_endauct = $('pref_ring_endauct').checked = (rd == "true" ? true : false);
329 preferences.ring_endauct = $('pref_ring_endauct').checked = true;
332 if ((rd = readCookie("CO_bin5_pref_deck")) != null && rd in deck_list) {
333 $$('#pref_deck').val(rd);
334 preferences.deck = rd;
335 preferences.deck_old = rd;
339 $$('#pref_deck').val(rd);
340 preferences.deck = rd;
341 preferences.deck_old = rd;
345 function preferences_update()
348 createCookie("CO_bin5_pref_ring_endauct", (preferences.ring_endauct ? "true" : "false"), 24*3650, cookiepath);
349 createCookie("CO_bin5_pref_deck", preferences.deck, 24*3650, cookiepath);
350 ret = server_request('mesg', 'preferences_update');
353 function act_preferences_update()
355 preferences_update();
356 if (preferences.deck != preferences.deck_old) {
357 // FIXME: with dynamic text
358 x = new notify(gst,'<br/>Per rendere visibile il nuovo mazzo di carte<br/><br/>occorre fare reload della pagina.',
359 0, "Close", 400, 110);
361 preferences_showhide();
364 function pref_ring_endauct_set(obj)
366 preferences.ring_endauct = obj.checked;
369 function pref_deck_set(obj)
371 preferences.deck = $$(obj).val();
375 function preferences_show()
379 div_show($('preferences'));
382 function preferences_showhide()
384 if ($('preferences').style.visibility == 'hidden') {
387 $('preferences').style.top = parseInt((document.body.clientHeight -
388 parseInt(getStyle($('preferences'), "height","height"))
389 ) / 2) + document.body.scrollTop;
390 $('preferences').style.visibility = 'visible';
393 $('preferences').style.visibility = 'hidden';
396 function act_select_rules(rule_id)
398 send_mesg("chatt|/rules " + rule_id);
401 function act_select_deck(deck_id)
403 preferences.deck = deck_id;
406 function rules_set(id)
408 $('select_rules').value = id;