75c442d0-a44a-477f-80a4-2570d6cb45dc.js 8.45 KB
"use strict";
cc._RF.push(module, '75c44LQpEpHf4CkJXDWy0Xc', 'SpecialPlotViewPresenter');
// script/game/ui/presenter/SpecialPlotViewPresenter.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 simba_config_manager_1 = require("simba-config-manager");
const simba_sdk_1 = require("simba-sdk");
const PresenterBase_1 = require("../../../common/classbase/PresenterBase");
const UIManager_1 = require("../../../common/gameplay/managers/UIManager");
const StoryTbl_1 = require("../../../config/StoryTbl");
const GameConfig_1 = require("../../../GameConfig");
const GameDotMgr_1 = require("../../GameDotMgr");
const GameModelManager_1 = require("../../model/GameModelManager");
const UnlockSpecialPlotEventManager_1 = require("../../model/UnlockSpecialPlotEventManager");
const UnlockSpecialPlotModelManager_1 = require("../../model/UnlockSpecialPlotModelManager");
const PresenterCCViewFactory_1 = require("../PresenterCCViewFactory");
const SpecialPlotView_1 = require("../view/type/SpecialPlotView");
let SpecialPlotViewPresenter = /** @class */ (() => {
    let SpecialPlotViewPresenter = class SpecialPlotViewPresenter extends PresenterBase_1.Presenter {
        constructor() {
            super();
            this._value = 0;
            this._cfg = undefined;
            this.onLeftBtnClickCallBack = () => {
                if (this._value <= 0) {
                    return;
                }
                else {
                    this._value -= 1;
                    this.showSpecialPlot(this._viewProps.specialPlotIds[this._value]);
                }
            };
            this.onRightBtnClickCallBack = () => {
                if (this._value >= this._viewProps.specialPlotIds.length - 1) {
                    UIManager_1.UIManager.showToast(this._cfg.toastMsg);
                    return;
                }
                else {
                    this._value += 1;
                    this.showSpecialPlot(this._viewProps.specialPlotIds[this._value]);
                }
            };
            this.createGameClubBtn = () => {
                this.view.getViewNode().getComponent(cc.Widget).updateAlignment();
                let info = simba_sdk_1.SDK.systemInfo.displayInfo;
                let aspect = info.windowSize.height / cc.view.getVisibleSize().height;
                this.view.getViewNode().getComponent(cc.Widget).updateAlignment();
                let pos = this.view.getForumBtnNode().convertToWorldSpaceAR(cc.v2(0, 0));
                pos.x += cc.view.getViewportRect().x / cc.view.getScaleX();
                let xPos = pos.x * aspect;
                let yPos = info.windowSize.height - pos.y * aspect;
                let width = this.view.getForumBtnNode().width * aspect;
                let height = this.view.getForumBtnNode().height * aspect;
                let left = xPos - width / 2;
                let top = yPos - height / 2;
                simba_sdk_1.SDK.createGameClubButton({
                    type: "text",
                    text: "",
                    style: {
                        left: left,
                        top: top,
                        width: width,
                        height: height
                    },
                    icon: "green"
                });
            };
            this.onShopBtnClickCallBack = () => {
                GameDotMgr_1.default.getInstance().dotClickUI("shop_btn_specoalPlot");
                let type = GameModelManager_1.GameModelManager.getTypeByBedroomItemId(this._viewProps.itemId);
                if (GameConfig_1.channel == "wechat") {
                    // GameCenter.getInstance().openSubProgram(GameConfig.youZanShopAppId);
                    if (type) {
                        let link = GameModelManager_1.GameModelManager.getYouZanShopUrlByType(type);
                        if (link) {
                            simba_sdk_1.SDK.openProgramV2(GameConfig_1.GameConfig.youZanShopAppId, link);
                        }
                    }
                }
                else if (GameConfig_1.channel == "android") {
                    if (type) {
                        let link = GameModelManager_1.GameModelManager.getTaoBaoShopUrlByType(type);
                        if (link) {
                            GameModelManager_1.GameModelManager.jumpToTaobaoShop(link);
                        }
                    }
                }
                else {
                    UIManager_1.UIManager.showToast("该功能在当前平台不可使用");
                }
            };
            this.onCloseBtnClick = () => {
                this.view.close();
                GameModelManager_1.GameModelManager.BackToBedRoom.emit();
            };
        }
        onOpen(props) {
            super.onOpen(props);
            this._viewProps = props;
            this._viewProps.onLeftBtnClick = this.onLeftBtnClickCallBack;
            this._viewProps.onRightBtnClick = this.onRightBtnClickCallBack;
            this._viewProps.createGameClubBtn = this.createGameClubBtn;
            this._viewProps.onShopBtnClick = this.onShopBtnClickCallBack;
            this._viewProps.onCloseBtnClick = this.onCloseBtnClick;
            this.view.setProps(this._viewProps);
            this.onShow();
        }
        onShow() {
            super.onShow();
            this.showSpecialPlot(this._viewProps.specialPlotIds[this._value]);
            this.createGameClubBtn();
            this.showGameClubBtn();
        }
        onClose() {
            super.onClose();
            simba_sdk_1.SDK.destroyGameClubButton();
        }
        onEnterBackground() {
            super.onEnterBackground();
            this.hideGameClubBtn();
        }
        onEnterForeground() {
            super.onEnterForeground();
            this.showGameClubBtn();
        }
        showGameClubBtn() {
            simba_sdk_1.SDK.showGameClubButton();
        }
        hideGameClubBtn() {
            simba_sdk_1.SDK.hideGameClubButton();
        }
        showSpecialPlot(specialPlotId) {
            try {
                if (specialPlotId) {
                    this._cfg = simba_config_manager_1.ConfigManager.getConfig(StoryTbl_1.storyTbl, specialPlotId);
                    if (this._cfg) {
                        this.view.getSpecialPlotTitleNode().getComponent(cc.Label).string = this._cfg.title;
                        let cfgStr = this._cfg.content.split("%%");
                        let specialPlotNodeStr = "";
                        for (let i = 0; i < cfgStr.length; i++) {
                            specialPlotNodeStr = specialPlotNodeStr + cfgStr[i] + "\n";
                        }
                        this.view.getSpecialPlotNode().getComponent(cc.Label).string = specialPlotNodeStr;
                        UnlockSpecialPlotModelManager_1.UnlockSpecialPlotModelManager.saveClickedSpecialPlotIdByItemIdToGameRecord(specialPlotId);
                    }
                    this.updateLeftOrRightBtnStatus();
                    this.updateRightBtnRedDotStatus();
                    this.view.getSpecialPlotScrollView().scrollToTop();
                }
            }
            catch (error) {
                console.error(error);
            }
        }
        updateLeftOrRightBtnStatus() {
            //处理左按钮显隐,右按钮暂不处理
            if (this._value <= 0) {
                this.view.showLeftBtn(false);
            }
            else {
                this.view.showLeftBtn(true);
            }
        }
        updateRightBtnRedDotStatus() {
            this.view.showRedDot(UnlockSpecialPlotEventManager_1.default.getInstance().isShowBedRoomRedDotStatus(this._viewProps.itemId));
        }
    };
    SpecialPlotViewPresenter.uuid = "SpecialPlotViewPresenter";
    SpecialPlotViewPresenter = __decorate([
        PresenterCCViewFactory_1.RegPresenter(SpecialPlotView_1.SpecialPlotViewType)
    ], SpecialPlotViewPresenter);
    return SpecialPlotViewPresenter;
})();
exports.default = SpecialPlotViewPresenter;

cc._RF.pop();