HTML_Helper.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. <?php
  2. /**
  3. * HTML helper file.
  4. *
  5. * Provides a helper to perform HTML operations.
  6. *
  7. * @category Helper.
  8. */
  9. /**
  10. * Require dependent files if not present.
  11. */
  12. require_once(PATH::HELPER . "Helper.php");
  13. require_once(PATH::ENTITY . "Unit.php");
  14. require_once(PATH::ENTITY . "K_Unit.php");
  15. require_once(PATH::ENTITY . "Building.php");
  16. require_once(PATH::ENTITY . "K_Building.php");
  17. require_once(PATH::ENTITY . "Decoration.php");
  18. require_once(PATH::ENTITY . "K_Decoration.php");
  19. require_once(PATH::ENTITY . "Rune.php");
  20. require_once(PATH::ENTITY . "Artifact.php");
  21. require_once(PATH::ENTITY . "Enchantment.php");
  22. require_once(PATH::ENTITY . "Inventory.php");
  23. /**
  24. * HTML helper.
  25. *
  26. * Contains utilities to parse and format HTML and to build elements.
  27. *
  28. * @category Helper.
  29. */
  30. final class HTML extends Helper{
  31. /**
  32. * Escapes HTML characters
  33. *
  34. * Alias for htmlspecialchars([input], ENT_QUOTES)
  35. *
  36. * @param string $input Text to escape.
  37. * @return string Escaped text.
  38. */
  39. public static function e($input){
  40. return htmlspecialchars($input, ENT_QUOTES);
  41. }
  42. /**
  43. * Generates a unit panel.
  44. *
  45. * @param Unit|K_Unit Entity to get the info from.
  46. * @return string HTML content for a monster panel. Empty on error.
  47. */
  48. public static function unit_panel($unit) {
  49. if ($unit instanceof Unit){
  50. $k = $unit->unit;
  51. $stars = $unit->stars;
  52. $level = true;
  53. $teams = (sizeof($unit->teams) > 0);
  54. $lock = $unit->lock;
  55. $storage = $unit->in_storage;
  56. $maxed = ($unit->level == 40 && $unit->are_skills_maxed());
  57. }
  58. elseif ($unit instanceof K_Unit){
  59. $k = $unit;
  60. $stars = $unit->base_stars;
  61. $level = false;
  62. $teams = 0;
  63. $lock = false;
  64. $storage = false;
  65. $maxed = false;
  66. }
  67. else{
  68. return "";
  69. }
  70. $html = "";
  71. if ($k->awakens_from == "" && $k->awakens_to == ""){
  72. // No to, no from
  73. if ($k->base_stars >= 4){
  74. // SFV Collab event units, always awakened.
  75. $star_class = "star_purple";
  76. }
  77. elseif($k->archetype == ARCHETYPE_ID::MATERIAL && $k->element == ELEMENT_ID::LIGHT){
  78. // Rainbowmon, always awakened
  79. $star_class = "star_purple";
  80. }
  81. elseif($k->archetype == ARCHETYPE_ID::MATERIAL && $k->element == ELEMENT_ID::DARK){
  82. // Devilmon, always unawakened
  83. $star_class = "star_silver";
  84. }
  85. else{
  86. // Unawakeable monster
  87. $star_class = "star_silver";
  88. }
  89. }
  90. elseif ($k->awakens_from != ""){
  91. // Already awakened
  92. if ($k->base_stars - $k->natural_stars == 1){
  93. // Normal awaken.
  94. $star_class ="star_purple";
  95. }
  96. else{
  97. // Second awaken.
  98. $star_class ="star_red";
  99. }
  100. }
  101. elseif ($k->awakens_to != ""){
  102. // Awakeable.
  103. $star_class ="star_gold";
  104. }
  105. $html .= "<span class='stars'>\n";
  106. for ($i = 0; $i < $stars; $i ++){
  107. $html .= "<img class='star $star_class' src='" . URL::IMG["ICON"] . "star.png'/>\n";
  108. }
  109. $html .= "</span>\n";
  110. $html .= "<img title='" . $unit->title . "' class='monster border_" . $k->element_name . "' src='" . $k->get_image() . "'/>\n";
  111. if ($level){
  112. $html .= "<span class='level'>\n";
  113. $html .= $unit->level . "\n";
  114. $html .= "</span>\n";
  115. }
  116. $html .= "<span class='badges'>\n";
  117. if ($maxed){
  118. $html .= "<img title='Maxed unit' src='" . URL::IMG["ICON"] . "maxed.png'>";
  119. }
  120. if ($teams > 0){
  121. $title = $teams . " teams";
  122. if ($teams == 1){
  123. $title = "1 team: " . $unit->teams[0]->name;
  124. }
  125. $html .= "<img title='$title' src='" . URL::IMG["ICON"] . "team.png'>";
  126. }
  127. if ($lock == 1){
  128. $html .= "<img title='Locked' src='" . URL::IMG["ICON"] . "lock.png'>";
  129. }
  130. if ($storage){
  131. $html .= "<img title='In storage' src='" . URL::IMG["ICON"] . "storage.png'>";
  132. }
  133. $html .= "</span>\n";
  134. return $html;
  135. }
  136. /**
  137. * Generates a transformed monster panel.
  138. *
  139. * @param Unit|K_Unit Entity to get the info from.
  140. * @return string HTML content for a monster panel. Empty on error.
  141. */
  142. public static function unit_transformation_panel($unit) {
  143. $html = "";
  144. if ($unit instanceof Unit){
  145. $k = $unit->unit;
  146. }
  147. elseif ($unit instanceof K_Unit){
  148. $k = $unit;
  149. }
  150. else{
  151. return "";
  152. }
  153. if ($k->transformation == null){
  154. return "";
  155. }
  156. $html .= "<div class='monster_transformation_panel'>\n";
  157. $html .= "<img title='" . $unit->title . " (transformed)' class='monster_transformation border_" . $k->element_name . "' src='" . $k->transformation->get_image() . "'/>\n";
  158. $html .= "</div>\n";
  159. return $html;
  160. }
  161. /**
  162. * Generates a rune panel.
  163. *
  164. * @param Rune rune Entity to get the info from.
  165. * @param Unit unit Optional. The unit the rune is assigned to.
  166. * @return string HTML content for a rune panel. Empty on error.
  167. */
  168. public static function rune_panel($rune, $unit = null) {
  169. if (!($rune instanceof Rune)){
  170. return "";
  171. }
  172. $html = "";
  173. $html .= "<div class='rune_panel rune_slot_" . $rune->slot . " rune_level_" . $rune->level . " rune_quality_" . strtolower($rune->quality_name) . " rune_original_quality_" . strtolower($rune->original_quality_name) . " rune_ancient_" . $rune->ancient . "'>\n";
  174. $html .= "<img class='rune_base' src='" . URL::IMG["RUNE"] . "base.png'/>\n";
  175. $html .= "<img class='rune_icon' src='" . $rune->type->get_image() . "'/>\n";
  176. $html .= "<span class='rune_stars'>\n";
  177. $star_color = "gold";
  178. if ($rune->level == 15){
  179. $star_color = "purple";
  180. }
  181. for ($i = 0; $i < $rune->stars; $i ++){
  182. $html .= "<img class='star star_$star_color' src='" . URL::IMG["ICON"] . "star.png'/>\n";
  183. }
  184. $html .= "</span>\n";
  185. $html .= "<span class='rune_level'>\n";
  186. $html .= $rune->level . "\n";
  187. $html .= "</span>\n";
  188. $html .= "</div>\n";
  189. if ($unit instanceof Unit){
  190. $html .= "<div class='assigned'>\n";
  191. $html .= "<a target='blank' href='/monsters/" . $unit->id . "'>\n";
  192. $html .= "<img title='" . $unit->title . "' class='monster_image border_" . $unit->unit->element_name . "' src='" . $unit->unit->get_image() . "'/>\n";
  193. $html .= "</a>\n";
  194. $html .= "</div>\n";
  195. }
  196. return $html;
  197. }
  198. /**
  199. * Generates a rune table.
  200. *
  201. * @param Rune rune Entity to get the info from.
  202. * @param Unit unit Optional. The unit the rune is assigned to.
  203. * @return string HTML content for a rune table. Empty on error.
  204. */
  205. public static function rune_table($rune, $unit = null) {
  206. if (!($rune instanceof Rune)){
  207. return "";
  208. }
  209. $html = "";
  210. $html .= "<table class='rune' id='rune-" . $rune->id . "'>\n";
  211. $html .= "<tr>\n";
  212. $html .= "<td class='icon'>\n";
  213. $html .= HTML::rune_panel($rune, $unit) . "\n";
  214. $html .= "</td>\n";
  215. $html .= "<td class='stats'>\n";
  216. $html .= "<table>\n";
  217. // Main stat
  218. $html .= "<tr class='main_stat'>\n";
  219. $html .= "<td class='stat'>\n";
  220. if (in_array($rune->main_stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  221. $stat_name = str_replace("%", "", $rune->main_stat_name);
  222. $stat_value = "+" . $rune->main_stat_value . "%";
  223. }
  224. else{
  225. $stat_name = $rune->main_stat_name;
  226. $stat_value = "+" . $rune->main_stat_value. "&nbsp;";
  227. }
  228. $html .= $stat_name . "\n";
  229. $html .= "</td>\n";
  230. $html .= "<td class='value'>\n";
  231. $html .= $stat_value . "\n";
  232. $html .= "</td>\n";
  233. $html .= "<td class='grind'>\n";
  234. $html .= "</td>\n";
  235. $html .= "<td class='enchant'>\n";
  236. $html .= "</td>\n";
  237. $html .= "</tr>\n";
  238. // Innate stat
  239. $html .= "<tr class='innate_stat'>\n";
  240. $html .= "<td class='stat'>\n";
  241. if (strlen($rune->innate_stat) == 0){
  242. $stat_name = "&nbsp;";
  243. $stat_value = "";
  244. }
  245. elseif (in_array($rune->innate_stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  246. $stat_name = str_replace("%", "", $rune->innate_stat_name);
  247. $stat_value = "+" . $rune->innate_stat_value . "%";
  248. }
  249. else{
  250. $stat_name = $rune->innate_stat_name;
  251. $stat_value = "+" . $rune->innate_stat_value. "&nbsp;";;
  252. }
  253. $html .= $stat_name . "\n";
  254. $html .= "</td>\n";
  255. $html .= "<td class='value'>\n";
  256. $html .= $stat_value . "\n";
  257. $html .= "</td>\n";
  258. $html .= "<td class='grind'>\n";
  259. $html .= "</td>\n";
  260. $html .= "</tr>\n";
  261. $substats_name = array($rune->substat_1_name, $rune->substat_2_name, $rune->substat_3_name, $rune->substat_4_name);
  262. $substats_value = array($rune->substat_1_value, $rune->substat_2_value, $rune->substat_3_value, $rune->substat_4_value);
  263. $substats_grind = array($rune->substat_1_grind, $rune->substat_2_grind, $rune->substat_3_grind, $rune->substat_4_grind);
  264. $substats_enchant = array($rune->substat_1_enchant, $rune->substat_2_enchant, $rune->substat_3_enchant, $rune->substat_4_enchant);
  265. for ($i = 0; $i < 4; $i ++){
  266. if (strlen($substats_name[$i]) == 0){
  267. $stat_name = "&nbsp;";
  268. $stat_value = "";
  269. }
  270. elseif (in_array($substats_name[$i], array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  271. $stat_name = str_replace("%", "", $substats_name[$i]);
  272. $stat_value = "+" . $substats_value[$i] . "%";
  273. }
  274. else{
  275. $stat_name = $substats_name[$i];
  276. $stat_value = "+" . $substats_value[$i]. "&nbsp;";
  277. }
  278. $grind = "";
  279. if ($substats_grind[$i] > 0){
  280. $grind = "+" . $substats_grind[$i];
  281. if (in_array($substats_name[$i], array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  282. $grind = $grind . "%";
  283. }
  284. }
  285. $html .= "<tr class=substat>\n";
  286. $html .= "<td class='stat'>\n";
  287. $html .= $stat_name . "\n";
  288. $html .= "</td>\n";
  289. $html .= "<td class='value'>\n";
  290. $html .= $stat_value . "\n";
  291. $html .= "<td class='grind grind_$grind'>\n";
  292. $html .= $grind . "\n";
  293. if ($substats_enchant[$i] == 1){
  294. $html .= "<img title='Enchanted' src='" . URL::IMG["RUNE"] . "enchanted.png'/>\n";
  295. }
  296. $html .= "</td>\n";
  297. $html .= "</tr>\n";
  298. }
  299. $html .= "</table>\n";
  300. $html .= "</td>\n";
  301. // Details
  302. $html .= "<td class='details'>\n";
  303. $html .= "<table class='table_details'>\n";
  304. $html .= "<tr>\n";
  305. $html .= "<td class='title'>\n";
  306. $html .= "QY.:\n";
  307. $html .= "</td>\n";
  308. $html .= "<td class='value'>\n";
  309. $html .= "<span class='quality quality_" . strtolower($rune->quality_name) . "'>\n";
  310. $html .= $rune->quality_name . "\n";
  311. $html .= "</span>\n";
  312. $html .= "</td>\n";
  313. $html .= "</tr>\n";
  314. $html .= "<tr>\n";
  315. $html .= "<td class='title'>\n";
  316. $html .= "O.QY.:\n";
  317. $html .= "</td>\n";
  318. $html .= "<td class='value'>\n";
  319. $html .= "<span class='quality quality_" . strtolower($rune->original_quality_name) . "'>\n";
  320. $html .= $rune->original_quality_name . "\n";
  321. $html .= "</span>\n";
  322. $html .= "</td>\n";
  323. $html .= "</tr>\n";
  324. $html .= "<tr>\n";
  325. $html .= "<td class='title'>\n";
  326. $html .= "Value:\n";
  327. $html .= "</td>\n";
  328. $html .= "<td class='value'>\n";
  329. $html .= number_format($rune->value, 0, ".", ",") . "\n";
  330. $html .= "</td>\n";
  331. $html .= "</tr>\n";
  332. $html .= "<tr>\n";
  333. $html .= "<td class='title'>\n";
  334. $html .= "EFF.:\n";
  335. $html .= "</td>\n";
  336. $html .= "<td class='value'>\n";
  337. $html .= number_format($rune->efficiency, 2, ".", ",") . "%\n";
  338. $html .= "</td>\n";
  339. $html .= "</tr>\n";
  340. $html .= "<tr>\n";
  341. $html .= "<td class='title'>\n";
  342. $html .= "MX.E.:\n";
  343. $html .= "</td>\n";
  344. $html .= "<td class='value'>\n";
  345. $html .= number_format($rune->max_efficiency, 2, ".", ",") . "%\n";
  346. $html .= "</td>\n";
  347. $html .= "</tr>\n";
  348. $html .= "</table>\n";
  349. $html .= "</td>\n";
  350. $html .= "</tr>\n";
  351. $html .= "</table>\n";
  352. return $html;
  353. }
  354. // TODO: Icon and background selection must go in the entity code.
  355. /**
  356. * Generates an artifact panel.
  357. *
  358. * @param Artifact artifact Entity to get the info from.
  359. * @param Unit unit Optional. The unit the artifact is assigned to.
  360. * @return string HTML content for an artifact panel. Empty on error.
  361. */
  362. public static function artifact_panel($artifact, $unit = null) {
  363. if (!($artifact instanceof Artifact)){
  364. return "";
  365. }
  366. $html = "";
  367. $html .= "<div class='artifact_panel artifact_level_" . $artifact->level . " artifact_quality_" . strtolower($artifact->quality_name) . " artifact_original_quality_" . strtolower($artifact->original_quality_name) . " '>\n";
  368. $background = "";
  369. $icon = "";
  370. if ($artifact->type == ARTIFACT_TYPE::ARCHETYPE){
  371. $background = URL::IMG["ARTIFACT"] . "type_" . strtolower($artifact->quality_name) . ".png";
  372. $icon = URL::IMG["ARTIFACT"] . "type_";
  373. switch ($artifact->type){
  374. case ARCHETYPE_ID::ATTACK:
  375. $icon .= "attack";
  376. break;
  377. case ARCHETYPE_ID::DEFENSE:
  378. $icon .= "defense";
  379. break;
  380. case ARCHETYPE_ID::HP:
  381. $icon .= "hp";
  382. break;
  383. case ARCHETYPE_ID::SUPPORT:
  384. $icon .= "support";
  385. break;
  386. }
  387. $icon .= ".png";
  388. }
  389. else{
  390. $background = URL::IMG["ARTIFACT"] . "element_" . strtolower($artifact->quality_name) . ".png";
  391. $icon = URL::IMG["ARTIFACT"] . "element_";
  392. switch ($artifact->element){
  393. case ELEMENT_ID::WATER:
  394. $icon .= "water";
  395. break;
  396. case ELEMENT_ID::WIND:
  397. $icon .= "wind";
  398. break;
  399. case ELEMENT_ID::FIRE:
  400. $icon .= "fire";
  401. break;
  402. case ELEMENT_ID::LIGHT:
  403. $icon .= "light";
  404. break;
  405. case ELEMENT_ID::DARK:
  406. $icon .= "dark";
  407. break;
  408. }
  409. $icon .= ".png";
  410. }
  411. $html .= "<img class='artifact_base' src='" . $background . "'/>\n";
  412. $html .= "<img class='artifact_icon' src='" . $icon . "'/>\n";
  413. $html .= "<span class='artifact_stars'>\n";
  414. $html .= "</span>\n";
  415. $html .= "<span class='artifact_level'>\n";
  416. $html .= $artifact->level . "\n";
  417. $html .= "</span>\n";
  418. $html .= "</div>\n";
  419. if ($unit instanceof Unit){
  420. $html .= "<div class='assigned'>\n";
  421. $html .= "<a target='blank' href='/monsters/" . $unit->id . "'>\n";
  422. $html .= "<img title='" . $unit->title . "' class='monster_image border_" . $unit->unit->element_name . "' src='" . $unit->unit->get_image() . "'/>\n";
  423. $html .= "</a>\n";
  424. $html .= "</div>\n";
  425. }
  426. return $html;
  427. }
  428. /**
  429. * Generates a artifact table.
  430. *
  431. * @param Artifact artifact Entity to get the info from.
  432. * @param Unit unit Optional. The unit the artifact is assigned to.
  433. * @return string HTML content for a artifact table. Empty on error.
  434. */
  435. public static function artifact_table($artifact, $unit = null) {
  436. if (!($artifact instanceof Artifact)){
  437. return "";
  438. }
  439. $html = "";
  440. $html .= "<table class='artifact' id='artifact-" . $artifact->id . "'>\n";
  441. $html .= "<tr>\n";
  442. $html .= "<td class='icon'>\n";
  443. $html .= HTML::artifact_panel($artifact, $unit) . "\n";
  444. $html .= "</td>\n";
  445. $html .= "<td class='effects'>\n";
  446. $html .= "<table>\n";
  447. // Main stat
  448. $html .= "<tr class='effect main_stat'>\n";
  449. $html .= "<td class='effect'>\n";
  450. $stat_name = $artifact->main_stat_name;
  451. $stat_value = "+" . $artifact->main_stat_value;
  452. $html .= $stat_name . "\n";
  453. $html .= $stat_value . "\n";
  454. $html .= "</td>\n";
  455. $html .= "</tr>\n";
  456. $effects = array($artifact->effect_1_description, $artifact->effect_2_description, $artifact->effect_3_description, $artifact->effect_4_description);
  457. for ($i = 0; $i < 4; $i ++){
  458. $html .= "<tr class='effect'>\n";
  459. $html .= "<td class='effect'>\n";
  460. $name = $effects[$i];
  461. $name = str_replace("Increasing", "Inc.", $name);
  462. $name = str_replace("Decrease", "Dec.", $name);
  463. $name = str_replace("Critical", "Crit.", $name);
  464. $name = str_replace("Received ", "", $name);
  465. $name = str_replace("Damage", "Dmg.", $name);
  466. $name = str_replace("Additional", "Addl.", $name);
  467. $name = str_replace("Proportional", "Rel.", $name);
  468. $name = str_replace("Counterattack", "Counter", $name);
  469. $name = str_replace("Dealt by Attacking Together", "Attacking Together", $name);
  470. $html .= $name;
  471. $html .= "</td>\n";
  472. $html .= "</tr>\n";
  473. }
  474. $html .= "</table>\n";
  475. $html .= "</td>\n";
  476. $html .= "</tr>\n";
  477. $html .= "</table>\n";
  478. return $html;
  479. }
  480. /**
  481. * Generates a grindstone or gem panel.
  482. *
  483. * @param Enchantment Entity to get the info from.
  484. * @return string HTML content for a rune panel. Empty on error.
  485. */
  486. public static function enchantment_panel($enchantment) {
  487. if (!($enchantment instanceof Enchantment)){
  488. return "";
  489. }
  490. $html = "";
  491. if ($enchantment->gem == 1){
  492. if ($enchantment->inmemorial == 1){
  493. $base = URL::IMG["GRIND"] . "gem_inmemorial.png";
  494. }
  495. else{
  496. $base = URL::IMG["GRIND"] . "gem.png";
  497. }
  498. }
  499. else{
  500. if ($enchantment->inmemorial == 1){
  501. $base = URL::IMG["GRIND"] . "grind_inmemorial.png";
  502. }
  503. else{
  504. $base = URL::IMG["GRIND"] . "grind.png";
  505. }
  506. }
  507. if ($enchantment->inmemorial == 0 && isset($enchantment->rune)){
  508. $icon = "<img class='enchantment_icon' src='" . $enchantment->rune->get_image() . "'/>\n";
  509. }
  510. else{
  511. $icon = "";
  512. }
  513. if (in_array($enchantment->stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  514. $stat_name = str_replace("%", "", $enchantment->stat_name);
  515. $stat_value = "+" . $enchantment->min . "~" . $enchantment->max . "%";
  516. }
  517. else{
  518. $stat_name = $enchantment->stat_name;
  519. $stat_value = "+" . $enchantment->min . "~" . $enchantment->max;
  520. }
  521. $html .= "<div class='enchantment_panel enchantment_quality_" . strtolower($enchantment->quality_name) . " enchantment_ancient_" . $enchantment->ancient . "'>\n";
  522. $html .= "<img class='enchantment_base' src='" . $base . "'/>\n";
  523. $html .= $icon;
  524. $html .= "<span class='enchantment_stat'>\n";
  525. $html .= "<span class='enchantment_stat_name'>" . $stat_name . "</span>\n";
  526. $html .= "<span class='enchantment_stat_value'>" . $stat_value . "</span>\n";
  527. $html .= "</span>\n";
  528. if ($enchantment->amount > 0){
  529. $html .= "<span class='enchantment_amount'>\n";
  530. $html .= "x" . $enchantment->amount . "\n";
  531. $html .= "</span>\n";
  532. }
  533. $html .= "</div>\n";
  534. return $html;
  535. }
  536. /**
  537. * Generates a building panel.
  538. *
  539. * @param Building|Decoration|K_Building|K_Decoration $building Entity to get the info from.
  540. * @return string HTML content for a building panel. Empty on error.
  541. */
  542. public static function building_panel($building) {
  543. if ($building instanceof Building){
  544. $level = false;
  545. $title = $building->building->name;
  546. $description = $building->building->description;
  547. $img = $building->building->get_image();
  548. }
  549. elseif ($building instanceof K_Building){
  550. $level = false;
  551. $title = $building->name;
  552. $description = $building->building->description;
  553. $img = $building->get_image();
  554. }
  555. elseif ($building instanceof Decoration){
  556. $level = $building->level;
  557. $title = $building->decoration->name;
  558. $description = $building->decoration->description;
  559. $img = $building->decoration->get_image();
  560. }
  561. elseif ($building instanceof K_Decoration){
  562. $level = false;
  563. $title = $building->name;
  564. $description = $building->building->description;
  565. $img = $building->get_image();
  566. }
  567. else{
  568. return "";
  569. }
  570. if (strlen($description) > 0){
  571. $title .= ": " . $description;
  572. }
  573. $html = "<div class='building_panel'>\n";
  574. $html .= "<img title='" . $title . "' class='building' src='" . $img . "'/>\n";
  575. if ($level){
  576. $html .= "<span class='level'>\n";
  577. $html .= $level . "\n";
  578. $html .= "</span>\n";
  579. }
  580. $html .= "</div>\n";
  581. return $html;
  582. }
  583. /**
  584. * Generates a item panel.
  585. *
  586. * @param Inventory $item Entity to get the info from.
  587. * @return string HTML content for an item panel. Empty on error.
  588. */
  589. public static function item_panel($item) {
  590. if (!($item instanceof Inventory)){
  591. return "";
  592. }
  593. $html = "<div class='item_panel'>\n";
  594. $html .= "<img title='" . $item->name . "' class='item' src='" . $item->get_image() . "'/>\n";
  595. $html .= "<span class='amount'>\n";
  596. $html .= $item->amount . "\n";
  597. $html .= "</span>\n";
  598. $html .= "</div>\n";
  599. return $html;
  600. }
  601. /**
  602. * Generates a source panel.
  603. *
  604. * @param Inventory $source Entity to get the info from.
  605. * @return string HTML content for a source panel. Empty on error.
  606. */
  607. public static function source_panel($source) {
  608. //if (!($item instanceof K_Source)){
  609. // return "";
  610. //}
  611. $html = "<div class='source_panel'>\n";
  612. $html .= "<img title='" . $source->name . "' class='item' src='" . $source->get_image() . "'/>\n";
  613. $html .= "</div>\n";
  614. return $html;
  615. }
  616. /**
  617. * Generates an arena rank icon image.
  618. *
  619. * @param int $d Arena rank id.
  620. * @return string HTML content for the image.
  621. */
  622. public static function arena_rank_icon($id) {
  623. switch ($id){
  624. case ARENA_RANK_ID::BEGINER:
  625. $src = URL::IMG["RANK"] . "0901.png";
  626. $tit = "Beginer";
  627. break;
  628. case ARENA_RANK_ID::CHALLENGER_1:
  629. $src = URL::IMG["RANK"] . "1001.png";
  630. $tit = "Challenger 1";
  631. break;
  632. case ARENA_RANK_ID::CHALLENGER_2:
  633. $src = URL::IMG["RANK"] . "1002.png";
  634. $tit = "Challenger 2";
  635. break;
  636. case ARENA_RANK_ID::CHALLENGER_3:
  637. $src = URL::IMG["RANK"] . "1003.png";
  638. $tit = "Challenger 3";
  639. break;
  640. case ARENA_RANK_ID::FIGHTER_1:
  641. $src = URL::IMG["RANK"] . "2001.png";
  642. $tit = "Fighter 1";
  643. break;
  644. case ARENA_RANK_ID::FIGHTER_2:
  645. $src = URL::IMG["RANK"] . "2002.png";
  646. $tit = "Fighter 2";
  647. break;
  648. case ARENA_RANK_ID::FIGHTER_3:
  649. $src = URL::IMG["RANK"] . "2003.png";
  650. $tit = "Fighter 3";
  651. break;
  652. case ARENA_RANK_ID::CONQUEROR_1:
  653. $src = URL::IMG["RANK"] . "3001.png";
  654. $tit = "Conqueror 1";
  655. break;
  656. case ARENA_RANK_ID::CONQUEROR_2:
  657. $src = URL::IMG["RANK"] . "3002.png";
  658. $tit = "Conqueror 2";
  659. break;
  660. case ARENA_RANK_ID::CONQUEROR_3:
  661. $src = URL::IMG["RANK"] . "3003.png";
  662. $tit = "Conqueror 3";
  663. break;
  664. case ARENA_RANK_ID::GUARDIAN_1:
  665. $src = URL::IMG["RANK"] . "4001.png";
  666. $tit = "Guardian 1";
  667. break;
  668. case ARENA_RANK_ID::GUARDIAN_2:
  669. $src = URL::IMG["RANK"] . "4002.png";
  670. $tit = "Guardian 2";
  671. break;
  672. case ARENA_RANK_ID::GUARDIAN_3:
  673. $src = URL::IMG["RANK"] . "4003.png";
  674. $tit = "Guardian 3";
  675. break;
  676. case ARENA_RANK_ID::LEGEND:
  677. $src = URL::IMG["RANK"] . "5001.png";
  678. $tit = "Legend";
  679. default:
  680. $src = URL::IMG["RANK"] . $id . ".png";
  681. }
  682. $html = "<img alt='$tit' title='$tit' src='$src'/>";
  683. return $html;
  684. }
  685. }
  686. ?>