cde0e608-3a09-4f9a-bc95-9aee3115c34f.js 6.56 KB
"use strict";
cc._RF.push(module, 'cde0eYIOglPmryVmu4xFcNP', 'DatingSceneViewImpl');
// script/game/ui/view/impl/dating/DatingSceneViewImpl.ts

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DatingSceneViewImpl = void 0;
const CCViewBase_1 = require("../../../../../common/classbase/CCViewBase");
const DatingSceneView_1 = require("../../type/DatingSceneView");
const PresenterCCViewFactory_1 = require("../../../PresenterCCViewFactory");
const CCDummyObjects_1 = require("../../../../../common/CCDummyObjects");
const ResUtils_1 = require("../../../../../common/utils/ResUtils");
const { ccclass, property } = cc._decorator;
let DatingSceneViewImpl = /** @class */ (() => {
    let DatingSceneViewImpl = class DatingSceneViewImpl extends CCViewBase_1.CCView {
        constructor() {
            super(...arguments);
            //#region editor bindings
            this.backgroundSprite = CCDummyObjects_1.DummySprite;
            this.portraitSprite = CCDummyObjects_1.DummySprite;
            this.selfSmallPortrait = CCDummyObjects_1.DummySprite;
            this.otherDialogNode = CCDummyObjects_1.DummyNode;
            this.selfDialogNode = CCDummyObjects_1.DummyNode;
            this.narratorDialogNode = CCDummyObjects_1.DummyNode;
            this.backRedDot = CCDummyObjects_1.DummyNode;
            this.touchEndHandler = () => {
                if (this.completePlotCallback)
                    this.completePlotCallback();
            };
        }
        closeAction() {
            this.backgroundSprite.spriteFrame = undefined;
            this.portraitSprite.spriteFrame = undefined;
            this.selfSmallPortrait.spriteFrame = undefined;
            this.otherDialogNode.active = false;
            this.selfDialogNode.active = false;
            this.narratorDialogNode.active = false;
            this.backRedDot.active = false;
            this.close();
        }
        onEnable() {
            this.node.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
        }
        onDisable() {
            this.node.off(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
        }
        guideBack() {
            this.backRedDot.active = true;
        }
        async setContent(isSelf, text, name, portraitImg, otherPortraitImg) {
            let promises = [];
            if (!((isSelf && otherPortraitImg) || portraitImg)) { // 防止切换过程中闪
                this.portraitSprite.spriteFrame = undefined;
            }
            if (portraitImg) {
                promises.push(ResUtils_1.ResUtils.loadRes(portraitImg, cc.SpriteFrame).then((sf) => {
                    if (this.node.active) {
                        if (isSelf) {
                            this.selfSmallPortrait.spriteFrame = sf;
                        }
                        else {
                            this.portraitSprite.spriteFrame = sf;
                        }
                    }
                }));
            }
            if (isSelf && otherPortraitImg) {
                promises.push(ResUtils_1.ResUtils.loadRes(otherPortraitImg, cc.SpriteFrame).then((sf) => {
                    this.portraitSprite.spriteFrame = sf;
                }));
            }
            this.otherDialogNode.active = false;
            this.selfDialogNode.active = false;
            this.narratorDialogNode.active = false;
            if (text) {
                if (isSelf) { // 自己
                    this.selfDialogNode.active = true;
                    this.selfDialogNode.children[0].getComponent(cc.Label).string = name;
                    this.selfDialogNode.children[1].getComponent(cc.RichText).string = text;
                }
                else if (name) { // 别人
                    this.otherDialogNode.active = true;
                    this.otherDialogNode.children[0].getComponent(cc.Label).string = name;
                    this.otherDialogNode.children[1].getComponent(cc.RichText).string = text;
                }
                else { // 旁白
                    this.narratorDialogNode.active = true;
                    this.narratorDialogNode.children[0].getComponent(cc.RichText).string = text;
                }
            }
            try {
                await Promise.all(promises);
            }
            catch (e) {
                console.error(e);
            }
        }
        async setBackground(bgImage) {
            if (!bgImage) {
                this.backgroundSprite.spriteFrame = undefined;
            }
            else {
                try {
                    let sf = await ResUtils_1.ResUtils.loadRes(bgImage, cc.SpriteFrame);
                    this.backgroundSprite.spriteFrame = sf;
                    this.backgroundSprite.node.height = this.node.height;
                    this.backgroundSprite.node.width = sf.getOriginalSize().width / sf.getOriginalSize().height * this.node.height;
                }
                catch (e) {
                    console.error(e);
                }
            }
        }
    };
    __decorate([
        property(cc.Sprite)
    ], DatingSceneViewImpl.prototype, "backgroundSprite", void 0);
    __decorate([
        property(cc.Sprite)
    ], DatingSceneViewImpl.prototype, "portraitSprite", void 0);
    __decorate([
        property(cc.Sprite)
    ], DatingSceneViewImpl.prototype, "selfSmallPortrait", void 0);
    __decorate([
        property(cc.Node)
    ], DatingSceneViewImpl.prototype, "otherDialogNode", void 0);
    __decorate([
        property(cc.Node)
    ], DatingSceneViewImpl.prototype, "selfDialogNode", void 0);
    __decorate([
        property(cc.Node)
    ], DatingSceneViewImpl.prototype, "narratorDialogNode", void 0);
    __decorate([
        property(cc.Node)
    ], DatingSceneViewImpl.prototype, "backRedDot", void 0);
    DatingSceneViewImpl = __decorate([
        ccclass,
        PresenterCCViewFactory_1.RegView(DatingSceneView_1.DatingSceneViewType, "prefab/ui/DatingSceneView")
    ], DatingSceneViewImpl);
    return DatingSceneViewImpl;
})();
exports.DatingSceneViewImpl = DatingSceneViewImpl;

cc._RF.pop();