218 lines
7.4 KiB
TypeScript
218 lines
7.4 KiB
TypeScript
import GameModel from "../../core/GameModel";
|
|
import GameUtil from "../../core/GameUtil";
|
|
import ItemUtil from "../../core/ItemUtil";
|
|
import FGUtil from "../../gear_2.3.4/fgui/FGUtil";
|
|
import SKDataUtil from "../../gear_2.3.4/util/SKDataUtil";
|
|
import MsgAlert from "../msg/MsgAlert";
|
|
|
|
export default class RecastAlert {
|
|
|
|
static shared: RecastAlert = new RecastAlert();
|
|
baldric: any;
|
|
main: fgui.GComponent;
|
|
recastData: any;
|
|
locks: number[];
|
|
|
|
constructor() {
|
|
}
|
|
|
|
isShow(): boolean {
|
|
if (this.main == null) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
show(baldric: any) {
|
|
this.baldric = baldric;
|
|
this.loadUI();
|
|
}
|
|
|
|
hide() {
|
|
FGUtil.dispose(this.main);
|
|
this.main = null;
|
|
}
|
|
|
|
loadUI() {
|
|
FGUtil.dispose(this.main);
|
|
this.main = fgui.UIPackage.createObject("main_ui", "recast").asCom;
|
|
FGUtil.root().addChild(this.main);
|
|
FGUtil.fitScreen(this.main);
|
|
this.initUI();
|
|
}
|
|
|
|
initUI() {
|
|
FGUtil.getButton(this.main, "alert/close_btn").onClick(this.hide, this);
|
|
this.refreshLeft();
|
|
let recast = SKDataUtil.jsonBy(this.baldric.recast);
|
|
this.refreshRight(recast);
|
|
this.refreshItems();
|
|
FGUtil.getTextField(this.main, "alert/right/content/title").text = "新屬性";
|
|
FGUtil.getButton(this.main, "alert/recast_btn").onClick(this.onClickRecast, this);
|
|
FGUtil.getButton(this.main, "alert/sure_btn").onClick(this.onClickSure, this);
|
|
this.locks = [];
|
|
for (let i = 1; i <= 4; i++) {
|
|
let right = FGUtil.getComponent(this.main, `alert/right/content/attr_${i}`);
|
|
right.touchable = false;
|
|
let left = FGUtil.getComponent(this.main, `alert/left/content/attr_${i}`);
|
|
left.touchable = false;
|
|
if (GameModel.player.hideIconList["lock"] == 0) {
|
|
} else {
|
|
left.touchable = true;
|
|
left.onClick(this.onClickLeftCell, this);
|
|
left.data = i - 1;
|
|
}
|
|
this.locks.push(0);
|
|
}
|
|
let tip = FGUtil.getTextField(this.main, "alert/lock_tip");
|
|
tip.text = "點擊左側屬性條可以鎖住屬性不替換!";
|
|
}
|
|
|
|
onClickLeftCell(event: fgui.Event) {
|
|
let cell = fgui.GObject.cast(event.currentTarget).asButton;
|
|
let total = 0;
|
|
for (let lock of this.locks) {
|
|
if (lock == 1) {
|
|
total++;
|
|
}
|
|
}
|
|
|
|
console.log(cell.selected)
|
|
let index = cell.data;
|
|
if (cell.selected && total >= 3) {
|
|
MsgAlert.addMsg(`您最多只能鎖住三條屬性進行替換!`);
|
|
cell.selected = false;
|
|
return;
|
|
}
|
|
this.locks[index] = (cell.selected ? 1 : 0);
|
|
total = 0;
|
|
for (let lock of this.locks) {
|
|
if (lock == 1) {
|
|
total++;
|
|
}
|
|
}
|
|
let tip = FGUtil.getTextField(this.main, "alert/lock_tip");
|
|
if (total < 1) {
|
|
tip.text = "點擊左側屬性條可以鎖住屬性不替換!";
|
|
} else {
|
|
total = SKDataUtil.clamp(total, 1, 3);
|
|
tip.text = `鎖住${total}條屬性,消耗${GameUtil.lockJade[total - 1]}碎片`;
|
|
}
|
|
}
|
|
|
|
onClickRecast() {
|
|
this.recastData = null;
|
|
let params = {
|
|
operation: 0,
|
|
roleid: GameModel.player.roleid,
|
|
equipid: this.baldric.EquipID,
|
|
locks: this.locks
|
|
}
|
|
GameModel.send("c2s_baldric_recast", params);
|
|
}
|
|
|
|
onClickSure() {
|
|
this.recastData = null;
|
|
let params = {
|
|
operation: 1,
|
|
roleid: GameModel.player.roleid,
|
|
equipid: this.baldric.EquipID,
|
|
locks: this.locks
|
|
}
|
|
GameModel.send("c2s_baldric_recast", params);
|
|
}
|
|
|
|
refresh(data: any) {
|
|
this.baldric = data;
|
|
this.refreshLeft();
|
|
this.refreshRight(data.recast);
|
|
this.refreshItems();
|
|
}
|
|
|
|
clearLocks() {
|
|
this.locks = [0, 0, 0, 0];
|
|
for (let i = 1; i <= 4; i++) {
|
|
let right = FGUtil.getButton(this.main, `alert/left/content/attr_${i}`);
|
|
right.selected = false;
|
|
}
|
|
let tip = FGUtil.getTextField(this.main, "alert/lock_tip");
|
|
tip.text = "點擊左側屬性條可以鎖住屬性不替換!";
|
|
}
|
|
|
|
refreshLeft() {
|
|
if (this.baldric.BaseAttr == null) {
|
|
let params = {
|
|
roleid: GameModel.player.roleid,
|
|
equipid: this.baldric.EquipID
|
|
}
|
|
GameModel.send('c2s_equip_info', params);
|
|
return;
|
|
}
|
|
FGUtil.getComponent(this.main, "alert/left/tip").visible = false;
|
|
FGUtil.getComponent(this.main, "alert/left/content").visible = true;
|
|
let index: number = 1;
|
|
let baseAttr = SKDataUtil.jsonBy(this.baldric.BaseAttr);
|
|
for (let item of baseAttr) {
|
|
for (let key in item) {
|
|
let type = SKDataUtil.toNumber(key);
|
|
let cell = FGUtil.getComponent(this.main, `alert/left/content/attr_${index}`);
|
|
FGUtil.getTextField(cell, "title").text = GameUtil.getAttrTypeL1Name(type);
|
|
let value = SKDataUtil.toNumber(item[key]);
|
|
let text = ``;
|
|
if (GameUtil.equipTypeNumerical.indexOf(type) == -1) {
|
|
text = `${value > 0 ? "+" : ""}${SKDataUtil.toDecimal1(value / 10)}%`;
|
|
} else {
|
|
text = `${value > 0 ? "+" : ""}${SKDataUtil.toDecimal1(value)}`;
|
|
}
|
|
FGUtil.getTextField(cell, "value").text = text;
|
|
break;
|
|
}
|
|
index++;
|
|
}
|
|
}
|
|
|
|
sync(data: any) {
|
|
this.refreshRight(data);
|
|
this.refreshItems();
|
|
}
|
|
|
|
refreshRight(data: any) {
|
|
let tip = FGUtil.getComponent(this.main, "alert/right/tip");
|
|
let content = FGUtil.getComponent(this.main, "alert/right/content");
|
|
if (data == null) {
|
|
tip.visible = true;
|
|
content.visible = false;
|
|
return;
|
|
}
|
|
tip.visible = false;
|
|
content.visible = true;
|
|
let index: number = 1;
|
|
let baseAttr = SKDataUtil.jsonBy(data);
|
|
for (let item of baseAttr) {
|
|
for (let key in item) {
|
|
let type = SKDataUtil.toNumber(key);
|
|
let cell = FGUtil.getComponent(this.main, `alert/right/content/attr_${index}`);
|
|
FGUtil.getTextField(cell, "title").text = GameUtil.getAttrTypeL1Name(type);
|
|
let value = SKDataUtil.toNumber(item[key]);
|
|
let text = ``;
|
|
if (GameUtil.equipTypeNumerical.indexOf(type) == -1) {
|
|
text = `${value > 0 ? "+" : ""}${SKDataUtil.toDecimal1(value / 10)}%`;
|
|
} else {
|
|
text = `${value > 0 ? "+" : ""}${SKDataUtil.toDecimal1(value)}`;
|
|
}
|
|
FGUtil.getTextField(cell, "value").text = text;
|
|
break;
|
|
}
|
|
index++;
|
|
}
|
|
}
|
|
|
|
refreshItems() {
|
|
let tip1 = FGUtil.getTextField(this.main, "alert/item_count_1");
|
|
let count1 = ItemUtil.getBagItemCount(10406);
|
|
tip1.text = `[color=${count1 < 1 ? `#c03025` : `#60d666`}]${count1}[/color]/5`;
|
|
let tip2 = FGUtil.getTextField(this.main, "alert/item_count_2")
|
|
let count2 = ItemUtil.getBagItemCount(10409);
|
|
tip2.text = `[color=${count2 < 5 ? `#c03025` : `#60d666`}]${count2}[/color]/1`;
|
|
}
|
|
} |