You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

86 lines
1.7 KiB

  1. define([
  2. 'js/system/events',
  3. 'js/system/client',
  4. 'html!ui/templates/wardrobe/template',
  5. 'css!ui/templates/wardrobe/styles'
  6. ], function (
  7. events,
  8. client,
  9. template,
  10. styles
  11. ) {
  12. return {
  13. tpl: template,
  14. centered: true,
  15. modal: true,
  16. skin: null,
  17. wardrobeId: null,
  18. postRender: function () {
  19. this.onEvent('onGetWardrobeSkins', this.onGetWardrobeSkins.bind(this));
  20. this.onEvent('onCloseWardrobe', this.hide.bind(this));
  21. this.on('.btnCancel', 'click', this.hide.bind(this));
  22. this.on('.btnApply', 'click', this.apply.bind(this));
  23. },
  24. onGetWardrobeSkins: function (msg) {
  25. let list = msg.skins;
  26. this.wardrobeId = msg.id;
  27. let container = this.find('.list').empty();
  28. list.forEach(function (l) {
  29. let html = '<div class="skinName">' + l.name + '</div>';
  30. let el = $(html)
  31. .appendTo(container);
  32. el.on('click', this.setPreview.bind(this, l, el));
  33. if (l.id == window.player.skinId) {
  34. el.addClass('current');
  35. this.setPreview(l, el);
  36. }
  37. }, this);
  38. this.show();
  39. },
  40. setPreview: function (skin, el) {
  41. this.find('.active').removeClass('active');
  42. el.addClass('active');
  43. this.skin = skin;
  44. let costume = skin.sprite.split(',');
  45. let spirteX = -costume[0] * 8;
  46. let spriteY = -costume[1] * 8;
  47. let spritesheet = skin.spritesheet || '../../../images/characters.png';
  48. this.find('.sprite')
  49. .css('background', 'url("' + spritesheet + '") ' + spirteX + 'px ' + spriteY + 'px');
  50. },
  51. apply: function () {
  52. client.request({
  53. cpn: 'player',
  54. method: 'performAction',
  55. data: {
  56. targetId: this.wardrobeId,
  57. cpn: 'wardrobe',
  58. method: 'apply',
  59. data: {
  60. skinId: this.skin.id
  61. }
  62. }
  63. });
  64. }
  65. };
  66. });