MainInfoViewSubpresenter.ts
4.37 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { delay } from "simba-utils";
import { GameRecord } from "../../../avg/AVG";
import { Subpresenter } from "../../../common/classbase/PresenterBase";
import { GameConstData } from "../../../common/gameplay/gamedata/GameConstData";
import { GameTextData } from "../../../common/gameplay/gamedata/GameTextData";
import { UIManager } from "../../../common/gameplay/managers/UIManager";
import { StringUtils } from "../../../common/utils/StringUtils";
import { GamePropType } from "../../Enums";
import { GameModelManager } from "../../model/GameModelManager";
import { RegSubpresenter } from "../PresenterCCViewFactory";
import { UIUtils } from "../UIUtils";
import { MainInfoSubview, MainInfoSubviewProps, MainInfoSubviewType } from "../view/type/MainInfoSubviewiew";
@RegSubpresenter(MainInfoSubviewType)
export class MainInfoViewSubpresneter extends Subpresenter<MainInfoSubview> {
constructor() {
super();
this._viewProps = {
energy: 1,
energycontent: "100%",
energybackindex: 0, //背景
timecontent: "",
onClick: this.onEnergyClickCallback
};
}
updateEnergy = () => {
// let player = GameModelManager.getPlayerData();
// let e = player.getEnergy();
// if (GameConfig.debug) {
// const OFFSETTIME = 1200000;
// const CYCLETIME = 1000;
// const ADDENERGY = GameConstData.GAME_CONST_PLOT_ENERGY_COST_VALUE;
// setTimeout(() => {
// let cachetime = GameRecord.globalVariables["autoaddenergy"];
// if (cachetime === undefined || e === 100) {
// cachetime = TimeManager.getTime() + OFFSETTIME;
// GameRecord.globalVariables["autoaddenergy"] = cachetime;
// GameRecord.autoSave();
// }
// let curtime = TimeManager.getTime();
// let deltime = (cachetime - curtime) / 1000;
// this._viewProps.timecontent = deltime.toFixed(0) + "秒";
// this.view.setProps(this._viewProps);
// this.updateEnergy();
// }, 1000);
// }
}
onEnergyClickCallback = async () => {
let player = GameModelManager.getPlayerData();
let e = player.getEnergy();
if (e == 0) {
await this.tipAddEnergy();
} else {
UIManager.showToast(StringUtils.format(GameModelManager.getLanguageTxt(GameTextData.GAME_TEXT_MAIN_ENERGY_VALUE), e));
}
}
async tipAddEnergy() {
// let player = GameModelManager.getPlayerData();
// // TODO 提示体力不足,跳转购买体力?
// let ret = await UIUtils.showAddEnergy(GameModelManager.getItemConfig(GameConstData.GAME_CONST_ENERGY_PROPS_ID), player.getProps(GameConstData.GAME_CONST_ENERGY_PROPS_ID));
// if (ret) {
// let itemconfig = GameModelManager.getItemConfig(GameConstData.GAME_CONST_ENERGY_PROPS_ID);
// player.addEnergy(itemconfig.energy_recover - GameConstData.GAME_CONST_PLOT_ENERGY_COST_VALUE);
// UIManager.showToast(GameModelManager.getLanguageTxt(GameTextData.GAME_TEXT_MAIN_ENERGY_ADADDSUCCESS_VALUE));
// }
}
onOpen() {
super.onOpen();
this.initData();
}
_viewProps: MainInfoSubviewProps;
initEnergy = () => {
let player = GameModelManager.getPlayerData();
let max = 100;
let value = player.getEnergy();
value = value ? value : 0;
let percent = value / max;
this._viewProps.energy = percent;
this._viewProps.energycontent = value + "%";
let index = 0;
if (value >= 70 && value <= 100) {
index = 0;
} else if (value >= 21 && value <= 69) {
index = 1;
} else {
index = 2;
}
this._viewProps.energybackindex = index;
this.view.setProps(this._viewProps);
}
initData = async () => {
while (!GameModelManager.getPlayerData()) await delay(0.1);
let k = "prop_" + GameModelManager.getPlayerData().getConfig().id + "_" + GamePropType.Energy + "_num";
GameRecord.onGlobalVariableChange(k, () => {
this.initEnergy();
});
this.initEnergy();
this.updateEnergy();
}
onOwnerEnterBackground() {
// console.log("on owner enter background");
}
}