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.
 
 
 

71 line
1.6 KiB

  1. define([
  2. 'js/system/events',
  3. 'html!ui/templates/middleHud/template',
  4. 'css!ui/templates/middleHud/styles'
  5. ], function (
  6. events,
  7. template,
  8. styles
  9. ) {
  10. return {
  11. tpl: template,
  12. postRender: function () {
  13. this.onEvent('onGetSelfCasting', this.onGetCasting.bind(this));
  14. if (isMobile) {
  15. this.onEvent('onEnterGatherNode', this.toggleGatherButton.bind(this, true));
  16. this.onEvent('onExitGatherNode', this.toggleGatherButton.bind(this, false));
  17. this.onEvent('onRespawn', this.toggleGatherButton.bind(this, false));
  18. this.onEvent('onShowProgress', this.toggleGatherButton.bind(this, false));
  19. this.onEvent('onGetServerActions', this.onGetServerActions.bind(this));
  20. this.find('.btnGather').on('click', this.gather.bind(this));
  21. }
  22. },
  23. onGetCasting: function (casting) {
  24. let el = this.find('.casting');
  25. if ((casting === 0) || (casting === 1))
  26. el.hide();
  27. else {
  28. el
  29. .show()
  30. .find('.bar')
  31. .width((casting * 100) + '%');
  32. }
  33. },
  34. toggleGatherButton: function (show) {
  35. let btn = this.find('.btnGather').hide().html('gather');
  36. if (show)
  37. btn.show();
  38. },
  39. gather: function () {
  40. let btn = this.find('.btnGather');
  41. let action = btn.data('action');
  42. if (action) {
  43. //Server actions use keyUp
  44. events.emit('onKeyUp', action.key);
  45. } else
  46. events.emit('onKeyDown', 'g');
  47. },
  48. onGetServerActions: function (actions) {
  49. let btn = this.find('.btnGather').hide().data('action', null);
  50. let firstAction = actions[0];
  51. if (!firstAction)
  52. return;
  53. btn
  54. .data('action', firstAction)
  55. .html(firstAction.name)
  56. .show();
  57. }
  58. };
  59. });