2025-04-24 17:03:28 +08:00

193 lines
5.9 KiB
JavaScript

import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil";
import ItemUtil from "../ts/core/ItemUtil";
cc.Class({
extends: cc.Component,
properties: {
itemBg: cc.Node,
itemIcon: cc.Sprite,
transformationType: cc.Sprite,
transformationChange: cc.Sprite,
itemCount: cc.Label,
selectedNode: cc.Node,
itemDetail: cc.Prefab,
EquipItemDetail: cc.Prefab,
},
onLoad() {
// this.node.on(cc.Node.EventType.TOUCH_START, this.onTouched.bind(this));
// this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouched.bind(this));
// this.node.on(cc.Node.EventType.TOUCH_END, this.onTouched.bind(this));
// this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouched.bind(this));
// this.onTouch = false;
this.panelLogic = null;
this.type = 0;
this.isequip = false;
this.count = 0;
this.itemBg.active = false;
this.selectedNode.active = false;
this.itemInfo = null;
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouched.bind(this));
this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouched.bind(this));
this.node.on(cc.Node.EventType.TOUCH_END, this.onTouched.bind(this));
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouched.bind(this));
},
loadInfo(itemid, itemcount) {
this.onTouch = false;
this.itemIcon.spriteFrame = null;
this.itemBg.active = false;
this.itemInfo = null
this.itemCount.string = ""
this.itemBg.getChildByName("maskIcon").getComponent(cc.Sprite).spriteFrame = null;
let data = ItemUtil.getItemData(itemid);
if (data) {
this.count = itemcount;
this.itemInfo = data;
this.itemInfo.count = itemcount;
this.itemBg.active = true;
this.itemCount.string = itemcount;
this.itemIcon.spriteFrame = ItemUtil.getItemIconBy(this.itemInfo);
this.itemBg.getChildByName("frame").color = new cc.Color(112, 255, 115)
if (data.type == 15) {
if (data.level == 1003) {
// 橘色
var typeArr = ["9CC2C05E", "44D85091", "4988966A"]//強 抗 物
this.transformationType.spriteFrame = ItemUtil.getItemIcon(typeArr[data.attrType - 1]);
this.transformationChange.spriteFrame = ItemUtil.getItemIcon("743CB1F3")
} else if (data.level == 1002) {
// 紫色
var typeArr = ["A1519957", "7844A6C6", "A71F8CC7"]//強 抗 物
this.transformationType.spriteFrame = ItemUtil.getItemIcon(typeArr[data.attrType - 1]);
this.transformationChange.spriteFrame = null
} else if (data.level == 1001) {
// 藍色
var typeArr = ["905A9C64", "56878EC7", "CD606498"]//強 抗 物
this.transformationType.spriteFrame = ItemUtil.getItemIcon(typeArr[data.attrType - 1]);
this.transformationChange.spriteFrame = ItemUtil.getItemIcon("4FF0E3B9")
} else if (data.level == 1000) {
// 綠色
var typeArr = ["ECAE61A5", "6A45551C", "71EA9A95"]//強 抗 物
this.transformationType.spriteFrame = ItemUtil.getItemIcon(typeArr[data.attrType - 1]);
this.transformationChange.spriteFrame = ItemUtil.getItemIcon("CE379C20")
} else {
return
}
this.transformationType.node.active = true;
this.transformationChange.node.active = true;
}
}
},
loadEquipInfo(info) {
this.onTouch = false;
this.itemBg.active = false;
this.itemIcon.spriteFrame = null;
this.itemCount.string = ""
this.itemBg.getChildByName("maskIcon").getComponent(cc.Sprite).spriteFrame = null;
this.itemInfo = null
if (info == null) {
return;
}
this.itemBg.getChildByName("frame").color = new cc.Color(255, 94, 97)
this.itemBg.active = true;
this.itemInfo = info;
this.itemIcon.spriteFrame = ItemUtil.getItemIconBy(info);
this.itemCount.string = info.Grade;
if (info.flag == 1) {
this.itemBg.getChildByName("maskIcon").getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIconBy({ icon: 1000 });
this.itemCount.string = ""
}
},
selected() {
this.selectedNode.active = true;
},
unSelected() {
this.selectedNode.active = false;
},
onTouched(e) {
if (this.itemInfo == null) return
if (e.type == cc.Node.EventType.TOUCH_START) {
this.onTouch = true;
this.beginPos = e.getLocation();
e.target.stopAllActions();
e.target.runAction(cc.scaleTo(0.1, 0.9));
this.scheduleOnce(this.showDetailInfo, 1);
}
else if (e.type == cc.Node.EventType.TOUCH_MOVE) {
if (this.onTouch && SKUIUtil.distanceByVec2(this.beginPos, e.getLocation()) > 5) {
this.onTouch = false;
e.target.stopAllActions();
e.target.runAction(cc.scaleTo(0.1, 1));
this.unschedule(this.showDetailInfo);
}
}
else if (e.type == cc.Node.EventType.TOUCH_CANCEL) {
e.target.stopAllActions();
e.target.runAction(cc.scaleTo(0.1, 1));
this.unschedule(this.showDetailInfo);
}
else if (e.type == cc.Node.EventType.TOUCH_END) {
e.target.stopAllActions();
e.target.runAction(cc.scaleTo(0.1, 1));
this.unschedule(this.showDetailInfo);
if (!this.onTouch) {
return;
}
if (this.panelLogic) {
if (this.itemInfo != null) {
if (this.isequip) {
this.panelLogic.changeEquipType(this.type, this.itemInfo);
}
else {
this.panelLogic.changeItemType(this.type, this.itemInfo.id);
}
}
}
}
},
showDetailInfo() {
this.onTouch = false;
if (this.itemInfo != null) {
let canvas = cc.find('Canvas');
// 是否為裝備
if (this.isequip) {
// 是否為佩飾
if (ItemUtil.isBaldric(this.itemInfo.EIndex)) {
if (!ItemUtil.isShowDetail()) {
ItemUtil.showMenu = false;
ItemUtil.showAccessDetail(this.itemInfo, false);
}
} else {
if (canvas.getChildByName('EquipItemDetail') == null) {
let detail = cc.instantiate(this.EquipItemDetail);
detail.parent = canvas;
detail.name = 'EquipItemDetail';
detail.getComponent('EquipItemDetail').loadInfo(this.itemInfo);
}
}
}
else {
if (canvas.getChildByName('BagItemDetail') == null) {
let detail = cc.instantiate(this.itemDetail);
detail.parent = canvas;
detail.name = 'BagItemDetail';
detail.getComponent('BagItemDetail').loadInfo(this.itemInfo);
}
}
}
}
});