/* ############################################################ ## ## 2008 (c) PiSolution GmbH ## ## File : $Id: pimp.js,v 1.4 2012/02/03 15:14:34 tom Exp $ ## Version : $Revision: 1.4 $ ## ## Purpose : Projekt - pimp your landscape ## ## Created : 08/12/01 ## Author : frank pietzsch ## ## Update : $Date: 2012/02/03 15:14:34 $ ## Author : $Author: tom $ ## ## Remarks : pimp - js file ## ## Log : $Log: pimp.js,v $ ## Log : Revision 1.4 2012/02/03 15:14:34 tom ## Log : layer selection modified ## Log : ## Log : Revision 1.3 2011/09/29 14:29:12 tom ## Log : add stackability for moveable divs ## Log : ## Log : Revision 1.2 2011/07/19 12:49:20 frank ## Log : new revision ## Log : ## ############################################################ */ var xCoord=0; var yCoord=0; var sel = 0; var px = 0; var py = 0; var difx = 0; var dify = 0; var sel_tool; var mouse_over_cell = 0; var cellinfo; var isFocus = false; var seed_x = 0; var seed_y = 0; var seed = -1; var playTime = 1; var gameStarted = 0; var playTimeAlert = 0; var isGame = 0; var undefined_field_type = -9999; var trace = 0; var load_complete = 0; function capture(id) { sel = id; px = document.getElementById(id).style.left.replace(/px/,''); py = document.getElementById(id).style.top.replace(/px/,''); foregroundDiv(sel); } function leave(id) { if(sel != id) return; sel = 0; difx = 0; dify = 0; px = 0; py = 0; } function getCoords(evt) { if(! evt) evt = window.event; var xOffset = (document.all)? document.body.scrollLeft : window.pageXOffset; var yOffset = (document.all)? document.body.scrollTop : window.pageYOffset; xCoord = evt.clientX + xOffset; yCoord = evt.clientY + yOffset; if(trace) document.forms[0].mtrace.value += xCoord+":"+yCoord+","; if(! sel) return; move_selected(); } document.onmousemove = getCoords; document.onmouseup = leaveMarker; function move_selected() { difx = (difx)? difx : xCoord - px; dify = (dify)? dify : yCoord - py; var pleft = xCoord - difx; var ptop = yCoord - dify; if (document.getElementById) { document.getElementById(sel).style.left = pleft + "px"; document.getElementById(sel).style.top = ptop + "px"; } document.getElementById(sel+"_x").value = pleft; document.getElementById(sel+"_y").value = ptop; } function sandglass(visible) { document.getElementById('sg').style.left = xCoord + ((document.all)? 10:12); document.getElementById('sg').style.top = yCoord + ((document.all)? 0:1); document.getElementById('sg').style.visibility = ((visible)? "visible" : "hidden"); } function switch_view(i) { if(document.simulation.view.value == i) return; // if((moveLog.length || mvc) && ! confirm("stop current run?")) if((moveLog.length || mvc) && ! confirm("\nSimulation abbrechen?\n")) return; document.simulation.action.value = 'init_map'; document.simulation.view.value = i; document.simulation.initial_selection.value = 1; document.simulation.submit(); } var sel_idx = -1; function save_idx(id) { sel_idx = document.getElementById(id).selectedIndex; } function refresh_selection(id) { // if((moveLog.length || mvc) && ! confirm("stop current run?")) if((moveLog.length || mvc) && ! confirm("\nSimulation abbrechen?\n")) { if(sel_idx != -1) document.getElementById(id).selectedIndex = sel_idx; sel_idx = -1; return; } document.simulation.action.value = 'init_map'; refresh(); } function save_new_type_def() { document.simulation.action.value = 'save_new_type_def'; document.simulation.submit(); } function save_new_type_values() { document.simulation.action.value = 'save_new_type_values'; document.simulation.submit(); } function watch_input_color(id) { var hxcl = document.getElementById("ip_"+id).value; for(i=0;i 5) document.getElementById("ip_"+id).value = hxcl.substring(0,i); } var cl = document.getElementById("ip_"+id).value; while(cl.length < 6) cl += '0'; document.getElementById("td_"+id).bgColor = cl; } function toggle_color() { if(! document.simulation.precol.checked) document.simulation.action.value = 'color_off'; refresh(); } function edit_type_def(id) { document.simulation.action.value = 'edit_type_def'; document.simulation.action_id.value = id; refresh(); } function update_type_def(id) { document.simulation.action.value = 'update_type_def'; document.simulation.action_id.value = id; refresh(); } function watch_range(id) { var max_val = (id.match(/val/))? 100 : 200; var inp = document.getElementById(id); inp.value = inp.value.replace(/\D/g,''); while(inp.value > max_val) inp.value = inp.value.substr(0,inp.value.length - 1); } function save_as_new_type_values() { // var p_name = prompt("save as:",""); var p_name = prompt("\nspeichern als:\n",""); if(p_name.match(/\S+/)) { document.simulation.param_set_name.value = p_name; document.simulation.action.value = 'save_as_new_type_values'; refresh(); } } function update_type_values() { document.simulation.action.value = 'update_type_values'; refresh(); } function delete_type_values(id) { // if(confirm("do you want to delete this value definition?")) if(confirm("\nLNF Set löschen?\n")) { document.simulation.action.value = 'delete_type_values'; document.simulation.action_id.value = id; refresh(); } } function save_time_axis() { var p_name = prompt("\nZeitachse:\n",""); if(p_name.match(/\S+/)) { document.simulation.param_set_name.value = p_name; document.simulation.action.value = 'save_time_axis_type_values'; refresh(); } } function delete_time_axis(id) { // if(confirm("do you want to delete this value time axis?")) if(confirm("\nZeitachse Set löschen?\n")) { document.simulation.action.value = 'delete_time_axis_type_values'; document.simulation.action_id.value = id; refresh(); } } function hide_div(id) { document.getElementById(id).style.visibility = 'hidden'; if(id == 'div_vtb') document.getElementById(id+"_visible").value = 0; } function unhide_div(id) { document.getElementById(id).style.visibility = 'visible'; } function toggle_div(id) { if(document.getElementById(id).style.visibility == "visible") { document.getElementById(id).style.visibility = "hidden"; document.getElementById(id+"_visible").value = 0; return; } document.getElementById(id+"_visible").value = 1; document.getElementById(id).style.visibility = "visible"; foregroundDiv(id); } function show_div(id,x_offset,y_offset) { document.getElementById(id).style.left = xCoord + x_offset; document.getElementById(id).style.top = yCoord + y_offset; document.getElementById(id).style.visibility = "visible"; foregroundDiv(id); } //------------------------------------------------------------------------------ var mLcnt = 0; var moveLog = new Array(); var mvc; var hSec = 0; var homogen = 1; var conditionFault = 0; var undefSec = 0; function getAttCat(att) { var cat = ""; for(var i=1,bit=16;i<11;i++,bit*=2) { if(att&bit) cat += (cat)? "|"+i : " [cat"+i; } cat += (cat)? "]" : ((att)? " [fixed]" : ""); return cat; } var Xy4id = new Array(); function Id2Xy(id) { Xy4id[0] = id % cx; Xy4id[1] = Math.floor(id / cx); } function Xy2Id(x,y) { return(y * cx + x); } function getSectorTableIE(sec_id,sec_size,cx) { var tb = new Array(""); // var row = Math.floor(sec_id * sec_size / cx); // var col = sec_id % (cx / sec_size); // var start_id = sec_size * cx * row + (sec_size * col); var row = Math.floor(sec_id * sec_size / (cx - 2*margin)); var col = sec_id % ((cx - 2*margin) / sec_size); var start_id = sec_size * cx * row + (sec_size * col); Id2Xy(start_id); start_id = Xy2Id(Xy4id[0] + margin, Xy4id[1] + margin); var cnt = sec_size * sec_size; var j = 0; var n = 1; var fid = 0; var tcl = 0; var sc = 0; var undef = 0; conditionFault = 0; homogen = 1; var title; var att; for(i=1;i<=cnt;i++) { fid = j + start_id; if(f[fid] == undefined_field_type) { homogen = 0; undef = 1; } att = getAttributes(fid,0); title = tpd[f[fid]]; if(att & 1) title += (att > 16)? ' & \nFluß\n' : ' & \nGewässer\n'; if(att & 8) { title = (f[fid] == 1)? '\nGewässer\n' : title + ' & \nGewässer\n'; if(f[fid] == 1) homogen = 0; } if(att & 2) title += ' & \nStraße/Bahn\n'; title += getAttCat(att); tb[n++] = ""; j++; if(i % sec_size == 0 && i < cnt) { start_id += cx; j=0; tb[n++] = ""; } if(i == 1) { tcl = f[fid]; sc = SCFi[fid]; } else { if(tcl != f[fid]) homogen = 0; if(sc != SCFi[fid]) conditionFault = 1; } } tb[n] = "
"; hSec += homogen; undefSec += undef; return tb.join(""); } function getSectorMapIE(scnt,ccnt,sec_size,cx) { var k; var l = 1; var clickAction; var secTable; var att; var table = new Array(""); for(k=1;k<=scnt;k++) { att = getAttributes(k-1,1); secTable = getSectorTableIE(k-1,sec_size,cx); clickAction = (homogen)? " onClick='showMenu("+(k-1)+",1,"+att+")'" : " onClick='showMenu("+(k-1)+",2,"+att+")'"; clickAction = (conditionFault && homogen)? " onClick='conflict()'" : clickAction; table[l++] = ""; table[l++] = secTable; table[l++] = ""; if(k % ccnt == 0 && k < scnt) { table[l++] = ""; } } table[l] = "
"; document.write(table.join("")); if(!isGame) document.write((scnt - undefSec)+" \nSektoren\n ["+hSec+" \nhomogen\n]"); } function getSectorTable(sec_id,sec_size,cx) { var tb = ""; // var row = Math.floor(sec_id * sec_size / cx); // var col = sec_id % (cx / sec_size); // var start_id = sec_size * cx * row + (sec_size * col); var row = Math.floor(sec_id * sec_size / (cx - 2*margin)); var col = sec_id % ((cx - 2*margin) / sec_size); var start_id = sec_size * cx * row + (sec_size * col); Id2Xy(start_id); start_id = Xy2Id(Xy4id[0] + margin, Xy4id[1] + margin); var cnt = sec_size * sec_size; var j = 0; var fid = 0; var tcl = 0; var sc = 0; conditionFault = 0; homogen = 1; var undef = 0; var title; var att; for(i=1;i<=cnt;i++) { fid = j + start_id; if(f[fid] == undefined_field_type) { homogen = 0; undef = 1; } att = getAttributes(fid,0); title = tpd[f[fid]]; if(att & 1) title += (att > 16)? ' & \nFluß\n' : ' & \nGewässer\n'; if(att & 8) { title = (f[fid] == 1)? '\nGewässer\n' : title + ' & \nGewässer\n'; if(f[fid] == 1) homogen = 0; } if(att & 2) title += ' & \nStraße/Bahn\n'; title += getAttCat(att); tb += ""; j++; if(i % sec_size == 0 && i < cnt) { start_id += cx; j=0; tb += ""; } if(i == 1) { tcl = f[fid]; sc = SCFi[fid]; } else { if(tcl != f[fid]) homogen = 0; if(sc != SCFi[fid]) conditionFault = 1; } } tb += "
"; hSec += homogen; undefSec += undef; return tb; } function getSectorMap(scnt,ccnt,sec_size,cx) { var k; var clickAction; var secTable; var att; var title; var table = ""; for(k=1;k<=scnt;k++) { att = getAttributes(k-1,1); secTable = getSectorTable(k-1,sec_size,cx); clickAction = (homogen)? " onClick='showMenu("+(k-1)+",1,"+att+")'" : " onClick='showMenu("+(k-1)+",2,"+att+")'"; clickAction = (conditionFault && homogen)? " onClick='conflict()'" : clickAction; table += ""; table += secTable; table += ""; if(k % ccnt == 0 && k < scnt) { table += ""; } } table += "
"; document.write(table); if(!isGame) document.write((scnt - undefSec)+" \nSektoren\n ["+hSec+" \nhomogen\n]"); Xy2Id(); } function getMapIE(cnt,cx) { var i; var j=1; var att; var title; var defined_fields = 0; table = new Array(""); for(i=0;i < cnt;i++) { if(isMargin(i) == 0 && (i % cx) - margin == 0) table[j++] = ""; att = getAttributes(i,0); title = tpd[f[i]]; if(att & 1) title += (att > 16)? ' & \nFluß\n' : ' & \nGewässer\n'; if(att & 8) title = (f[i] == 1)? '\nGewässer\n' : title + ' & \nGewässer\n'; if(att & 2) title += ' & \nStraße/Bahn\n'; title += getAttCat(att); if(isMargin(i) == 0) { if(f[i] != undefined_field_type) defined_fields++; table[j++] = ""; } if( (isMargin(i) == 0) && ((i + margin + 1) % cx == 0) ) table[j++] = ""; } table[j] = "
"; document.write(table.join("")); // alert(typeof(table)); delete(table); // alert(typeof(table)); if(!isGame) document.write(defined_fields+" \nFelder\n"); } function getMap(cnt,cx) { var i; var att; var title; var defined_fields = 0; table = ""; for(i=0;i < cnt;i++) { if(isMargin(i) == 0 && (i % cx) - margin == 0) table += ""; att = getAttributes(i,0); title = tpd[f[i]]; if(att & 1) title += (att > 16)? ' & \nFluß\n' : ' & \nGewässer\n'; if(att & 8) title = (f[i] == 1)? '\nGewässer\n' : title + ' & \nGewässer\n'; if(att & 2) title += ' & \nStraße/Bahn\n'; title += getAttCat(att); //title += " ("+i+")"; if(isMargin(i) == 0) { if(f[i] != undefined_field_type) defined_fields++; table += ""; } if( (isMargin(i) == 0) && ((i + margin + 1) % cx == 0) ) table += ""; } table += "
"; document.write(table); // alert(typeof(table)); delete(table); // alert(typeof(table)); if(!isGame) document.write(defined_fields+" \nFelder\n"); } function isMargin(id) { var x = id % cx; var y = Math.floor(id / cx); if( x < margin || x + margin >= cx || y < margin || y + margin >= cy ) return 1; return 0; } //------------------------------------------------------------------------------ function completeArray() { var i; var clidx; for(i=0;i -1) { // document.getElementById(id).bgColor = "#" + clr[val]; document.getElementById(id).style.backgroundColor = "#" + clr[val]; document.getElementById(id).title = tpd[val]; moveLog[mLcnt++]= id+"x"+val; f[id] = val; form.move_count.value++; document.getElementById('step_panel').style.visibility = 'hidden'; } if(id == -1) { form.action.value = "area_fill"; form.selected_id.value = val; saveChanges(); } if(id == -2) { form.action.value = "flood_fill"; form.selected_id.value = val; saveChanges(); } if(id == -3) { form.action.value = "type_fill"; form.selected_id.value = val; saveChanges(); } isFocus = true; hideMenu(); } function changeSectorType() { hideMenu(); sandglass(1); window.setTimeout("__changeSectorType()",0); } function __changeSectorType() { gameStarted = 1; var form = document.simulation; var sec_id = form.selected_id.value; var val = form.menu_list[form.menu_list.selectedIndex].value; if(val && sec_id > -1) { var SecFields = getSectorFields(sec_id); for(var i=0;i 0 && o > 0)? s + 1 : -1; no = (n > 0 && o > 0)? n + 1 : -1; sw = (w >= 0 && s > 0)? s - 1 : -1; nw = (w > 0 && n > 0)? n - 1 : -1; NeighborFields = new Array(n,no,o,so,s,sw,w,nw); for(var i = 0;i 0 && (moveLog.length > interval)) { saveChanges(); return; } window.setTimeout("autoRefresh("+is_select+")",200); } function area_selection(id) { var act = (id)? 'load_area' : 'delete_area'; document.simulation.action.value = act; saveChanges(); } function upload() { var form = document.simulation; var type_sel = (form.map_image.value || form.map_gis.value)? true : false; if(! form.dataset_name.value.match(/\S/)) { // alert("name required!"); alert("\nBitte Namen eingeben!\n"); form.dataset_name.focus(); return; } for(var i=0;i= 0) { for(i=idx;i < len - 1;i++) { _select[i].text = _select[i+1].text; _select[i].value = _select[i+1].value; } _select.length = i; } else { // alert("select option"); alert("\nOption auswählen!\n"); } } function exchange_selected(direction) { var form = document.simulation; var _select = (direction)? form.special_condition : form.condition_set; var _target = (direction)? 'condition_set' : 'special_condition'; var _source = (direction)? 'special_condition' : 'condition_set'; var idx = _select.selectedIndex; if(idx < 0) { // alert("select option"); alert("\nOption auswählen!\n"); return; } var txt = _select[idx].text; var val = _select[idx].value; addOption(_target,txt,val); remOption(_source); getSelectedSCR(); getSCDesc(); } function move_sel_option(dir) { var form = document.simulation; var _select = form.condition_set; var mem_txt; var mem_val; var mem_class; var idx = _select.selectedIndex; if(idx < 0) return; var jump = (dir)? 1 : -1; if((idx > 0 && dir == 0) || (idx < _select.length - 1 && dir == 1)) { mem_txt = _select[idx + jump].text; mem_val = _select[idx + jump].value; mem_class = _select[idx + jump].className; _select[idx + jump].text = _select[idx].text; _select[idx + jump].value = _select[idx].value; _select[idx + jump].className = _select[idx].className; _select[idx].text = mem_txt; _select[idx].value = mem_val; _select[idx].className = mem_class; _select.selectedIndex = idx + jump; } getSelectedSCR(); } function step(dir) { if(playTime < 1) { if(! playTimeAlert) { alert("\nZeit abgelaufen!\n"); //alert("time is up!"); playTimeAlert = 1; saveChanges(); } return; } var form = document.simulation; form.action.value = 'stepping'; form.action_id.value = dir; form.submit(); } function reset_selection(sel_list) { var sel_id = sel_list.split(","); for(var i=0;i= rp.length) { return saveChanges(); } var vsplit = rp[rpcnt].split(","); var id = vsplit[0]; var cl = clr[vsplit[1]]; f[id]=vsplit[1]; if(isMargin(id) == 0) { //document.getElementById(id).bgColor = "#" + cl; document.getElementById(id).style.backgroundColor = "#" + cl; } rpcnt++; } window.setTimeout("Replay()",delay); } function initReplay() { var form = document.simulation; form.action.value = 'replay'; saveChanges(); } function gradient_select(type) { var form = document.simulation; form.action.value = 'load_gradient'; saveChanges(); } function move_gradient() { var form = document.simulation; form.action.value = 'move_gradient'; leave("grd_layer"); saveChanges(); } function check_grd_bx(cnt) { for(var i=1;i<=cnt;i++) { document.getElementById("grd"+i+"#").checked = true; } } function invert_grd_bx(cnt) { for(var i=1;i<=cnt;i++) { document.getElementById("grd"+i+"#").checked = (document.getElementById("grd"+i+"#").checked)? false : true; } } function toggle_border() { var form = document.simulation; form.border.value = (form.border.value == 1)? 0 : 1; saveChanges(); } function zoom(dir) { var form = document.simulation; if(dir) form.zoom.value++; else form.zoom.value--; saveChanges(); } function ssselection() { document.getElementById('sss_tb').style.top = yCoord - 10; document.getElementById('sss_tb').style.left = xCoord - 10; document.getElementById('sss_tb').style.visibility = 'visible'; window.setTimeout("hide_div(\"sss_tb\")",5000); } function set_sec_size(size) { var form = document.simulation; form.sector_size.value = size; saveChanges(); } var to; function arfselection() { window.clearTimeout(to); document.getElementById('arf_tb').style.top = yCoord - 10; document.getElementById('arf_tb').style.left = xCoord - 10; document.getElementById('arf_tb').style.visibility = 'visible'; to = window.setTimeout("hide_div(\"arf_tb\")",5000); } function set_arf(arf) { var form = document.simulation; form.auto_refresh.value = arf; form.arfdsp.value = (arf)? arf : 'nie'; hide_div('arf_tb'); window.clearTimeout(to); } var remain = 0; var dt = new Date(); var sts = Math.floor(dt.getTime()/1000); function countdown(seconds) { remain = (seconds)? seconds : remain; var form = document.simulation; var now = new Date(); var nts = Math.floor(now.getTime()/1000); if(gameStarted == 0) sts = nts; var secdiff = nts - sts; var remain_sec = remain - secdiff; remain_sec = (remain_sec < 1)? 0 : remain_sec; playTime = remain_sec; var min = Math.floor(remain_sec/60); var hours = Math.floor(min/60); var sec = remain_sec % 60; min = min % 60; hours = hours % 24; sec = (sec<10)? '0'+sec : sec; min = (min<10)? '0'+min : min; hours = (hours<10)? '0'+hours : hours; form.stime.value = (hours+":"+min+":"+sec); form.elapsed_seconds.value = secdiff; if(playTime > 0) window.setTimeout('countdown(0)',1000); } function save_score() { var form = document.simulation; form.action.value = 'save_score'; form.submit(); } function special_condition_rule_action(action_id,rule_id) { var form = document.simulation; switch (action_id) { case 0 : if(rule_id) form.action.value = "update_special_condition_rule"; else { if(get_rname()) { form.action.value = "save_special_condition_rule"; } } break; case 1 : if(get_rname()) { form.action.value = "save_special_condition_rule"; } break; case 2 : //if(confirm("delete environmental restriction?")) if(confirm("\nUmweltrestriktion löschen?\n")) { form.action.value = "delete_special_condition_rule"; } default : break; } form.submit(); } function getER_description() { getHelp(ER_desc.join('\n\n')); } function getPR_description() { getHelp(PR_desc); } function getPE_description() { getHelp(PE_desc); } function getSD_description() { getHelp(SD_desc); } function toggleStatus(id) { if(document.getElementById(id).value == 1) document.getElementById(id).value = 0; else document.getElementById(id).value = 1; saveChanges(); } function add_ext_att() { var form = document.simulation; form.action.value = 'add_ext_att'; form.submit(); } function del_ext_att(att_id,used) { var form = document.simulation; if(used) { // alert("this attribute is in use \nunable to delete!"); alert("\nEs existieren Daten, die sich auf dieses Attribut beziehen.\nLöschen verweigert!\n"); return; } else { // if(confirm("delete attribute?")) if(confirm("\nWollen Sie dises Attribut löschen?\n")) { form.action.value = 'delete_ext_att'; form.action_id.value = att_id; form.submit(); } } } function set_language(lang) { var form = document.simulation; if(form.language.value == lang) return; form.language.value = lang; saveChanges(); } function finish_game() { if(! confirm("\nSpiel beenden?\n")) return; var form = document.simulation; form.action.value = 'finish_game'; form.submit(); } function add_aero_upload() { document.getElementById("aero_upload").style.visibility = 'visible'; } function upload_aero_photo() { var form = document.simulation; form.action.value = 'upload_aero_photo'; form.submit(); } var focused_gdv = 0; function scroll_gdv(sel) { focused_gdv = (sel <= gdv_cnt)? sel : 0; for(var i=0;i 1 && focused_gdv < gdv_cnt) show_div("grd_select_div",20,-10); else hide_div("grd_select_div"); focused_gdv++; } //------------------------------------------------------------------------------ var maxZindex = 0; var foregroundZindex = 0; var divStack = new Array(); function getMaxZindex() { if(maxZindex) return; var divs = document.getElementsByTagName("div"); for(var i=0;i zi)? maxZindex : zi; } foregroundZindex = maxZindex+1; } function foregroundDiv(div_id) { getMaxZindex(); if(document.getElementById(div_id).style.zIndex < foregroundZindex) { foregroundZindex++; document.getElementById(div_id).style.zIndex = foregroundZindex; saveDivStack(div_id); } } function alreadyListedDiv(idx) { var div_id = divStack[idx]; for(i=idx+1;i<=foregroundZindex;i++) { if(divStack[i] == div_id) return true; } return false; } function saveDivStack(div_id) { if(! load_complete) return; document.getElementById('div_stack').value = ''; divStack[foregroundZindex] = div_id; for(var i=foregroundZindex;i>maxZindex+1;i--) { if(alreadyListedDiv(i)) continue; document.getElementById('div_stack').value += ' '+divStack[i]+' '; } } function reorderDivStack() { load_complete = 1; if(! document.getElementById('div_stack').value.match(/\S/)) return; var divs = document.getElementById('div_stack').value.split(/\s+/); for(var i=divs.length-1;i>=0;i--) { if(document.getElementById(divs[i])) foregroundDiv(divs[i]); } }