DiscoverSettingViewPresenter.ts 2.76 KB
import { RegPresenter } from "../../PresenterCCViewFactory";
import { DiscoverSettingViewType, DiscoverSettingView } from "../../view/type/discover/DiscoverSettingView";
import { Presenter } from "../../../../common/classbase/PresenterBase";
import { GameBasicSettings } from "../../../../common/gameplay/settings/GameBasicSettings";
import { HttpRequests } from "../../../network/HttpRequests";
import { GameModelManager } from "../../../model/GameModelManager";
import { GameTextData } from "../../../../common/gameplay/gamedata/GameTextData";
import { UIManager } from "../../../../common/gameplay/managers/UIManager";
import NoticeViewPresenter from "../NoticeViewPresenter";
import { GameConfig } from "../../../../GameConfig";
import ExchangeCodeViewPresenter from "../ExchangeCodeViewPresenter";

@RegPresenter(DiscoverSettingViewType)
export class DiscoverSettingViewPresenter extends Presenter<undefined, DiscoverSettingView> {
    static uuid = "DiscoverSettingViewPresenter";

    onOpen() {
        super.onOpen(undefined);
        this.view.setProps({
            soundEnabled: GameBasicSettings.soundVolume > 0,
            musicEnabled: GameBasicSettings.musicVolume > 0,
            onToggleSound: this.toggleSound,
            onToggleMusic: this.toggleMusic,
            onToggleNotice: this.toggleNotice,
            onToggleExchangeCode: this.toggleExchangeCode
        })
    }

    toggleSound = () => {
        GameBasicSettings.soundVolume = GameBasicSettings.soundVolume > 0 ? 0 : 1;
        this.view.updateProps({
            soundEnabled: GameBasicSettings.soundVolume > 0
        });
    }

    toggleMusic = () => {
        GameBasicSettings.musicVolume = GameBasicSettings.musicVolume > 0 ? 0 : 1;
        this.view.updateProps({
            musicEnabled: GameBasicSettings.musicVolume > 0
        });
    }

    toggleNotice = () => {//公告
        HttpRequests.getNotice().then((ret) => {
            if (ret != null && ret.length > 0) {
                let titleTxt = GameModelManager.getLanguageTxt(GameTextData.TEXT_NOTICETITLE_VALUE);
                let contentTxt = ret[0].msg;
                UIManager.pushPresenter(NoticeViewPresenter, {
                    title: titleTxt,
                    content: contentTxt
                });
            } else {
                console.log("notice is not setting:" + `notice_${GameConfig.gameVersion}.json`);
            }
        });
    }

    toggleExchangeCode = () => {//兑换码 
        let title = GameModelManager.getLanguageTxt(GameTextData.TEXT_EXCHANGETITLE_VALUE);
        let content = "";
        UIManager.pushPresenter(ExchangeCodeViewPresenter, {
            titletxt: title,
            contenttxt: content
        });
    }

    onClose() {
        super.onClose();
        UIManager.popToPresenter(this);
    }
}