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.
 
 
 

70 lines
1.2 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('onRezone', this.onRezone.bind(this));
  20. },
  21. onRezone: function () {
  22. this.hide();
  23. },
  24. onGetTalk: function (dialogue) {
  25. this.state = dialogue;
  26. if (!dialogue) {
  27. this.hide();
  28. return;
  29. }
  30. this.show();
  31. this.find('.name').html(dialogue.from);
  32. this.find('.msg').html('"' + dialogue.msg + '"');
  33. let options = this.find('.options').empty();
  34. dialogue.options.forEach(function (o) {
  35. let html = tplOption;
  36. $(html)
  37. .appendTo(options)
  38. .html('- ' + o.msg)
  39. .on('click', this.onReply.bind(this, o));
  40. }, this);
  41. this.center(true, false);
  42. },
  43. onReply: function (option) {
  44. client.request({
  45. cpn: 'player',
  46. method: 'performAction',
  47. data: {
  48. cpn: 'dialogue',
  49. method: 'talk',
  50. data: {
  51. target: this.state.id,
  52. state: option.id
  53. }
  54. }
  55. });
  56. }
  57. };
  58. });