HTML_Helper.php 28 KB

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