DiscoverViewPresenter.ts 4.08 KB
import { SDK } from "simba-sdk";
import { GameRecord } from "../../../avg/AVG";
import { Presenter } from "../../../common/classbase/PresenterBase";
import { UIManager } from "../../../common/gameplay/managers/UIManager";
import { GameModelManager } from "../../model/GameModelManager";
import { RegPresenter } from "../PresenterCCViewFactory";
import { DiscoverView, DiscoverViewProps, DiscoverViewType } from "../view/type/DiscoverView";
import { DiscoverSettingViewPresenter } from "./discover/DiscoverSettingViewPresenter";
import { GameTextData } from "../../../common/gameplay/gamedata/GameTextData";
import { DiscoverItemType } from "../../Enums";
import QRCodeViewPresenter from "./QRCodeViewPresenter";
import GameDotMgr from "../../GameDotMgr";
import ProductionTeamViewPresenter from "./discover/ProductionTeamViewPresenter";

@RegPresenter(DiscoverViewType)
export default class DiscoverViewPresenter extends Presenter<undefined, DiscoverView>  {
    static uuid = "DiscoverViewPresenter";

    private _viewProps: DiscoverViewProps;

    static isShowRedDot() {
        return false;
    }

    constructor() {
        super();
    }

    initViewProps() {
        this._viewProps = {
            manName: "",
            manId: "",
            manIcon: "",
            onCopyInfo: this.onCopyInfo,
            onItemClick: this.itemClickCallBack
        };
    }

    itemClickCallBack = (itemType: DiscoverItemType) => {
        switch (itemType) {
            case DiscoverItemType.Settings:
                this.hideGameClubBtn();
                UIManager.pushPresenter(DiscoverSettingViewPresenter, undefined);
                break;
            case DiscoverItemType.Forum:
                break;
            case DiscoverItemType.CustomerService:
                this.hideGameClubBtn();
                //点击二维码打点
                GameDotMgr.getInstance().dotClickUI("CustomerService");
                UIManager.pushPresenter(QRCodeViewPresenter, undefined);
                break;
            case DiscoverItemType.ProductionTeam:
                this.hideGameClubBtn();
                //点击二维码打点
                UIManager.pushPresenter(ProductionTeamViewPresenter, undefined);
                break;
            default:
                UIManager.showToast(GameModelManager.getLanguageTxt(GameTextData.GAME_TEXT_DEVELOPING_VALUE));
                break;
        }
    }

    onCopyInfo = async () => {
        await SDK.setClipboardData(this._viewProps.manId);
        UIManager.showToast("用户ID:" + this._viewProps.manId);
    }

    initItemConfig() {
        this._viewProps.manName = GameRecord.globalVariables.playerName;
        if (SDK.getLoginInfo()?.playerId) {
            this._viewProps.manId = SDK.getLoginInfo()?.playerId as string;
        }
        let player = GameModelManager.getPlayerData();
        this._viewProps.manName = player.getConfig().name;
        this._viewProps.manIcon = player.getHeadIcon();
    }

    onOpen() {
        super.onOpen(undefined);
        this._disposable.add(GameModelManager.PlayerOptionSkin.on(this.onPlayerOptionSkin));
        this._disposable.add(GameModelManager.ForceEnterDiscoverSubView.on(this.onForceEnterDiscoverSubView));
        this.onShow();
    }

    onForceEnterDiscoverSubView = (itemType: DiscoverItemType) => {
        this.itemClickCallBack(itemType);
    }

    onPlayerOptionSkin = () => {
        this.initViewProps();
        this.initItemConfig();
        this._view.updateProps(this._viewProps);
    }

    onShow() {
        super.onShow();
        this.initViewProps();
        this.initItemConfig();
        this.view.setProps(this._viewProps);
        this.view.createGameClubBtn();
        this.showGameClubBtn();
    }

    onEnterBackground() {
        super.onEnterBackground();
        this.hideGameClubBtn();
    }

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

    onHide() {
        super.onHide();
        SDK.destroyGameClubButton();
    }

    showGameClubBtn() {
        SDK.showGameClubButton();
    }

    hideGameClubBtn() {
        SDK.hideGameClubButton();
    }
}