DiscoverViewImpl.ts 3.82 KB
import { SDK } from "simba-sdk";
import { DummyButton, DummyLabel, DummyNode, DummySprite } from "../../../../common/CCDummyObjects";
import { CCPureView } from "../../../../common/classbase/CCViewBase";
import { ResUtils } from "simba-cc-resutils";
import { RegView } from "../../PresenterCCViewFactory";
import { DiscoverView, DiscoverViewProps, DiscoverViewType } from "../type/DiscoverView";
import { DiscoverItemType } from "../../../Enums";

const enum Tabs {
    forum,
    edit,
    customerService,
    productionTeam,
};

const { ccclass, property } = cc._decorator;
@ccclass
@RegView(DiscoverViewType, "prefab/ui/DiscoverView")
export class DiscoverViewImpl extends CCPureView<DiscoverViewProps> implements DiscoverView {
    //#region editor bindings
    // @property({ type: cc.Label, tooltip: "人物名字" })
    // private manName: cc.Label = DummyLabel;
    @property({ type: cc.Label, tooltip: "人物 ID" })
    private manId: cc.Label = DummyLabel;
    @property({ type: cc.Sprite, tooltip: "人物头像" })
    private menSprite: cc.Sprite = DummySprite;
    @property({ type: cc.Node, tooltip: "人物根结点" })
    private infoRootNode: cc.Node = DummyNode;
    @property({ type: cc.Button, tooltip: "论坛按钮" })
    private forum: cc.Button = DummyButton;

    onLoad() {
        // this.bindProp("manName", this.manName, "string");
        this.bindProp("manId", this.manId, "string");
        this.bindProp("manIcon", async (value) => {
            if (value != "")
                this.menSprite.spriteFrame = await ResUtils.loadRes(value, cc.SpriteFrame);
        });

        this.infoRootNode.on(cc.Node.EventType.TOUCH_END, this.onTouchMainInfo, this);
    }

    createGameClubBtn = () => {
        this.node.getComponent(cc.Widget).updateAlignment();
        this.node.getComponent(cc.Layout).updateLayout();
        let info = SDK.systemInfo.displayInfo;
        let aspect = info.windowSize.height / cc.view.getVisibleSize().height;
        this.node.getComponent(cc.Widget).updateAlignment();

        let pos = this.forum.node.convertToWorldSpaceAR(cc.v2(0, 0));
        pos.x += cc.view.getViewportRect().x / cc.view.getScaleX();
        let xPos = pos.x * aspect;
        let yPos = info.windowSize.height - pos.y * aspect;
        let width = this.forum.node.width * aspect;
        let height = this.forum.node.height * aspect;
        let left = xPos - width / 2;
        let top = yPos - height / 2;

        // this.forum.node.active = false;
        SDK.createGameClubButton({
            type: "text",
            text: "",
            style: {
                left: left,
                top: top,
                width: width,
                height: height
            },
            icon: "green"
        });
    }

    onForumCallback() {

    }

    onTabClick(target: cc.Button, data: string) {
        switch (parseInt(data)) {
            case Tabs.forum:
                // GameDotMgr.getInstance().dotClickUI("click_forum");
                this._props.onItemClick(DiscoverItemType.Forum);
                break;
            case Tabs.edit:
                // GameDotMgr.getInstance().dotClickUI("click_setting");
                this._props.onItemClick(DiscoverItemType.Settings);
                break;
            case Tabs.customerService:
                // GameDotMgr.getInstance().dotClickUI("click_customerService");
                this._props.onItemClick(DiscoverItemType.CustomerService);
                break;
            case Tabs.productionTeam:
                this._props.onItemClick(DiscoverItemType.ProductionTeam);
                break;
        }
    }

    onPropsLoad(props: Readonly<DiscoverViewProps>) {
        super.onPropsLoad(props);
    }

    onPropChange(key: Extract<keyof DiscoverViewProps, string>) {
        super.onPropChange(key);
    }

    onTouchMainInfo = () => {
        this._props.onCopyInfo();
    }
}