HTML_Helper.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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->stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  221. $stat_name = str_replace("%", "", $rune->main_stat->stat_name);
  222. $stat_value = "+" . $rune->main_stat->value . "%";
  223. }
  224. else{
  225. $stat_name = $rune->main_stat->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 ($rune->innate_stat == null){
  242. $stat_name = "&nbsp;";
  243. $stat_value = "";
  244. }
  245. elseif (in_array($rune->innate_stat->stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  246. $stat_name = str_replace("%", "", $rune->innate_stat->stat_name);
  247. $stat_value = "+" . $rune->innate_stat->value . "%";
  248. }
  249. else{
  250. $stat_name = $rune->innate_stat->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. for ($i = 0; $i < 4; $i ++){
  262. if ($rune->substats[$i] == null){
  263. $stat_name = "&nbsp;";
  264. $stat_value = "";
  265. }
  266. elseif (in_array($rune->substats[$i]->stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  267. $stat_name = str_replace("%", "", $rune->substats[$i]->stat_name);
  268. $stat_value = "+" . $rune->substats[$i]->value . "%";
  269. }
  270. else{
  271. $stat_name = $rune->substats[$i]->stat_name;
  272. $stat_value = "+" . $rune->substats[$i]->value. "&nbsp;";
  273. }
  274. $grind = "";
  275. if ($rune->substats[$i] != null && $rune->substats[$i]->grind > 0){
  276. $grind = "+" . $rune->substats[$i]->grind;
  277. if (in_array($rune->substats[$i]->stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  278. $grind = $grind . "%";
  279. }
  280. }
  281. $html .= "<tr class=substat>\n";
  282. $html .= "<td class='stat'>\n";
  283. $html .= $stat_name . "\n";
  284. $html .= "</td>\n";
  285. $html .= "<td class='value'>\n";
  286. $html .= $stat_value . "\n";
  287. $html .= "<td class='grind grind_$grind'>\n";
  288. $html .= $grind . "\n";
  289. if ($rune->substats[$i] != null && $rune->substats[$i]->enchant == 1){
  290. $html .= "<img title='Enchanted' src='" . URL::IMG["RUNE"] . "enchanted.png'/>\n";
  291. }
  292. $html .= "</td>\n";
  293. $html .= "</tr>\n";
  294. }
  295. $html .= "</table>\n";
  296. $html .= "</td>\n";
  297. // Details
  298. $html .= "<td class='details'>\n";
  299. $html .= "<table class='table_details'>\n";
  300. $html .= "<tr>\n";
  301. $html .= "<td class='title'>\n";
  302. $html .= "QY.:\n";
  303. $html .= "</td>\n";
  304. $html .= "<td class='value'>\n";
  305. $html .= "<span class='quality quality_" . strtolower($rune->quality_name) . "'>\n";
  306. $html .= $rune->quality_name . "\n";
  307. $html .= "</span>\n";
  308. $html .= "</td>\n";
  309. $html .= "</tr>\n";
  310. $html .= "<tr>\n";
  311. $html .= "<td class='title'>\n";
  312. $html .= "O.QY.:\n";
  313. $html .= "</td>\n";
  314. $html .= "<td class='value'>\n";
  315. $html .= "<span class='quality quality_" . strtolower($rune->original_quality_name) . "'>\n";
  316. $html .= $rune->original_quality_name . "\n";
  317. $html .= "</span>\n";
  318. $html .= "</td>\n";
  319. $html .= "</tr>\n";
  320. $html .= "<tr>\n";
  321. $html .= "<td class='title'>\n";
  322. $html .= "Value:\n";
  323. $html .= "</td>\n";
  324. $html .= "<td class='value'>\n";
  325. $html .= number_format($rune->value, 0, ".", ",") . "\n";
  326. $html .= "</td>\n";
  327. $html .= "</tr>\n";
  328. $html .= "<tr>\n";
  329. $html .= "<td class='title'>\n";
  330. $html .= "EFF.:\n";
  331. $html .= "</td>\n";
  332. $html .= "<td class='value'>\n";
  333. $html .= number_format($rune->efficiency, 2, ".", ",") . "%\n";
  334. $html .= "</td>\n";
  335. $html .= "</tr>\n";
  336. $html .= "<tr>\n";
  337. $html .= "<td class='title'>\n";
  338. $html .= "MX.E.:\n";
  339. $html .= "</td>\n";
  340. $html .= "<td class='value'>\n";
  341. $html .= number_format($rune->max_efficiency, 2, ".", ",") . "%\n";
  342. $html .= "</td>\n";
  343. $html .= "</tr>\n";
  344. $html .= "</table>\n";
  345. $html .= "</td>\n";
  346. $html .= "</tr>\n";
  347. $html .= "</table>\n";
  348. return $html;
  349. }
  350. // TODO: Icon and background selection must go in the entity code.
  351. /**
  352. * Generates an artifact panel.
  353. *
  354. * @param Artifact artifact Entity to get the info from.
  355. * @param Unit unit Optional. The unit the artifact is assigned to.
  356. * @return string HTML content for an artifact panel. Empty on error.
  357. */
  358. public static function artifact_panel($artifact, $unit = null) {
  359. if (!($artifact instanceof Artifact)){
  360. return "";
  361. }
  362. $html = "";
  363. $html .= "<div class='artifact_panel artifact_level_" . $artifact->level . " artifact_quality_" . strtolower($artifact->quality_name) . " artifact_original_quality_" . strtolower($artifact->original_quality_name) . " '>\n";
  364. $background = "";
  365. $icon = "";
  366. if ($artifact->type == ARTIFACT_TYPE::ARCHETYPE){
  367. $background = URL::IMG["ARTIFACT"] . "type_" . strtolower($artifact->quality_name) . ".png";
  368. $icon = URL::IMG["ARTIFACT"] . "type_";
  369. switch ($artifact->type){
  370. case ARCHETYPE_ID::ATTACK:
  371. $icon .= "attack";
  372. break;
  373. case ARCHETYPE_ID::DEFENSE:
  374. $icon .= "defense";
  375. break;
  376. case ARCHETYPE_ID::HP:
  377. $icon .= "hp";
  378. break;
  379. case ARCHETYPE_ID::SUPPORT:
  380. $icon .= "support";
  381. break;
  382. }
  383. $icon .= ".png";
  384. }
  385. else{
  386. $background = URL::IMG["ARTIFACT"] . "element_" . strtolower($artifact->quality_name) . ".png";
  387. $icon = URL::IMG["ARTIFACT"] . "element_";
  388. switch ($artifact->element){
  389. case ELEMENT_ID::WATER:
  390. $icon .= "water";
  391. break;
  392. case ELEMENT_ID::WIND:
  393. $icon .= "wind";
  394. break;
  395. case ELEMENT_ID::FIRE:
  396. $icon .= "fire";
  397. break;
  398. case ELEMENT_ID::LIGHT:
  399. $icon .= "light";
  400. break;
  401. case ELEMENT_ID::DARK:
  402. $icon .= "dark";
  403. break;
  404. }
  405. $icon .= ".png";
  406. }
  407. $html .= "<img class='artifact_base' src='" . $background . "'/>\n";
  408. $html .= "<img class='artifact_icon' src='" . $icon . "'/>\n";
  409. $html .= "<span class='artifact_stars'>\n";
  410. $html .= "</span>\n";
  411. $html .= "<span class='artifact_level'>\n";
  412. $html .= $artifact->level . "\n";
  413. $html .= "</span>\n";
  414. $html .= "</div>\n";
  415. if ($unit instanceof Unit){
  416. $html .= "<div class='assigned'>\n";
  417. $html .= "<a target='blank' href='/monsters/" . $unit->id . "'>\n";
  418. $html .= "<img title='" . $unit->title . "' class='monster_image border_" . $unit->unit->element_name . "' src='" . $unit->unit->get_image() . "'/>\n";
  419. $html .= "</a>\n";
  420. $html .= "</div>\n";
  421. }
  422. return $html;
  423. }
  424. /**
  425. * Generates a artifact table.
  426. *
  427. * @param Artifact artifact Entity to get the info from.
  428. * @param Unit unit Optional. The unit the artifact is assigned to.
  429. * @return string HTML content for a artifact table. Empty on error.
  430. */
  431. public static function artifact_table($artifact, $unit = null) {
  432. if (!($artifact instanceof Artifact)){
  433. return "";
  434. }
  435. $html = "";
  436. $html .= "<table class='artifact' id='artifact-" . $artifact->id . "'>\n";
  437. $html .= "<tr>\n";
  438. $html .= "<td class='icon'>\n";
  439. $html .= HTML::artifact_panel($artifact, $unit) . "\n";
  440. $html .= "</td>\n";
  441. $html .= "<td class='effects'>\n";
  442. $html .= "<table>\n";
  443. // Main stat
  444. $html .= "<tr class='effect main_stat'>\n";
  445. $html .= "<td class='effect'>\n";
  446. $stat_name = $artifact->stat->name;
  447. $stat_value = "+" . $artifact->stat->value;
  448. $html .= $stat_name . "\n";
  449. $html .= $stat_value . "\n";
  450. $html .= "</td>\n";
  451. $html .= "</tr>\n";
  452. //$effects = array($artifact->effect_1_description, $artifact->effect_2_description, $artifact->effect_3_description, $artifact->effect_4_description);
  453. for ($i = 0; $i < 4; $i ++){
  454. $html .= "<tr class='effect'>\n";
  455. $html .= "<td class='effect'>\n";
  456. if (count($artifact->effects) <= $i){
  457. $name = "&nbsp;";
  458. }
  459. else{
  460. $name = $artifact->effects[$i]->name;
  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. $name = str_replace("HP condition is bad", "bad HP", $name);
  471. $name = str_replace("HP condition is good", "good HP", $name);
  472. }
  473. $html .= $name;
  474. $html .= "</td>\n";
  475. $html .= "</tr>\n";
  476. }
  477. $html .= "</table>\n";
  478. $html .= "</td>\n";
  479. $html .= "</tr>\n";
  480. $html .= "</table>\n";
  481. return $html;
  482. }
  483. /**
  484. * Generates a grindstone or gem panel.
  485. *
  486. * @param Enchantment Entity to get the info from.
  487. * @return string HTML content for a rune panel. Empty on error.
  488. */
  489. public static function enchantment_panel($enchantment) {
  490. if (!($enchantment instanceof Enchantment)){
  491. return "";
  492. }
  493. $html = "";
  494. if ($enchantment->gem == 1){
  495. if ($enchantment->inmemorial == 1){
  496. $base = URL::IMG["GRIND"] . "gem_inmemorial.png";
  497. }
  498. else{
  499. $base = URL::IMG["GRIND"] . "gem.png";
  500. }
  501. }
  502. else{
  503. if ($enchantment->inmemorial == 1){
  504. $base = URL::IMG["GRIND"] . "grind_inmemorial.png";
  505. }
  506. else{
  507. $base = URL::IMG["GRIND"] . "grind.png";
  508. }
  509. }
  510. if ($enchantment->inmemorial == 0 && isset($enchantment->rune)){
  511. $icon = "<img class='enchantment_icon' src='" . $enchantment->rune->get_image() . "'/>\n";
  512. }
  513. else{
  514. $icon = "";
  515. }
  516. if (in_array($enchantment->stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  517. $stat_name = str_replace("%", "", $enchantment->stat_name);
  518. $stat_value = "+" . $enchantment->min . "~" . $enchantment->max . "%";
  519. }
  520. else{
  521. $stat_name = $enchantment->stat_name;
  522. $stat_value = "+" . $enchantment->min . "~" . $enchantment->max;
  523. }
  524. $html .= "<div class='enchantment_panel enchantment_quality_" . strtolower($enchantment->quality_name) . " enchantment_ancient_" . $enchantment->ancient . "'>\n";
  525. $html .= "<img class='enchantment_base' src='" . $base . "'/>\n";
  526. $html .= $icon;
  527. $html .= "<span class='enchantment_stat'>\n";
  528. $html .= "<span class='enchantment_stat->stat_name'>" . $stat_name . "</span>\n";
  529. $html .= "<span class='enchantment_stat->value'>" . $stat_value . "</span>\n";
  530. $html .= "</span>\n";
  531. if ($enchantment->amount > 0){
  532. $html .= "<span class='enchantment_amount'>\n";
  533. $html .= "x" . $enchantment->amount . "\n";
  534. $html .= "</span>\n";
  535. }
  536. $html .= "</div>\n";
  537. return $html;
  538. }
  539. /**
  540. * Generates a building panel.
  541. *
  542. * @param Building|Decoration|K_Building|K_Decoration $building Entity to get the info from.
  543. * @return string HTML content for a building panel. Empty on error.
  544. */
  545. public static function building_panel($building) {
  546. if ($building instanceof Building){
  547. $level = false;
  548. $title = $building->building->name;
  549. $description = $building->building->description;
  550. $img = $building->building->get_image();
  551. }
  552. elseif ($building instanceof K_Building){
  553. $level = false;
  554. $title = $building->name;
  555. $description = $building->building->description;
  556. $img = $building->get_image();
  557. }
  558. elseif ($building instanceof Decoration){
  559. $level = $building->level;
  560. $title = $building->decoration->name;
  561. $description = $building->decoration->description;
  562. $img = $building->decoration->get_image();
  563. }
  564. elseif ($building instanceof K_Decoration){
  565. $level = false;
  566. $title = $building->name;
  567. $description = $building->building->description;
  568. $img = $building->get_image();
  569. }
  570. else{
  571. return "";
  572. }
  573. if (strlen($description) > 0){
  574. $title .= ": " . $description;
  575. }
  576. $html = "<div class='building_panel'>\n";
  577. $html .= "<img title='" . $title . "' class='building' src='" . $img . "'/>\n";
  578. if ($level){
  579. $html .= "<span class='level'>\n";
  580. $html .= $level . "\n";
  581. $html .= "</span>\n";
  582. }
  583. $html .= "</div>\n";
  584. return $html;
  585. }
  586. /**
  587. * Generates a item panel.
  588. *
  589. * @param Inventory $item Entity to get the info from.
  590. * @return string HTML content for an item panel. Empty on error.
  591. */
  592. public static function item_panel($item) {
  593. if (!($item instanceof Inventory)){
  594. return "";
  595. }
  596. $html = "<div class='item_panel'>\n";
  597. $html .= "<img title='" . $item->name . "' class='item' src='" . $item->get_image() . "'/>\n";
  598. $html .= "<span class='amount'>\n";
  599. $html .= $item->amount . "\n";
  600. $html .= "</span>\n";
  601. $html .= "</div>\n";
  602. return $html;
  603. }
  604. /**
  605. * Generates a source panel.
  606. *
  607. * @param Inventory $source Entity to get the info from.
  608. * @return string HTML content for a source panel. Empty on error.
  609. */
  610. public static function source_panel($source) {
  611. //if (!($item instanceof K_Source)){
  612. // return "";
  613. //}
  614. $html = "<div class='source_panel'>\n";
  615. $html .= "<img title='" . $source->name . "' class='item' src='" . $source->get_image() . "'/>\n";
  616. $html .= "</div>\n";
  617. return $html;
  618. }
  619. /**
  620. * Generates an arena rank icon image.
  621. *
  622. * @param int $d Arena rank id.
  623. * @return string HTML content for the image.
  624. */
  625. public static function arena_rank_icon($id) {
  626. switch ($id){
  627. case ARENA_RANK_ID::BEGINER:
  628. $src = URL::IMG["RANK"] . "0901.png";
  629. $tit = "Beginer";
  630. break;
  631. case ARENA_RANK_ID::CHALLENGER_1:
  632. $src = URL::IMG["RANK"] . "1001.png";
  633. $tit = "Challenger 1";
  634. break;
  635. case ARENA_RANK_ID::CHALLENGER_2:
  636. $src = URL::IMG["RANK"] . "1002.png";
  637. $tit = "Challenger 2";
  638. break;
  639. case ARENA_RANK_ID::CHALLENGER_3:
  640. $src = URL::IMG["RANK"] . "1003.png";
  641. $tit = "Challenger 3";
  642. break;
  643. case ARENA_RANK_ID::FIGHTER_1:
  644. $src = URL::IMG["RANK"] . "2001.png";
  645. $tit = "Fighter 1";
  646. break;
  647. case ARENA_RANK_ID::FIGHTER_2:
  648. $src = URL::IMG["RANK"] . "2002.png";
  649. $tit = "Fighter 2";
  650. break;
  651. case ARENA_RANK_ID::FIGHTER_3:
  652. $src = URL::IMG["RANK"] . "2003.png";
  653. $tit = "Fighter 3";
  654. break;
  655. case ARENA_RANK_ID::CONQUEROR_1:
  656. $src = URL::IMG["RANK"] . "3001.png";
  657. $tit = "Conqueror 1";
  658. break;
  659. case ARENA_RANK_ID::CONQUEROR_2:
  660. $src = URL::IMG["RANK"] . "3002.png";
  661. $tit = "Conqueror 2";
  662. break;
  663. case ARENA_RANK_ID::CONQUEROR_3:
  664. $src = URL::IMG["RANK"] . "3003.png";
  665. $tit = "Conqueror 3";
  666. break;
  667. case ARENA_RANK_ID::GUARDIAN_1:
  668. $src = URL::IMG["RANK"] . "4001.png";
  669. $tit = "Guardian 1";
  670. break;
  671. case ARENA_RANK_ID::GUARDIAN_2:
  672. $src = URL::IMG["RANK"] . "4002.png";
  673. $tit = "Guardian 2";
  674. break;
  675. case ARENA_RANK_ID::GUARDIAN_3:
  676. $src = URL::IMG["RANK"] . "4003.png";
  677. $tit = "Guardian 3";
  678. break;
  679. case ARENA_RANK_ID::LEGEND:
  680. $src = URL::IMG["RANK"] . "5001.png";
  681. $tit = "Legend";
  682. default:
  683. $src = URL::IMG["RANK"] . $id . ".png";
  684. }
  685. $html = "<img alt='$tit' title='$tit' src='$src'/>";
  686. return $html;
  687. }
  688. }
  689. ?>