09017250-b1a4-4eb8-af03-3e292018a356.js 10.5 KB
"use strict";
cc._RF.push(module, '09017JQsaROuK8DPikgGKNW', 'PhoneCallViewImpl');
// script/game/ui/view/impl/PhoneCallViewImpl.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.PhoneCallViewImpl = void 0;
const CCViewBase_1 = require("../../../../common/classbase/CCViewBase");
const PhoneCallView_1 = require("../type/PhoneCallView");
const PresenterCCViewFactory_1 = require("../../PresenterCCViewFactory");
const CCDummyObjects_1 = require("../../../../common/CCDummyObjects");
const PlotModel_1 = require("../../../../avg/model/PlotModel");
const RichTextUtils_1 = require("../../../../avg/utils/RichTextUtils");
const ResUtils_1 = require("../../../../common/utils/ResUtils");
const AudioManager_1 = require("../../../../common/gameplay/managers/AudioManager");
const { ccclass, property } = cc._decorator;
let PhoneCallViewImpl = /** @class */ (() => {
    let PhoneCallViewImpl = class PhoneCallViewImpl extends CCViewBase_1.CCPureView {
        constructor() {
            super(...arguments);
            //#region editor bindings
            this.scrollView = CCDummyObjects_1.DummyScrollView;
            this.contentLayout = CCDummyObjects_1.DummyLayout;
            this.callingNode = CCDummyObjects_1.DummyNode;
            this.messageNode = CCDummyObjects_1.DummyNode;
            this.nameLabel1 = CCDummyObjects_1.DummyLabel;
            this.nameLabel2 = CCDummyObjects_1.DummyLabel;
            this.headIcon1 = CCDummyObjects_1.DummySprite;
            this.headIcon2 = CCDummyObjects_1.DummySprite;
            this.rejectTipNode = CCDummyObjects_1.DummyNode;
            this.nextPlotNode = CCDummyObjects_1.DummyNode;
            this.playPhoneMusic = () => {
                const PhoneBgmCallSound = "/audio/bgm/iPhoneXSCallSound";
                AudioManager_1.AudioManager.playMusic(PhoneBgmCallSound);
            };
            this.stopPhoneMusic = () => {
                AudioManager_1.AudioManager.stopMusic();
            };
            //#endregion
            this._newCall = true;
        }
        onRejectCall() {
            this.node.children[1].active = true;
            this.rejectTipNode.runAction(cc.sequence(cc.fadeIn(0.3), cc.delayTime(0.3), cc.callFunc(() => {
                this.rejectTipNode.opacity = 0;
                this.node.children[0].opacity = 0;
                this.stopPhoneMusic();
                this.scheduleOnce(() => {
                    this.node.children[0].opacity = 255;
                    this.node.children[1].active = false;
                    this.playPhoneMusic();
                }, 0.8);
            })));
        }
        onAcceptCall() {
            this.callingNode.active = false;
            this.messageNode.active = true;
            this.stopPhoneMusic();
            if (PhoneCallView_1.PhoneCallListAutoNextPlot) {
                this.scheduleOnce(() => {
                    this._props.onCompletePlot();
                }, 0.6);
            }
        }
        onNextPlotBtnClick() {
            if (!PhoneCallView_1.PhoneCallListAutoNextPlot) {
                this._props.onCompletePlot(this._selectIndex);
                this._selectIndex = undefined;
            }
        }
        onLoad() {
            this.bindProp("name", this.nameLabel1, "string");
            this.bindProp("name", this.nameLabel2, "string");
            this.bindProp("icon", async (v) => {
                if (v) {
                    let sf = await ResUtils_1.ResUtils.loadRes(v, cc.SpriteFrame, 2);
                    // if (v === this._props.icon) { // 理论上这里没必要
                    this.headIcon1.spriteFrame = sf;
                    this.headIcon2.spriteFrame = sf;
                    // }
                }
            });
            // this.bindProp("select", (value) => {
            //     if (value >= 0) {
            //         let item = this._props.items[this._props.items.length - 1];
            //         item.select = value;
            //         this.processItem(item);
            //     }
            // });
        }
        select(value) {
            if (value >= 0) {
                let item = this._props.items[this._props.items.length - 1];
                item.select = value;
                this.processItem(item);
            }
        }
        scrollToTop() {
            this.scrollView.scrollToTop();
        }
        scrollToBottom(animate = true) {
            if (this.contentLayout.node.height > this.scrollView.node.height) {
                this.scrollView.scrollToBottom(animate ? 0.3 : undefined);
            }
        }
        open(parent) {
            super.open(parent);
            this.callingNode.active = true;
            this.messageNode.active = false;
            this.node.children[0].opacity = 0;
            this.node.children[1].active = true;
            this.stopPhoneMusic();
            this.node.children[0].runAction(cc.sequence(cc.delayTime(0.2), cc.fadeIn(0.1), cc.callFunc(() => {
                this.node.children[0].opacity = 255;
                this.node.children[1].active = false;
                this.playPhoneMusic();
            })));
        }
        close(clean) {
            super.close(clean);
            // 清除内容,防止下次打开的时候先显示上次的内容
            this.contentLayout.node.removeAllChildren();
            this.headIcon1.spriteFrame = undefined;
            this.nameLabel1.string = "";
            this.stopPhoneMusic();
            delete this._props;
        }
        onPropsLoad(props) {
            super.onPropsLoad(props);
            for (let item of this._props.items) { // 应该只有一条
                this.processItem(item);
            }
        }
        onPropChange(propName) {
            super.onPropChange(propName);
            if (propName === "items") {
                for (let i = this.contentLayout.node.children.length; i < this._props.items.length; i++) {
                    this.processItem(this._props.items[i]);
                }
            }
        }
        processItem(item) {
            let content = item.sentence.content;
            if (item.isSelf && content.type === PlotModel_1.SentenceType.SELECT && item.select === undefined) { // show selector
                this._props.onSetContent(content);
                this.nextPlotNode.active = false;
            }
            else {
                this.nextPlotNode.active = true;
                if (content.type === PlotModel_1.SentenceType.SELECT && item.select === undefined) {
                    console.error("Something went wrong. ", item.sentence);
                    return;
                }
                let node = new cc.Node;
                let richLabel = node.addComponent(cc.RichText);
                richLabel.fontSize = 32;
                richLabel.maxWidth = 585;
                if (item.isSelf) {
                    node.anchorX = 1;
                    node.x = 300;
                    node.color = cc.color(62, 46, 198);
                    richLabel.horizontalAlign = cc.macro.TextAlignment.RIGHT;
                }
                else {
                    node.anchorX = 0;
                    node.x = -300;
                    richLabel.horizontalAlign = cc.macro.TextAlignment.LEFT;
                }
                if (content.type === PlotModel_1.SentenceType.SELECT) {
                    let option = content.value[item.select];
                    if (option.content) {
                        if (option.content.type === PlotModel_1.SentenceType.TEXT) {
                            richLabel.string = RichTextUtils_1.richNodesToCocosString(option.content.value);
                        }
                        else {
                            richLabel.string = `SentenceType(${option.content.type}) not supported in phone call.`;
                        }
                    }
                    else {
                        richLabel.string = option.summary;
                    }
                }
                else if (content.type === PlotModel_1.SentenceType.TEXT) {
                    richLabel.string = RichTextUtils_1.richNodesToCocosString(content.value);
                }
                else {
                    richLabel.string = `SentenceType(${content.type}) not supported in phone call.`;
                }
                node.parent = this.contentLayout.node;
            }
            if (PhoneCallView_1.PhoneCallListAutoNextPlot && this.messageNode.active && !this._props.isSentenceSelectVisible()) {
                this.scheduleOnce(() => {
                    this._props.onCompletePlot(item.select);
                }, 1);
            }
            else {
                this._selectIndex = item.select;
            }
            this.contentLayout.updateLayout();
            this.scrollToBottom();
        }
    };
    __decorate([
        property(cc.ScrollView)
    ], PhoneCallViewImpl.prototype, "scrollView", void 0);
    __decorate([
        property(cc.Layout)
    ], PhoneCallViewImpl.prototype, "contentLayout", void 0);
    __decorate([
        property(cc.Node)
    ], PhoneCallViewImpl.prototype, "callingNode", void 0);
    __decorate([
        property(cc.Node)
    ], PhoneCallViewImpl.prototype, "messageNode", void 0);
    __decorate([
        property(cc.Label)
    ], PhoneCallViewImpl.prototype, "nameLabel1", void 0);
    __decorate([
        property(cc.Label)
    ], PhoneCallViewImpl.prototype, "nameLabel2", void 0);
    __decorate([
        property(cc.Sprite)
    ], PhoneCallViewImpl.prototype, "headIcon1", void 0);
    __decorate([
        property(cc.Sprite)
    ], PhoneCallViewImpl.prototype, "headIcon2", void 0);
    __decorate([
        property(cc.Node)
    ], PhoneCallViewImpl.prototype, "rejectTipNode", void 0);
    __decorate([
        property(cc.Node)
    ], PhoneCallViewImpl.prototype, "nextPlotNode", void 0);
    PhoneCallViewImpl = __decorate([
        ccclass,
        PresenterCCViewFactory_1.RegView(PhoneCallView_1.PhoneCallViewType, "prefab/ui/PhoneCallView")
    ], PhoneCallViewImpl);
    return PhoneCallViewImpl;
})();
exports.PhoneCallViewImpl = PhoneCallViewImpl;

cc._RF.pop();