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.

66 lines
1.1 KiB

  1. define([
  2. 'js/system/events',
  3. 'js/system/client',
  4. 'html!ui/templates/talk/template',
  5. 'css!ui/templates/talk/styles',
  6. 'html!ui/templates/talk/tplOption'
  7. ], function (
  8. events,
  9. client,
  10. template,
  11. styles,
  12. tplOption
  13. ) {
  14. return {
  15. tpl: template,
  16. modal: true,
  17. postRender: function () {
  18. this.onEvent('onGetTalk', this.onGetTalk.bind(this));
  19. this.onEvent('clearUis', this.hide.bind(this));
  20. },
  21. onGetTalk: function (dialogue) {
  22. this.state = dialogue;
  23. if (!dialogue) {
  24. this.hide();
  25. return;
  26. }
  27. this.show();
  28. this.find('.name').html(dialogue.from);
  29. this.find('.msg').html('"' + dialogue.msg + '"');
  30. let options = this.find('.options').empty();
  31. dialogue.options.forEach(function (o) {
  32. let html = tplOption;
  33. $(html)
  34. .appendTo(options)
  35. .html('- ' + o.msg)
  36. .on('click', this.onReply.bind(this, o));
  37. }, this);
  38. this.center(true, false);
  39. },
  40. onReply: function (option) {
  41. client.request({
  42. cpn: 'player',
  43. method: 'performAction',
  44. data: {
  45. cpn: 'dialogue',
  46. method: 'talk',
  47. data: {
  48. target: this.state.id,
  49. state: option.id
  50. }
  51. }
  52. });
  53. }
  54. };
  55. });