73860035-95fb-42c3-a0c8-4a1754585f6c.js 5.84 KB
"use strict";
cc._RF.push(module, '73860A1lftCw6DIShdUWF9s', 'MainViewPresenter');
// script/game/ui/presenter/MainViewPresenter.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 PlotModel_1 = require("../../../avg/model/PlotModel");
const PlotManager_1 = require("../../../avg/PlotManager");
const PresenterBase_1 = require("../../../common/classbase/PresenterBase");
const GameTextData_1 = require("../../../common/gameplay/gamedata/GameTextData");
const UIManager_1 = require("../../../common/gameplay/managers/UIManager");
const Enums_1 = require("../../Enums");
const GameModelManager_1 = require("../../model/GameModelManager");
const PresenterCCViewFactory_1 = require("../PresenterCCViewFactory");
const AlertToBeContinueImpl_1 = require("../view/impl/AlertToBeContinueImpl");
const MainView_1 = require("../view/type/MainView");
const DatingEventViewPresenter_1 = require("./DatingEventViewPresenter");
const MessageViewPresenter_1 = require("./MessageViewPresenter");
var Tabs;
(function (Tabs) {
    Tabs[Tabs["messageTab"] = 0] = "messageTab";
    Tabs[Tabs["datingEventTab"] = 1] = "datingEventTab";
})(Tabs || (Tabs = {}));
const TabPresenterFactory = [MessageViewPresenter_1.default, DatingEventViewPresenter_1.default];
let MainViewPresenter = /** @class */ (() => {
    let MainViewPresenter = class MainViewPresenter extends PresenterBase_1.Presenter {
        constructor() {
            super();
            this._subPresenters = [];
            this._currentTab = 0;
            this._loadingTab = false;
            this.checkRedDot = (plots) => {
                if (plots[0].plotSceneType === Enums_1.PlotSceneType.Message || plots[0].plotSceneType === Enums_1.PlotSceneType.PhoneCall) {
                    this._viewProps.messageRedDot = true;
                }
                else {
                    this._viewProps.messageRedDot = false;
                }
                this._viewProps.datingEventRedDot = false;
                for (let plot of plots) {
                    if (plot.plotSceneType === Enums_1.PlotSceneType.DatingEvent) {
                        this._viewProps.datingEventRedDot = true;
                    }
                }
                this.view.setProps(this._viewProps);
            };
            this.onTabClick = (index) => {
                if (!GameModelManager_1.GameModelManager.checkFuncUnloced(TabPresenterFactory[index].uuid)) {
                    UIManager_1.UIManager.showToast(GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.GAME_TEXT_MAIN_FUNCTION_NOT_OPEN));
                    return;
                }
                if (this._loadingTab)
                    return;
                if (this._currentTab !== index) {
                    this._subPresenters[this._currentTab].view.hide();
                    this._currentTab = index;
                    this._viewProps.selectedTab = index;
                    this._view.setProps(this._viewProps);
                    if (!this._subPresenters[this._currentTab]) {
                        this._loadingTab = true;
                        PresenterBase_1.createPresenter(TabPresenterFactory[this._currentTab]).then((presenter) => {
                            this._loadingTab = false;
                            this._subPresenters[this._currentTab] = presenter;
                            presenter.open(this.view.getTabContentContainer(), undefined);
                        });
                    }
                    else {
                        this._subPresenters[this._currentTab].view.show();
                    }
                }
            };
            this._viewProps = {
                selectedTab: 0,
                messageRedDot: false,
                datingEventRedDot: false,
                onTabClick: this.onTabClick
            };
        }
        async start() {
            // 开始游戏
            this._subPresenters[0] = await PresenterBase_1.createPresenter(TabPresenterFactory[0]);
            this._subPresenters[0].open(this._view.getTabContentContainer(), undefined);
            this.checkRedDot(PlotManager_1.PlotManager.getCurrentPlots());
            PlotManager_1.PlotManager.PlotStartEvent.on(this.checkRedDot);
            if (PlotManager_1.PlotManager.getCurrentPlots()[0].id === PlotModel_1.SpecialPlotId.ToBeContinued) {
                AlertToBeContinueImpl_1.showToBeContinue();
            }
        }
        onClose() {
            super.onClose();
            UIManager_1.UIManager.popToPresenter(this);
        }
        onOpen() {
            super.onOpen(undefined);
        }
        onEnterBackground() {
            super.onEnterBackground();
            this._subPresenters[this._currentTab].onEnterBackground();
        }
        onEnterForeground() {
            super.onEnterForeground();
            this._subPresenters[this._currentTab].onEnterForeground();
            if (PlotManager_1.PlotManager.getCurrentPlots()[0].id === PlotModel_1.SpecialPlotId.ToBeContinued) {
                AlertToBeContinueImpl_1.showToBeContinue();
            }
        }
    };
    MainViewPresenter.uuid = "MainViewPresenter";
    MainViewPresenter = __decorate([
        PresenterCCViewFactory_1.RegPresenter(MainView_1.MainViewType)
    ], MainViewPresenter);
    return MainViewPresenter;
})();
exports.default = MainViewPresenter;

cc._RF.pop();