e63cdc30-10ed-42f8-b5cf-cc34fb2da07b.js 6.44 KB
"use strict";
cc._RF.push(module, 'e63cdwwEO1C+LXPzDT7LaB7', 'MessageViewPresenter');
// script/game/ui/presenter/MessageViewPresenter.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 });
const PresenterBase_1 = require("../../../common/classbase/PresenterBase");
const MessageView_1 = require("../view/type/MessageView");
const GameModelManager_1 = require("../../model/GameModelManager");
const PlotModel_1 = require("../../../avg/model/PlotModel");
const RichTextUtils_1 = require("../../../avg/utils/RichTextUtils");
const UIManager_1 = require("../../../common/gameplay/managers/UIManager");
const ChatListViewPresenter_1 = require("./ChatListViewPresenter");
const PresenterCCViewFactory_1 = require("../PresenterCCViewFactory");
const PlotManager_1 = require("../../../avg/PlotManager");
const Enums_1 = require("../../Enums");
const PhoneCallViewPresenter_1 = require("./PhoneCallViewPresenter");
function getSentenceText(content) {
    let text = "";
    switch (content.type) {
        case PlotModel_1.SentenceType.TEXT:
            text = RichTextUtils_1.richNodesToCocosString(content.value);
            break;
        case PlotModel_1.SentenceType.AUDIO:
            text = "[Voice]";
            break;
        case PlotModel_1.SentenceType.IMAGE:
            text = "[Image]";
            break;
        case PlotModel_1.SentenceType.VIDEO:
            text = "[Video]";
            break;
    }
    return text;
}
function getPlotString(plot) {
    if (plot) {
        let text = "";
        let sentence = plot.sentences[0];
        if (sentence.content) {
            if (sentence.content.type === PlotModel_1.SentenceType.SELECT) {
                let select = PlotManager_1.PlotManager.getPlotSelection(plot.id);
                if (select !== undefined) {
                    let option = sentence.content.value[select];
                    if (option.content) {
                        text = getSentenceText(option.content);
                    }
                    else {
                        text = option.summary;
                    }
                }
            }
            else {
                text = getSentenceText(sentence.content);
            }
        }
        return text;
    }
    return "";
}
let MessageViewPresenter = /** @class */ (() => {
    let MessageViewPresenter = class MessageViewPresenter extends PresenterBase_1.Presenter {
        constructor() {
            super(...arguments);
            this._scenesActive = {};
            this._currPlotHasMsg = false;
            this.checkScenesActive = () => {
                this._currPlotHasMsg = false;
                this._scenesActive = GameModelManager_1.GameModelManager.getMessageScenesModel().reduce((pv, v) => (pv[v.id] = this.checkSceneActive(v), pv), {});
            };
            this.checkSceneActive = (model) => {
                let ret = PlotManager_1.PlotManager.getCurrentPlots().findIndex(v => v.plotSceneType === Enums_1.PlotSceneType.Message && v.plotSceneTypeId === model.id) >= 0;
                if (ret)
                    this._currPlotHasMsg = true;
                return ret;
            };
            this.onItemClick = (key) => {
                console.log("item click", key);
                let sceneModel = GameModelManager_1.GameModelManager.getMessageSceneModel(parseInt(key));
                if (!sceneModel) {
                    console.error("message scene model not found ", key);
                    return;
                }
                UIManager_1.UIManager.pushPresenter(ChatListViewPresenter_1.ChatListViewPresenter, sceneModel);
            };
        }
        onOpen() {
            super.onOpen(undefined);
            this.checkScenesActive();
            this.setViewProps();
            this._disposable.add(GameModelManager_1.GameModelManager.MessageSceneChanged.on(() => {
                if (!this._currPlotHasMsg && !this._view.isHidden && !this._isInBackground) {
                    this.checkScenesActive();
                    this.setViewProps();
                }
            }));
            this._disposable.add(PlotManager_1.PlotManager.PlotStartEvent.on(() => {
                if (this._currPlotHasMsg && !this._view.isHidden && !this._isInBackground) {
                    this.checkScenesActive();
                    this.setViewProps();
                }
            }));
            this.checkPhoneCall();
        }
        onShow() {
            super.onShow();
            this.checkScenesActive();
            this.setViewProps();
            this.checkPhoneCall();
        }
        checkPhoneCall() {
            if (PlotManager_1.PlotManager.getCurrentPlots()[0].plotSceneType === Enums_1.PlotSceneType.PhoneCall) {
                UIManager_1.UIManager.pushPresenter(PhoneCallViewPresenter_1.PhoneCallViewPresenter, undefined);
            }
        }
        onEnterForeground() {
            super.onEnterForeground();
            this.checkScenesActive();
            this.setViewProps();
            this.checkPhoneCall();
        }
        setViewProps() {
            this._view.setProps({
                items: GameModelManager_1.GameModelManager.getMessageScenesModel().map(v => {
                    return {
                        key: v.id + "",
                        icons: [GameModelManager_1.GameModelManager.getRoleData(v.config.roles[0]).getHeadIcon(true)],
                        title: GameModelManager_1.GameModelManager.getConfigLanguageTxt(v.config.title), lastMsg: getPlotString(v.lastPlot),
                        redDot: this._scenesActive[v.id]
                    };
                }),
                onItemClick: this.onItemClick
            });
        }
    };
    MessageViewPresenter.uuid = "MessageViewPresenter";
    MessageViewPresenter = __decorate([
        PresenterCCViewFactory_1.RegPresenter(MessageView_1.MessageViewType)
    ], MessageViewPresenter);
    return MessageViewPresenter;
})();
exports.default = MessageViewPresenter;

cc._RF.pop();