LikeLevelSubpresenter.ts
1.61 KB
import { RegSubpresenter } from "../PresenterCCViewFactory";
import { LikeLevelViewType, LikeLevelView } from "../view/type/LikeLevelSubview";
import { Subpresenter } from "../../../common/classbase/PresenterBase";
import { GameModelManager } from "../../model/GameModelManager";
import { RoleType } from "../../../avg/EditorEnums";
import GameRoleDataModel from "../../model/GameRoleDataModel";
import { GameRecord } from "../../../avg/game-data/GameRecord";
@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 {
this.view.setProps({ visible: false, level: 0, percent: 0 });
}
}
updateView(role: GameRoleDataModel) {
let data = role.getRoleLikeLevel();
this.view.setProps({ visible: true, level: data.level, percent: data.level === data.maxLevel ? 1 : (data.currLike / data.nextLevelLike) });
}
}