460 lines
16 KiB
TypeScript
460 lines
16 KiB
TypeScript
import AudioUtil from "../core/AudioUtil";
|
|
import FGUtil from "../gear_2.3.4/fgui/FGUtil";
|
|
import SKUIUtil from "../gear_2.3.4/util/SKUIUtil";
|
|
import ItemUtil from "../core/ItemUtil";
|
|
import GameModel from "../core/GameModel";
|
|
import SKDataUtil from "../gear_2.3.4/util/SKDataUtil";
|
|
import zhenFa from "./zhenfa";
|
|
import AdvanceRecast from "./advanceRecast";
|
|
import MsgAlert from "../game/msg/MsgAlert";
|
|
const {ccclass, property} = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class myXinwu extends cc.Component {
|
|
/**
|
|
* 信物面板單例實例
|
|
*/
|
|
public static Instance: myXinwu = null;
|
|
/**
|
|
* 信物面板
|
|
*/
|
|
xinwu: fgui.GComponent = null;
|
|
/**
|
|
* 選擇索引
|
|
*/
|
|
private selectGoodsIdx:number = 0;
|
|
/**
|
|
* 舊選擇信物
|
|
*/
|
|
private oldXwItem:any = null;
|
|
/**
|
|
* 類型
|
|
*/
|
|
private cls:number = 0;
|
|
/**
|
|
* 代理
|
|
*/
|
|
private delegte:any = null;
|
|
/**
|
|
* 舊的選擇
|
|
*/
|
|
private oldSelectIndex:number = 0;
|
|
/**
|
|
* 需要加載的預製體
|
|
*/
|
|
prefabObject: any = {};
|
|
|
|
onLoad() {
|
|
if (myXinwu.Instance === null) {
|
|
myXinwu.Instance = this;
|
|
this.loadPrefab();
|
|
} else {
|
|
this.destroy();
|
|
return;
|
|
}
|
|
}
|
|
|
|
loadPrefab() {
|
|
// 加載所需的預製體
|
|
var prefabList = [
|
|
// { url: "Prefabs/UIRole", name: "UIRole" },
|
|
]
|
|
this.prefabObject = {}
|
|
for (let item of prefabList) {
|
|
cc.loader.loadRes(item.url, cc.Prefab, (err, prefab) => {
|
|
if (err)
|
|
console.warn(err);
|
|
else {
|
|
this.prefabObject[item.name] = prefab;
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
setDelegte(delegte:any) {
|
|
this.delegte = delegte
|
|
}
|
|
|
|
openMyXinwu() {
|
|
if (!this.xinwu || (this.xinwu && !this.xinwu.node && !SKUIUtil.isValid(this.xinwu.node))) {
|
|
this.xinwu = FGUtil.create("main_ui", "bagua_my_keepsake");
|
|
FGUtil.root().addChild(this.xinwu);
|
|
FGUtil.fitScreen(this.xinwu)
|
|
}
|
|
|
|
this.oldSelectIndex = 0
|
|
this.selectGoodsIdx = 0
|
|
this.cls = 0
|
|
|
|
FGUtil.getTextField(this.xinwu, "n113").text = `0/1`
|
|
FGUtil.getControl(this.xinwu, "ctrl_type").selectedIndex = 0
|
|
|
|
let btnClose = FGUtil.getComponent(this.xinwu, "close")
|
|
this.pushCloseEvent(btnClose, this.xinwu, () => {
|
|
GameModel.send('c2s_clearNewAttrInfo',{})
|
|
AudioUtil.playCloseAudio()
|
|
this.destroy()
|
|
});
|
|
FGUtil.getTextField(this.xinwu, "recast_btn/title").text = "300000"
|
|
FGUtil.getButton(this.xinwu, "btn_type_quanbu").clearClick()
|
|
FGUtil.getButton(this.xinwu, "btn_type_quanbu").onClick(this.clickQuanBu, this);
|
|
FGUtil.getButton(this.xinwu, "btn_type_qiangxi").clearClick()
|
|
FGUtil.getButton(this.xinwu, "btn_type_qiangxi").onClick(this.clickQiangxi, this);
|
|
FGUtil.getButton(this.xinwu, "btn_type_shouhu").clearClick()
|
|
FGUtil.getButton(this.xinwu, "btn_type_shouhu").onClick(this.clickShouhu, this);
|
|
|
|
FGUtil.getButton(this.xinwu, "n111").onClick(this.clickReplaceAttribute, this);
|
|
FGUtil.getButton(this.xinwu, "recast_btn").onClick(this.clickRecast, this);
|
|
|
|
var info = ItemUtil.getItemData(2000031)
|
|
FGUtil.getLoader(this.xinwu,"n112/img_item").url = `ui://main_ui/${info.icon}`;
|
|
FGUtil.getControl(this.xinwu,'n112/ctrl_state').selectedIndex = 1
|
|
|
|
FGUtil.getImage(this.xinwu,"btn_unlock").onClick((e: Event, id: number = 0) => {
|
|
AudioUtil.playCloseAudio()
|
|
let mainUI = GameModel.player.getMainUILogic();
|
|
if (!!mainUI) {
|
|
mainUI.hideZhenFa()
|
|
this.destroy()
|
|
FGUtil.dispose(this.xinwu);
|
|
this.xinwu = null;
|
|
mainUI.showDuoBaoShop()
|
|
}
|
|
},this)
|
|
// 設置物品列表初始化方法
|
|
var itemList = FGUtil.getList(this.xinwu, "list_item");
|
|
itemList.itemRenderer = this.initXinwuItem.bind(this);
|
|
// 虛擬列表
|
|
itemList.setVirtual();
|
|
this.refreshXinwuListPanel();
|
|
|
|
this.updateWuseshi()
|
|
}
|
|
|
|
updateWuseshi(){
|
|
let label = FGUtil.getRichTextField(this.xinwu, "n113")
|
|
label.ubbEnabled = true
|
|
let cnt = ItemUtil.getBagItemCount(2000031)
|
|
if(cnt < 1){
|
|
label.text = `[color=#FF0000]${cnt}[/color][color=#FFFFFF]/1[/color]`
|
|
}else{
|
|
label.text = `[color=#00FF00]${cnt}[/color][color=#FFFFFF]/1[/color]`
|
|
}
|
|
label.flushVars()
|
|
}
|
|
|
|
initXinwuItem(idx, obj: fairygui.GObject) {
|
|
var item = obj.asCom;
|
|
var tempList = this.getCurTypeAllXw()
|
|
const useState = this.getXwUseState(tempList[idx].id)
|
|
FGUtil.getLoader(item, "img_item").url = `ui://main_ui/${tempList[idx].icon}`;
|
|
FGUtil.getControl(item,'ctrl_state').selectedIndex = useState
|
|
FGUtil.getControl(item,'ctrl_selected').selectedIndex = (FGUtil.getControl(this.xinwu, "ctrl_type").selectedIndex == this.cls && this.selectGoodsIdx == idx) ? 1 : 0
|
|
|
|
if (2 == useState) {
|
|
FGUtil.getControl(item,'ctrl_type').selectedIndex = this.getXwPosition(tempList[idx].id)
|
|
}
|
|
|
|
var index = FGUtil.getControl(this.xinwu, "ctrl_type").selectedIndex
|
|
// const _type = index
|
|
const _idx = idx
|
|
item.clearClick()
|
|
item.onClick((e: Event, id: number = 0) => {
|
|
this.oldSelectIndex = _idx;
|
|
this.oldXwItem = tempList[this.oldSelectIndex]
|
|
GameModel.send('c2s_getAttrInfo',{
|
|
itemID: tempList[this.oldSelectIndex].id
|
|
})
|
|
}, this);
|
|
}
|
|
//獲取信物位置
|
|
getXwPosition(id:number) {
|
|
var index = 0
|
|
var zhenfaInfo = this.delegte.info
|
|
const count = zhenfaInfo.length
|
|
for (var i = 0;i < count;++i) {
|
|
if (0 != zhenfaInfo[i].itemID && id == zhenfaInfo[i].itemID) {
|
|
index = zhenfaInfo[i].index
|
|
break
|
|
}
|
|
}
|
|
return index
|
|
}
|
|
|
|
getXwUseState(id) {
|
|
var itemList = GameModel.player.itemList;
|
|
var bHas = false
|
|
for (var itemId in itemList) {
|
|
if (id == parseInt(itemId)) {
|
|
bHas = true
|
|
break
|
|
}
|
|
}
|
|
|
|
if (!!bHas)
|
|
return 1
|
|
|
|
var zhenfaInfo = this.delegte.info
|
|
const s = zhenfaInfo.length
|
|
for (var i = 0;i < s;++i) {
|
|
if (0 != zhenfaInfo[i].itemID && zhenfaInfo[i].itemID == id) {
|
|
return 2
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
getXwClassify() {
|
|
var cls = FGUtil.getControl(this.xinwu, "ctrl_type").selectedIndex - 1
|
|
var list = ItemUtil.getItemsByType(18);
|
|
if (-1 == cls) return list
|
|
const size = list.length
|
|
var tempList = []
|
|
for (var i = 0;i < size;++i) {
|
|
if (cls == list[i].classify) {
|
|
tempList.push(list[i])
|
|
}
|
|
}
|
|
return tempList
|
|
}
|
|
|
|
refreshXinwuListPanel() {
|
|
var itemList = FGUtil.getList(this.xinwu, "list_item");
|
|
var list = this.getXwClassify();
|
|
itemList.numItems = list.length
|
|
this.updateXwTopRightInfo()
|
|
}
|
|
|
|
clickReplaceAttribute() {
|
|
GameModel.send('c2s_replaceattribute',{
|
|
itemID: this.oldXwItem.id,
|
|
index: 0
|
|
})
|
|
}
|
|
|
|
clickRecast() {
|
|
//首先獲取到該道具
|
|
var tempList = this.getCurTypeAllXw()
|
|
this.oldXwItem = tempList[this.selectGoodsIdx]
|
|
|
|
GameModel.send('c2s_xw_normal_succinct',{
|
|
itemID: tempList[this.selectGoodsIdx].id,
|
|
type: 0
|
|
})
|
|
}
|
|
|
|
clickQuanBu() {
|
|
FGUtil.getControl(this.xinwu, "ctrl_type").selectedIndex = 0;
|
|
this.selectGoodsIdx = 0;
|
|
this.cls = 0
|
|
var tempList = this.getCurTypeAllXw()
|
|
this.oldXwItem = tempList[this.selectGoodsIdx]
|
|
GameModel.send('c2s_getXwAttrInfo',{
|
|
itemID: tempList[this.selectGoodsIdx].id
|
|
})
|
|
this.refreshXinwuListPanel()
|
|
}
|
|
|
|
clickQiangxi() {
|
|
FGUtil.getControl(this.xinwu, "ctrl_type").selectedIndex = 1;
|
|
this.selectGoodsIdx = 0;
|
|
this.cls = 1
|
|
var tempList = this.getCurTypeAllXw()
|
|
this.oldXwItem = tempList[this.selectGoodsIdx]
|
|
GameModel.send('c2s_getXwAttrInfo',{
|
|
itemID: tempList[this.selectGoodsIdx].id
|
|
})
|
|
this.refreshXinwuListPanel()
|
|
}
|
|
|
|
clickShouhu() {
|
|
FGUtil.getControl(this.xinwu, "ctrl_type").selectedIndex = 2;
|
|
this.selectGoodsIdx = 0;
|
|
this.cls = 2
|
|
var tempList = this.getCurTypeAllXw()
|
|
this.oldXwItem = tempList[this.selectGoodsIdx]
|
|
GameModel.send('c2s_getXwAttrInfo',{
|
|
itemID: tempList[this.selectGoodsIdx].id
|
|
})
|
|
this.refreshXinwuListPanel()
|
|
}
|
|
|
|
//更新右邊頂部信物信息
|
|
updateXwTopRightInfo() {
|
|
if (this.cls != FGUtil.getControl(this.xinwu, "ctrl_type").selectedIndex)
|
|
return
|
|
var tempList = this.getCurTypeAllXw()
|
|
var info = tempList[this.selectGoodsIdx]
|
|
FGUtil.getLoader(this.xinwu,"comp_item/img_item").url = `ui://main_ui/${info.icon}`;
|
|
FGUtil.getControl(this.xinwu,'comp_item/ctrl_state').selectedIndex = (this.getXwUseState(info.id) == 0)? 0: 1
|
|
FGUtil.getControl(this.xinwu,'comp_item/ctrl_selected').selectedIndex = 0
|
|
FGUtil.getTextField(this.xinwu,'label_itemName').text = `${info.name}-` + info.typedetail
|
|
FGUtil.getTextField(this.xinwu,'label_itemBelong').text = `信物屬於:` + info.detailshot
|
|
FGUtil.getTextField(this.xinwu,'label_desc').text = info.description
|
|
// FGUtil.getComponent(this.xinwu,"n6").visible = (0 == this.getXwUseState(info.id))? false : true
|
|
FGUtil.getControl(this.xinwu,"ctrl_hasitem").selectedIndex = (0 == this.getXwUseState(info.id)) ? 1 : 0
|
|
this.oldXwItem = tempList[this.selectGoodsIdx]
|
|
GameModel.send('c2s_getXwAttrInfo',{
|
|
itemID: tempList[this.selectGoodsIdx].id,
|
|
type: 0
|
|
})
|
|
}
|
|
|
|
pushCloseEvent(item: fairygui.GComponent, target: fairygui.GComponent, call: Function = null) {
|
|
item.clearClick();
|
|
item.onClick(() => {
|
|
call && call();
|
|
FGUtil.dispose(target);
|
|
target = null;
|
|
}, this)
|
|
}
|
|
|
|
pushButtonEvent(item: fairygui.GComponent, call: Function = null) {
|
|
item.clearClick();
|
|
item.onClick(() => {
|
|
call && call();
|
|
}, this)
|
|
}
|
|
|
|
updateAttrInfo(data) {
|
|
var code = ((data.pos1 != -1 && data.pos2 != -1 && data.pos3 != -1)? 0 : 1)
|
|
FGUtil.getControl(this.xinwu,"ctrl_hasAttr").selectedIndex = code
|
|
FGUtil.getControl(this.xinwu, "n23/ctrl_type").selectedIndex = data.pos1
|
|
FGUtil.getControl(this.xinwu, "n120/ctrl_type").selectedIndex = data.pos2
|
|
FGUtil.getControl(this.xinwu, "n121/ctrl_type").selectedIndex = data.pos3
|
|
FGUtil.getTextField(this.xinwu, "n23/label_attrDesc1").text = this.getAttrName(data.attr1)
|
|
FGUtil.getTextField(this.xinwu, "n120/label_attrDesc1").text = this.getAttrName(data.attr2)
|
|
FGUtil.getTextField(this.xinwu, "n121/label_attrDesc1").text = this.getAttrName(data.attr3)
|
|
|
|
FGUtil.getTextField(this.xinwu, "n23/label_attr1").text = (data.value1 / 10).toFixed(1) + "%"
|
|
FGUtil.getTextField(this.xinwu, "n120/label_attr1").text = (data.value2 / 10).toFixed(1) + "%"
|
|
FGUtil.getTextField(this.xinwu, "n121/label_attr1").text = (data.value3 / 10).toFixed(1) + "%"
|
|
|
|
FGUtil.getProgressBar(this.xinwu, "n23/n40").value = (data.value1 / data.max1) * 100
|
|
FGUtil.getProgressBar(this.xinwu, "n120/n40").value = (data.value2 / data.max2) * 100
|
|
FGUtil.getProgressBar(this.xinwu, "n121/n40").value = (data.value3 / data.max3) * 100
|
|
}
|
|
|
|
getCurTypeAllXw() {
|
|
var list = this.getXwClassify();
|
|
var tempList = []
|
|
var zhenfaInfo = this.delegte.info
|
|
const s = zhenfaInfo.length
|
|
const count = list.length
|
|
for (var i = 0;i < s;++i) {
|
|
if (0 != zhenfaInfo[i].itemID) {
|
|
for (var j = 0;j < count;++j) {
|
|
if (list[j].id == zhenfaInfo[i].itemID) {
|
|
tempList.push(list[j])
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
var itemList = GameModel.player.itemList;
|
|
const size = list.length
|
|
for (var itemId in itemList) {
|
|
for (var i = 0;i < size;++i) {
|
|
if (list[i].id == parseInt(itemId)) {
|
|
tempList.push(list[i])
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
for (var i = 0;i < size;++i) {
|
|
var bFind = false
|
|
for (var j = 0;j < tempList.length;++j) {
|
|
if (list[i].id == tempList[j].id) {
|
|
bFind = true
|
|
break
|
|
}
|
|
}
|
|
if (!bFind) tempList.push(list[i])
|
|
}
|
|
return tempList
|
|
}
|
|
|
|
updateNewAttrInfo(data:any) {
|
|
if(data.ret == 0){
|
|
MsgAlert.addMsg("恭喜,信物洗練成功!");
|
|
}else if(data.ret == 1){
|
|
return MsgAlert.addMsg("洗練失敗,缺少五色石");
|
|
}else if(data.ret == 2){
|
|
return MsgAlert.addMsg("洗練失敗,缺少銀兩");
|
|
}
|
|
if (!data.list) return
|
|
var info = SKDataUtil.jsonBy(data.list)
|
|
FGUtil.getControl(this.xinwu,"ctrl_newAttr").selectedIndex = ((info[0].pos1 != -1 && info[0].pos2 != -1 && info[0].pos3 != -1)? 1 : 0)
|
|
FGUtil.getControl(this.xinwu, "n123/ctrl_type").selectedIndex = info[0].pos1
|
|
FGUtil.getControl(this.xinwu, "n124/ctrl_type").selectedIndex = info[0].pos2
|
|
FGUtil.getControl(this.xinwu, "n125/ctrl_type").selectedIndex = info[0].pos3
|
|
FGUtil.getTextField(this.xinwu, "n123/label_attrDesc1").text = this.getAttrName(info[0].attr1)
|
|
FGUtil.getTextField(this.xinwu, "n124/label_attrDesc1").text = this.getAttrName(info[0].attr2)
|
|
FGUtil.getTextField(this.xinwu, "n125/label_attrDesc1").text = this.getAttrName(info[0].attr3)
|
|
FGUtil.getTextField(this.xinwu, "n123/label_attr1").text = (info[0].value1 / 10).toFixed(1) + "%"
|
|
FGUtil.getTextField(this.xinwu, "n124/label_attr1").text = (info[0].value2 / 10).toFixed(1) + "%"
|
|
FGUtil.getTextField(this.xinwu, "n125/label_attr1").text = (info[0].value3 / 10).toFixed(1) + "%"
|
|
|
|
FGUtil.getProgressBar(this.xinwu, "n123/n40").value = (info[0].value1 / info[0].max1) * 100
|
|
FGUtil.getProgressBar(this.xinwu, "n124/n40").value = (info[0].value2 / info[0].max2) * 100
|
|
FGUtil.getProgressBar(this.xinwu, "n125/n40").value = (info[0].value3 / info[0].max3) * 100
|
|
|
|
this.updateWuseshi()
|
|
}
|
|
|
|
getAttrName(attr:number) {
|
|
if (0 == this.oldXwItem.classify) {
|
|
const attr_name = ['加強攻擊','加強速度','加強魅惑','加強加防','加強治愈','加強橫掃','加強破甲'
|
|
,'加強震擊','忽視水','忽視雷','忽視火','忽視風','忽視封印','忽視混亂','忽視昏睡','忽視毒'
|
|
,'忽視遺忘','忽視鬼火','忽視三尸蟲','忽視抗震懾','強力克金','強力克木','強力克水','強力克火'
|
|
,'強力剋土']
|
|
return attr_name[attr]
|
|
} else {
|
|
const attr_name = ['抗水法','抗雷法','抗火法','抗風法','抗封印','抗混亂','抗昏睡'
|
|
,'抗中毒','抗遺忘','抗鬼火','抗三尸蟲','物理吸收','抗震懾','躲閃']
|
|
return attr_name[attr]
|
|
}
|
|
}
|
|
|
|
updateUI(data:any) {
|
|
var list = SKDataUtil.jsonBy(data.attrList)
|
|
this.updateAttrInfo(list)
|
|
|
|
let info = {
|
|
attr1: {
|
|
pos: list.pos1,
|
|
index:list.attr1,
|
|
value: list.value1,
|
|
max:list.max1
|
|
},
|
|
attr2: {
|
|
pos: list.pos2,
|
|
index:list.attr2,
|
|
value: list.value2,
|
|
max:list.max2
|
|
},
|
|
attr3: {
|
|
pos: list.pos3,
|
|
index:list.attr3,
|
|
value: list.value3,
|
|
max:list.max3
|
|
},
|
|
}
|
|
GameModel.player.updateXw(data.itemID, info)
|
|
}
|
|
|
|
updateXWAllInfo(data:any) {
|
|
var list = SKDataUtil.jsonBy(data.attrList)
|
|
this.updateAttrInfo(list)
|
|
this.updateNewAttrInfo(data.succintAttrList)
|
|
}
|
|
|
|
changeSelect() {
|
|
this.selectGoodsIdx = this.oldSelectIndex
|
|
var goodsList = FGUtil.getList(this.xinwu, "list_item");
|
|
goodsList.refreshVirtualList();
|
|
this.updateXwTopRightInfo()
|
|
}
|
|
}
|