DiscoverSettingViewPresenter.ts 2.69 KB
import { AudioSettings } from "simba-cc-audio-manager";
import { SDK } from "simba-sdk";
import { PageIndex } from "../../../../avg/EditorEnums";
import { Presenter } from "../../../../common/classbase/PresenterBase";
import { GameTextData } from "../../../../common/gameplay/gamedata/GameTextData";
import { UIManager } from "../../../../common/gameplay/managers/UIManager";
import GameDotMgr from "../../../GameDotMgr";
import { GameModelManager } from "../../../model/GameModelManager";
import { RegPresenter } from "../../PresenterCCViewFactory";
import { DiscoverSettingView, DiscoverSettingViewType } from "../../view/type/discover/DiscoverSettingView";
import { SourceView } from "../../view/type/notice/NewNoticeView";
import ExchangeCodeViewPresenter from "../ExchangeCodeViewPresenter";
import NewNoticeViewPresenter from "../notice/NewNoticeViewPresenter";

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

    onOpen() {
        super.onOpen(undefined);
        this.view.setProps({
            soundEnabled: AudioSettings.soundVolume > 0,
            musicEnabled: AudioSettings.musicVolume > 0,
            onToggleSound: this.toggleSound,
            onToggleMusic: this.toggleMusic,
            onToggleNotice: this.toggleNotice,
            onToggleExchangeCode: this.toggleExchangeCode
        });
        this._disposable.add(GameModelManager.CloseSettingView.on(this.onCloseSettingView));
    }

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

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

    toggleNotice = () => {//公告
        UIManager.pushPresenter(NewNoticeViewPresenter, SourceView.SettingView);
    }

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

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

    onCloseSettingView = (index: PageIndex) => {
        this.view.close(true);
        GameModelManager.JumpToViewInGame.emit(index);
    }
}