5bcc8dd6-cc23-448f-bc19-a6292ec711a0.js 16.8 KB
"use strict";
cc._RF.push(module, '5bcc83WzCNEj7wZpikuxxGg', 'ExtraPlotDatingEventSubViewPresenter');
// script/game/ui/presenter/ExtraPlotDatingEventSubViewPresenter.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.ExtraPlotDatingEventSubViewPresenter = void 0;
const simba_config_manager_1 = require("simba-config-manager");
const AVG_1 = require("../../../avg/AVG");
const EditorEnums_1 = require("../../../avg/EditorEnums");
const PresenterBase_1 = require("../../../common/classbase/PresenterBase");
const GameTextData_1 = require("../../../common/gameplay/gamedata/GameTextData");
const UIManager_1 = require("../../../common/gameplay/managers/UIManager");
const StringUtils_1 = require("../../../common/utils/StringUtils");
const DateSceneConfig_1 = require("../../../config/DateSceneConfig");
const Enums_1 = require("../../Enums");
const GameDotMgr_1 = require("../../GameDotMgr");
const CDKeyEventManager_1 = require("../../model/CDKeyEventManager");
const DatingEventSceneModel_1 = require("../../model/DatingEventSceneModel");
const ExtraStoryModelManager_1 = require("../../model/ExtraStoryModelManager");
const GameModelManager_1 = require("../../model/GameModelManager");
const PresenterCCViewFactory_1 = require("../PresenterCCViewFactory");
const ExtraPlotDatingEventSubView_1 = require("../view/type/ExtraPlotDatingEventSubView");
const AlertDialogViewPresenter_1 = require("./AlertDialogViewPresenter");
const DatingScenePresenter_1 = require("./DatingScenePresenter");
const GuideViewPresenter_1 = require("./GuideViewPresenter");
let ExtraPlotDatingEventSubViewPresenter = /** @class */ (() => {
    let ExtraPlotDatingEventSubViewPresenter = class ExtraPlotDatingEventSubViewPresenter extends PresenterBase_1.Subpresenter {
        constructor() {
            super(...arguments);
            this._modelMap = {};
            this._dailySceneNum = -1;
            this._curChapterIndex = 1;
            this._maxChapterIndex = 1;
            this._maxChapterIsChange = false;
            this.onItemAdModeClick = (key) => {
                GameModelManager_1.GameModelManager.setGuideEventItemRecord(key, Enums_1.GuideState.Complete);
                let m = this._modelMap[key];
                let hasRecord = this.checkIsSceneHasAdRecord(m.id);
                CDKeyEventManager_1.default.getInstance().shiftCDKeyRemovePlotAD();
                let removeAdCardNum = CDKeyEventManager_1.default.getInstance().checkCDKeyRemovePlotAD();
                if (m.status !== DatingEventSceneModel_1.DatingEventStatus.Completed) {
                    GameDotMgr_1.default.getInstance().dotClickUI("click_date_card" + m.config.id);
                }
                let showAdAlert = !(removeAdCardNum > 0) && !hasRecord && m.config.ads === 1 && m.status == DatingEventSceneModel_1.DatingEventStatus.New;
                if (showAdAlert) {
                    let temp = {
                        dataptr: { key },
                        titlecontent: GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.GAME_TEXT_WAIT_VALUE),
                        content: GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.GAME_TEXT_SHOW_AD_UNLOCK_DATE_VALUE),
                        ishasad: true,
                        istwobtn: true,
                        adconfig: "inject_fruit",
                        location: Enums_1.CommonLocation.Event,
                        callback: this.showAdCallBack,
                        hasBanner: false,
                        isthreebtn: true
                    };
                    console.log("Push AlertDialogViewPros data end");
                    UIManager_1.UIManager.pushPresenter(AlertDialogViewPresenter_1.default, temp);
                    console.log("pushPresenter=========");
                }
                else {
                    this.enterDatingScene(key);
                }
            };
            this.showAdCallBack = (type, ret, param) => {
                if (ret) {
                    if (true) {
                        let key = param["key"];
                        let m = this._modelMap[key];
                        this.pushSceneAdToRecord(m.id);
                        setTimeout(() => {
                            this.enterDatingScene(key);
                        }, 300);
                    }
                }
            };
            this.checkGuideItem = () => {
                let k = GameModelManager_1.GameModelManager.getEventItemGuideKey();
                if (k && "" !== k) {
                    let node = this.view.getItemNode(k);
                    if (node) {
                        let wp = node.convertToWorldSpaceAR(cc.v2(0, 0));
                        let m = {
                            x: wp.x,
                            y: wp.y,
                            w: node.width,
                            h: node.height,
                            d: Enums_1.DirectionType.DOWM,
                            call: () => {
                                this.onItemAdModeClick(k);
                                // this.onItemEnergyCostClick(k);
                                GameModelManager_1.GameModelManager.setGuideEventItemRecord(k, Enums_1.GuideState.Complete);
                            }
                        };
                        UIManager_1.UIManager.pushPresenter(GuideViewPresenter_1.default, m);
                        GameDotMgr_1.default.getInstance().dotGuide(Enums_1.GuideOperationType.Show, Enums_1.GuideLocation.EventItem);
                    }
                }
            };
            this.onOptionChapter = (stepType) => {
                let tempIndex = stepType === Enums_1.StepType.Add ? this._curChapterIndex + 1 : this._curChapterIndex - 1;
                this._curChapterIndex = tempIndex >= 1 && tempIndex <= this._maxChapterIndex ? tempIndex : this._curChapterIndex;
                this.refreshItems();
            };
            this.onRefreshDateSceneProgress = () => {
                this.refreshItems();
            };
            this.onForceClickItem = (id) => {
                console.log("DatingEventSubpresenter onForceClickItem id = ", id);
                let k = id + "";
                if (!this._modelMap || !this._modelMap[k]) {
                    return;
                }
                this.onItemAdModeClick(k);
            };
            this.onRefreshExtraPlotByType = (id) => {
                this._curChapterIndex = id;
                this.refreshItems();
            };
        }
        sceneModelToViewModel(item, index) {
            this._modelMap[item.id.toString()] = item;
            let direct = Enums_1.DatePrefabDirectType.Left;
            if (this._curChapterIndex % 2 === 1) {
                direct = (index + 1) % 2 === 1 ? Enums_1.DatePrefabDirectType.Left : Enums_1.DatePrefabDirectType.Right;
            }
            else {
                direct = (index + 1) % 2 === 0 ? Enums_1.DatePrefabDirectType.Left : Enums_1.DatePrefabDirectType.Right;
            }
            return {
                key: item.id + "",
                title: GameModelManager_1.GameModelManager.getConfigLanguageTxt(item.config.name),
                status: item.status,
                coverImage: "textures/dating_event/cover/" + item.config.background,
                itype: direct
            };
        }
        // async refreshItems() {
        //     let items: ExtraDateItemViewProps[] = [];
        //     let cfgIdArr: number[] = this.getCfgIdArr();
        //     let role = GameModelManager.getRoleData(this._viewProps.roleId);
        //     for (let i = 0; i < cfgIdArr.length; i++) {
        //         let cfg = ConfigManager.getConfig(extraSceneConfig, cfgIdArr[i]);
        //         if (role && role.getRelationValue() >= cfg.relationCondition) {
        //             await ExtraStoryModelManager.startBranches([cfg.start_plot_id]);
        //         }
        //         let sceneModel = new DatingEventSceneModel(cfg.id, false);
        //         await sceneModel.initFromRecords();
        //         if (sceneModel.status === DatingEventStatus.Locked && role!.getRelationValue() >= cfg.relationCondition) {
        //             sceneModel.status = DatingEventStatus.New;
        //         }
        //         let p = this.sceneModelToViewModel(sceneModel);
        //         p.showLine = i !== cfgIdArr.length - 1;
        //         items.push(p);
        //     }
        //     this._viewProps.items = items;
        // }
        async refreshItems() {
            let items = [];
            let srcModels = [];
            let cfg = simba_config_manager_1.ConfigManager.getAllConfig(DateSceneConfig_1.dateSceneConfig);
            for (const id in cfg) {
                if (cfg[id].DateType == EditorEnums_1.DateType.Date_Sp && cfg[id].chapter_index == this._curChapterIndex) {
                    await ExtraStoryModelManager_1.ExtraStoryModelManager.startBranches([cfg[id].start_plot_id]);
                    let plot = await AVG_1.getPlot(cfg[id].start_plot_id);
                    let model = new DatingEventSceneModel_1.DatingEventSceneModel(Number(id));
                    // model.status = ExtraStoryModelManager.getBranchStatus(model.id, model.config.start_plot_id);
                    await model.initFromRecords();
                    if (model.status === DatingEventSceneModel_1.DatingEventStatus.Locked) {
                        model.status = DatingEventSceneModel_1.DatingEventStatus.New;
                    }
                    // model.firstPlot = plot;
                    model.isExtra = true;
                    srcModels.push(model);
                }
            }
            for (let i = srcModels.length - 1; i >= 0; i--) {
                items.push(this.sceneModelToViewModel(srcModels[i], i));
            }
            if (this._dailySceneNum == -1) {
                let maxItemsNum = 0;
                let cfg = simba_config_manager_1.ConfigManager.getAllConfig(DateSceneConfig_1.dateSceneConfig);
                for (let id in cfg) {
                    let c = cfg[id];
                    if (c) {
                        maxItemsNum++;
                    }
                }
                this._dailySceneNum = maxItemsNum;
            }
            let showContinue = false;
            if (srcModels.length !== 0) {
                let c = 0;
                let cfgs = simba_config_manager_1.ConfigManager.getAllConfig(DateSceneConfig_1.dateSceneConfig);
                for (let id in cfgs) {
                    let cfg = cfgs[id];
                    if (cfg) {
                        c++;
                    }
                }
                let last = srcModels[srcModels.length - 1];
                showContinue = last.id === c;
            }
            this.view.setProps({
                items,
                onItemClick: this.onItemAdModeClick,
                showContinue: showContinue,
                chapterName: this.getChapterName(this._curChapterIndex),
                showLeft: this._curChapterIndex !== 1,
                showRight: this._curChapterIndex !== this._maxChapterIndex,
                showChapterClear: this.checkChapterClear(items, this._curChapterIndex),
                onOptionChapter: this.onOptionChapter,
                chapterIndex: this._curChapterIndex
            });
        }
        checkChapterClear(items, chapterIndex) {
            let showClear = true;
            let cfg = simba_config_manager_1.ConfigManager.getAllConfig(DateSceneConfig_1.dateSceneConfig);
            let cnt = 0;
            for (let id in cfg) {
                let c = cfg[id];
                if (c && c.chapter_index === chapterIndex) {
                    cnt++;
                }
            }
            if (cnt !== items.length) {
                return false;
            }
            return showClear;
        }
        getChapterName(chapterIndex) {
            chapterIndex -= 1;
            let nameArr = [
                "一", "二", "三", "四", "五", "六", "七", "八", "九", "十",
                "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十"
            ];
            let name = StringUtils_1.StringUtils.format(GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.GAME_TEXT_CHAPTER_NAME), nameArr[chapterIndex]);
            return name;
        }
        checkIsSceneHasAdRecord(id) {
            let ret = false;
            let record = AVG_1.GameRecord.globalVariables["date_ad_arr"];
            if (record) {
                let a = JSON.parse(record);
                let i = a.findIndex((v) => v === id);
                ret = i !== -1;
            }
            return ret;
        }
        pushSceneAdToRecord(id) {
            let record = AVG_1.GameRecord.globalVariables["date_ad_arr"];
            let a = [];
            let isExsit = false;
            if (record) {
                a = JSON.parse(record);
                let i = a.findIndex((v) => v === id);
                if (i >= 0) {
                    isExsit = true;
                }
            }
            if (!isExsit) {
                a.push(id);
                a.reverse();
                AVG_1.GameRecord.globalVariables["date_ad_arr"] = JSON.stringify(a);
                AVG_1.GameRecord.autoSave();
            }
        }
        enterDatingScene(key) {
            ExtraStoryModelManager_1.ExtraStoryModelManager.enterExtraStoryByStartPlotId(this._modelMap[key].config.start_plot_id);
            GameModelManager_1.GameModelManager.ShowDatingEventArrowGuide.emit(false);
            UIManager_1.UIManager.pushPresenter(DatingScenePresenter_1.DatingScenePresenter, this._modelMap[key], true);
        }
        onOwnerShow() {
            if (!this.view.isHidden) {
                this.selectCurChapter();
                this.refreshMaxChapterIndex();
                // this.refreshItems();
            }
        }
        onOwnerEnterForeground() {
            if (!this.view.isHidden) {
                this.refreshMaxChapterIndex();
                this.refreshItems();
            }
            if (this._maxChapterIsChange) {
                this.selectCurChapter();
            }
        }
        onOpen() {
            super.onOpen();
            this._disposable.add(GameModelManager_1.GameModelManager.CheckDateGuide.on(this.checkGuideItem));
            this._disposable.add(GameModelManager_1.GameModelManager.RefreshDateSceneProgress.on(this.onRefreshDateSceneProgress));
            this._disposable.add(GameModelManager_1.GameModelManager.ForceClickDatingItem.on(this.onForceClickItem));
            this._disposable.add(GameModelManager_1.GameModelManager.RefreshExtraPlotByType.on(this.onRefreshExtraPlotByType));
            this.selectCurChapter();
            if (!this.view.isHidden) {
                this.refreshMaxChapterIndex();
                this.onShow();
            }
        }
        onShow() {
            this.refreshMaxChapterIndex();
            // this.refreshItems();
            this.checkGuideItem();
        }
        onHide() {
        }
        selectCurChapter() {
            let models = GameModelManager_1.GameModelManager.getMainDatingEventScenesModel();
            if (models && models.length) {
                let last = models[models.length - 1];
                this._curChapterIndex = last.config.chapter_index;
                if (this._curChapterIndex !== 1) {
                    GameModelManager_1.GameModelManager.setNotNeedEnterCurDateChapter();
                }
            }
        }
        refreshMaxChapterIndex() {
            let maxChapterIndex = this._maxChapterIndex;
            let arr = GameModelManager_1.GameModelManager.getMainDatingEventScenesModel();
            if (arr && arr.length) {
                let dId = arr[arr.length - 1].id;
                let cfg = simba_config_manager_1.ConfigManager.getConfig(DateSceneConfig_1.dateSceneConfig, dId);
                this._maxChapterIndex = cfg.chapter_index;
            }
            this._maxChapterIsChange = maxChapterIndex == this._maxChapterIndex ? false : true;
        }
    };
    ExtraPlotDatingEventSubViewPresenter = __decorate([
        PresenterCCViewFactory_1.RegSubpresenter(ExtraPlotDatingEventSubView_1.ExtraPlotDatingEventSubViewType)
    ], ExtraPlotDatingEventSubViewPresenter);
    return ExtraPlotDatingEventSubViewPresenter;
})();
exports.ExtraPlotDatingEventSubViewPresenter = ExtraPlotDatingEventSubViewPresenter;

cc._RF.pop();