SamsaraGame/assets/Script/ts/horse/HorseSkillMap.ts
2025-04-24 17:03:28 +08:00

111 lines
3.8 KiB
TypeScript

import FGUtil from "../gear_2.3.4/fgui/FGUtil";
import SkillUtil from "../game/skill/core/SkillUtil";
import SkillBase, { ESkillQuality } from "../game/skill/core/SkillBase";
import SKUIUtil from "../gear_2.3.4/util/SKUIUtil";
// 坐騎技能圖鑑
export default class HorseSkillMap {
static shared = new HorseSkillMap();
horseIndex: number = 1;
gridIndex: number = 1;
current: any[];
main: fgui.GComponent;
alert: fgui.GComponent;
skillList: fgui.GList;
skillNameLabel: fgui.GTextField;
skillIcon: fgui.GComponent;
skillDescRTF: fgui.GRichTextField;
constructor() {
}
show(horseIndex: number) {
this.horseIndex = horseIndex;
this.loadUI();
}
hide() {
FGUtil.dispose(this.main);
this.main = null;
}
onDestory() {
this.hide();
}
loadUI() {
FGUtil.dispose(this.main);
this.main = fgui.UIPackage.createObject("main_ui", "horse_skill_map").asCom;
FGUtil.root().addChild(this.main);
FGUtil.fitScreen(this.main);
this.alert = FGUtil.getComponent(this.main, "alert");
this.alert.getController("tab").onChanged(this.changeTab, this);
let canvasHeight = cc.view.getCanvasSize().height;
let winHeight = cc.view.getCanvasSize().height;
let frameHeight = cc.view.getFrameSize().height;
this.skillList = FGUtil.getList(this.alert, "skill_list");
this.skillIcon = FGUtil.getComponent(this.alert, "skill_icon");
this.skillNameLabel = FGUtil.getTextField(this.alert, "skill_name");
this.skillDescRTF = FGUtil.getRichTextField(this.alert, "skill_desc");
this.refreshList();
this.alert.getChild("close_btn").onClick(this.hide, this);
}
changeTab(event: fgui.Event) {
this.gridIndex = this.alert.getController("tab").selectedIndex + 1;
this.refreshList();
}
refreshList() {
this.current = SkillUtil.getHorseSkillGroup((this.horseIndex - 1) * 3 + this.gridIndex - 1);
this.skillList.removeChildrenToPool();
for (let skillId of this.current) {
let skill: SkillBase = SkillUtil.getHorseSkill(skillId);
if (skill == null) {
continue;
}
let cell = this.skillList.addItemFromPool().asButton;
let icon = `ui://main_ui/${skill.icon}`;
if (skill.quality == ESkillQuality.LOW) {
cell.getController("type").selectedIndex = 0;
} else {
cell.getController("type").selectedIndex = 1;
}
cell.icon = icon;
}
this.skillList.selectedIndex = 0;
this.skillList.scrollToView(0, true, true);
this.refreshSkill();
this.skillList.on(fgui.Event.CLICK_ITEM, this.onClickSkillItem, this);
}
onClickSkillItem(item: fgui.GObject) {
let index = this.skillList.getChildIndex(item);
this.skillList.selectedIndex = index;
this.refreshSkill();
}
refreshSkill() {
let skillId = this.current[this.skillList.selectedIndex];
if (!skillId) {
return;
}
let skill: SkillBase = SkillUtil.getHorseSkill(skillId);
this.skillIcon.icon = `ui://main_ui/${skill.icon}`;
if (skill.quality == ESkillQuality.LOW) {
this.skillIcon.getController("type").selectedIndex = 0;
this.skillNameLabel.color = SKUIUtil.colorOfString("#6D0903");
} else {
this.skillIcon.getController("type").selectedIndex = 1;
this.skillNameLabel.color = SKUIUtil.colorOfString("#CA84F8");
}
this.skillNameLabel.text = skill.name;
let text = "";
text = skill.desc;
text += skill.getSkillDesc(1, 0);
this.skillDescRTF.ubbEnabled = true;
this.skillDescRTF.text = text;
}
}