4c1e1ec2-e61e-474d-b4e2-9268b8a524a5.js 9.1 KB
"use strict";
cc._RF.push(module, '4c1e17C5h5HTbTikmi4pSSl', 'ItemIntroductionViewPresenter');
// script/game/ui/presenter/ItemIntroductionViewPresenter.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_cc_resutils_1 = require("simba-cc-resutils");
const simba_config_manager_1 = require("simba-config-manager");
const simba_sdk_1 = require("simba-sdk");
const PresenterBase_1 = require("../../../common/classbase/PresenterBase");
const GameConstData_1 = require("../../../common/gameplay/gamedata/GameConstData");
const UIManager_1 = require("../../../common/gameplay/managers/UIManager");
const ItemTbl_1 = require("../../../config/ItemTbl");
const GameConfig_1 = require("../../../GameConfig");
const GameDotMgr_1 = require("../../GameDotMgr");
const GameModelManager_1 = require("../../model/GameModelManager");
const UnlockItemModelManager_1 = require("../../model/UnlockItemModelManager");
const UnlockSpecialPlotEventManager_1 = require("../../model/UnlockSpecialPlotEventManager");
const UnlockSpecialPlotModelManager_1 = require("../../model/UnlockSpecialPlotModelManager");
const PresenterCCViewFactory_1 = require("../PresenterCCViewFactory");
const ItemIntroductionView_1 = require("../view/type/ItemIntroductionView");
const SpecialPlotViewPresenter_1 = require("./SpecialPlotViewPresenter");
let ItemIntroductionViewPresenter = /** @class */ (() => {
    let ItemIntroductionViewPresenter = class ItemIntroductionViewPresenter extends PresenterBase_1.Presenter {
        constructor() {
            super();
            this.specialPresenter = undefined;
            this.showItemSpr = async (itemId) => {
                try {
                    let cfg = undefined;
                    if (itemId) {
                        cfg = simba_config_manager_1.ConfigManager.getConfig(ItemTbl_1.itemTbl, itemId);
                        if (cfg) {
                            //如果没有模糊图,那么直接展示简介图
                            if (cfg.foggy === 0) {
                                UnlockItemModelManager_1.UnlockItemModelManager.saveUnlockedIntroductionItemIdToGameRecord(itemId);
                                let path = GameConstData_1.GameConstData.GAME_CONST_ITEM_BIG_SPR_DIR + cfg.type;
                                let itemSpriteFrame = await simba_cc_resutils_1.ResUtils.loadRes(path, cc.SpriteFrame);
                                this.view.getItemSpriteNode().spriteFrame = itemSpriteFrame;
                            }
                            //如果有模糊图,那么就判断是否已经解锁了清晰的简介图
                            else {
                                let unlockedIntroduction = false;
                                let unlockedIntroductionItems = UnlockItemModelManager_1.UnlockItemModelManager.unlockedIntroductionItems;
                                for (let i = 0; i < unlockedIntroductionItems.length; i++) {
                                    if (itemId == unlockedIntroductionItems[i]) {
                                        unlockedIntroduction = true;
                                    }
                                }
                                if (!unlockedIntroduction) {
                                    let path = GameConstData_1.GameConstData.GAME_CONST_ITEM_BIG_SPR_DIR + cfg.foggyPicture;
                                    let itemSpriteFrame = await simba_cc_resutils_1.ResUtils.loadRes(path, cc.SpriteFrame);
                                    this.view.getItemSpriteNode().spriteFrame = itemSpriteFrame;
                                }
                                else {
                                    UnlockItemModelManager_1.UnlockItemModelManager.saveUnlockedIntroductionItemIdToGameRecord(itemId);
                                    let path = GameConstData_1.GameConstData.GAME_CONST_ITEM_BIG_SPR_DIR + cfg.type;
                                    let itemSpriteFrame = await simba_cc_resutils_1.ResUtils.loadRes(path, cc.SpriteFrame);
                                    this.view.getItemSpriteNode().spriteFrame = itemSpriteFrame;
                                }
                            }
                        }
                    }
                    this.updateSpecialPlotBtnRedDotStatus();
                }
                catch (error) {
                    console.error(error);
                }
            };
            this.onSpecialPlotClickCallBack = () => {
                let itemCfg = undefined;
                itemCfg = simba_config_manager_1.ConfigManager.getConfig(ItemTbl_1.itemTbl, this._viewProps.itemId);
                let unlockedSpecialPlots = UnlockSpecialPlotModelManager_1.UnlockSpecialPlotModelManager.unlockedSpecialPlotIdByItemId(this._viewProps.itemId);
                if (itemCfg) {
                    let unlockedSpecialPlot = false;
                    if (unlockedSpecialPlots.length > 0) {
                        unlockedSpecialPlot = true;
                    }
                    if (unlockedSpecialPlot) {
                        this.openSpecialPlotView(this._viewProps.itemId, unlockedSpecialPlots);
                    }
                    else {
                        UIManager_1.UIManager.showToast(itemCfg.toastMsg);
                        return;
                    }
                }
                this.view.close();
            };
            this.onShopBtnClickCallBack = () => {
                GameDotMgr_1.default.getInstance().dotClickUI("shop_btn_introduction");
                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("该功能在当前平台不可使用");
                }
            };
        }
        onOpen(props) {
            super.onOpen(props);
            this._viewProps = props;
            this._viewProps.showItemSpr = this.showItemSpr;
            this._viewProps.onSpecialPlotBtnClick = this.onSpecialPlotClickCallBack;
            this._viewProps.onShopBtnClick = this.onShopBtnClickCallBack;
            this.view.setProps(this._viewProps);
            this.onShow();
            PresenterBase_1.createPresenter(SpecialPlotViewPresenter_1.default).then((presenter) => {
                this.specialPresenter = presenter;
            });
        }
        onShow() {
            super.onShow();
            this.showItemSpr(this._viewProps.itemId);
        }
        onEnterBackground() {
            super.onEnterBackground();
        }
        onEnterForeground() {
            super.onEnterForeground();
        }
        onClose() {
            super.onClose();
        }
        openSpecialPlotView(itemId, specialPlotIds) {
            if (this.specialPresenter) {
                let temp = {
                    itemId: itemId,
                    specialPlotIds: specialPlotIds,
                    onLeftBtnClick: () => { },
                    onRightBtnClick: () => { },
                    createGameClubBtn: () => { },
                    onShopBtnClick: () => { },
                    onCloseBtnClick: () => { }
                };
                this.specialPresenter.open(this.view.getContainer(), temp);
            }
        }
        updateSpecialPlotBtnRedDotStatus() {
            this.view.showSpecialPlotBtnRedDot(UnlockSpecialPlotEventManager_1.default.getInstance().isShowBedRoomRedDotStatus(this._viewProps.itemId));
        }
    };
    ItemIntroductionViewPresenter.uuid = "ItemIntroductionViewPresenter";
    ItemIntroductionViewPresenter = __decorate([
        PresenterCCViewFactory_1.RegPresenter(ItemIntroductionView_1.ItemIntroductionViewType)
    ], ItemIntroductionViewPresenter);
    return ItemIntroductionViewPresenter;
})();
exports.default = ItemIntroductionViewPresenter;

cc._RF.pop();