DiscoverSettingViewPresenter.ts
2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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);
}
}