a21abc61-863d-4b61-9f90-995f04a35c25.js 5.35 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 CCDummyObjects_1 = require("../../../../../common/CCDummyObjects");
const PlotModel_1 = require("../../../../../avg/model/PlotModel");
const RichTextUtils_1 = require("../../../../../avg/utils/RichTextUtils");
const PresenterCCViewFactory_1 = require("../../../PresenterCCViewFactory");
const SentenceSelectorView_1 = require("../../type/SentenceSelectorView");
const CCViewBase_1 = require("../../../../../common/classbase/CCViewBase");
const ResUtils_1 = require("../../../../../common/utils/ResUtils");
const { ccclass, property } = cc._decorator;
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;
            //#endregion
            this.onButtonClick = (index) => {
                return () => {
                    this._props.onSelectIndexCallback(index);
                };
            };
            this.setContent = (content) => {
                this.contentLayout.node.removeAllChildren();
                for (let i = 0; i < content.value.length; i++) {
                    let option = content.value[i];
                    let node = cc.instantiate(this._props.optionStyle1 ? this.selectButtonTemplate1 : this.selectButtonTemplate);
                    node.parent = this.contentLayout.node;
                    node.active = true;
                    let label = node.getChildByName("Label").getComponent(cc.RichText);
                    if (option.content && option.content.type === PlotModel_1.SentenceType.TEXT && !option.summary) {
                        label.string = RichTextUtils_1.richNodesToCocosString(option.content.value);
                    }
                    else {
                        label.string = option.summary;
                    }
                    node.on("click", this.onButtonClick(i));
                }
            };
        }
        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 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;
                }
            });
        }
        onPropsLoad(props) {
            super.onPropsLoad(props);
            if (this._props.clickcausehide) {
                this.node.on(cc.Node.EventType.TOUCH_END, this.onCloseHandleClick, this);
            }
            else {
                this.node.off(cc.Node.EventType.TOUCH_END);
            }
        }
        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);
    SentenceSelectorViewImpl = __decorate([
        ccclass,
        PresenterCCViewFactory_1.RegView(SentenceSelectorView_1.SentenceSelectorViewType, "prefab/ui/SentenceSelectorView")
    ], SentenceSelectorViewImpl);
    return SentenceSelectorViewImpl;
})();
exports.default = SentenceSelectorViewImpl;

cc._RF.pop();