52f06191-b63c-4fbb-9df6-1c1bbda46344.js 10.5 KB
"use strict";
cc._RF.push(module, '52f06GRtjxPu532HBu9pGNE', 'DatingScenePresenter');
// script/game/ui/presenter/DatingScenePresenter.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.DatingScenePresenter = void 0;
const PresenterBase_1 = require("../../../common/classbase/PresenterBase");
const DatingEventSceneModel_1 = require("../../model/DatingEventSceneModel");
const DatingSceneView_1 = require("../view/type/DatingSceneView");
const PresenterCCViewFactory_1 = require("../PresenterCCViewFactory");
const simba_utils_1 = require("simba-utils");
const PlotModel_1 = require("../../../avg/model/PlotModel");
const PlotManager_1 = require("../../../avg/PlotManager");
const PlotsData_1 = require("../../../avg/game-data/PlotsData");
const Enums_1 = require("../../Enums");
const ActionManager_1 = require("../../../avg/ActionManager");
const GameConstData_1 = require("../../../common/gameplay/gamedata/GameConstData");
const RichTextUtils_1 = require("../../../avg/utils/RichTextUtils");
const UIManager_1 = require("../../../common/gameplay/managers/UIManager");
const SentenceSelectorViewPresenter_1 = require("./SentenceSelectorViewPresenter");
const GameModelManager_1 = require("../../model/GameModelManager");
const GameRecord_1 = require("../../../avg/game-data/GameRecord");
const EditorEvents_1 = require("../../../avg/EditorEvents");
const AudioManager_1 = require("../../../common/gameplay/managers/AudioManager");
let DatingScenePresenter = /** @class */ (() => {
    let DatingScenePresenter = class DatingScenePresenter extends PresenterBase_1.Presenter {
        constructor() {
            super(...arguments);
            this._executingPlot = false;
            this._completingPlot = false;
            this._isReview = false;
            // private _actionFilter?: (action: DeepReadonly<Action>) => boolean;
            this._plotBranch = 0;
            this._currSelect = undefined;
            this._finished = false;
            this.completePlot = async () => {
                if (this._executingPlot || this._completingPlot || !this._currPlot || this._finished)
                    return;
                let content = this._currPlot.sentences[0].content;
                if (content && content.type === PlotModel_1.SentenceType.SELECT && this._currSelect === undefined)
                    return;
                this._completingPlot = true;
                if (this._isReview) {
                    let nextPlot = await PlotManager_1.PlotManager.getNextPlot(this._currPlot, this._currSelect);
                    if (nextPlot) {
                        this._currPlot = nextPlot;
                    }
                }
                else {
                    this._model.status = DatingEventSceneModel_1.DatingEventStatus.InProgress;
                    let nextPlots = await PlotManager_1.PlotManager.completePlot(this._currPlot, this._currSelect);
                    this._currPlot = nextPlots[this._plotBranch];
                }
                this._currSelect = undefined;
                this._completingPlot = false;
                this.execPlot();
            };
        }
        onOpen(param) {
            super.onOpen(param);
            this._finished = false;
            this.view.completePlotCallback = this.completePlot;
            this._model = param;
            simba_utils_1.delay(0.1).then(async () => {
                if (param.status === DatingEventSceneModel_1.DatingEventStatus.Completed) {
                    this._isReview = true;
                    // this._actionFilter = (action) => {
                    //     return action.type !== ActionType.ModifyVariable;
                    // }
                    this._model.background = "";
                    this._currPlot = await PlotsData_1.getPlot(param.config.start_plot_id);
                }
                else {
                    let plots = PlotManager_1.PlotManager.getCurrentPlots();
                    this._plotBranch = plots.findIndex(v => v.plotSceneType === Enums_1.PlotSceneType.DatingEvent && v.plotSceneTypeId === param.id);
                    this._currPlot = plots[this._plotBranch];
                    if (this._currPlot.id === this._model.firstPlot.id) {
                        GameRecord_1.GameRecord.recordVariables.bgm = ""; // 新约会,不继承之前剧情的背景音乐存档
                        this._model.background = "";
                    }
                    this._currSelect = PlotManager_1.PlotManager.getPlotSelection(this._currPlot.id);
                    if (GameRecord_1.GameRecord.recordVariables.bgm) {
                        AudioManager_1.AudioManager.playMusic(GameRecord_1.GameRecord.recordVariables.bgm);
                    }
                }
                if (this._model.background) {
                    await this.view.setBackground("textures/background/dating_event/" + this._model.background);
                }
                this.execPlot();
            });
            this._disposable.add(EditorEvents_1.EditorEvents.SET_DATING_BG.on((bgPath) => {
                this._model.background = bgPath;
                if (bgPath)
                    bgPath = "textures/background/dating_event/" + bgPath;
                return this.view.setBackground(bgPath);
            }));
        }
        onClose() {
            UIManager_1.UIManager.popToPresenter(this);
        }
        async execPlot() {
            if (this._currPlot) {
                if (this._currPlot.plotSceneType === Enums_1.PlotSceneType.DatingEvent && this._currPlot.plotSceneTypeId === this._model.id) {
                    this._executingPlot = true;
                    const sentence = this._currPlot.sentences[0];
                    const content = sentence.content;
                    const roleData = GameModelManager_1.GameModelManager.getRoleData(sentence.roleId);
                    let otherPortrait = undefined;
                    if (this._currPlot.portrait !== undefined) {
                        let otherRole = GameModelManager_1.GameModelManager.getRoleData(this._currPlot.portrait);
                        if (otherRole) {
                            otherPortrait = otherRole.getPortrait(this._currPlot.portraitFace);
                        }
                    }
                    if (content) { // TODO 图片设置
                        if (content.type === PlotModel_1.SentenceType.TEXT) {
                            await this.view.setContent(sentence.roleId === GameConstData_1.GameConstData.GAME_CONST_PLAYER_ROLE_VALUE, RichTextUtils_1.richNodesToCocosString(content.value), sentence.roleId === 1 ? undefined : roleData.getConfig().name, sentence.roleId === 1 ? otherPortrait : roleData.getPortrait(this._currPlot.face), otherPortrait);
                        }
                        else if (content.type === PlotModel_1.SentenceType.SELECT) {
                            let setSelection = async () => {
                                let value = content.value[this._currSelect];
                                let str = value.summary;
                                if (value.content && value.content.type === PlotModel_1.SentenceType.EMPTY) { // 空类型,不做展示
                                    this.completePlot();
                                    return;
                                }
                                else if (value.content && value.content.type === PlotModel_1.SentenceType.TEXT) {
                                    str = RichTextUtils_1.richNodesToCocosString(value.content.value);
                                }
                                await this.view.setContent(true, str, roleData.getConfig().name, roleData.getPortrait(this._currPlot.face), otherPortrait);
                            };
                            if (this._currSelect === undefined) {
                                let props = {
                                    sentence: content,
                                    backgroundpath: "",
                                    clickcausehide: false,
                                    optionStyle1: true,
                                    y: -250,
                                    onSelectIndexCallback: (index) => { this._currSelect = index; setSelection(); }
                                };
                                UIManager_1.UIManager.pushPresenter(SentenceSelectorViewPresenter_1.default, props);
                                await this.view.setContent(true, "", roleData.getConfig().name, roleData.getPortrait(this._currPlot.face), otherPortrait);
                            }
                            else {
                                await setSelection();
                            }
                        }
                        else {
                            console.error("不支持的约会剧情", content);
                        }
                    }
                    else { // 没有句子,只设置其立绘、背景等
                        await this.view.setContent(false, "", "", roleData.getPortrait(this._currPlot.face), otherPortrait);
                    }
                    if (this._currPlot.sentences[0].actions.actions.length) {
                        await ActionManager_1.ActionManager.executeActions(this._currPlot.sentences[0].actions, undefined, !this._isReview);
                    }
                    this._executingPlot = false;
                }
                else {
                    // 本次约会剧情结束
                    this._model.status = DatingEventSceneModel_1.DatingEventStatus.Completed;
                    this._finished = true;
                    UIManager_1.UIManager.showToast("本次剧情结束");
                    this.view.guideBack();
                }
            }
        }
    };
    DatingScenePresenter.uuid = "DatingScenePresenter";
    DatingScenePresenter = __decorate([
        PresenterCCViewFactory_1.RegPresenter(DatingSceneView_1.DatingSceneViewType)
    ], DatingScenePresenter);
    return DatingScenePresenter;
})();
exports.DatingScenePresenter = DatingScenePresenter;

cc._RF.pop();