123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529 |
- System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
- "use strict";
- var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, director, error, instantiate, Node, UITransform, Widget, assetManager, tween, v3, UIOpacity, Vec3, Tween, ui_base, ResolutionAutoFit, ui, _dec, _class, _crd, ccclass, property, ui_updater, GameUILayers, gui;
- function _reportPossibleCrUseOfui_base(extras) {
- _reporterNs.report("ui_base", "./ui_base", _context.meta, extras);
- }
- function _reportPossibleCrUseOfResolutionAutoFit(extras) {
- _reporterNs.report("ResolutionAutoFit", "./ui_ResolutionAutoFit", _context.meta, extras);
- }
- return {
- setters: [function (_unresolved_) {
- _reporterNs = _unresolved_;
- }, function (_cc) {
- _cclegacy = _cc.cclegacy;
- __checkObsolete__ = _cc.__checkObsolete__;
- __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
- _decorator = _cc._decorator;
- Component = _cc.Component;
- director = _cc.director;
- error = _cc.error;
- instantiate = _cc.instantiate;
- Node = _cc.Node;
- UITransform = _cc.UITransform;
- Widget = _cc.Widget;
- assetManager = _cc.assetManager;
- tween = _cc.tween;
- v3 = _cc.v3;
- UIOpacity = _cc.UIOpacity;
- Vec3 = _cc.Vec3;
- Tween = _cc.Tween;
- }, function (_unresolved_2) {
- ui_base = _unresolved_2.default;
- }, function (_unresolved_3) {
- ResolutionAutoFit = _unresolved_3.ResolutionAutoFit;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "81e48wxjGBMPp2rQOJDljTG", "ui", undefined);
- __checkObsolete__(['_decorator', 'Component', 'director', 'error', 'instantiate', 'Node', 'Prefab', 'UITransform', 'Widget', 'assetManager', 'AssetManager', 'tween', 'v3', 'UIOpacity', 'Vec3', 'ProgressBar', 'Sprite', 'Tween']);
- ({
- ccclass,
- property
- } = _decorator);
- ui_updater = (_dec = ccclass('ui_updater'), _dec(_class = class ui_updater extends Component {
- update(dt) {
- (_crd && ui_base === void 0 ? (_reportPossibleCrUseOfui_base({
- error: Error()
- }), ui_base) : ui_base).updateAll(dt);
- }
- }) || _class);
- _export("GameUILayers", GameUILayers = /*#__PURE__*/function (GameUILayers) {
- GameUILayers[GameUILayers["GAME"] = 0] = "GAME";
- GameUILayers[GameUILayers["JOY_STICK"] = 1] = "JOY_STICK";
- GameUILayers[GameUILayers["HUD"] = 2] = "HUD";
- GameUILayers[GameUILayers["POPUP"] = 3] = "POPUP";
- GameUILayers[GameUILayers["ALERT"] = 4] = "ALERT";
- GameUILayers[GameUILayers["NOTICE"] = 5] = "NOTICE";
- GameUILayers[GameUILayers["LOADING"] = 6] = "LOADING";
- GameUILayers[GameUILayers["OVERLAY"] = 7] = "OVERLAY";
- return GameUILayers;
- }({}));
- /**ui管理模块*/
- ui = class ui {
- constructor() {
- this._uiCanvas = void 0;
- this._uiRoot = void 0;
- this._clss_loading = new Set();
- }
- static getInstance() {
- if (!this._instance) this._instance = new ui();
- return this._instance;
- }
- delay(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
- }
- delay_second(s) {
- return new Promise(resolve => setTimeout(resolve, s * 1000));
- }
- progressBar_anim(bar, progress, duration = 0.2) {
- if (bar.progress >= progress) {
- bar.progress = progress;
- return;
- } else {
- return new Promise(resolve => tween(bar).to(duration, {
- progress: progress
- }).call(() => {
- resolve();
- }).start());
- }
- }
- fillRange_anim(sp, progress, duration = 0.2, limt = 0) {
- if (limt > 0 && sp.fillRange >= progress && limt < 0 && sp.fillRange <= progress) {
- sp.fillRange = progress;
- return;
- } else {
- return new Promise(resolve => tween(sp).to(duration, {
- fillRange: progress
- }).call(() => {
- resolve();
- }).start());
- }
- }
- scale_anim(node, duration = 0.2, start = 0.5, end = 1) {
- node.setScale(start, start, 1);
- return new Promise(resolve => tween(node).to(duration, {
- scale: v3(end, end, 1)
- }).call(() => {
- resolve();
- }).start());
- }
- scale_elasticOut_anim(node, duration = 0.2, start = 0.5, end = 1) {
- node.setScale(start, start, 1);
- return new Promise(resolve => tween(node).to(duration, {
- scale: v3(end, end, 1)
- }, {
- easing: 'elasticOut'
- }).call(() => {
- resolve();
- }).start());
- }
- fade_anim(node, duration = 0.2, startOpacity = 0, targetOpacity = 255) {
- var _node$getComponent;
- const opacity = (_node$getComponent = node.getComponent(UIOpacity)) != null ? _node$getComponent : node.addComponent(UIOpacity);
- opacity.opacity = startOpacity;
- return new Promise(resolve => {
- tween(opacity).to(duration, {
- opacity: targetOpacity
- }).call(() => {
- resolve();
- }).start();
- });
- }
- shake_anim(node, duration = 0.2, intensity = 5, shakeCount = 7) {
- return new Promise(resolve => {
- const originalPosition = node.position.clone(); // 保存原始位置
- const shakeDuration = duration / (shakeCount * 2); // 每次抖动的持续时间
- const shakeTween = tween(node);
- for (let i = 0; i < shakeCount; i++) {
- const offsetX = i % 2 === 0 ? intensity : -intensity; // 交替偏移
- shakeTween.to(shakeDuration, {
- position: v3(originalPosition.x + offsetX, originalPosition.y, originalPosition.z)
- }).to(shakeDuration, {
- position: originalPosition
- }); // 回到原位
- }
- shakeTween.call(() => {
- resolve();
- }).start(); // 开始抖动动画
- });
- }
- rotate_shake_anim(node, duration = 0.3, intensity = 5, shakeCount = 5) {
- return new Promise(resolve => {
- const originalAngle = node.angle; // 保存原始角度
- const shakeDuration = duration / (shakeCount * 2); // 每次晃动的持续时间
- const shakeTween = tween(node);
- for (let i = 0; i < shakeCount; i++) {
- const offsetAngle = i % 2 === 0 ? intensity : -intensity; // 交替旋转
- shakeTween.to(shakeDuration, {
- angle: originalAngle + offsetAngle
- }).to(shakeDuration, {
- angle: originalAngle
- }); // 回到原位
- }
- shakeTween.call(() => {
- resolve();
- }).start(); // 开始角度晃动动画
- });
- }
- scale_shake_anim(node, duration = 0.3, intensity = 0.1, shakeCount = 10, reset = null) {
- if (reset) {
- Tween.stopAllByTarget(node);
- node.setScale(reset, reset, reset);
- }
- return new Promise(resolve => {
- const originalScale = node.scale.clone(); // 保存原始缩放
- const shakeDuration = duration / (shakeCount * 2); // 每次震动的持续时间
- const shakeTween = tween(node);
- for (let i = 0; i < shakeCount; i++) {
- const offsetScale = i % 2 === 0 ? intensity : -intensity; // 交替缩放
- shakeTween.to(shakeDuration, {
- scale: v3(originalScale.x + offsetScale, originalScale.y + offsetScale, originalScale.z)
- }).to(shakeDuration, {
- scale: originalScale
- }); // 回到原位
- }
- shakeTween.call(() => {
- resolve();
- }).start(); // 开始缩放震动动画
- });
- }
- opacity_shake_anim(node, duration = 0.8, intensity = 80, shakeCount = 5) {
- var _node$getComponent2;
- const opacity = (_node$getComponent2 = node.getComponent(UIOpacity)) != null ? _node$getComponent2 : node.addComponent(UIOpacity);
- const originalOpacity = opacity.opacity;
- const shakeDuration = duration / (shakeCount * 2);
- return new Promise(resolve => {
- const shakeTween = tween(opacity);
- for (let i = 0; i < shakeCount; i++) {
- const offsetOpacity = i % 2 === 0 ? intensity : -intensity;
- shakeTween.to(shakeDuration, {
- opacity: Math.min(Math.max(originalOpacity + offsetOpacity, 0), 255)
- }).to(shakeDuration, {
- opacity: originalOpacity
- });
- }
- shakeTween.call(() => {
- resolve();
- }).start(); // 开始透明度震动动画
- });
- }
- /**处理弹跳动画*/
- bounce_anim(node, height = 100, duration = 0.5) {
- return new Promise(resolve => {
- tween(node).to(duration, {
- position: node.position.clone().add(new Vec3(0, height, 0))
- }, {
- easing: 'bounceOut'
- }) // 向上弹跳
- .to(duration, {
- position: node.position
- }, {
- easing: 'bounceIn'
- }) // 回到原位
- .call(() => {
- resolve();
- }) //完成动画
- .start(); //开始动画
- });
- }
- /**
- * 奖励物飞行动画
- * @param node 奖励物节点
- * @param startPos 起始爆开点
- * @param targetPos 最终目标点
- * @param explosionDistance 爆开距离
- * @param explosionDuration 爆开时间
- * @param stayDuration 停留时间
- * @param moveDuration 移动到目标的时间
- * @returns
- */
- reward_fly_anim(node, startPos, targetPos, explosionDistance = 100, explosionDuration = 0.3, stayDuration = 0.5, moveDuration = 0.3) {
- node.setPosition(startPos);
- return new Promise(resolve => {
- //随机方向
- const randomDirection = new Vec3(Math.random() * 2 - 1, Math.random() * 2 - 1, 0).normalize();
- const explosionEndPos = startPos.add(randomDirection.multiplyScalar(explosionDistance)); // 爆炸效果的位置
- tween(node).to(explosionDuration, {
- worldPosition: explosionEndPos
- }) // 爆炸动画
- .delay(stayDuration) //停留时间
- .to(moveDuration, {
- worldPosition: targetPos
- }, {
- easing: 'cubicIn'
- }).call(() => {
- resolve();
- }).start();
- });
- }
- createFullScreenNode() {
- let canvas = this._uiCanvas.getComponent(UITransform);
- let node = new Node();
- node.layer = this._uiCanvas.layer;
- let uiTransform = node.addComponent(UITransform);
- uiTransform.width = canvas.width;
- uiTransform.height = canvas.height;
- let widget = node.addComponent(Widget);
- widget.isAlignBottom = true;
- widget.isAlignTop = true;
- widget.isAlignLeft = true;
- widget.isAlignRight = true;
- widget.left = 0;
- widget.right = 0;
- widget.top = 0;
- widget.bottom = 0;
- return node;
- }
- getLayers() {
- return Object.values(GameUILayers).filter(value => typeof value === 'number');
- }
- /**
- * @en init,`don't call more than once`.
- * @zh 初始化UIMgr,`不要多次调用`
- * */
- init(uiCanvas) {
- if (this._uiCanvas) return;
- if (!uiCanvas) throw error('uiCanvas must be a Node or Prefab');
- if (uiCanvas instanceof Node) {
- this._uiCanvas = uiCanvas;
- } else {
- this._uiCanvas = instantiate(uiCanvas);
- director.getScene().addChild(this._uiCanvas);
- }
- this._uiCanvas.name = '__ui_canvas__';
- director.addPersistRootNode(this._uiCanvas);
- if (!this._uiCanvas.getComponent(ui_updater)) {
- this._uiCanvas.addComponent(ui_updater);
- }
- let canvas = this._uiCanvas.getComponent(UITransform);
- this._uiCanvas.addComponent(_crd && ResolutionAutoFit === void 0 ? (_reportPossibleCrUseOfResolutionAutoFit({
- error: Error()
- }), ResolutionAutoFit) : ResolutionAutoFit);
- this._uiRoot = this.createFullScreenNode();
- this._uiRoot.name = 'root';
- canvas.node.addChild(this._uiRoot);
- const layers = this.getLayers(); //create layers
- for (let i = 0; i < layers.length; ++i) {
- let layerNode = this.createFullScreenNode();
- layerNode.name = 'layer_' + GameUILayers[layers[i]];
- this._uiRoot.addChild(layerNode);
- }
- }
- /**获取层级节点*/
- getLayerNode(layerIndex) {
- return this._uiRoot.children[layerIndex] || this._uiRoot;
- }
- /**关闭所有界面*/
- closeAll() {
- (_crd && ui_base === void 0 ? (_reportPossibleCrUseOfui_base({
- error: Error()
- }), ui_base) : ui_base).closeAll();
- }
- /**关闭和释放所有界面 */
- closeAndReleaseAll() {
- (_crd && ui_base === void 0 ? (_reportPossibleCrUseOfui_base({
- error: Error()
- }), ui_base) : ui_base).closeAndReleaseAll();
- }
- /**关闭某个界面*/
- close(uiCls) {
- var _this$get;
- (_this$get = this.get(uiCls)) == null || _this$get.close();
- }
- /**获取界面*/
- get(uiCls) {
- let all = ui_base._uis;
- for (let i = 0; i < all.length; ++i) {
- let c = all[i];
- if (c instanceof uiCls) {
- return c;
- }
- }
- return null;
- }
- /**某个界面是否显示中*/
- isShowing(uiCls) {
- return ui_base._hasCls(uiCls);
- }
- /**是否有正在加载中的界面*/
- isLoading(uiCls) {
- if (!uiCls) return this._clss_loading.size > 0;
- return this._clss_loading.has(uiCls);
- }
- /***
- * @en show ui by the given parameters.
- * @zh 显示UI
- * @param uiCls the class, must inherits from the class `UIController`.
- * @returns the instance of `uiCls`
- * */
- async show(uiCls, ...data) {
- if (this.isLoading(uiCls)) return null;
- if (this.isShowing(uiCls)) return null;
- let ui = new uiCls();
- this._clss_loading.add(uiCls);
- let bundleName = ui.bundle;
- if (bundleName) {
- let bundle = assetManager.getBundle(bundleName);
- if (!bundle) {
- try {
- const loadedBundle = await this.loadBundleAsync(bundleName);
- return await this._create(loadedBundle, ui, uiCls, ...data);
- } catch (err) {
- console.error(err);
- this._clss_loading.delete(uiCls);
- }
- } else {
- return await this._create(bundle, ui, uiCls, ...data);
- }
- } else {
- this._clss_loading.delete(uiCls);
- console.error("ui no bundle name");
- return null;
- }
- }
- async _create(bundle, ui, uiCls, ...p) {
- try {
- const data = await this.loadPrefabAsync(bundle, ui.prefab);
- let node = instantiate(data);
- let parent = this.getLayerNode(ui.layer);
- parent.addChild(node);
- ui._setup(uiCls, node, ...p);
- this._clss_loading.delete(uiCls);
- return ui;
- } catch (err) {
- console.error(err);
- this._clss_loading.delete(uiCls);
- return;
- }
- }
- loadBundleAsync(bundleName) {
- return new Promise((resolve, reject) => {
- assetManager.loadBundle(bundleName, null, (err, loadedBundle) => {
- if (err) {
- reject(err);
- } else {
- resolve(loadedBundle);
- }
- });
- });
- }
- loadPrefabAsync(bundle, prefabName) {
- return new Promise((resolve, reject) => {
- bundle.load(prefabName, (err, data) => {
- if (err) {
- reject(err);
- } else {
- resolve(data);
- }
- });
- });
- }
- };
- ui._instance = void 0;
- _export("gui", gui = ui.getInstance());
- _export("ui_base", ui_base);
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=e2c07fd606d93eb79afeed6ef4de521f2be03414.js.map
|