e63cdc30-10ed-42f8-b5cf-cc34fb2da07b.js 15.6 KB
"use strict";
cc._RF.push(module, 'e63cdwwEO1C+LXPzDT7LaB7', 'MessageViewPresenter');
// script/game/ui/presenter/MessageViewPresenter.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 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 RelationLevelConfig_1 = require("../../../config/RelationLevelConfig");
const Role_1 = require("../../../config/Role");
const Enums_1 = require("../../Enums");
const GameDotMgr_1 = require("../../GameDotMgr");
const GameModelManager_1 = require("../../model/GameModelManager");
const PresenterCCViewFactory_1 = require("../PresenterCCViewFactory");
const MessageView_1 = require("../view/type/MessageView");
const AlertDialogViewPresenter_1 = require("./AlertDialogViewPresenter");
const ChatListViewPresenter_1 = require("./ChatListViewPresenter");
const GuideViewPresenter_1 = require("./GuideViewPresenter");
const PhoneCallViewPresenter_1 = require("./PhoneCallViewPresenter");
const PlotStopViewPresenter_1 = require("./PlotStopViewPresenter");
function getSentenceText(content) {
    let text = "";
    switch (content.type) {
        case AVG_1.SentenceType.TEXT:
            text = AVG_1.richNodesToCocosString(content.value);
            const CHAR_LIMIT = 15;
            // text = '<color=#000000>亲,你说不说?</color>,<color=#000000>111</color>';
            // text = '亲,你说不说?亲,你说不说?亲,你说不说?';
            const regex = /<color=#[0-9A-Za-z]{6,6}>/g;
            let str = text.replace(regex, '');
            let textStr = str.replace(/<\/color>/g, '');
            text = textStr.length > CHAR_LIMIT ? textStr.slice(0, CHAR_LIMIT - 3) + "..." : textStr;
            break;
        case AVG_1.SentenceType.AUDIO:
            text = "[Voice]";
            break;
        case AVG_1.SentenceType.IMAGE:
            text = "[Image]";
            break;
        case AVG_1.SentenceType.VIDEO:
            text = "[Video]";
            break;
    }
    return text;
}
function getPlotString(plot) {
    if (plot) {
        let text = "";
        let sentence = plot.sentences[0];
        if (sentence.content) {
            if (sentence.content.type === AVG_1.SentenceType.SELECT) {
                let select = AVG_1.PlotManager.getPlotSelection(plot.id);
                if (select !== undefined) {
                    let option = sentence.content.value[select];
                    if (option.content) {
                        if (option.content.type === AVG_1.SentenceType.EMPTY) {
                            console.error("TODO handle empty plots in message");
                        }
                        else {
                            text = getSentenceText(option.content);
                        }
                    }
                    else {
                        text = option.summary;
                    }
                }
            }
            else {
                if (sentence.content.type === AVG_1.SentenceType.EMPTY) {
                    console.error("TODO handle empty plots in message");
                }
                else {
                    text = getSentenceText(sentence.content);
                }
            }
        }
        return text;
    }
    return GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.TEXT_NEW_CHAT_MSG_VALUE);
}
let MessageViewPresenter = /** @class */ (() => {
    let MessageViewPresenter = class MessageViewPresenter extends PresenterBase_1.Presenter {
        constructor() {
            super(...arguments);
            this._scenesActive = {};
            this._currPlotHasMsg = false;
            this._isCheckingPhoneCall = false;
            this.onForceClickItem = (id) => {
                console.log("MessageViewPresenter onForceClickItem id = ", id);
                if (!this._viewProps.items || 0 === this._viewProps.items.length) {
                    return;
                }
                let c = id + "";
                let i = this._viewProps.items.findIndex((v) => v.key === c);
                if ((-1) !== i) {
                    this.onItemClick(c);
                }
            };
            this.checkScenesActive = () => {
                this._currPlotHasMsg = false;
                this._scenesActive = GameModelManager_1.GameModelManager.getMessageScenesModel().reduce((pv, v) => (pv[v.id] = this.checkSceneActive(v), pv), {});
            };
            this.checkSceneActive = (model) => {
                let ret = AVG_1.PlotManager.getCurrentPlots().findIndex(v => v.plotSceneType === Enums_1.PlotSceneType.Message && v.plotSceneTypeId === model.id) >= 0;
                if (ret)
                    this._currPlotHasMsg = true;
                return ret;
            };
            this.PlotStopTipBtnCallback = () => {
                UIManager_1.UIManager.pushPresenter(PlotStopViewPresenter_1.default, undefined);
            };
            this.addGraceClickCallBack = (roleId) => {
                // GameDotMgr.getInstance().dotClickUI("click_grace");
                let r = GameModelManager_1.GameModelManager.getRoleData(roleId);
                if (!r || r.getConfig().RoleType !== EditorEnums_1.RoleType.Role_Major) {
                    return;
                }
                let l = r.getRoleLikeLevel();
                let m = -1;
                let t = simba_config_manager_1.ConfigManager.getAllConfig(RelationLevelConfig_1.relationLevelConfig);
                for (let id in t) {
                    let c = t[id];
                    m = m < c.id ? c.id : m;
                    //暂时修改最大等级为10
                    m = 10;
                }
                if (m <= l.level) {
                    UIManager_1.UIManager.showToast(GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.GAME_TEXT_GRACE_LEVEL_MAX_VALUE));
                    return;
                }
                else {
                    // UIManager.showToast(StringUtils.format(GameModelManager.getLanguageTxt(GameTextData.GAME_TEXT_GRACE_TIP_ROLE), r.getRoleName(), l.level));
                    let temp = {
                        dataptr: { roleId: roleId },
                        titlecontent: "提升好感度",
                        content: `当前与${r.getRoleName()}好感度等级为${l.level},观看视频提升好感度等级!`,
                        ishasad: true,
                        istwobtn: true,
                        adconfig: "inject_fruit",
                        // items: [],
                        hasBanner: false,
                        callback: (type, ret, param) => {
                            if (ret) {
                                if (type === "video") {
                                    let rid = param.roleId;
                                    let role = GameModelManager_1.GameModelManager.getRoleData(rid);
                                    if (role) {
                                        role.addRoleLike(1000);
                                        this.setViewProps();
                                    }
                                }
                                else {
                                    UIManager_1.UIManager.showToast("只能通过观看视频提升好感度等级!");
                                }
                            }
                        }
                    };
                    UIManager_1.UIManager.pushPresenter(AlertDialogViewPresenter_1.default, temp);
                }
            };
            this.onItemClick = (key) => {
                // console.log("item click", key);
                GameModelManager_1.GameModelManager.setGuideMsgItemRecord(key, Enums_1.GuideState.Complete);
                let sceneModel = GameModelManager_1.GameModelManager.getMessageSceneModel(parseInt(key));
                if (!sceneModel) {
                    console.error("message scene model not found ", key);
                    return;
                }
                let isNew = AVG_1.PlotManager.getCurrentPlots().findIndex(v => v.plotSceneType === Enums_1.PlotSceneType.Message && v.plotSceneTypeId === sceneModel.id) !== (-1);
                if (isNew || sceneModel.firstPlot.sentences[0].roleId == 3) {
                    GameDotMgr_1.default.getInstance().dotClickUI("click_chat_card" + sceneModel.id);
                }
                UIManager_1.UIManager.pushPresenter(ChatListViewPresenter_1.ChatListViewPresenter, sceneModel);
            };
            this.checkGuideItem = () => {
                let k = GameModelManager_1.GameModelManager.getMsgItemGuideKey();
                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.onItemClick(k);
                            }
                        };
                        UIManager_1.UIManager.pushPresenter(GuideViewPresenter_1.default, m);
                        GameDotMgr_1.default.getInstance().dotGuide(Enums_1.GuideOperationType.Show, Enums_1.GuideLocation.MsgItem);
                    }
                }
            };
            this.onShowPlotBlocked = () => {
                this._viewProps.isShowPlotStopTipBtn = GameModelManager_1.GameModelManager.checkIsPlotBlocked();
                this.view.updateProps(this._viewProps);
            };
            this.onRefreshAllStatus = () => {
                this.initViewProps();
                this.checkScenesActive();
                this.setViewProps();
                this._isCheckingPhoneCall = false;
                this.checkPhoneCall();
            };
        }
        onOpen() {
            super.onOpen(undefined);
            this.initViewProps();
            this.checkScenesActive();
            this.setViewProps();
            this._disposable.add(GameModelManager_1.GameModelManager.MessageSceneChanged.on(() => {
                if (!this._currPlotHasMsg && !this._view.isHidden && !this._isInBackground) {
                    this.checkScenesActive();
                    this.setViewProps();
                }
            }));
            this._disposable.add(AVG_1.PlotManager.PlotStartEvent.on(() => {
                if (this._currPlotHasMsg && !this._view.isHidden && !this._isInBackground) {
                    this.checkScenesActive();
                    this.setViewProps();
                }
            }));
            // this._disposable.add(GameModelManager.CheckMsgGuide.on(this.checkGuideItem));
            this._disposable.add(GameModelManager_1.GameModelManager.ShowPlotBlocked.on(this.onShowPlotBlocked));
            this._disposable.add(GameModelManager_1.GameModelManager.PlotBlockedChanged.on(this.onShowPlotBlocked));
            this._disposable.add(GameModelManager_1.GameModelManager.ForceClickMsgItem.on(this.onForceClickItem));
            this._disposable.add(GameModelManager_1.GameModelManager.RefreshAllStatus.on(this.onRefreshAllStatus));
            this._isCheckingPhoneCall = false;
            this.checkPhoneCall();
        }
        onShow() {
            super.onShow();
            this.checkScenesActive();
            this.setViewProps();
            this.checkPhoneCall();
            // this.checkGuideItem();
        }
        initViewProps() {
            this._viewProps = {
                items: [],
                onItemClick: this.onItemClick,
                PlotStopTipBtnCallback: this.PlotStopTipBtnCallback,
                isShowPlotStopTipBtn: false,
            };
        }
        async checkPhoneCall() {
            if (this._isCheckingPhoneCall) {
                return;
            }
            this._isCheckingPhoneCall = true;
            if (AVG_1.PlotManager.getCurrentPlots()[0].plotSceneType === Enums_1.PlotSceneType.PhoneCall) {
                await UIManager_1.UIManager.pushPresenter(PhoneCallViewPresenter_1.PhoneCallViewPresenter, undefined);
            }
            this._isCheckingPhoneCall = false;
        }
        onEnterForeground() {
            super.onEnterForeground();
            this.checkScenesActive();
            this.setViewProps();
            this.checkPhoneCall();
        }
        setViewProps() {
            let items = GameModelManager_1.GameModelManager.getMessageScenesModel().map(v => {
                let roleConfig = simba_config_manager_1.ConfigManager.getConfig(Role_1.role, v.config.roles[0]);
                let isMajor = roleConfig.RoleType === EditorEnums_1.RoleType.Role_Major;
                let roleData = GameModelManager_1.GameModelManager.getRoleData(v.config.roles[0]);
                let data = roleData.getRoleLikeLevel();
                let nameSpr = GameModelManager_1.GameModelManager.getRoleData(v.config.roles[0]).getNameIcon();
                if (v.config.roles[0] === 3) {
                    nameSpr = "/textures/name_icon/laoda";
                }
                return {
                    key: v.id + "",
                    icons: [GameModelManager_1.GameModelManager.getRoleData(v.config.roles[0]).getHeadIcon()],
                    title: GameModelManager_1.GameModelManager.getConfigLanguageTxt(v.config.title),
                    lastMsg: getPlotString(v.lastPlot),
                    redDot: this._scenesActive[v.id],
                    isShowGrace: isMajor,
                    level: isMajor ? data.level : undefined,
                    roleId: v.config.roles[0],
                    addGraceClickCallBack: this.addGraceClickCallBack,
                    isShowAddGrace: isMajor && data.level !== data.maxLevel,
                    nameSpr: nameSpr
                };
            });
            //对列表进行排序,有红点的(新对话消息)排在最前面,也就是置顶
            items.sort((a, b) => {
                if (a.redDot) {
                    return -1;
                }
                if (b.redDot) {
                    return 1;
                }
                return 0;
            });
            this._viewProps = {
                items: items,
                onItemClick: this.onItemClick,
                isShowPlotStopTipBtn: GameModelManager_1.GameModelManager.checkIsPlotBlocked(),
                PlotStopTipBtnCallback: this.PlotStopTipBtnCallback,
            };
            this.view.setProps(this._viewProps);
        }
    };
    MessageViewPresenter.uuid = "MessageViewPresenter";
    MessageViewPresenter = __decorate([
        PresenterCCViewFactory_1.RegPresenter(MessageView_1.MessageViewType)
    ], MessageViewPresenter);
    return MessageViewPresenter;
})();
exports.default = MessageViewPresenter;

cc._RF.pop();