HTML_Helper.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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 . "Rune_Craft.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, silver monster.
  73. $star_class ="star_silver";
  74. }
  75. elseif ($k->awakens_from != ""){
  76. // Already awakened
  77. if ($k->base_stars - $k->natural_stars == 1){
  78. // Normal awaken.
  79. $star_class ="star_purple";
  80. }
  81. else{
  82. // Second awaken.
  83. $star_class ="star_red";
  84. }
  85. }
  86. elseif ($k->awakens_to != ""){
  87. // Awakeable.
  88. $star_class ="star_gold";
  89. }
  90. $html .= "<span class='stars'>\n";
  91. for ($i = 0; $i < $stars; $i ++){
  92. $html .= "<img class='star $star_class' src='" . URL::IMG["ICON"] . "star.png'/>\n";
  93. }
  94. $html .= "</span>\n";
  95. $html .= "<img title='" . $unit->title . "' class='monster border_" . $k->element_name . "' src='" . $k->get_image() . "'/>\n";
  96. if ($level){
  97. $html .= "<span class='level'>\n";
  98. $html .= $unit->level . "\n";
  99. $html .= "</span>\n";
  100. }
  101. $html .= "<span class='badges'>\n";
  102. if ($maxed){
  103. $html .= "<img title='Maxed unit' src='" . URL::IMG["ICON"] . "maxed.png'>";
  104. }
  105. if ($teams > 0){
  106. $title = $teams . " teams";
  107. if ($teams == 1){
  108. $title = "1 team: " . $unit->teams[0]->name;
  109. }
  110. $html .= "<img title='$title' src='" . URL::IMG["ICON"] . "team.png'>";
  111. }
  112. if ($lock == 1){
  113. $html .= "<img title='Locked' src='" . URL::IMG["ICON"] . "lock.png'>";
  114. }
  115. if ($storage){
  116. $html .= "<img title='In storage' src='" . URL::IMG["ICON"] . "storage.png'>";
  117. }
  118. $html .= "</span>\n";
  119. return $html;
  120. }
  121. /**
  122. * Generates a transformed monster panel.
  123. *
  124. * @param Unit|K_Unit Entity to get the info from.
  125. * @return string HTML content for a monster panel. Empty on error.
  126. */
  127. public static function unit_transformation_panel($unit) {
  128. $html = "";
  129. if ($unit instanceof Unit){
  130. $k = $unit->unit;
  131. }
  132. elseif ($unit instanceof K_Unit){
  133. $k = $unit;
  134. }
  135. else{
  136. return "";
  137. }
  138. if ($k->transformation == null){
  139. return "";
  140. }
  141. $html .= "<div class='monster_transformation_panel'>\n";
  142. $html .= "<img title='" . $unit->title . " (transformed)' class='monster_transformation border_" . $k->element_name . "' src='" . $k->transformation->get_image() . "'/>\n";
  143. $html .= "</div>\n";
  144. return $html;
  145. }
  146. /**
  147. * Generates a rune panel.
  148. *
  149. * @param Rune rune Entity to get the info from.
  150. * @param Unit unit Optional. The unit the rune is assigned to.
  151. * @return string HTML content for a rune panel. Empty on error.
  152. */
  153. public static function rune_panel($rune, $unit = null) {
  154. if (!($rune instanceof Rune)){
  155. return "";
  156. }
  157. $html = "";
  158. $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";
  159. $html .= "<img class='rune_base' src='" . URL::IMG["RUNE"] . "base.png'/>\n";
  160. $html .= "<img class='rune_icon' src='" . $rune->type->get_image() . "'/>\n";
  161. $html .= "<span class='rune_stars'>\n";
  162. for ($i = 0; $i < $rune->stars; $i ++){
  163. $html .= "<img class='star' src='" . URL::IMG["ICON"] . "star.png'/>\n";
  164. }
  165. $html .= "</span>\n";
  166. $html .= "<span class='rune_level'>\n";
  167. $html .= $rune->level . "\n";
  168. $html .= "</span>\n";
  169. $html .= "</div>\n";
  170. if ($unit instanceof Unit){
  171. $html .= "<div class='assigned'>\n";
  172. $html .= "<a target='blank' href='/monsters/" . $unit->id . "'>\n";
  173. $html .= "<img title='" . $unit->title . "' class='monster_image border_" . $unit->unit->element_name . "' src='" . $unit->unit->get_image() . "'/>\n";
  174. $html .= "</a>\n";
  175. $html .= "</div>\n";
  176. }
  177. return $html;
  178. }
  179. /**
  180. * Generates a rune table.
  181. *
  182. * @param Rune rune Entity to get the info from.
  183. * @param Unit unit Optional. The unit the rune is assigned to.
  184. * @return string HTML content for a rune table. Empty on error.
  185. */
  186. public static function rune_table($rune, $unit = null) {
  187. if (!($rune instanceof Rune)){
  188. return "";
  189. }
  190. $html = "";
  191. $html .= "<table class='rune' id='rune-" . $rune->id . "'>\n";
  192. $html .= "<tr>\n";
  193. $html .= "<td class='icon'>\n";
  194. $html .= HTML::rune_panel($rune, $unit) . "\n";
  195. $html .= "</td>\n";
  196. $html .= "<td class='stats'>\n";
  197. $html .= "<table>\n";
  198. // Main stat
  199. $html .= "<tr class='main_stat'>\n";
  200. $html .= "<td class='stat'>\n";
  201. if (in_array($rune->main_stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  202. $stat_name = str_replace("%", "", $rune->main_stat_name);
  203. $stat_value = "+ " . $rune->main_stat_value . "%";
  204. }
  205. else{
  206. $stat_name = $rune->main_stat_name;
  207. $stat_value = "+ " . $rune->main_stat_value;
  208. }
  209. $html .= $stat_name . "\n";
  210. $html .= "</td>\n";
  211. $html .= "<td class='value'>\n";
  212. $html .= $stat_value . "\n";
  213. $html .= "<td>\n";
  214. $html .= "</tr>\n";
  215. // Innate stat
  216. $html .= "<tr class='innate_stat'>\n";
  217. $html .= "<td class='stat'>\n";
  218. if (strlen($rune->innate_stat) == 0){
  219. $stat_name = "&nbsp;";
  220. $stat_value = "";
  221. }
  222. elseif (in_array($rune->innate_stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  223. $stat_name = str_replace("%", "", $rune->innate_stat_name);
  224. $stat_value = "+ " . $rune->innate_stat_value . "%";
  225. }
  226. else{
  227. $stat_name = $rune->innate_stat_name;
  228. $stat_value = "+ " . $rune->innate_stat_value;
  229. }
  230. $html .= $stat_name . "\n";
  231. $html .= "</td>\n";
  232. $html .= "<td class='value'>\n";
  233. $html .= $stat_value . "\n";
  234. $html .= "<td>\n";
  235. $html .= "</tr>\n";
  236. $substats = array($rune->substat_1, $rune->substat_2, $rune->substat_3, $rune->substat_4);
  237. $substats_name = array($rune->substat_1_name, $rune->substat_2_name, $rune->substat_3_name, $rune->substat_4_name);
  238. $substats_value = array($rune->substat_1_value, $rune->substat_2_value, $rune->substat_3_value, $rune->substat_4_value);
  239. $substats_grind = array($rune->substat_1_grind, $rune->substat_2_grind, $rune->substat_3_grind, $rune->substat_4_grind);
  240. $substats_enchant = array($rune->substat_1_enchant, $rune->substat_2_enchant, $rune->substat_3_enchant, $rune->substat_4_enchant);
  241. for ($i = 0; $i < 4; $i ++){
  242. if (strlen($substats_name[$i]) == 0){
  243. $stat_name = "&nbsp;";
  244. $stat_value = "";
  245. }
  246. elseif (in_array($substats_name[$i], array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  247. $stat_name = str_replace("%", "", $substats_name[$i]);
  248. $stat_value = "+ " . $substats_value[$i] . "%";
  249. }
  250. else{
  251. $stat_name = $substats_name[$i];
  252. $stat_value = "+ " . $substats_value[$i];
  253. }
  254. $grind = "";
  255. if ($substats_grind[$i] > 0){
  256. $grind = "+" . $substats_grind[$i];
  257. if (in_array($substats_name[$i], array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  258. $grind = $grind . "%";
  259. }
  260. }
  261. $html .= "<tr class=substat>\n";
  262. $html .= "<td class='stat'>\n";
  263. $html .= $stat_name . "\n";
  264. $html .= "</td>\n";
  265. $html .= "<td class='value'>\n";
  266. $html .= $stat_value . "\n";
  267. $html .= "<span class='grind grind_$grind'>\n";
  268. $html .= $grind . "\n";
  269. $html .= "</span>\n";
  270. if ($substats_enchant[$i] == 1){
  271. $html .= "<img title='Enchanted' src='" . URL::IMG["RUNE"] . "enchanted.png'/>\n";
  272. }
  273. $html .= "</td>\n";
  274. $html .= "</tr>\n";
  275. }
  276. $html .= "</table>\n";
  277. $html .= "</td>\n";
  278. // Details
  279. $html .= "<td class='details'>\n";
  280. $html .= "<table class='table_details'>\n";
  281. $html .= "<tr>\n";
  282. $html .= "<td class='title'>\n";
  283. $html .= "Quality:\n";
  284. $html .= "</td>\n";
  285. $html .= "<td class='value'>\n";
  286. $html .= "<span class='quality quality_" . strtolower($rune->quality_name) . "'>\n";
  287. $html .= $rune->quality_name . "\n";
  288. $html .= "</span>\n";
  289. $html .= "</td>\n";
  290. $html .= "</tr>\n";
  291. $html .= "<tr>\n";
  292. $html .= "<td class='title'>\n";
  293. $html .= "Original q.:\n";
  294. $html .= "</td>\n";
  295. $html .= "<td class='value'>\n";
  296. $html .= "<span class='quality quality_" . strtolower($rune->original_quality_name) . "'>\n";
  297. $html .= $rune->original_quality_name . "\n";
  298. $html .= "</span>\n";
  299. $html .= "</td>\n";
  300. $html .= "</tr>\n";
  301. $html .= "<tr>\n";
  302. $html .= "<td class='title'>\n";
  303. $html .= "Value:\n";
  304. $html .= "</td>\n";
  305. $html .= "<td class='value'>\n";
  306. $html .= number_format($rune->value, 0, ".", ",") . "\n";
  307. $html .= "</td>\n";
  308. $html .= "</tr>\n";
  309. $html .= "<tr>\n";
  310. $html .= "<td class='title'>\n";
  311. $html .= "Efficiency:\n";
  312. $html .= "</td>\n";
  313. $html .= "<td class='value'>\n";
  314. $html .= number_format($rune->efficiency, 2, ".", ",") . "%\n";
  315. $html .= "</td>\n";
  316. $html .= "</tr>\n";
  317. $html .= "<tr>\n";
  318. $html .= "<td class='title'>\n";
  319. $html .= "Max. eff.:\n";
  320. $html .= "</td>\n";
  321. $html .= "<td class='value'>\n";
  322. $html .= number_format($rune->max_efficiency, 2, ".", ",") . "%\n";
  323. $html .= "</td>\n";
  324. $html .= "</tr>\n";
  325. $html .= "<tr>\n";
  326. $html .= "<td class='title'>\n";
  327. $html .= "Reached. eff.:\n";
  328. $html .= "</td>\n";
  329. $html .= "<td class='value'>\n";
  330. $html .= number_format($rune->efficiency * 100 / $rune->max_efficiency, 2, ".", ",") . "%\n";
  331. $html .= "</td>\n";
  332. $html .= "</tr>\n";
  333. $html .= "</table>\n";
  334. $html .= "</td>\n";
  335. $html .= "</tr>\n";
  336. $html .= "</table>\n";
  337. return $html;
  338. }
  339. // TODO: Icon and background selection must go in the entity code.
  340. /**
  341. * Generates an artifact panel.
  342. *
  343. * @param Artifact artifact Entity to get the info from.
  344. * @param Unit unit Optional. The unit the artifact is assigned to.
  345. * @return string HTML content for an artifact panel. Empty on error.
  346. */
  347. public static function artifact_panel($artifact, $unit = null) {
  348. if (!($artifact instanceof Artifact)){
  349. return "";
  350. }
  351. $html = "";
  352. $html .= "<div class='artifact_panel artifact_level_" . $artifact->level . " artifact_quality_" . strtolower($artifact->quality_name) . " artifact_original_quality_" . strtolower($artifact->original_quality_name) . " '>\n";
  353. $background = "";
  354. $icon = "";
  355. if ($artifact->type == ARTIFACT_TYPE::ARCHETYPE){
  356. $background = URL::IMG["ARTIFACT"] . "type_" . strtolower($artifact->quality_name) . ".png";
  357. $icon = URL::IMG["ARTIFACT"] . "type_";
  358. switch ($artifact->type){
  359. case ARCHETYPE_ID::ATTACK:
  360. $icon .= "attack";
  361. break;
  362. case ARCHETYPE_ID::DEFENSE:
  363. $icon .= "defense";
  364. break;
  365. case ARCHETYPE_ID::HP:
  366. $icon .= "hp";
  367. break;
  368. case ARCHETYPE_ID::SUPPORT:
  369. $icon .= "support";
  370. break;
  371. }
  372. $icon .= ".png";
  373. }
  374. else{
  375. $background = URL::IMG["ARTIFACT"] . "element_" . strtolower($artifact->quality_name) . ".png";
  376. $icon = URL::IMG["ARTIFACT"] . "element_";
  377. switch ($artifact->element){
  378. case ELEMENT_ID::WATER:
  379. $icon .= "water";
  380. break;
  381. case ELEMENT_ID::WIND:
  382. $icon .= "wind";
  383. break;
  384. case ELEMENT_ID::FIRE:
  385. $icon .= "fire";
  386. break;
  387. case ELEMENT_ID::LIGHT:
  388. $icon .= "light";
  389. break;
  390. case ELEMENT_ID::DARK:
  391. $icon .= "dark";
  392. break;
  393. }
  394. $icon .= ".png";
  395. }
  396. $html .= "<img class='artifact_base' src='" . $background . "'/>\n";
  397. $html .= "<img class='artifact_icon' src='" . $icon . "'/>\n";
  398. $html .= "<span class='artifact_stars'>\n";
  399. $html .= "</span>\n";
  400. $html .= "<span class='artifact_level'>\n";
  401. $html .= $artifact->level . "\n";
  402. $html .= "</span>\n";
  403. $html .= "</div>\n";
  404. if ($unit instanceof Unit){
  405. $html .= "<div class='assigned'>\n";
  406. $html .= "<a target='blank' href='/monsters/" . $unit->id . "'>\n";
  407. $html .= "<img title='" . $unit->title . "' class='monster_image border_" . $unit->unit->element_name . "' src='" . $unit->unit->get_image() . "'/>\n";
  408. $html .= "</a>\n";
  409. $html .= "</div>\n";
  410. }
  411. return $html;
  412. }
  413. /**
  414. * Generates a artifact table.
  415. *
  416. * @param Artifact artifact Entity to get the info from.
  417. * @param Unit unit Optional. The unit the artifact is assigned to.
  418. * @return string HTML content for a artifact table. Empty on error.
  419. */
  420. public static function artifact_table($artifact, $unit = null) {
  421. if (!($artifact instanceof Artifact)){
  422. return "";
  423. }
  424. $html = "";
  425. $html .= "<table class='artifact' id='artifact-" . $artifact->id . "'>\n";
  426. $html .= "<tr>\n";
  427. $html .= "<td class='icon'>\n";
  428. $html .= HTML::artifact_panel($artifact, $unit) . "\n";
  429. $html .= "</td>\n";
  430. $html .= "<td class='effects'>\n";
  431. $html .= "<table>\n";
  432. // Main stat
  433. $html .= "<tr class='effect main_stat'>\n";
  434. $html .= "<td class='effect'>\n";
  435. $stat_name = $artifact->main_stat_name;
  436. $stat_value = "+ " . $artifact->main_stat_value;
  437. $html .= $stat_name . "\n";
  438. $html .= $stat_value . "\n";
  439. $html .= "</td>\n";
  440. $html .= "</tr>\n";
  441. $effects = array($artifact->effect_1_description, $artifact->effect_2_description, $artifact->effect_3_description, $artifact->effect_4_description);
  442. for ($i = 0; $i < 4; $i ++){
  443. $html .= "<tr class='effect'>\n";
  444. $html .= "<td class='effect'>\n";
  445. $html .= $effects[$i];
  446. $html .= "</td>\n";
  447. $html .= "</tr>\n";
  448. }
  449. $html .= "</table>\n";
  450. $html .= "</td>\n";
  451. // Details
  452. /* TODO: Only quaity data, and for that the icon is enough
  453. $html .= "<td class='details'>\n";
  454. $html .= "<table class='table_details'>\n";
  455. $html .= "<tr>\n";
  456. $html .= "<td class='title'>\n";
  457. $html .= "Quality:\n";
  458. $html .= "</td>\n";
  459. $html .= "<td class='value'>\n";
  460. $html .= "<span class='quality quality_" . strtolower($artifact->quality_name) . "'>\n";
  461. $html .= $artifact->quality_name . "\n";
  462. $html .= "</span>\n";
  463. $html .= "</td>\n";
  464. $html .= "</tr>\n";
  465. $html .= "<tr>\n";
  466. $html .= "<td class='title'>\n";
  467. $html .= "Original q.:\n";
  468. $html .= "</td>\n";
  469. $html .= "<td class='value'>\n";
  470. $html .= "<span class='quality quality_" . strtolower($artifact->original_quality_name) . "'>\n";
  471. $html .= $artifact->original_quality_name . "\n";
  472. $html .= "</span>\n";
  473. $html .= "</td>\n";
  474. $html .= "</tr>\n";
  475. $html .= "<tr>\n";
  476. $html .= "<td class='title'>\n";
  477. // TODO: No data on value yet
  478. $html .= ""; //"Value:\n";
  479. $html .= "</td>\n";
  480. $html .= "<td class='value'>\n";
  481. // TODO: No data on value yet
  482. $html .= ""; //number_format($artifact->value, 0, ".", ",") . "\n";
  483. $html .= "</td>\n";
  484. $html .= "</tr>\n";
  485. $html .= "<tr>\n";
  486. $html .= "<td class='title'>\n";
  487. // TODO: No data on efficiencies yet
  488. $html .= ""; //"Efficiency:\n";
  489. $html .= "</td>\n";
  490. $html .= "<td class='value'>\n";
  491. // TODO: No data on efficiencies yet
  492. $html .= ""; //number_format($artifact->efficiency, 2, ".", ",") . "%\n";
  493. $html .= "</td>\n";
  494. $html .= "</tr>\n";
  495. $html .= "<tr>\n";
  496. $html .= "<td class='title'>\n";
  497. // TODO: No data on efficiencies yet
  498. $html .= ""; //"Max. eff.:\n";
  499. $html .= "</td>\n";
  500. $html .= "<td class='value'>\n";
  501. // TODO: No data on efficiencies yet
  502. $html .= ""; //number_format($artifact->max_efficiency, 2, ".", ",") . "%\n";
  503. $html .= "</td>\n";
  504. $html .= "</tr>\n";
  505. $html .= "<tr>\n";
  506. $html .= "<td class='title'>\n";
  507. // TODO: No data on efficiencies yet
  508. $html .= ""; //"Reached. eff.:\n";
  509. $html .= "</td>\n";
  510. $html .= "<td class='value'>\n";
  511. // TODO: No data on efficiencies yet
  512. $html .= ""; //number_format($artifact->efficiency * 100 / $artifact->max_efficiency, 2, ".", ",") . "%\n";
  513. $html .= "</td>\n";
  514. $html .= "</tr>\n";
  515. $html .= "</table>\n";
  516. */
  517. $html .= "</td>\n";
  518. $html .= "</tr>\n";
  519. $html .= "</table>\n";
  520. return $html;
  521. }
  522. /**
  523. * Generates a grindstone or gem panel.
  524. *
  525. * @param Rune_Craft craft Entity to get the info from.
  526. * @return string HTML content for a rune panel. Empty on error.
  527. */
  528. public static function craft_panel($craft) {
  529. if (!($craft instanceof Rune_Craft)){
  530. return "";
  531. }
  532. $html = "";
  533. if ($craft->gem == 1){
  534. if ($craft->inmemorial == 1){
  535. $base = URL::IMG["GRIND"] . "gem_inmemorial.png";
  536. }
  537. else{
  538. $base = URL::IMG["GRIND"] . "gem.png";
  539. }
  540. }
  541. else{
  542. if ($craft->inmemorial == 1){
  543. $base = URL::IMG["GRIND"] . "grind_inmemorial.png";
  544. }
  545. else{
  546. $base = URL::IMG["GRIND"] . "grind.png";
  547. }
  548. }
  549. if ($craft->inmemorial == 0 && isset($craft->rune)){
  550. $icon = "<img class='craft_icon' src='" . $craft->rune->get_image() . "'/>\n";
  551. }
  552. else{
  553. $icon = "";
  554. }
  555. if (in_array($craft->stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  556. $stat_name = str_replace("%", "", $craft->stat_name);
  557. $stat_value = "+ " . $craft->min . "~" . $craft->max . "%";
  558. }
  559. else{
  560. $stat_name = $craft->stat_name;
  561. $stat_value = "+ " . $craft->min . "~" . $craft->max;
  562. }
  563. $html .= "<div class='craft_panel craft_quality_" . strtolower($craft->quality_name) . " rune_ancient_" . $craft->ancient . "'>\n";
  564. $html .= "<img class='craft_base' src='" . $base . "'/>\n";
  565. $html .= $icon;
  566. $html .= "<span class='craft_stat'>\n";
  567. $html .= "<span class='craft_stat_name'>" . $stat_name . "</span>\n";
  568. $html .= "<span class='craft_stat_value'>" . $stat_value . "</span>\n";
  569. $html .= "</span>\n";
  570. $html .= "<span class='craft_amount'>\n";
  571. $html .= "x" . $craft->amount . "\n";
  572. $html .= "</span>\n";
  573. $html .= "</div>\n";
  574. return $html;
  575. }
  576. /**
  577. * Generates a building panel.
  578. *
  579. * @param Building|Decoration|K_Building|K_Decoration $building Entity to get the info from.
  580. * @return string HTML content for a building panel. Empty on error.
  581. */
  582. public static function building_panel($building) {
  583. if ($building instanceof Building){
  584. $level = false;
  585. $title = $building->building->name;
  586. $description = $building->building->description;
  587. $img = $building->building->get_image();
  588. }
  589. elseif ($building instanceof K_Building){
  590. $level = false;
  591. $title = $building->name;
  592. $description = $building->building->description;
  593. $img = $building->get_image();
  594. }
  595. elseif ($building instanceof Decoration){
  596. $level = $building->level;
  597. $title = $building->decoration->name;
  598. $description = $building->decoration->description;
  599. $img = $building->decoration->get_image();
  600. }
  601. elseif ($building instanceof K_Decoration){
  602. $level = false;
  603. $title = $building->name;
  604. $description = $building->building->description;
  605. $img = $building->get_image();
  606. }
  607. else{
  608. return "";
  609. }
  610. if (strlen($description) > 0){
  611. $title .= ": " . $description;
  612. }
  613. $html = "";
  614. $html = "<div class='building_panel'>\n";
  615. $html .= "<img title='" . $title . "' class='building' src='" . $img . "'/>\n";
  616. if ($level){
  617. $html .= "<span class='level'>\n";
  618. $html .= $level . "\n";
  619. $html .= "</span>\n";
  620. }
  621. $html .= "</div>\n";
  622. return $html;
  623. }
  624. /**
  625. * Generates a item panel.
  626. *
  627. * @param Inventory $item Entity to get the info from.
  628. * @return string HTML content for a building panel. Empty on error.
  629. */
  630. public static function item_panel($item) {
  631. if (!($item instanceof Inventory)){
  632. return "";
  633. }
  634. $html = "";
  635. $html = "<div class='item_panel'>\n";
  636. $html .= "<img title='" . $item->name . "' class='item' src='" . $item->get_image() . "'/>\n";
  637. $html .= "<span class='amount'>\n";
  638. $html .= $item->amount . "\n";
  639. $html .= "</span>\n";
  640. $html .= "</div>\n";
  641. return $html;
  642. }
  643. }
  644. ?>