DatingEventViewPresenter.ts 3.37 KB
import { Presenter, Subpresenter } from "../../../common/classbase/PresenterBase";
import { DatingEventViewType, DatingEventView } from "../view/type/DatingEventView";
import { RegPresenter, RegSubpresenter } from "../PresenterCCViewFactory";
import { DatingEventSubviewType, DatingEventItemProps, DatingEventSubview } from "../view/type/DatingEventSubview";
import { GameModelManager } from "../../model/GameModelManager";
import { DatingEventSceneModel, DatingEventStatus } from "../../model/DatingEventSceneModel";
import { UIManager } from "../../../common/gameplay/managers/UIManager";
import { DatingScenePresenter } from "./DatingScenePresenter";

@RegPresenter(DatingEventViewType)
export default class DatingEventViewPresenter extends Presenter<undefined, DatingEventView> {
    static uuid = "DatingEventViewPresenter";

    onOpen() {
        super.onOpen(undefined);
        this.checkRedDot();
    }

    onEnterForeground() {
        super.onEnterForeground();
        this.checkRedDot();
    }

    onShow() {
        super.onShow();
        this.checkRedDot();
    }

    private checkRedDot() {
        let mainRedDot = false;
        for (let model of GameModelManager.getMainDatingEventScenesModel()) {
            if (model.status === DatingEventStatus.New || model.status === DatingEventStatus.InProgress) {
                mainRedDot = true;
            }
        }
        this.view.setProps({ mainEventRedDot: mainRedDot, extraEventRedDot: false });
    }
}

@RegSubpresenter(DatingEventSubviewType)
export class DatingEventSubpresenter extends Subpresenter<DatingEventSubview> {
    // private _items: DatingEventItemProps[];
    private _lineStyle: 0 | 1 = 0;
    private _modelMap: { [key: string]: DatingEventSceneModel } = {};

    private sceneModelToViewModel(item: DatingEventSceneModel): DatingEventItemProps {
        this._modelMap[item.id] = item;
        return {
            key: item.id + "",
            title: item.config.name,
            date: item.config.date,
            time: item.config.time,
            status: item.status,
            coverImage: "textures/dating_event/cover/" + item.config.background,
            lineStyle: this._lineStyle
        }
    }

    refreshItems() {
        // if (!this._items) {
        if (this.view.name.indexOf("MainEvent") < 0) this._lineStyle = 1;
        let items: DatingEventItemProps[] = [];
        if (this.view.name.indexOf("MainEvent") === 0) {
            items = GameModelManager.getMainDatingEventScenesModel().map(v => this.sceneModelToViewModel(v));
            if (items.length) {
                items[items.length - 1].lineStyle = "none";
            }
        }
        this.view.setProps({
            items, onItemClick: (key: string) => {
                console.log("start dating event", key);
                UIManager.pushPresenter(DatingScenePresenter, this._modelMap[key], true);
            }
        });
        // } else {
        //     this.view.updateProps({ items: [...this._items] });
        // }
    }

    onOwnerShow() {
        if (!this.view.isHidden) {
            this.refreshItems();
        }
    }

    onOwnerEnterForeground() {
        if (!this.view.isHidden) {
            this.refreshItems();
        }
    }

    onOpen() {
        super.onOpen();
        if (!this.view.isHidden) {
            this.refreshItems();
        }
    }

    onShow() {
        this.refreshItems();
    }

    onHide() {

    }
}