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

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