fb1edb424bf8362496b54be34aa20a86b867ca79.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Button, CCInteger, Enum, Node, Sprite, UIOpacity, UIRenderer, _decorator, color, VMBase, VM, _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _descriptor12, _descriptor13, _descriptor14, _crd, ccclass, property, menu, help, CONDITION, ACTION, CHILD_MODE_TYPE, VMState;
  4. function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
  5. function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
  6. function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
  7. function _reportPossibleCrUseOfVMBase(extras) {
  8. _reporterNs.report("VMBase", "./VMBase", _context.meta, extras);
  9. }
  10. function _reportPossibleCrUseOfVM(extras) {
  11. _reporterNs.report("VM", "./ViewModel", _context.meta, extras);
  12. }
  13. return {
  14. setters: [function (_unresolved_) {
  15. _reporterNs = _unresolved_;
  16. }, function (_cc) {
  17. _cclegacy = _cc.cclegacy;
  18. __checkObsolete__ = _cc.__checkObsolete__;
  19. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  20. Button = _cc.Button;
  21. CCInteger = _cc.CCInteger;
  22. Enum = _cc.Enum;
  23. Node = _cc.Node;
  24. Sprite = _cc.Sprite;
  25. UIOpacity = _cc.UIOpacity;
  26. UIRenderer = _cc.UIRenderer;
  27. _decorator = _cc._decorator;
  28. color = _cc.color;
  29. }, function (_unresolved_2) {
  30. VMBase = _unresolved_2.VMBase;
  31. }, function (_unresolved_3) {
  32. VM = _unresolved_3.VM;
  33. }],
  34. execute: function () {
  35. _crd = true;
  36. _cclegacy._RF.push({}, "47052uw/Y5O1LXaLObj4ARx", "VMState", undefined);
  37. __checkObsolete__(['Button', 'CCInteger', 'Color', 'Enum', 'Node', 'Sprite', 'UIOpacity', 'UIRenderer', '_decorator', 'color']);
  38. ({
  39. ccclass,
  40. property,
  41. menu,
  42. help
  43. } = _decorator);
  44. /** 比较条件 */
  45. CONDITION = /*#__PURE__*/function (CONDITION) {
  46. CONDITION[CONDITION["=="] = 0] = "==";
  47. CONDITION[CONDITION["!="] = 1] = "!=";
  48. CONDITION[CONDITION[">"] = 2] = ">";
  49. CONDITION[CONDITION[">="] = 3] = ">=";
  50. CONDITION[CONDITION["<"] = 4] = "<";
  51. CONDITION[CONDITION["<="] = 5] = "<=";
  52. CONDITION[CONDITION["range"] = 6] = "range";
  53. return CONDITION;
  54. }(CONDITION || {});
  55. ACTION = /*#__PURE__*/function (ACTION) {
  56. ACTION[ACTION["NODE_ACTIVE"] = 0] = "NODE_ACTIVE";
  57. ACTION[ACTION["NODE_VISIBLE"] = 1] = "NODE_VISIBLE";
  58. ACTION[ACTION["NODE_OPACITY"] = 2] = "NODE_OPACITY";
  59. ACTION[ACTION["NODE_COLOR"] = 3] = "NODE_COLOR";
  60. ACTION[ACTION["COMPONENT_CUSTOM"] = 4] = "COMPONENT_CUSTOM";
  61. ACTION[ACTION["SPRITE_GRAYSCALE"] = 5] = "SPRITE_GRAYSCALE";
  62. ACTION[ACTION["BUTTON_INTERACTABLE"] = 6] = "BUTTON_INTERACTABLE";
  63. return ACTION;
  64. }(ACTION || {});
  65. CHILD_MODE_TYPE = /*#__PURE__*/function (CHILD_MODE_TYPE) {
  66. CHILD_MODE_TYPE[CHILD_MODE_TYPE["NODE_INDEX"] = 0] = "NODE_INDEX";
  67. CHILD_MODE_TYPE[CHILD_MODE_TYPE["NODE_NAME"] = 1] = "NODE_NAME";
  68. return CHILD_MODE_TYPE;
  69. }(CHILD_MODE_TYPE || {});
  70. /**
  71. * [VM-State]
  72. * 监听数值状态,根据数值条件设置节点是否激活
  73. */
  74. _export("default", VMState = (_dec = menu('OopsFramework/Mvvm/VM-State (状态控制)'), _dec2 = help('https://gitee.com/dgflash/oops-framework/wikis/pages?sort_id=12037846&doc_id=2873565'), _dec3 = property({
  75. tooltip: '遍历子节点,根据子节点的名字或名字转换为值,判断值满足条件 来激活'
  76. }), _dec4 = property({
  77. type: Enum(CONDITION)
  78. }), _dec5 = property({
  79. type: Enum(CHILD_MODE_TYPE),
  80. tooltip: '遍历子节点,根据子节点的名字转换为值,判断值满足条件 来激活',
  81. visible: function () {
  82. // @ts-ignore
  83. return this.foreachChildMode === true;
  84. }
  85. }), _dec6 = property({
  86. displayName: 'Value: a',
  87. visible: function () {
  88. // @ts-ignore
  89. return this.foreachChildMode === false;
  90. }
  91. }), _dec7 = property({
  92. displayName: 'Value: b',
  93. visible: function () {
  94. // @ts-ignore
  95. return this.foreachChildMode === false && this.condition === CONDITION.range;
  96. }
  97. }), _dec8 = property({
  98. type: Enum(ACTION),
  99. tooltip: '一旦满足条件就对节点执行操作'
  100. }), _dec9 = property({
  101. visible: function () {
  102. // @ts-ignore
  103. return this.valueAction === ACTION.NODE_OPACITY;
  104. },
  105. range: [0, 255],
  106. type: CCInteger,
  107. displayName: 'Action Opacity'
  108. }), _dec10 = property({
  109. visible: function () {
  110. // @ts-ignore
  111. return this.valueAction === ACTION.NODE_COLOR;
  112. },
  113. displayName: 'Action Color'
  114. }), _dec11 = property({
  115. visible: function () {
  116. // @ts-ignore
  117. return this.valueAction === ACTION.COMPONENT_CUSTOM;
  118. },
  119. displayName: 'Component Name'
  120. }), _dec12 = property({
  121. visible: function () {
  122. // @ts-ignore
  123. return this.valueAction === ACTION.COMPONENT_CUSTOM;
  124. },
  125. displayName: 'Component Property'
  126. }), _dec13 = property({
  127. visible: function () {
  128. // @ts-ignore
  129. return this.valueAction === ACTION.COMPONENT_CUSTOM;
  130. },
  131. displayName: 'Default Value'
  132. }), _dec14 = property({
  133. visible: function () {
  134. // @ts-ignore
  135. return this.valueAction === ACTION.COMPONENT_CUSTOM;
  136. },
  137. displayName: 'Action Value'
  138. }), _dec15 = property({
  139. type: [Node],
  140. tooltip: '需要执行条件的节点,如果不填写则默认会执行本节点以及本节点的所有子节点 的状态'
  141. }), ccclass(_class = _dec(_class = _dec2(_class = (_class2 = class VMState extends (_crd && VMBase === void 0 ? (_reportPossibleCrUseOfVMBase({
  142. error: Error()
  143. }), VMBase) : VMBase) {
  144. constructor(...args) {
  145. super(...args);
  146. _initializerDefineProperty(this, "watchPath", _descriptor, this);
  147. _initializerDefineProperty(this, "foreachChildMode", _descriptor2, this);
  148. _initializerDefineProperty(this, "condition", _descriptor3, this);
  149. _initializerDefineProperty(this, "foreachChildType", _descriptor4, this);
  150. _initializerDefineProperty(this, "valueA", _descriptor5, this);
  151. _initializerDefineProperty(this, "valueB", _descriptor6, this);
  152. _initializerDefineProperty(this, "valueAction", _descriptor7, this);
  153. _initializerDefineProperty(this, "valueActionOpacity", _descriptor8, this);
  154. _initializerDefineProperty(this, "valueActionColor", _descriptor9, this);
  155. _initializerDefineProperty(this, "valueComponentName", _descriptor10, this);
  156. _initializerDefineProperty(this, "valueComponentProperty", _descriptor11, this);
  157. _initializerDefineProperty(this, "valueComponentDefaultValue", _descriptor12, this);
  158. _initializerDefineProperty(this, "valueComponentActionValue", _descriptor13, this);
  159. _initializerDefineProperty(this, "watchNodes", _descriptor14, this);
  160. }
  161. onLoad() {
  162. super.onLoad(); // 如果数组里没有监听值,那么默认把所有子节点给监听了
  163. if (this.watchNodes.length == 0) {
  164. if (this.valueAction !== ACTION.NODE_ACTIVE && this.foreachChildMode === false) {
  165. this.watchNodes.push(this.node);
  166. }
  167. this.watchNodes = this.watchNodes.concat(this.node.children);
  168. }
  169. }
  170. start() {
  171. if (this.enabled) {
  172. this.onValueInit();
  173. }
  174. } // 当值初始化时
  175. onValueInit() {
  176. let value = (_crd && VM === void 0 ? (_reportPossibleCrUseOfVM({
  177. error: Error()
  178. }), VM) : VM).getValue(this.watchPath);
  179. this.checkNodeFromValue(value);
  180. } // 当值被改变时
  181. onValueChanged(newVar, oldVar, pathArr) {
  182. this.checkNodeFromValue(newVar);
  183. } // 检查节点值更新
  184. checkNodeFromValue(value) {
  185. if (this.foreachChildMode) {
  186. this.watchNodes.forEach((node, index) => {
  187. let v = this.foreachChildType === CHILD_MODE_TYPE.NODE_INDEX ? index : node.name;
  188. let check = this.conditionCheck(value, v); // log('遍历模式', value, node.name, check);
  189. this.setNodeState(node, check);
  190. });
  191. } else {
  192. let check = this.conditionCheck(value, this.valueA, this.valueB);
  193. this.setNodesStates(check);
  194. }
  195. } // 更新 多个节点 的 状态
  196. setNodesStates(checkState) {
  197. let nodes = this.watchNodes;
  198. let check = checkState;
  199. nodes.forEach(node => {
  200. this.setNodeState(node, check);
  201. });
  202. }
  203. /** 更新单个节点的状态 */
  204. setNodeState(node, checkState) {
  205. let n = this.valueAction;
  206. let check = checkState;
  207. switch (n) {
  208. case ACTION.NODE_ACTIVE:
  209. node.active = check ? true : false;
  210. break;
  211. case ACTION.NODE_VISIBLE:
  212. {
  213. let opacity = node.getComponent(UIOpacity);
  214. if (opacity == null) opacity = node.addComponent(UIOpacity);
  215. if (opacity) {
  216. opacity.opacity = check ? 255 : 0;
  217. }
  218. break;
  219. }
  220. case ACTION.NODE_OPACITY:
  221. {
  222. let opacity = node.getComponent(UIOpacity);
  223. if (opacity == null) opacity = node.addComponent(UIOpacity);
  224. if (opacity) {
  225. opacity.opacity = check ? this.valueActionOpacity : 255;
  226. }
  227. break;
  228. }
  229. case ACTION.NODE_COLOR:
  230. {
  231. let uir = node.getComponent(UIRenderer);
  232. if (uir) {
  233. uir.color = check ? this.valueActionColor : color(255, 255, 255);
  234. }
  235. break;
  236. }
  237. case ACTION.COMPONENT_CUSTOM:
  238. let comp = node.getComponent(this.valueComponentName);
  239. if (comp == null) return;
  240. if (this.valueComponentProperty in comp) {
  241. comp[this.valueComponentProperty] = check ? this.valueComponentActionValue : this.valueComponentDefaultValue;
  242. }
  243. break;
  244. case ACTION.SPRITE_GRAYSCALE:
  245. {
  246. let sprite = node.getComponent(Sprite);
  247. if (sprite) {
  248. sprite.grayscale = check;
  249. }
  250. break;
  251. }
  252. case ACTION.BUTTON_INTERACTABLE:
  253. {
  254. let sprite = node.getComponent(Button);
  255. if (sprite) {
  256. sprite.interactable = check;
  257. }
  258. break;
  259. }
  260. default:
  261. break;
  262. }
  263. }
  264. /** 条件检查 */
  265. conditionCheck(v, a, b) {
  266. let cod = CONDITION;
  267. switch (this.condition) {
  268. case cod["=="]:
  269. if (v == a) return true;
  270. break;
  271. case cod["!="]:
  272. if (v != a) return true;
  273. break;
  274. case cod["<"]:
  275. if (v < a) return true;
  276. break;
  277. case cod[">"]:
  278. if (v > a) return true;
  279. break;
  280. case cod[">="]:
  281. if (v >= a) return true;
  282. break;
  283. case cod["<"]:
  284. if (v < a) return true;
  285. break;
  286. case cod["<="]:
  287. if (v <= a) return true;
  288. break;
  289. case cod["range"]:
  290. if (v >= a && v <= b) return true;
  291. break;
  292. default:
  293. break;
  294. }
  295. return false;
  296. }
  297. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "watchPath", [property], {
  298. configurable: true,
  299. enumerable: true,
  300. writable: true,
  301. initializer: function () {
  302. return "";
  303. }
  304. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "foreachChildMode", [_dec3], {
  305. configurable: true,
  306. enumerable: true,
  307. writable: true,
  308. initializer: function () {
  309. return false;
  310. }
  311. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "condition", [_dec4], {
  312. configurable: true,
  313. enumerable: true,
  314. writable: true,
  315. initializer: function () {
  316. return CONDITION["=="];
  317. }
  318. }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "foreachChildType", [_dec5], {
  319. configurable: true,
  320. enumerable: true,
  321. writable: true,
  322. initializer: function () {
  323. return CHILD_MODE_TYPE.NODE_INDEX;
  324. }
  325. }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "valueA", [_dec6], {
  326. configurable: true,
  327. enumerable: true,
  328. writable: true,
  329. initializer: function () {
  330. return 0;
  331. }
  332. }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "valueB", [_dec7], {
  333. configurable: true,
  334. enumerable: true,
  335. writable: true,
  336. initializer: function () {
  337. return 0;
  338. }
  339. }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "valueAction", [_dec8], {
  340. configurable: true,
  341. enumerable: true,
  342. writable: true,
  343. initializer: function () {
  344. return ACTION.NODE_ACTIVE;
  345. }
  346. }), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "valueActionOpacity", [_dec9], {
  347. configurable: true,
  348. enumerable: true,
  349. writable: true,
  350. initializer: function () {
  351. return 0;
  352. }
  353. }), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "valueActionColor", [_dec10], {
  354. configurable: true,
  355. enumerable: true,
  356. writable: true,
  357. initializer: function () {
  358. return color(155, 155, 155);
  359. }
  360. }), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "valueComponentName", [_dec11], {
  361. configurable: true,
  362. enumerable: true,
  363. writable: true,
  364. initializer: function () {
  365. return '';
  366. }
  367. }), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "valueComponentProperty", [_dec12], {
  368. configurable: true,
  369. enumerable: true,
  370. writable: true,
  371. initializer: function () {
  372. return '';
  373. }
  374. }), _descriptor12 = _applyDecoratedDescriptor(_class2.prototype, "valueComponentDefaultValue", [_dec13], {
  375. configurable: true,
  376. enumerable: true,
  377. writable: true,
  378. initializer: function () {
  379. return '';
  380. }
  381. }), _descriptor13 = _applyDecoratedDescriptor(_class2.prototype, "valueComponentActionValue", [_dec14], {
  382. configurable: true,
  383. enumerable: true,
  384. writable: true,
  385. initializer: function () {
  386. return '';
  387. }
  388. }), _descriptor14 = _applyDecoratedDescriptor(_class2.prototype, "watchNodes", [_dec15], {
  389. configurable: true,
  390. enumerable: true,
  391. writable: true,
  392. initializer: function () {
  393. return [];
  394. }
  395. })), _class2)) || _class) || _class) || _class));
  396. _cclegacy._RF.pop();
  397. _crd = false;
  398. }
  399. };
  400. });
  401. //# sourceMappingURL=fb1edb424bf8362496b54be34aa20a86b867ca79.js.map