Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

225 linhas
4.9 KiB

  1. define([
  2. 'js/system/events',
  3. 'js/system/client',
  4. 'html!ui/templates/createCharacter/template',
  5. 'css!ui/templates/createCharacter/styles',
  6. 'ui/factory',
  7. 'js/system/globals'
  8. ], function (
  9. events,
  10. client,
  11. template,
  12. styles,
  13. uiFactory,
  14. globals
  15. ) {
  16. return {
  17. tpl: template,
  18. centered: true,
  19. classSprites: null,
  20. class: null,
  21. costume: 0,
  22. skinId: null,
  23. prophecies: [],
  24. beforeRender: function () {
  25. const { clientConfig: { logoPath } } = globals;
  26. if (!logoPath)
  27. return;
  28. const tempEl = $(this.tpl);
  29. tempEl.find('.logo').attr('src', logoPath);
  30. this.tpl = tempEl.prop('outerHTML');
  31. },
  32. postRender: function () {
  33. this.getSkins();
  34. uiFactory.build('tooltips');
  35. this.find('.txtClass')
  36. .on('click', this.changeClass.bind(this))
  37. .on('mousemove', this.onClassHover.bind(this))
  38. .on('mouseleave', this.onClassUnhover.bind(this));
  39. this.find('.skinBox .btn').on('click', this.changeCostume.bind(this));
  40. this.find('.btnBack').on('click', this.back.bind(this));
  41. this.find('.btnCreate').on('click', this.create.bind(this));
  42. this.find('.prophecy')
  43. .on('click', this.onProphecyClick.bind(this))
  44. .on('mousemove', this.onProphecyHover.bind(this))
  45. .on('mouseleave', this.onProphecyUnhover.bind(this));
  46. },
  47. getSkins: function () {
  48. this.el.addClass('disabled');
  49. client.request({
  50. cpn: 'auth',
  51. method: 'getSkinList',
  52. data: {
  53. },
  54. callback: this.onGetSkins.bind(this)
  55. });
  56. },
  57. onGetSkins: function (result) {
  58. this.el.removeClass('disabled');
  59. this.classSprites = result;
  60. this.costume = 0;
  61. this.class = 'owl';
  62. this.find('.txtClass').html('Owl');
  63. this.changeCostume();
  64. },
  65. onProphecyHover: function (e) {
  66. let el = $(e.target);
  67. let pos = {
  68. x: e.clientX + 25,
  69. y: e.clientY
  70. };
  71. let text = el.attr('tooltip');
  72. events.emit('onShowTooltip', text, el[0], pos);
  73. $('.uiTooltips .tooltip').addClass('bright');
  74. },
  75. onProphecyUnhover: function (e) {
  76. let el = $(e.target);
  77. events.emit('onHideTooltip', el[0]);
  78. },
  79. onProphecyClick: function (e) {
  80. let el = $(e.target);
  81. let pName = el.attr('prophecy');
  82. if (el.hasClass('active')) {
  83. this.prophecies.spliceWhere(function (p) {
  84. return (p === pName);
  85. });
  86. el.removeClass('active');
  87. } else {
  88. this.prophecies.push(pName);
  89. el.addClass('active');
  90. }
  91. },
  92. clear: function () {
  93. this.prophecies = [];
  94. this.find('.prophecy').removeClass('active');
  95. },
  96. back: function () {
  97. this.clear();
  98. this.destroy();
  99. uiFactory.build('characters', {});
  100. },
  101. create: function () {
  102. this.el.addClass('disabled');
  103. client.request({
  104. cpn: 'auth',
  105. method: 'createCharacter',
  106. data: {
  107. name: this.find('.txtName').val(),
  108. class: this.class,
  109. skinId: this.skinId,
  110. prophecies: this.prophecies
  111. },
  112. callback: this.onCreate.bind(this)
  113. });
  114. },
  115. onCreate: function (result) {
  116. this.el.removeClass('disabled');
  117. if (!result) {
  118. this.clear();
  119. this.destroy();
  120. } else
  121. this.el.find('.message').html(result);
  122. },
  123. onClassHover: function (e) {
  124. let el = $(e.target);
  125. let pos = {
  126. x: e.clientX + 25,
  127. y: e.clientY
  128. };
  129. let text = ({
  130. owl: 'The wise Owl guides you; granting you the focus needed to cast spells. <br /><br />Upon level up, you gain 1 Intellect.',
  131. bear: 'The towering Bear strenghtens you; lending force to your blows. <br /><br />Upon level up, you gain 1 Strength.',
  132. lynx: 'The nimble Lynx hastens you; allowing your strikes to land true. <br /><br />Upon level up, you gain 1 Dexterity.'
  133. })[this.class];
  134. events.emit('onShowTooltip', text, el[0], pos, 200);
  135. $('.uiTooltips .tooltip').addClass('bright');
  136. },
  137. onClassUnhover: function (e) {
  138. let el = $(e.target);
  139. events.emit('onHideTooltip', el[0]);
  140. },
  141. changeClass: function (e) {
  142. let el = $(e.target);
  143. let classes = ['owl', 'bear', 'lynx'];
  144. let nextIndex = (classes.indexOf(this.class) + 1) % classes.length;
  145. let newClass = classes[nextIndex];
  146. el.html(newClass[0].toUpperCase() + newClass.substr(1));
  147. this.class = newClass;
  148. this.onClassHover(e);
  149. },
  150. changeCostume: function (e) {
  151. let delta = e ? ~~$(e.target).attr('delta') : 0;
  152. let spriteList = this.classSprites;
  153. if (!spriteList)
  154. return;
  155. this.costume = (this.costume + delta) % spriteList.length;
  156. if (this.costume < 0)
  157. this.costume = spriteList.length - 1;
  158. this.skinId = spriteList[this.costume].id;
  159. $('.txtCostume').html(spriteList[this.costume].name);
  160. this.setSprite();
  161. },
  162. setSprite: function () {
  163. let classSprite = this.classSprites[this.costume];
  164. let costume = classSprite.sprite.split(',');
  165. let spirteX = -costume[0] * 8;
  166. let spriteY = -costume[1] * 8;
  167. let spritesheet = classSprite.spritesheet || '../../../images/characters.png';
  168. this.find('.sprite')
  169. .css('background', 'url("' + spritesheet + '") ' + spirteX + 'px ' + spriteY + 'px');
  170. }
  171. };
  172. });