159 lines
5.2 KiB
TypeScript
159 lines
5.2 KiB
TypeScript
import GameModel from "../../core/GameModel";
|
|
import ItemUtil from "../../core/ItemUtil";
|
|
import FGUtil from "../../gear_2.3.4/fgui/FGUtil";
|
|
import SKDataUtil from "../../gear_2.3.4/util/SKDataUtil";
|
|
import RecastAlert from "./RecastAlert";
|
|
|
|
export default class RecastPanel {
|
|
|
|
static shared: RecastPanel = new RecastPanel();
|
|
itemData: any;
|
|
main: fgui.GComponent;
|
|
list: fgui.GList;
|
|
item_1: fgui.GComponent;
|
|
item_2: fgui.GComponent;
|
|
item: fgui.GComponent;
|
|
|
|
constructor() {
|
|
}
|
|
|
|
isShow(): boolean {
|
|
if (this.main == null) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
show(itemData: any) {
|
|
this.itemData = itemData;
|
|
this.loadUI();
|
|
}
|
|
|
|
hide() {
|
|
FGUtil.dispose(this.main);
|
|
this.main = null;
|
|
}
|
|
|
|
loadUI() {
|
|
FGUtil.dispose(this.main);
|
|
this.main = fgui.UIPackage.createObject("main_ui", "baldric_recast").asCom;
|
|
FGUtil.root().addChild(this.main);
|
|
FGUtil.fitScreen(this.main);
|
|
this.initUI();
|
|
}
|
|
|
|
initUI() {
|
|
this.list = FGUtil.getList(this.main, "alert/list");
|
|
let info = GameModel.equipData.info;
|
|
this.list.removeChildrenToPool()
|
|
let baldrics: any[] = [];
|
|
for (let key in info) {
|
|
let itemInfo = info[key];
|
|
// 非佩飾不顯示
|
|
if (!SKDataUtil.atRange(itemInfo.EIndex, [7, 8, 9, 10, 12])) {
|
|
continue;
|
|
}
|
|
baldrics.push(itemInfo);
|
|
}
|
|
baldrics.sort((a: any, b: any) => {
|
|
let ae = ItemUtil.isEquip(a);
|
|
let be = ItemUtil.isEquip(b);
|
|
if (ae) {
|
|
if (!be) {
|
|
return -1;
|
|
}
|
|
} else {
|
|
if (be) {
|
|
return 1;
|
|
}
|
|
}
|
|
return a.EquipID - b.EquipID;
|
|
});
|
|
let index: number = 0;
|
|
let selectedIndex: number = 0;
|
|
for (let baldric of baldrics) {
|
|
let data = ItemUtil.getItemData(baldric.Type);
|
|
if (data == null) {
|
|
continue;
|
|
}
|
|
let cell = this.list.addItemFromPool().asCom;
|
|
cell.data = baldric;
|
|
let item = FGUtil.getButton(cell, "item");
|
|
item.icon = `ui://main_ui/${data.icon}`;
|
|
item.data = baldric;
|
|
item.onClick(this.onClickIcon, this);
|
|
FGUtil.getTextField(cell, "title").text = baldric.EName;
|
|
FGUtil.getTextField(cell, "grade").text = ItemUtil.getGrade(baldric);
|
|
FGUtil.getImage(cell, "equip_flag").visible = ItemUtil.isEquip(baldric);
|
|
FGUtil.getControl(cell, "item/grade").selectedIndex = baldric.Grade;
|
|
if (this.itemData.EquipID == baldric.EquipID) {
|
|
selectedIndex = index;
|
|
}
|
|
index++;
|
|
}
|
|
this.list.selectedIndex = selectedIndex;
|
|
this.list.scrollToView(selectedIndex, true, true);
|
|
FGUtil.getButton(this.main, "alert/close_btn").onClick(this.hide, this);
|
|
this.item_1 = FGUtil.getComponent(this.main, "alert/item_1");
|
|
this.item_2 = FGUtil.getComponent(this.main, "alert/item_2");
|
|
this.item = FGUtil.getComponent(this.main, "alert/baldric_item");
|
|
this.refresh(this.itemData);
|
|
this.refreshItems();
|
|
this.list.on(fgui.Event.CLICK_ITEM, this.onClickItem, this);
|
|
this.item.onClick(this.onClickBaldric, this);
|
|
FGUtil.getButton(this.main, "alert/recast_btn").onClick(this.onClickRecast, this);
|
|
}
|
|
|
|
onClickIcon(event: fgui.Event) {
|
|
let target = fgui.GObject.cast(event.currentTarget);
|
|
ItemUtil.showMenu = false;
|
|
ItemUtil.showAccessDetail(target.data, false);
|
|
}
|
|
|
|
onClickBaldric(event: fgui.Event) {
|
|
let target = fgui.GObject.cast(event.currentTarget);
|
|
ItemUtil.showMenu = false;
|
|
ItemUtil.showAccessDetail(target.data, false);
|
|
}
|
|
|
|
onClickRecast(event: fgui.Event) {
|
|
let baldric = this.list.getChildAt(this.list.selectedIndex).data;
|
|
RecastAlert.shared.show(baldric);
|
|
}
|
|
|
|
onClickItem(item: fgui.GObject) {
|
|
let index = this.list.getChildIndex(item);
|
|
this.list.selectedIndex = index;
|
|
this.refresh(item.data);
|
|
}
|
|
|
|
sync() {
|
|
let baldric = this.list.getChildAt(this.list.selectedIndex).data;
|
|
baldric.BaseAttr = null;
|
|
if (this.item.data) {
|
|
this.item.data.BaseAttr = null;
|
|
}
|
|
this.refreshItems();
|
|
}
|
|
|
|
refresh(baldric: any) {
|
|
let data = ItemUtil.getItemData(baldric.Type);
|
|
if (data == null) {
|
|
return;
|
|
}
|
|
this.item.icon = `ui://main_ui/${data.icon}`;
|
|
this.item.data = baldric;
|
|
FGUtil.getControl(this.item, "grade").selectedIndex = baldric.Grade;
|
|
}
|
|
|
|
refreshItems() {
|
|
let tip1 = FGUtil.getTextField(this.item_1, "tip");
|
|
let count1 = ItemUtil.getBagItemCount(10406);
|
|
tip1.text = `[color=${count1 < 1 ? `#c03025` : `#ffffff`}]${count1}[/color]/5`;
|
|
tip1.visible = true;
|
|
let tip2 = FGUtil.getTextField(this.item_2, "tip")
|
|
let count2 = ItemUtil.getBagItemCount(10409);
|
|
tip2.text = `[color=${count2 < 5 ? `#c03025` : `#ffffff`}]${count2}[/color]/1`;
|
|
tip2.visible = true;
|
|
}
|
|
} |