選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

115 行
2.1 KiB

  1. define([
  2. 'js/system/client',
  3. 'js/system/events',
  4. 'html!ui/templates/quests/template',
  5. 'html!ui/templates/quests/templateQuest',
  6. 'css!ui/templates/quests/styles'
  7. ], function(
  8. client,
  9. events,
  10. tpl,
  11. templateQuest,
  12. styles
  13. ) {
  14. return {
  15. tpl: tpl,
  16. quests: [],
  17. container: '.right',
  18. postRender: function() {
  19. this.onEvent('onRezone', this.onRezone.bind(this));
  20. this.onEvent('onObtainQuest', this.onObtainQuest.bind(this));
  21. this.onEvent('onUpdateQuest', this.onUpdateQuest.bind(this));
  22. this.onEvent('onCompleteQuest', this.onCompleteQuest.bind(this));
  23. },
  24. onRezone: function() {
  25. this.quests = [];
  26. this.el.find('.list').empty();
  27. },
  28. onObtainQuest: function(quest) {
  29. var list = this.el.find('.list');
  30. var html = templateQuest
  31. .replace('$NAME$', quest.name)
  32. .replace('$DESCRIPTION$', quest.description);
  33. var el = $(html).appendTo(list);
  34. if (quest.isReady)
  35. el.addClass('ready');
  36. if (quest.active)
  37. el.addClass('active');
  38. else if (!quest.isReady)
  39. el.addClass('disabled');
  40. el.on('click', this.onClick.bind(this, el, quest));
  41. this.quests.push({
  42. id: quest.id,
  43. el: el,
  44. quest: quest
  45. });
  46. var quests = list.find('.quest');
  47. quests
  48. .sort(function(a, b) {
  49. a = $(a).hasClass('active') ? 1 : 0;
  50. b = $(b).hasClass('active') ? 1 : 0;
  51. return b - a;
  52. })
  53. .appendTo(list);
  54. },
  55. onClick: function(el, quest) {
  56. if (!el.hasClass('ready'))
  57. return;
  58. client.request({
  59. cpn: 'player',
  60. method: 'performAction',
  61. data: {
  62. cpn: 'quests',
  63. method: 'complete',
  64. data: quest.id
  65. }
  66. });
  67. },
  68. onUpdateQuest: function(quest) {
  69. var q = this.quests.find(function(q) {
  70. return (q.id == quest.id);
  71. });
  72. q.quest.isReady = quest.isReady;
  73. q.el.find('.description').html(quest.description);
  74. q.el.removeClass('ready');
  75. if (quest.isReady) {
  76. q.el.removeClass('disabled');
  77. q.el.addClass('ready');
  78. }
  79. },
  80. onCompleteQuest: function(id) {
  81. var q = this.quests.find(function(q) {
  82. return (q.id == id);
  83. });
  84. if (!q)
  85. return;
  86. q.el.remove();
  87. this.quests.spliceWhere(function(q) {
  88. return (q.id == id);
  89. });
  90. }
  91. }
  92. });