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.
 
 
 

60 lines
1.0 KiB

  1. define([
  2. 'js/system/events',
  3. 'js/system/client',
  4. 'html!ui/templates/dialogue/template',
  5. 'css!ui/templates/dialogue/styles'
  6. ], function (
  7. events,
  8. client,
  9. template,
  10. styles
  11. ) {
  12. return {
  13. tpl: template,
  14. text: [],
  15. centeredX: true,
  16. postRender: function () {
  17. this.onEvent('onGetDialogue', this.onGetDialogue.bind(this));
  18. this.onEvent('onRemoveDialogue', this.onRemoveDialogue.bind(this));
  19. },
  20. onGetDialogue: function (msg) {
  21. this.text.spliceWhere(function (t) {
  22. return (t.src == msg.src);
  23. });
  24. this.text.push(msg);
  25. this.setText();
  26. },
  27. onRemoveDialogue: function (msg) {
  28. this.text.spliceWhere(function (t) {
  29. return (t.src == msg.src);
  30. });
  31. this.setText();
  32. },
  33. setText: function () {
  34. let text = '';
  35. for (let i = 0; i < this.text.length; i++) {
  36. let t = this.text[i];
  37. text += t.msg;
  38. if (i < this.text.length - 1)
  39. text += '<br /><hr>';
  40. }
  41. this.find('.textBox').html(text);
  42. if (text != '')
  43. this.show();
  44. else
  45. this.hide();
  46. }
  47. };
  48. });