last update: Mon, 05 Sep 2011 17:16:55 +0000
  1. <?php
  2. class GuiParser
  3. {
  4. var $text_line_array;
  5. var $line_tabs;
  6. function GuiParser()
  7. {
  8. $this->text_line_array = array();
  9. $this->line_tabs = array();
  10. }
  11. function ParseGui($input, $argv)
  12. {
  13. return convert_gui($input, "./extensions/GuiParserPics/", $argv, 0);
  14. }
  15. function ParseTrigger($input, $argv)
  16. {
  17. return convert_gui($input, "./extensions/GuiParserPics/", $argv , 2);
  18. }
  19. ##--------real code--------
  20. function fill_line_array($_text)
  21. {
  22. $line_start = array();
  23. $line_end = array();
  24. $line = 0;
  25. $pos = 0;
  26. $line_start[$line] = 0;
  27. while ($pos = (strpos($_text,"<br />",$pos)))
  28. {
  29. $line_end[$line] = $pos;
  30. $line++;
  31. $pos+=strlen("<br />");
  32. $line_start[$line] = $pos+2;
  33. }
  34. for ($i=0;$i<=$line+10;$i++)
  35. {
  36. if ($line > $i)
  37. {
  38. if ($i > 0)
  39. $this->text_line_array[$i] = rtrim(substr($_text, $line_start[$i], $line_end[$i] - $line_start[$i]));
  40. else
  41. $this->text_line_array[$i] = rtrim(substr($_text, $line_start[$i], $line_end[$i] - $line_start[$i]));
  42. }
  43. else
  44. $this->text_line_array[$i] = 0;
  45. }
  46. }
  47. function get_tabs($_text)
  48. {
  49. //echo "get_tabs( $_text )<br>";
  50. $text = $_text;
  51. $pos = 0;
  52. $tabs = 0;
  53. while (substr($text,$pos,4) == " ")
  54. {
  55. $pos+=4;
  56. $tabs++;
  57. }
  58. return $tabs;
  59. }
  60. function get_line_tabs($_text_line, $line)
  61. {
  62. //echo "get_line_tabs( $line )<br>";
  63. if ( ! isset($this->line_tabs[$line]))
  64. {
  65. //$line_tabs[$line] = get_tabs(get_line($_text,$line));
  66. $this->line_tabs[$line] = $this->get_tabs($_text_line[$line]);
  67. }
  68. return $this->line_tabs[$line];
  69. }
  70. function get_intended($_text_line,$linenr,$offset)
  71. {
  72. //echo "get_intended( $linenr, $offset)<br>";
  73. return $this->get_line_tabs($_text_line,$linenr) - $this->get_line_tabs($_text_line,$linenr + $offset);
  74. }
  75. function get_type($_text)
  76. {
  77. //echo "get_type ( $_text )<br>";
  78. $text = str_replace(" ","",$_text);
  79. //echo $text."<br>";
  80. //echo 'get_type( '.$text." )<br>";
  81. if ((substr($text,0,10) == "Ereignisse") || (substr($text,0,6) == "Events"))
  82. {
  83. return 1;
  84. }
  85. else if ((substr($text,0,11) == "Bedingungen") || (substr($text,0,10) == "Conditions"))
  86. {
  87. return 2;
  88. }
  89. else if ((substr($text,0,8) == "Aktionen") || (substr($text,0,7) == "Actions"))
  90. {
  91. return 3;
  92. }
  93. else if (substr($text,0,7) == "Foreach")
  94. {
  95. return 4;
  96. }
  97. else if ((substr($text,0,18) == "Schleifen-Aktionen") || (substr($text,0,12) == "Loop-Actions"))
  98. {
  99. return 5;
  100. }
  101. else if ((substr($text,0,4) == "'IF'") || (substr($text,0,13) == "If-Conditions"))
  102. {
  103. return 7;
  104. }
  105. else if ((substr($text,0,6) == "'THEN'") || (substr($text,0,12) == "Then-Actions"))
  106. {
  107. return 8;
  108. }
  109. else if ((substr($text,0,6) == "'ELSE'") || (substr($text,0,12) == "Else-Actions"))
  110. {
  111. return 9;
  112. }
  113. else if (substr($text,0,2) == "If")
  114. {
  115. return 6;
  116. }
  117. else if ((substr($text,0,13) == "Spielergruppe") || (substr($text,0,11) == "PlayerGroup"))
  118. {
  119. return 10;
  120. }
  121. else if ((substr($text,0,15) == "Einheitengruppe") || (substr($text,0,9) == "UnitGroup"))
  122. {
  123. return 11;
  124. }
  125. else
  126. {
  127. return 0;
  128. }
  129. }
  130. function get_symbol($_text)
  131. {
  132. //echo "get_symbol( $_text )<br>";
  133. $text = str_replace(" ","",$_text);
  134. //echo $text."<br>";
  135. if (substr($text,0,4) == "Wait")
  136. {
  137. return "wait";
  138. }
  139. else if (substr($text,0,3) == "Set")
  140. {
  141. return "set";
  142. }
  143. else if ((substr($text,0,2) == "KI") || (substr($text,0,2) == "AI"))
  144. {
  145. return "ki";
  146. }
  147. else if (substr($text,0,8) == "--------")
  148. {
  149. return "comment";
  150. }
  151. else if (substr($text,0,9) == "Animation")
  152. {
  153. return "animation";
  154. }
  155. else if ((substr($text,0,6) == "Kamera") || (substr($text,0,6) == "Camera"))
  156. {
  157. return "cam";
  158. }
  159. else if ((substr($text,0,5) == "Video") || (substr($text,0,9) == "Cinematic"))
  160. {
  161. return "cam";
  162. }
  163. else if ((substr($text,0,15) == "Countdown-Timer") || (substr($text,0,14) == "CountdownTimer") || (substr($text,0,4) == "Time") || (substr($text,0,4) == "Zeit") )
  164. {
  165. return "timer";
  166. }
  167. else if ((substr($text,0,11) == "Zerstörbar") || (substr($text,0,12) == "Destructible"))
  168. {
  169. return "destructable";
  170. }
  171. else if (substr($text,0,6) == "Zerstrbar")
  172. {
  173. return "destructable";
  174. }
  175. else if (substr($text,0,6) == "Dialog")
  176. {
  177. return "dialog";
  178. }
  179. else if ((substr($text,0,8) == "Umgebung") || (substr($text,0,11) == "Environment"))
  180. {
  181. return "enviroment";
  182. }
  183. else if ((substr($text,0,11) == "Spiel-Cache") || (substr($text,0,9) == "GameCache"))
  184. {
  185. return "set";
  186. }
  187. else if ((substr($text,0,4) == "Held") || (substr($text,0,4) == "Hero"))
  188. {
  189. return "hero";
  190. }
  191. else if ((substr($text,0,10) == "Gegenstand") || (substr($text,0,4) == "Item"))
  192. {
  193. return "item";
  194. }
  195. else if ((substr($text,0,11) == "Bestenliste") || (substr($text,0,11) == "Leaderboard"))
  196. {
  197. return "quest";
  198. }
  199. else if ((substr($text,0,8) == "Nahkampf") || (substr($text,0,5) == "Melee"))
  200. {
  201. return "mellee";
  202. }
  203. else if (substr($text,0,10) == "Multiboard")
  204. {
  205. return "quest";
  206. }
  207. else if (substr($text,0,7) == "Neutral")
  208. {
  209. return "neutral";
  210. }
  211. else if ((substr($text,0,7) == "Spieler") || (substr($text,0,6) == "Player"))
  212. {
  213. return "player";
  214. }
  215. else if ((substr($text,0,5) == "Spiel") || (substr($text,0,4) == "Game"))
  216. {
  217. return "game";
  218. }
  219. else if (substr($text,0,4) == "Quest")
  220. {
  221. return "quest";
  222. }
  223. else if ((substr($text,0,6) == "Gebiet") || (substr($text,0,4) == "Rect"))
  224. {
  225. return "rect";
  226. }
  227. else if ((substr($text,0,7) == "Auswahl") || (substr($text,0,9) == "Selection"))
  228. {
  229. return "selection";
  230. }
  231. else if (substr($text,0,5) == "Sound")
  232. {
  233. return "sound";
  234. }
  235. else if ((substr($text,0,13) == "Spezialeffekt") || (substr($text,0,13) == "SpecialEffect"))
  236. {
  237. return "animation";
  238. }
  239. else if ((substr($text,0,7) == "Einheit") || (substr($text,0,4) == "Unit"))
  240. {
  241. return "unit";
  242. }
  243. else if ((substr($text,0,12) == "Sichtbarkeit") || (substr($text,0,10) == "Visibility"))
  244. {
  245. return "visibility";
  246. }
  247. else
  248. return "page";
  249. }
  250. function make_aufklapp_picture($div_id,$src1,$src2)
  251. {
  252. $result= '<img style="border: 0px;vertical-align: middle;" src="'.$src1.'"
  253. onclick = \'
  254. my_node = document.getElementById("'.$div_id.'");
  255. if ( my_node.style.visibility=="hidden" )
  256. {
  257. joinminus = new Image();
  258. joinminus.src = "'.$src1.'";
  259. this.src = joinminus.src;
  260. my_node.style.visibility="inherit";
  261. my_node.style.position = "static";
  262. } else {
  263. joinplus = new Image();
  264. joinplus.src = "'.$src2.'";
  265. this.src = joinplus.src;
  266. my_node.style.visibility="hidden";
  267. my_node.style.position = "absolute";
  268. }
  269. \'
  270. >';
  271. return $result;
  272. }
  273. function convert_gui($_trigger, $symbolpath, $args = 0, $arg_noheader = 2 )
  274. {
  275. //Hier die maximale Höhe eintragen :
  276. $max_height = 400;
  277. $trigger = nl2br(htmlspecialchars(trim($_trigger)))."<br />";
  278. $trigger = str_replace("\'","'",$trigger);
  279. $ausgabe = '';
  280. $source = '';
  281. $noheader = (isset($args['noheader'])) ? 2 : $arg_noheader;
  282. $header = ($noheader==0) ? 1 : 0;;
  283. $open_divs = 0;
  284. $bedingungen = -1;
  285. $blocks2close = 0;
  286. $nextlinecode = '';
  287. $trigger_name = "";
  288. $intend_line = array();
  289. //$line_tabs = array();
  290. //$text_line_array = array();
  291. $this->fill_line_array($trigger);
  292. for ($i=0;$i<=10;$i++) $intend_line[$i]=0;
  293. $line_nr = 0;
  294. while ($line = $this->text_line_array[$line_nr])
  295. {
  296. //echo $line;
  297. if ($nextlinecode != '')
  298. {
  299. $ausgabe.=$nextlinecode;
  300. $nextlinecode='';
  301. }
  302. $ausgabe.='<span>';
  303. $tabs = $this->get_line_tabs($this->text_line_array,$line_nr);
  304. //echo $tabs;
  305. if ($bedingungen != -1)
  306. {
  307. if ($this->get_line_tabs($this->text_line_array,$line_nr) <= $bedingungen)
  308. {
  309. $bedingungen = -1;
  310. }
  311. }
  312. if (($tabs == 0) && ($header == 0) )
  313. {
  314. if (($line != "Ereignisse") && ($line != "Bedingungen") && ($line != "Aktionen") && ($line != "no_header"))
  315. {
  316. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'base.gif">';
  317. $ausgabe.=$line;
  318. //$ausgabe.='<br>';
  319. $header ++;
  320. $trigger_name = $line;
  321. }
  322. else
  323. {
  324. if ($line == "Bedingungen")
  325. {
  326. $bedingungen=$tabs;
  327. }
  328. if ($line != "no_header")
  329. $line_nr--;
  330. else
  331. $noheader = 1;
  332. $header++;
  333. }
  334. } else {
  335. for ($i=1+($trigger_name != "" ? 1 : 0 );$i<=$this->get_line_tabs($this->text_line_array,$line_nr);$i++)
  336. {
  337. //Einrückungen
  338. if ($intend_line[$i])
  339. {
  340. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'line.gif">';
  341. }
  342. else
  343. {
  344. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'empty.gif">';
  345. }
  346. }
  347. if ($this->get_intended($this->text_line_array,$line_nr,1) == 0)
  348. {
  349. //keine Einrückungen
  350. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'join.gif">';
  351. }
  352. else if ($this->get_intended($this->text_line_array,$line_nr,1) == -1)
  353. {
  354. //Einrüclung nach rechts
  355. $a=1;
  356. $intended_lines = 0;
  357. while ($this->get_intended($this->text_line_array,$line_nr,$a)<0) $a++;
  358. if (($this->get_intended($this->text_line_array,$line_nr,$a)==0) && ($this->text_line_array[$a]!="") )
  359. {
  360. $intended_lines++;
  361. $intend_line[$tabs+1]=1;
  362. }
  363. else
  364. {
  365. $intend_line[$tabs+1]=0;
  366. }
  367. if ($intended_lines > 0)
  368. {
  369. //$ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'joinminus.gif">';
  370. $div_id = uniqid("block_") ;
  371. $src1 = ''.$symbolpath.'joinminus.gif';
  372. $src2 = ''.$symbolpath.'joinplus.gif';
  373. $ausgabe.=$this->make_aufklapp_picture($div_id,$src1,$src2);
  374. $nextlinecode.='<div id="'.$div_id.'">';
  375. $open_divs++;
  376. }
  377. else
  378. {
  379. //$ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'joinbottomminus.gif">';
  380. $div_id = uniqid("block_") ;
  381. $src1 = ''.$symbolpath.'joinbottomminus.gif';
  382. $src2 = ''.$symbolpath.'joinbottomplus.gif';
  383. $ausgabe.=$this->make_aufklapp_picture($div_id,$src1,$src2);
  384. $nextlinecode.='<div id="'.$div_id.'">';
  385. $open_divs++;
  386. }
  387. }
  388. else
  389. {
  390. //Ende einer Einrückung
  391. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'joinbottom.gif">';
  392. $intend_line[$tabs]=0;
  393. $blocks2close = $this->get_intended($this->text_line_array,$line_nr,1);
  394. //$ausgabe.=$blocks2close;
  395. }
  396. $line_type = $this->get_type(trim($line));
  397. if ($line_type == 1 )
  398. {
  399. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'events.gif">';
  400. }
  401. else if ($line_type == 2 )
  402. {
  403. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'cond.gif">';
  404. if ($bedingungen == -1)
  405. {
  406. $bedingungen=$tabs;
  407. }
  408. }
  409. else if ($line_type == 3 )
  410. {
  411. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'actions.gif">';
  412. }
  413. else if ($line_type == 4 )
  414. {
  415. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'struct.gif">';
  416. }
  417. else if ($line_type == 5 )
  418. {
  419. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'actions.gif">';
  420. }
  421. else if ($line_type == 6 )
  422. {
  423. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'struct.gif">';
  424. }
  425. else if ($line_type == 7 )
  426. {
  427. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'cond.gif">';
  428. if ($bedingungen == -1)
  429. {
  430. $bedingungen=$tabs;
  431. }
  432. }
  433. else if ($line_type == 8 )
  434. {
  435. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'actions.gif">';
  436. }
  437. else if ($line_type == 9 )
  438. {
  439. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'actions.gif">';
  440. }
  441. else if ($line_type == 10 )
  442. {
  443. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'force.gif">';
  444. }
  445. else if ($line_type == 11 )
  446. {
  447. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'group.gif">';
  448. } else
  449. {
  450. //Aktion
  451. if ($bedingungen == -1)
  452. {
  453. $ausgabe.='<img style="margin-top:0px;margin-bottom:0px;padding-top:0px;padding-bottom:0px;border: 0px;vertical-align: middle;" src="'.$symbolpath.$this->get_symbol(trim($line)).'.gif">';
  454. }
  455. else
  456. {
  457. $ausgabe.='<img style="border: 0px;vertical-align: middle;" src="'.$symbolpath.'struct.gif">';
  458. }
  459. }
  460. $ausgabe.=$line;
  461. //$ausgabe.='<br>';
  462. }
  463. $ausgabe.="</span>";
  464. if ((($line_nr != 0) && ($noheader==1)) || ($noheader!=1))
  465. {
  466. $ausgabe.="<br />";
  467. }
  468. $ausgabe.='
  469. ';
  470. for ($c=0;$c<$blocks2close;$c++)
  471. {
  472. if ($open_divs > 0)
  473. {
  474. //$ausgabe.="\r\n</div>";
  475. $ausgabe.="</div>";
  476. $open_divs--;
  477. }
  478. }
  479. $blocks2close = 0;
  480. $line_nr++;
  481. }
  482. #fixed the Unicode-Bug with german letters
  483. //egal, was ich mache - wenn ich einen Auslöser aus dem Editor irgendwo hin kopiere werden die Sonderzeichen falsch angezeigt
  484. //ich nehm den Teil deshalb wieder rein, damit man nicht jedes mal von Hand die Umlaute ändern muss
  485. //da wohl kaum einer in nem Trigger "Ä" schreibt, wird es auch keinen stören
  486. //Außerdem denk ich, dass das Problem nicht nur bei mir auftritt, da man auch im inWarcraft-Forum immer wirder diese Zeichen sieht.
  487. // mfg peq
  488. $ausgabe = str_replace("Ä","Ä",$ausgabe);
  489. $ausgabe = str_replace("Ãœ","Ü",$ausgabe);
  490. $ausgabe = str_replace("Ö","Ö",$ausgabe);
  491. $ausgabe = str_replace("ä","ä",$ausgabe);
  492. $ausgabe = str_replace("ü","ü",$ausgabe);
  493. $ausgabe = str_replace("ö","ö",$ausgabe);
  494. $ausgabe = str_replace("ß","ß",$ausgabe);
  495. $ausgabe = str_replace("\r","",$ausgabe);
  496. $ausgabe = str_replace("\n","",$ausgabe);
  497. //Höhe :
  498. $height = 16*($line_nr - (($noheader==0) ? 0 : 1));
  499. //für den Internet-Explorer:
  500. $height += 20;
  501. if ($height>$max_height)
  502. {
  503. $height = $max_height;
  504. $scroll = 'auto';
  505. }
  506. else
  507. {
  508. //$scroll='auto';
  509. $scroll = 'auto';
  510. }
  511. #this is strange... it's interpreted by the wikiparser. But it works atm. Better not touch this string!
  512. $ausgabe2 = '';
  513. $ausgabe2.= '<nowiki><div style="margin: 5px 20px 20px;">';
  514. if (isset($args['text']))
  515. {
  516. if ($args['text']!='false'){
  517. $ausgabe2.='<div style="font: 11px verdana, geneva, lucida, \'lucida grande\', arial, helvetica, sans-serif; margin-bottom: 2px;">Trigger:</div>';
  518. }
  519. }
  520. $ausgabe2.='<div style="font-family:Tahoma,Arial;font-size:11px;color:#000000; background-color:#FFFFFF; margin-top:0px; margin-bottom:0px; border:1px solid #999999;white-space: nowrap; width: 97%;overflow:'.$scroll.'; line-height:10px; height:'.$height.'px;">';
  521. $ausgabe2.=$ausgabe;
  522. $ausgabe2.='</div></div></nowiki>';
  523. return $ausgabe2;
  524. }
  525. }
  526. ?>

goto line:
Compare with:
text copy window edit this code post new code