HTML.php 28 KB

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