442 lines
14 KiB
JavaScript
442 lines
14 KiB
JavaScript
import GameModel from "../ts/core/GameModel";
|
|
import AudioUtil from "../ts/core/AudioUtil";
|
|
import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil";
|
|
import WingUtil from "../ts/wing/WingUtil";
|
|
import ItemUtil from "../ts/core/ItemUtil";
|
|
import SuitSkillItem from "../ts/game/baldric/SuitSkillItem";
|
|
import PopupManager from "../ts/gear_2.3.4/manager/PopupManager";
|
|
import FGAlert from "../ts/gear_2.3.4/fgui/FGAlert";
|
|
import FGUtil, { TipAlign } from "../ts/gear_2.3.4/fgui/FGUtil";
|
|
import MsgAlert from "../ts/game/msg/MsgAlert";
|
|
import Transformation from "../ts/transformation/Transformation";
|
|
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
itemContent: cc.Node,
|
|
checkMark: cc.Node,
|
|
equipNodes: [cc.Node],
|
|
baldricNodes: [cc.Node],
|
|
baldricSkill: cc.Node,
|
|
roleNode: cc.Node,
|
|
scoreLabel: cc.Label,
|
|
bagItem: cc.Prefab,
|
|
equipItem: cc.Prefab,
|
|
schemeName: cc.Label,
|
|
SchemePanel: cc.Prefab,
|
|
lockerPrefab: cc.Prefab,
|
|
m_BagGoods: cc.Toggle,
|
|
m_SortIcon: cc.Node,
|
|
},
|
|
|
|
onLoad() {
|
|
this.currentY = 0;
|
|
this.currentSelected = -1;
|
|
this.itemNodes = [];
|
|
this.firstTime = true;
|
|
this.slideDuration = 0.2;
|
|
// GameModel.send('c2s_get_bagitem', { roleid: GameModel.player.roleid });
|
|
this.roleNode.getComponent('UIRole').setInfo(GameModel.player);
|
|
this.setSchemeName();
|
|
},
|
|
|
|
clickEquipTab(event, data) {
|
|
if (data == "0") {// 裝備
|
|
var equipNode = cc.find("mask/equipItems", this.node);
|
|
if (equipNode.active == true) return;
|
|
var baldricNode = cc.find("mask/baldricItems", this.node);
|
|
cc.find("equip_tc/title2", this.node).active = true;
|
|
cc.find("equip_tc/title1", this.node).active = false;
|
|
let t = cc.tween;
|
|
t(baldricNode)
|
|
.parallel(
|
|
t().to(this.slideDuration, { opacity: 0 }),
|
|
t().by(this.slideDuration, { x: -300 })
|
|
)
|
|
.call(() => {
|
|
baldricNode.active = false
|
|
})
|
|
.start();
|
|
equipNode.active = true;
|
|
t(equipNode)
|
|
.parallel(
|
|
t().to(this.slideDuration, { opacity: 255 }),
|
|
t().by(this.slideDuration, { x: -300 })
|
|
)
|
|
.start();
|
|
t(this.checkMark)
|
|
.to(this.slideDuration, { x: -44.255 })
|
|
.start();
|
|
} else if (data == "1") {// 佩飾
|
|
var baldricNode = cc.find("mask/baldricItems", this.node);
|
|
if (baldricNode.active == true) return;
|
|
var equipNode = cc.find("mask/equipItems", this.node);
|
|
cc.find("equip_tc/title1", this.node).active = true;
|
|
cc.find("equip_tc/title2", this.node).active = false;
|
|
let t = cc.tween;
|
|
t(equipNode)
|
|
.parallel(
|
|
t().to(this.slideDuration, { opacity: 0 }),
|
|
t().by(this.slideDuration, { x: 300 })
|
|
)
|
|
.call(() => {
|
|
equipNode.active = false
|
|
})
|
|
.start();
|
|
baldricNode.active = true;
|
|
t(baldricNode)
|
|
.parallel(
|
|
t().to(this.slideDuration, { opacity: 255 }),
|
|
t().by(this.slideDuration, { x: 300 })
|
|
)
|
|
.start();
|
|
t(this.checkMark)
|
|
.to(this.slideDuration, { x: 44.255 })
|
|
.start();
|
|
}
|
|
},
|
|
|
|
// 點擊倉庫
|
|
clickWareHouse(event, data) {
|
|
let canvas = cc.find('Canvas');
|
|
if (!canvas.getChildByName('LockerPanel')) {
|
|
let locker = cc.instantiate(this.lockerPrefab);
|
|
locker.parent = canvas;
|
|
locker.name = 'LockerPanel';
|
|
}
|
|
},
|
|
setSchemeName() {
|
|
if (GameModel.player.schemename && GameModel.player.schemename != '') {
|
|
this.schemeName.string = GameModel.player.schemename;
|
|
}
|
|
},
|
|
start() {
|
|
if (GameModel.player.getItemList() == null || GameModel.player.getItemNum() == 0) {
|
|
GameModel.send('c2s_get_bagitem', {
|
|
roleid: GameModel.player.roleid
|
|
});
|
|
} else {
|
|
this.loadBagList();
|
|
}
|
|
},
|
|
loadBagList() {
|
|
this.unscheduleAllCallbacks();
|
|
this.itemContent.destroyAllChildren();
|
|
this.itemNodes = [];
|
|
let list = [];
|
|
if (GameModel.equipData) {
|
|
let score = GameModel.equipData.score;
|
|
if (!score) {
|
|
score = 0;
|
|
}
|
|
this.scoreLabel.string = score;
|
|
for (let index = 0; index < this.equipNodes.length; index++) {
|
|
let equipid = GameModel.equipData.use[index + 1];
|
|
let equipNode = this.equipNodes[index];
|
|
equipNode.getComponent('EquipItem').reset();
|
|
let hasWing = false;
|
|
if (equipid && GameModel.equipData.info[equipid]) {
|
|
equipNode.getChildByName('itembg').active = true;
|
|
let data = GameModel.equipData.info[equipid];
|
|
// if (data.EIndex == 6) {
|
|
// hasWing = true;
|
|
// let wingId = SKDataUtil.findByDict(GameModel.game_conf.wing, "resid", data.Shape, "id", 0);
|
|
// WingUtil.playAni(this.roleNode, GameModel.player.resid, 1, "stand", 0, wingId);
|
|
// }
|
|
equipNode.getComponent('EquipItem').loadInfo(data);
|
|
}
|
|
// if (!hasWing) {
|
|
// console.log("has no wingwinwwin")
|
|
// WingUtil.playAni(this.roleNode, GameModel.player.resid, 1, "stand", 0, 0);
|
|
// }
|
|
}
|
|
let equipData = GameModel.equipData;
|
|
for (let index = 0; index < this.baldricNodes.length; index++) {
|
|
let equipid = equipData.use[index + 7];
|
|
let equipNode = this.baldricNodes[index];
|
|
equipNode.getComponent('EquipItem').reset();
|
|
if (equipid && equipData.info[equipid]) {
|
|
equipNode.getChildByName('itembg').active = true;
|
|
let data = equipData.info[equipid];
|
|
equipNode.getComponent('EquipItem').loadInfo(data);
|
|
}
|
|
}
|
|
|
|
let suitSkill = ItemUtil.getBaldricSuitSkill();
|
|
if (suitSkill) {
|
|
if (this.firstTime) {
|
|
this.firstTime = false;
|
|
} else {
|
|
suitSkill.name.split(".");
|
|
//MsgAlert.addMsg(`您已激活套裝技能 [img]ui://main_ui/${suitSkill.icon}[/img][color=#00FF7F]【${suitSkill.name.split(".")[0]}】[/color]!`);
|
|
}
|
|
this.baldricSkill.active = true;
|
|
let item = this.baldricSkill.getComponent(SuitSkillItem);
|
|
item.load(suitSkill);
|
|
} else {
|
|
this.baldricSkill.active = false;
|
|
}
|
|
for (const equip of equipData.list) {
|
|
if (equipData.info[equip]) {
|
|
let info = {
|
|
itemid: equip,
|
|
info: GameModel.equipData.info[equip],
|
|
type: 1
|
|
};
|
|
list.push(info);
|
|
}
|
|
}
|
|
}
|
|
let itemList = GameModel.player.itemList;
|
|
for (let itemId in itemList) {
|
|
let count = SKDataUtil.valueForKey(GameModel.player.itemList, itemId);
|
|
if (count != null && count > 0) {
|
|
if (ItemUtil.getItemData(itemId).type == 15) continue
|
|
if (itemId >= 1003010 && itemId <= 1003100) continue
|
|
let info = {
|
|
itemid: itemId,
|
|
count: count,
|
|
type: 0
|
|
};
|
|
list.push(info);
|
|
}
|
|
}
|
|
let bagMaxLength = GameModel.player.bagKindNum;
|
|
let maxLength = 0;
|
|
if (list.length > maxLength) {
|
|
maxLength = list.length;
|
|
}
|
|
this.itemContent.height = (Math.ceil(bagMaxLength / 5) + 1) * 75;
|
|
let timeWait = 0;
|
|
for (let index = 0; index < bagMaxLength + 5; index++) {
|
|
this.scheduleOnce(() => {
|
|
if (!this.itemContent) return
|
|
let item = null;
|
|
if (index < list.length) {
|
|
if (list[index].type == 1) {
|
|
item = cc.instantiate(this.equipItem);
|
|
item.parent = this.itemContent;
|
|
item.getComponent('EquipItem').loadInfo(list[index].info);
|
|
} else {
|
|
item = cc.instantiate(this.bagItem);
|
|
item.parent = this.itemContent;
|
|
if (index < list.length) {
|
|
item.getComponent('BagItem').loadInfo(list[index]);
|
|
}
|
|
}
|
|
item.x = -150 + index % 5 * 75;
|
|
item.y = -37.5 - Math.floor(index / 5) * 75;
|
|
let btn = item.getComponent(cc.Button);
|
|
var clickEventHandler = new cc.Component.EventHandler();
|
|
clickEventHandler.target = this.node;
|
|
clickEventHandler.component = "BagPanel";
|
|
clickEventHandler.customEventData = index;
|
|
clickEventHandler.handler = "bagItemClicked";
|
|
btn.clickEvents.push(clickEventHandler);
|
|
this.itemNodes.push(item);
|
|
} else if (index < bagMaxLength) {
|
|
item = cc.instantiate(this.bagItem);
|
|
item.getComponent('BagItem').loadInfo({ canSelect: !1 });
|
|
item.parent = this.itemContent;
|
|
this.itemNodes.push(item);
|
|
} else {
|
|
item = cc.instantiate(this.bagItem);
|
|
item.getComponent('BagItem').loadInfo({ canSelect: !1, lock: !0 });
|
|
item.parent = this.itemContent;
|
|
//添加解鎖事件
|
|
let btn = item.getComponent(cc.Button);
|
|
var clickEventHandler = new cc.Component.EventHandler();
|
|
clickEventHandler.target = this.node;
|
|
clickEventHandler.component = "BagPanel";
|
|
clickEventHandler.handler = "bagItemUnclock";
|
|
btn.clickEvents.push(clickEventHandler);
|
|
this.itemNodes.push(item);
|
|
}
|
|
}, timeWait)
|
|
timeWait += 0.01;
|
|
}
|
|
this.SetMoneyInfo();
|
|
|
|
this.itemNodesTemp = this.itemNodes
|
|
// 自然
|
|
this.m_SortIcon.getChildByName("sort_0").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIcon("1002");
|
|
// 裝備
|
|
this.m_SortIcon.getChildByName("sort_1").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIcon("102305");
|
|
// 其他
|
|
this.m_SortIcon.getChildByName("sort_2").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIcon("5503");
|
|
// 五行
|
|
this.m_SortIcon.getChildByName("sort_3").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIcon("20011");
|
|
// 寶石
|
|
this.m_SortIcon.getChildByName("sort_4").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIcon("10001");
|
|
// 技能
|
|
this.m_SortIcon.getChildByName("sort_5").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIcon("8229");
|
|
// 藥品
|
|
this.m_SortIcon.getChildByName("sort_6").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIcon("40006");
|
|
},
|
|
// 點擊佩飾套裝技能
|
|
clickSuitSkill(event, data) {
|
|
let target = event.target;
|
|
let suitSkillItem = target.getComponent(SuitSkillItem);
|
|
if (suitSkillItem) {
|
|
ItemUtil.showSuitSkill(ItemUtil.suitId);
|
|
}
|
|
},
|
|
useEquipClicked(e, d) {
|
|
e.target.getComponent('EquipItem').selected();
|
|
},
|
|
bagItemClicked(e, d) {
|
|
if (this.currentSelected == d) {
|
|
return;
|
|
}
|
|
for (const item of this.itemNodes) {
|
|
if (e.target == item) {
|
|
continue;
|
|
}
|
|
item.getComponent('BagItem') && item.getComponent('BagItem').unSelected();
|
|
item.getComponent('EquipItem') && item.getComponent('EquipItem').unSelected();
|
|
}
|
|
},
|
|
|
|
bagItemUnclock() {
|
|
var iconId = "", priceStr = "", color = "FF74FF";
|
|
var self = this;
|
|
if (GameModel.player.bagKindNum > 65) {
|
|
iconId = "9004";
|
|
priceStr = "500";
|
|
console.log(`消耗${priceStr}仙玉開啟背包格子?`);
|
|
} else {
|
|
iconId = "90001";
|
|
var price = (((GameModel.player.bagKindNum - 50) / 5 * 500 + 500) * 50).toString();
|
|
priceStr = `[color=#${color}]${price}[/color]`;
|
|
console.log(`消耗${price}銀幣開啟背包格子?`);
|
|
}
|
|
FGAlert.show(`是否花費[img]ui://main_ui/${iconId}[/img]${priceStr}開啟5個格子?`, () => {
|
|
FGAlert.hide();
|
|
}, () => {
|
|
FGAlert.hide();
|
|
GameModel.send("c2c_open_backpack_grid", {
|
|
roleId: GameModel.player.roleid
|
|
});
|
|
});
|
|
},
|
|
|
|
onCloseBtnClicked(event, data) {
|
|
AudioUtil.playCloseAudio();
|
|
this.roleNode.getComponent('UIRole').clear();
|
|
this.unscheduleAllCallbacks();
|
|
this.node.destroy();
|
|
},
|
|
|
|
SetMoneyInfo() {
|
|
let topnode = cc.find('topInfo', this.node);
|
|
let toplogic = topnode.getComponent('TopInfo');
|
|
toplogic.updateGameMoney();
|
|
},
|
|
|
|
showSchemeListPanel() {
|
|
let schemePanel = cc.instantiate(this.SchemePanel);
|
|
schemePanel.parent = cc.find('Canvas/MainUI');
|
|
},
|
|
|
|
onAccessorySuitClick() {
|
|
let url = `Prefabs/Accessory/AccessorySuit`;
|
|
cc.loader.loadRes(url, cc.Prefab, (error, prefab) => {
|
|
if (error) {
|
|
SKLogger.warn(`$警告:加載資源${url}錯誤!`);
|
|
return;
|
|
}
|
|
PopupManager.showView(prefab);
|
|
});
|
|
},
|
|
|
|
// 排序規則
|
|
onBtnSort(event, custom) {
|
|
for (const item of this.itemNodes) {
|
|
item.getComponent('BagItem') && item.getComponent('BagItem').unSelected();
|
|
item.getComponent('EquipItem') && item.getComponent('EquipItem').unSelected();
|
|
item.parent = null
|
|
}
|
|
var temp = []
|
|
for (const item of this.itemNodes) {
|
|
switch (custom) {
|
|
case "0": // 自然排序
|
|
temp = this.itemNodesTemp
|
|
break;
|
|
case "1": // 裝備
|
|
if (item.getComponent('EquipItem') && item.getComponent('EquipItem').itemInfo.classify == 1) {
|
|
item.parent = this.itemContent
|
|
} else if (item.getComponent('BagItem') && item.getComponent('BagItem').itemInfo && item.getComponent('BagItem').itemInfo.classify == 1) {
|
|
item.parent = this.itemContent
|
|
} else {
|
|
temp.push(item)
|
|
}
|
|
continue;
|
|
case "2": // 其他
|
|
if (item.getComponent('EquipItem') && (item.getComponent('EquipItem').itemInfo.classify == 0)) {
|
|
item.parent = this.itemContent
|
|
} else if (item.getComponent('BagItem') && item.getComponent('BagItem').itemInfo && (item.getComponent('BagItem').itemInfo.classify == 0)) {
|
|
item.parent = this.itemContent
|
|
} else {
|
|
temp.push(item)
|
|
}
|
|
continue;
|
|
case "3": // 五行
|
|
if (item.getComponent('EquipItem') && item.getComponent('EquipItem').itemInfo.classify == 2) {
|
|
item.parent = this.itemContent
|
|
} else if (item.getComponent('BagItem') && item.getComponent('BagItem').itemInfo && item.getComponent('BagItem').itemInfo.classify == 2) {
|
|
item.parent = this.itemContent
|
|
} else {
|
|
temp.push(item)
|
|
}
|
|
continue;
|
|
case "4": // 寶石
|
|
if (item.getComponent('EquipItem') && item.getComponent('EquipItem').itemInfo.classify == 3) {
|
|
item.parent = this.itemContent
|
|
} else if (item.getComponent('BagItem') && item.getComponent('BagItem').itemInfo && item.getComponent('BagItem').itemInfo.classify == 3) {
|
|
item.parent = this.itemContent
|
|
} else {
|
|
temp.push(item)
|
|
}
|
|
continue;
|
|
case "5": // 技能
|
|
if (item.getComponent('EquipItem') && item.getComponent('EquipItem').itemInfo.classify == 4) {
|
|
item.parent = this.itemContent
|
|
} else if (item.getComponent('BagItem') && item.getComponent('BagItem').itemInfo && item.getComponent('BagItem').itemInfo.classify == 4) {
|
|
item.parent = this.itemContent
|
|
} else {
|
|
temp.push(item)
|
|
}
|
|
continue;
|
|
case "6": // 藥品
|
|
if (item.getComponent('EquipItem') && item.getComponent('EquipItem').itemInfo.classify == 5) {
|
|
item.parent = this.itemContent
|
|
} else if (item.getComponent('BagItem') && item.getComponent('BagItem').itemInfo && item.getComponent('BagItem').itemInfo.classify == 5) {
|
|
item.parent = this.itemContent
|
|
} else {
|
|
temp.push(item)
|
|
}
|
|
continue;
|
|
default:
|
|
continue;
|
|
}
|
|
}
|
|
|
|
for (const item of temp) {
|
|
item.parent = this.itemContent
|
|
}
|
|
|
|
this.m_BagGoods.isChecked = true
|
|
},
|
|
|
|
clickTransformation(e, d) {
|
|
if (d == "2") {
|
|
AudioUtil.playCloseAudio();
|
|
this.unscheduleAllCallbacks();
|
|
this.roleNode.getComponent('UIRole').clear();
|
|
this.node.destroy();
|
|
Transformation.Instance.openTransformation()
|
|
}
|
|
}
|
|
});
|