LikeLevelSubpresenter.ts
1.9 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
import { GameRecord } from "../../../avg/AVG";
import { RoleType } from "../../../avg/EditorEnums";
import { Subpresenter } from "../../../common/classbase/PresenterBase";
import { GameConfig } from "../../../GameConfig";
import { GameModelManager } from "../../model/GameModelManager";
import GameRoleDataModel from "../../model/GameRoleDataModel";
import { RegSubpresenter } from "../PresenterCCViewFactory";
import { LikeLevelView, LikeLevelViewType } from "../view/type/LikeLevelSubview";
@RegSubpresenter(LikeLevelViewType)
export class LikeLevelSubpresenter extends Subpresenter<LikeLevelView> {
onOpen() {
super.onOpen();
if (!(this.owner as any)["getRoleId"]) {
console.error("owner need provide roleId by getRoleId");
return;
}
let roleId = (this.owner as any)["getRoleId"]() as number;
let roleData = GameModelManager.getRoleData(roleId)!;
if (roleData.getConfig().RoleType === RoleType.Role_Major) {
this.updateView(roleData);
this._disposable.add(GameRecord.onRecordVariableChange("like" + roleId, () => {
this.updateView(roleData);
}));
this._disposable.add(GameRecord.onGlobalVariableChange("like" + roleId, () => {
this.updateView(roleData);
}));
} else {
let likestr = GameConfig.debug ? "0" : "";
this.view.setProps({ visible: false, level: 0, percent: 0, like: likestr });
}
}
updateView(role: GameRoleDataModel) {
let data = role.getRoleLikeLevel();
data.currLike = data.currLike ? data.currLike : 0;
let v = role.getRoleLike();
let value = GameConfig.debug && v ? v as unknown as string : "";
this.view.setProps({ visible: true, level: data.level ? data.level : 0, percent: data.level === data.maxLevel ? 1 : (data.currLike / data.nextLevelLike), like: value });
}
}