MainViewImpl.ts 2.74 KB
import { DummyLabel, DummyNode, DummySprite } from "../../../../common/CCDummyObjects";
import { CCPureView, CCView } from "../../../../common/classbase/CCViewBase";
import { View } from "../../../../common/classbase/ViewBase";
import { UIManager } from "../../../../common/gameplay/managers/UIManager";
import { DiscoverSettingViewPresenter } from "../../presenter/discover/DiscoverSettingViewPresenter";
import { RegView } from "../../PresenterCCViewFactory";
import { MainView, MainViewProps, MainViewType } from "../type/MainView";
const { ccclass, property } = cc._decorator;

@ccclass
@RegView(MainViewType, "prefab/ui/MainView")
export class MainViewImpl extends CCPureView<MainViewProps> implements MainView {
    //#region editor bindings
    @property({ type: cc.Node })
    private contentParent: cc.Node = DummyNode;
    @property({ type: cc.Sprite })
    private titleSprite: cc.Sprite = DummySprite;
    @property({ type: [cc.Button], displayName: "Tabbar Buttons" })
    private tabbarButtons: cc.Button[] = [];
    @property({ type: [cc.SpriteFrame], displayName: "Tabbar Spriteframes" })
    private tabbarSpriteFrames: cc.SpriteFrame[] = [];
    @property({ type: [cc.SpriteFrame], displayName: "Title Spriteframes" })
    private titleSpriteFrames: cc.SpriteFrame[] = [];

    onTabButtonClick = (event, index: string) => {
        this._props.onTabClick(parseInt(index));
    }

    private _tabContentContainer: View;


    onLoad() {
        this._tabContentContainer = this.contentParent.addComponent(CCView);

        this.bindProp("messageRedDot", this.tabbarButtons[0].node.getChildByName("RedDot"), "active");
        this.bindProp("datingEventRedDot", this.tabbarButtons[1].node.getChildByName("RedDot"), "active");
    }




    getTabContentContainer(): View {
        return this._tabContentContainer;
    }

    onPropsLoad(props: Readonly<MainViewProps>) {
        super.onPropsLoad(props);
        let currTab = this._props.selectedTab;
        this.tabbarButtons[currTab].normalSprite = this.tabbarSpriteFrames[currTab * 2 + 1];
        this.titleSprite.spriteFrame = this.titleSpriteFrames[currTab];
    }

    onPropChange(key: Extract<keyof MainViewProps, string>) {
        super.onPropChange(key);
        if (key === "selectedTab") {
            let prevTab = this._prevProps.selectedTab;
            this.tabbarButtons[prevTab].normalSprite = this.tabbarSpriteFrames[prevTab * 2];
            let currTab = this._props.selectedTab;
            this.tabbarButtons[currTab].normalSprite = this.tabbarSpriteFrames[currTab * 2 + 1];
            this.titleSprite.spriteFrame = this.titleSpriteFrames[currTab];
        }
    }

    onSettingClick(event:cc.Event.EventTouch,eventData:string){
        UIManager.pushPresenter(DiscoverSettingViewPresenter,undefined);
    }
}