editor.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. 'use strict';
  2. const { join } = require('path');
  3. module.paths.push(join(Editor.App.path, 'node_modules'));
  4. const eventItem = require('./event-item');
  5. exports.template = `<section v-if="show" id="event-editor" @mousedown.stop>
  6. <header class="flex">
  7. <ui-label class="title" :value="'Current Animation Frame: ' + RealFrame"></ui-label>
  8. <ui-icon value="close" @click="hide" tooltip="Close"></ui-icon>
  9. </header>
  10. <div class="functions">
  11. <div class="tools flex">
  12. <ui-input class="f1" placeholder="i18n:animator.event.func_placeholder"
  13. tooltip="i18n:animator.event.func_placeholder"
  14. :value="newFuncName"
  15. @change.stop="newFuncName = $event.target.value.trim()"
  16. @keydown.enter="addFunc"
  17. ></ui-input>
  18. <ui-icon value="add"
  19. tooltip="i18n:animator.event.add_func"
  20. @mousedown="addFunc"
  21. ></ui-icon>
  22. </div>
  23. <div v-if="value.length">
  24. <event-item class="func"
  25. v-for="(event, index) in value"
  26. :event="event"
  27. :index="index"
  28. :key="index"
  29. @update="updateValue"
  30. @delete="deleteValue"
  31. ></event-item>
  32. </div>
  33. <div v-if="!value.length" class="empty">
  34. <ui-label value="i18n:animator.event.empty"></ui-label>
  35. </div>
  36. </div>
  37. <div class="toast" v-if="toast">
  38. {{toast}}
  39. </div>
  40. </section>
  41. `;
  42. exports.data = function() {
  43. return {
  44. toast: '',
  45. toastTask: [],
  46. newFuncName: '',
  47. value: [],
  48. dirty: false,
  49. debounceSave: null,
  50. // time value
  51. frame: -1,
  52. RealFrame: -1,
  53. show: false,
  54. };
  55. };
  56. exports.components = {
  57. 'event-item': eventItem,
  58. };
  59. exports.methods = {
  60. t(key, type = 'event.') {
  61. return Editor.I18n.t(`animator.${type}${key}`);
  62. },
  63. addFunc() {
  64. const that = this;
  65. if (!that.newFuncName) {
  66. that.showToast(Editor.I18n.t('animator.event.enter_func_name'));
  67. return;
  68. }
  69. that.$emit('addFunc', that.frame, that.newFuncName);
  70. setTimeout(() => {
  71. that.newFuncName = '';
  72. });
  73. },
  74. updateValue(eventInfo, index) {
  75. const that = this;
  76. that.value[index] = eventInfo;
  77. that.dirty = true;
  78. that.debounceSave();
  79. },
  80. deleteValue(index) {
  81. const that = this;
  82. const eventInfo = that.value[index];
  83. if (eventInfo) {
  84. that.$emit('delFunc', eventInfo.frame, eventInfo);
  85. }
  86. },
  87. showToast(msg, time = 800) {
  88. const that = this;
  89. if (that.toast) {
  90. that.toastTask.push(msg);
  91. return;
  92. }
  93. that.toast = msg;
  94. setTimeout(() => {
  95. that.toast = null;
  96. if (that.toastTask.length > 0) {
  97. that.showToast(that.toastTask.shift());
  98. }
  99. }, time);
  100. },
  101. saveData() {
  102. const that = this;
  103. that.$emit('update', that.value);
  104. that.dirty = false;
  105. },
  106. refresh(events) {
  107. const that = this;
  108. const infos = [];
  109. if (Array.isArray(events)) {
  110. if (!events.length) {
  111. this.frame = -1;
  112. }
  113. events.forEach((item) => {
  114. if (item.info.frame === that.frame) {
  115. infos.push(item.info);
  116. }
  117. });
  118. }
  119. that.value = infos;
  120. that.show = !!infos.length;
  121. },
  122. hide() {
  123. this.$emit('hide');
  124. },
  125. unselect() {
  126. this.show = false;
  127. },
  128. };
  129. exports.mounted = function() {
  130. // @ts-ignore
  131. const that = this;
  132. that.debounceSave = require('lodash').debounce(that.saveData, 300);
  133. };