a21abc61-863d-4b61-9f90-995f04a35c25.js 16.7 KB
"use strict";
cc._RF.push(module, 'a21abxhhj1LYZ+QmV8Eo1wl', 'SentenceSelectorViewImpl');
// script/game/ui/view/impl/message/SentenceSelectorViewImpl.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 AVG_1 = require("../../../../../avg/AVG");
const CCDummyObjects_1 = require("../../../../../common/CCDummyObjects");
const CCViewBase_1 = require("../../../../../common/classbase/CCViewBase");
const GameTextData_1 = require("../../../../../common/gameplay/gamedata/GameTextData");
const UIManager_1 = require("../../../../../common/gameplay/managers/UIManager");
const StringUtils_1 = require("../../../../../common/utils/StringUtils");
const Enums_1 = require("../../../../Enums");
const GameDotMgr_1 = require("../../../../GameDotMgr");
const GameModelManager_1 = require("../../../../model/GameModelManager");
const AlertDialogViewPresenter_1 = require("../../../presenter/AlertDialogViewPresenter");
const PresenterCCViewFactory_1 = require("../../../PresenterCCViewFactory");
const SentenceSelectorView_1 = require("../../type/SentenceSelectorView");
const { ccclass, property } = cc._decorator;
var DateSelectNodeType;
(function (DateSelectNodeType) {
    DateSelectNodeType[DateSelectNodeType["Invalid"] = 0] = "Invalid";
    DateSelectNodeType[DateSelectNodeType["SpecialGrace"] = 1] = "SpecialGrace";
    DateSelectNodeType[DateSelectNodeType["SpecialSkin"] = 2] = "SpecialSkin";
    DateSelectNodeType[DateSelectNodeType["GraceLocked"] = 3] = "GraceLocked";
    DateSelectNodeType[DateSelectNodeType["SkinLocked"] = 4] = "SkinLocked";
    DateSelectNodeType[DateSelectNodeType["Nomal_HasSpecial"] = 5] = "Nomal_HasSpecial";
    DateSelectNodeType[DateSelectNodeType["Nomal"] = 6] = "Nomal";
})(DateSelectNodeType || (DateSelectNodeType = {}));
let SentenceSelectorViewImpl = /** @class */ (() => {
    let SentenceSelectorViewImpl = class SentenceSelectorViewImpl extends CCViewBase_1.CCPureView {
        constructor() {
            super(...arguments);
            //#region 
            this.background = CCDummyObjects_1.DummySprite;
            this.contentLayout = CCDummyObjects_1.DummyLayout;
            this.selectButtonTemplate = CCDummyObjects_1.DummyNode;
            this.selectButtonTemplate1 = CCDummyObjects_1.DummyNode;
            this.template_date_special = CCDummyObjects_1.DummyNode;
            this.template_date_grace_unclick = CCDummyObjects_1.DummyNode;
            this.template_date_skin_unclick = CCDummyObjects_1.DummyNode;
            this.template_date_not_special = CCDummyObjects_1.DummyNode;
            //#endregion
            this.onButtonClick = (index, hasSpecial, specialType, specialStatus) => {
                return () => {
                    if (this._props.isFromDate && hasSpecial && this._props.dateSceneId && this._props.plotId) {
                        GameDotMgr_1.default.getInstance().dotSpecialPlot(this._props.dateSceneId, this._props.plotId, index, specialType, specialStatus);
                    }
                    this._props.onSelectIndexCallback(index);
                };
            };
            this.setContent = (content) => {
                this.contentLayout.node.removeAllChildren();
                let hasSpecial = this.checkHasSpecial(content);
                for (let i = 0; i < content.value.length; i++) {
                    let option = content.value[i];
                    let modelNode = this.selectButtonTemplate;
                    let modelType = DateSelectNodeType.Invalid;
                    let index = i;
                    let specialType = Enums_1.SpecialDateContentType.Invalid;
                    let specialStatus = Enums_1.SpecialDateContentStatus.Invalid;
                    if (this._props.isFromDate) {
                        modelType = this.getDateNodeModelType(option, hasSpecial);
                        switch (modelType) {
                            case DateSelectNodeType.SpecialGrace:
                                {
                                    modelNode = this.template_date_special;
                                    specialType = Enums_1.SpecialDateContentType.Grace;
                                    specialStatus = Enums_1.SpecialDateContentStatus.Unlocked;
                                }
                                break;
                            case DateSelectNodeType.SpecialSkin:
                                {
                                    modelNode = this.template_date_special;
                                    specialType = Enums_1.SpecialDateContentType.Skin;
                                    specialStatus = Enums_1.SpecialDateContentStatus.Unlocked;
                                }
                                break;
                            case DateSelectNodeType.GraceLocked:
                                {
                                    modelNode = this.template_date_grace_unclick;
                                    specialType = Enums_1.SpecialDateContentType.Grace;
                                    specialStatus = Enums_1.SpecialDateContentStatus.Locked;
                                }
                                break;
                            case DateSelectNodeType.SkinLocked:
                                {
                                    modelNode = this.template_date_skin_unclick;
                                    specialType = Enums_1.SpecialDateContentType.Skin;
                                    specialStatus = Enums_1.SpecialDateContentStatus.Locked;
                                }
                                break;
                            case DateSelectNodeType.Nomal_HasSpecial:
                                {
                                    modelNode = this.template_date_not_special;
                                    specialType = Enums_1.SpecialDateContentType.Nomal;
                                    specialStatus = Enums_1.SpecialDateContentStatus.Unlocked;
                                }
                                break;
                            case DateSelectNodeType.Nomal:
                                {
                                    modelNode = this.selectButtonTemplate1;
                                }
                                break;
                        }
                    }
                    if (!modelNode) {
                        return;
                    }
                    let node = cc.instantiate(modelNode);
                    node.parent = this.contentLayout.node;
                    node.active = true;
                    let label = node.getChildByName("Label").getComponent(cc.RichText);
                    if (option.content && option.content.type === AVG_1.SentenceType.TEXT && !option.summary) {
                        label.string = AVG_1.richNodesToCocosString(option.content.value);
                    }
                    else {
                        label.string = option.summary;
                    }
                    if (this._props.isFromDate && modelType === DateSelectNodeType.GraceLocked || modelType === DateSelectNodeType.SkinLocked) {
                        let tipStr = "";
                        let titleStr = "";
                        if (modelType === DateSelectNodeType.GraceLocked && option.enableCondition) {
                            let roleIdStr = option.enableCondition.groups[0].items[0].target.replace("r.like", "");
                            let role = GameModelManager_1.GameModelManager.getRoleData(parseInt(roleIdStr));
                            let graceLevel = GameModelManager_1.GameModelManager.getGraceLevelByGraceValue(parseInt(option.enableCondition.groups[0].items[0].oprand.value));
                            // tipStr = StringUtils.format(GameModelManager.getLanguageTxt(GameTextData.GAME_TEXT_GRACE_LOCKED), role?.getRoleName(), graceLevel);
                            tipStr = StringUtils_1.StringUtils.format(GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.GAME_TEXT_WEAK_GRACE_TIP_FORMAT), role === null || role === void 0 ? void 0 : role.getRoleName(), graceLevel, role === null || role === void 0 ? void 0 : role.getRoleName());
                            titleStr = GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.GAME_TEXT_WEAK_GRACE);
                        }
                        else if (modelType === DateSelectNodeType.SkinLocked && option.enableCondition) {
                            // let roleIdStr = option.enableCondition.groups[0].items[0].target.replace("r.skin", "");
                            // let role = GameModelManager.getRoleData(parseInt(roleIdStr));
                            // let v = parseInt(option.enableCondition.groups[0].items[0].oprand.value);
                            // let skinName = GameModelManager.getI18LanguageTxt(ConfigManager.getConfig(itemConfig, v).name);
                            // // tipStr = StringUtils.format(GameModelManager.getLanguageTxt(GameTextData.GAME_TEXT_SKIN_LOCKED), role?.getRoleName(), skinName);
                            // tipStr = StringUtils.format(GameModelManager.getLanguageTxt(GameTextData.GAME_TEXT_INVALID_SKIN_TIP_FORMAT), role?.getRoleName(), skinName);
                            // titleStr = GameModelManager.getLanguageTxt(GameTextData.GAME_TEXT_INVALID_SKIN);
                        }
                        node.on("click", () => {
                            // UIManager.showToast(tipStr);
                            this.showSpecialPlotTip(titleStr, tipStr);
                            if (this._props.isFromDate && hasSpecial && this._props.dateSceneId && this._props.plotId) {
                                GameDotMgr_1.default.getInstance().dotSpecialPlot(this._props.dateSceneId, this._props.plotId, index, specialType, specialStatus);
                            }
                        });
                    }
                    else {
                        node.on("click", this.onButtonClick(index, hasSpecial, specialType, specialStatus));
                    }
                }
            };
            this.showSpecialPlotTip = (title, content) => {
                let temp = {
                    dataptr: {},
                    titlecontent: title,
                    content: content,
                    ishasad: false,
                    istwobtn: false,
                    adconfig: "",
                    // items: [],
                    hasBanner: false,
                    callback: () => {
                    }
                    // location: CommonLocation.Event
                };
                UIManager_1.UIManager.pushPresenter(AlertDialogViewPresenter_1.default, temp);
            };
            this.getDateNodeModelType = (sentenceOption, hasSpeical) => {
                let modelType = hasSpeical ? DateSelectNodeType.Nomal : DateSelectNodeType.Nomal;
                if (sentenceOption.enableCondition) {
                    let ret = GameModelManager_1.GameModelManager.checkSkinAndGraceCondition(sentenceOption.enableCondition);
                    if (sentenceOption.enableCondition.groups && sentenceOption.enableCondition.groups.length > 0
                        && sentenceOption.enableCondition.groups[0].items
                        && sentenceOption.enableCondition.groups[0].items.length > 0
                        && sentenceOption.enableCondition.groups[0].items[0].target) {
                        if (sentenceOption.enableCondition.groups[0].items[0].target.startsWith("r.like")) {
                            modelType = ret ? DateSelectNodeType.SpecialGrace : DateSelectNodeType.GraceLocked;
                        }
                        // else if (sentenceOption.enableCondition.groups[0].items[0].target.startsWith("r.skin")) {
                        //     modelType = ret ? DateSelectNodeType.SpecialSkin : DateSelectNodeType.SkinLocked;
                        // }
                    }
                }
                return modelType;
            };
        }
        checkHasSpecial(content) {
            let hasSpecial = false;
            if (!content || !content.value || !content.value.length) {
                return false;
            }
            for (let i = 0; i < content.value.length; i++) {
                let sentenceOption = content.value[i];
                if (sentenceOption && sentenceOption.enableCondition) {
                    if (sentenceOption.enableCondition.groups && sentenceOption.enableCondition.groups.length > 0
                        && sentenceOption.enableCondition.groups[0].items
                        && sentenceOption.enableCondition.groups[0].items.length > 0
                        && sentenceOption.enableCondition.groups[0].items[0].target) {
                        if ((sentenceOption.enableCondition.groups[0].items[0].target.startsWith("r.like")) ||
                            (sentenceOption.enableCondition.groups[0].items[0].target.startsWith("r.skin"))) {
                            hasSpecial = true;
                            break;
                        }
                    }
                }
            }
            return hasSpecial;
        }
        open(parent) {
            super.open(parent);
            this.background.node.opacity = 0;
        }
        onPropsReceive() {
            super.onPropsReceive();
            this.background.node.opacity = 255;
        }
        onLoad() {
            this.bindProp("sentence", async (value) => {
                if (value != null)
                    this.setContent(value);
            });
            this.bindProp("backgroundpath", async (value) => {
                if (value !== "") {
                    this.background.spriteFrame = await simba_cc_resutils_1.ResUtils.loadRes(value, cc.SpriteFrame);
                }
                else {
                    this.background.spriteFrame = undefined;
                }
            });
            this.bindProp("y", (v) => {
                if (v === undefined) {
                    this.background.getComponent(cc.Widget).enabled = true;
                    this.background.node.y = -this.node.height / 2;
                }
                else {
                    this.background.getComponent(cc.Widget).enabled = false;
                    this.background.node.y = v;
                }
            });
            this.bindProp("clickcausehide", async (value) => {
                this.node.off(cc.Node.EventType.TOUCH_END);
                this.background.node.off(cc.Node.EventType.TOUCH_END);
                if (this._props.clickcausehide) {
                    this.node.on(cc.Node.EventType.TOUCH_END, this.onCloseHandleClick, this);
                    this.background.node.on(cc.Node.EventType.TOUCH_END, this.onCloseHandleClick, this);
                }
            });
        }
        onPropsLoad(props) {
            super.onPropsLoad(props);
        }
        onCloseHandleClick(event) {
            this.close();
        }
        onPropChange(key) {
            super.onPropChange(key);
        }
    };
    __decorate([
        property(cc.Sprite)
    ], SentenceSelectorViewImpl.prototype, "background", void 0);
    __decorate([
        property(cc.Layout)
    ], SentenceSelectorViewImpl.prototype, "contentLayout", void 0);
    __decorate([
        property(cc.Node)
    ], SentenceSelectorViewImpl.prototype, "selectButtonTemplate", void 0);
    __decorate([
        property(cc.Node)
    ], SentenceSelectorViewImpl.prototype, "selectButtonTemplate1", void 0);
    __decorate([
        property(cc.Node)
    ], SentenceSelectorViewImpl.prototype, "template_date_special", void 0);
    __decorate([
        property(cc.Node)
    ], SentenceSelectorViewImpl.prototype, "template_date_grace_unclick", void 0);
    __decorate([
        property(cc.Node)
    ], SentenceSelectorViewImpl.prototype, "template_date_skin_unclick", void 0);
    __decorate([
        property(cc.Node)
    ], SentenceSelectorViewImpl.prototype, "template_date_not_special", void 0);
    SentenceSelectorViewImpl = __decorate([
        ccclass,
        PresenterCCViewFactory_1.RegView(SentenceSelectorView_1.SentenceSelectorViewType, "prefab/ui/SentenceSelectorView")
    ], SentenceSelectorViewImpl);
    return SentenceSelectorViewImpl;
})();
exports.default = SentenceSelectorViewImpl;

cc._RF.pop();