176 lines
6.3 KiB
JavaScript
Raw Permalink Normal View History

2025-04-24 17:03:28 +08:00
import GameModel from "../ts/core/GameModel";
import ItemUtil from "../ts/core/ItemUtil";
import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil";
import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil";
let CPubFunction = require('./PubFunction');
let CMainPlayerInfo = require('./MainPlayerInfo');
cc.Class({
extends: cc.Component,
properties:
{
selectedItem:{
default:0,
type:cc.Integer,
},
nodComposItem: cc.Prefab,
NumPad: cc.Prefab,
num_bar: {
default: null,
type: cc.ProgressBar,
},
num_slider:{
default: null,
type: cc.Slider,
}
},
onLoad() {
this.num_slider.progress=0;
this.num_bar.progress=0;
},
start() {
this.btnFatherItem = cc.find('btnFatherItem', this.node);
this.stFatherItemInfo = null;
this.vecTempA = [];
this.vecTempB = [];
cc.find('btnClose', this.node).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "ComposUI", "Close", 0));
cc.find('btnFatherItem', this.node).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "ComposUI", "OpenNumPad", 0));
cc.find('btnOK', this.node).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "ComposUI", "OnOK", 0));
if(this.selectedItem != 0){
this.stFatherItemInfo = { nItemID:this.selectedItem, nNum: 1 };
}
this.InitFatherItemList();
},
Close() {
this.node.destroy();
},
onSliderClicked(slider, data) {
this.num_bar.progress = slider.progress;
this.resetSendCount();
},
resetSendCount(){
let n = Math.floor(this.currNum / this.needNum);
let label = cc.find('numStr', this.node).getComponent(cc.Label);
let m = Math.floor(this.num_slider.progress * n);
if (n > 0 && m <= 0) {
m = 1;
}
this.numSend = m;
label.string = m + '/' + n;
},
InitFatherItemList() {
let goContent = cc.find('scvFather/view/content', this.node);
SKUIUtil.destroyList(this.vecTempA);
let stStart = { nX: -90, nY: -58 };
let nIndex = -1;
let synthesis=ItemUtil.synthesisMap();
for (let key in synthesis) {
nIndex++;
let stPos = cc.v2(stStart.nX + (nIndex % 3) * 90, stStart.nY - Math.floor(nIndex / 3) * 90);
let goItem = SKUIUtil.createSubNode(goContent, stPos, this.nodComposItem, '');
goItem.getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node,"ComposUI",'SetFatherItem',{ nItemID:key, nNum: 1 }));
if (this.stFatherItemInfo == null) {
this.stFatherItemInfo = { nItemID:key, nNum: 1 };
}
this.SetItemInfo(goItem,key, '');
this.vecTempA.push(goItem);
}
this.SetFatherItem(0, this.stFatherItemInfo);
let height=Math.max(goContent.height, Math.ceil((SKDataUtil.getLength(synthesis) + 1) / 3) * 90 + 20);
goContent.height = height;
},
SetItemInfo(goItem, nID, strText) {
let data = ItemUtil.getItemData(nID);
cc.find('Icon', goItem).getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIconBy(data);
if (Math.floor(this.cunt) < 1 && strText.length >= 3) {
cc.find('Label', goItem).getComponent(cc.Label).node.color = new cc.color(255, 0, 0, 255);
}
cc.find('Label', goItem).getComponent(cc.Label).string = strText;
},
SetFatherItem(event, data) {
if(data==null){
cc.warn(`$警告:設置父道具為空!`);
return;
}
this.stFatherItemInfo = data;
this.SetItemInfo(this.btnFatherItem, data.nItemID, data.nNum);
SKUIUtil.destroyList(this.vecTempB);
let goContent = cc.find('scvSon/view/content', this.node);
let vecSonItem = ItemUtil.getSynthesisItem(data.nItemID);
let nLen = vecSonItem.length;
let index=0;
for (let key in vecSonItem) {
let vecData = vecSonItem[key].split(':');
let stSonInfo = { nItemID: parseInt(vecData[0]), nNum: parseInt(vecData[1]) };
let stPos = cc.v2( - 90 * (nLen - 1) / 2 + index * 90, 0 );
let goSun = SKUIUtil.createSubNode(goContent, stPos, this.nodComposItem, '');
this.currNum = CMainPlayerInfo.GetBagItemCnt(stSonInfo.nItemID);
this.needNum = this.stFatherItemInfo.nNum * stSonInfo.nNum;
let n = 0;
this.cunt = this.currNum / this.needNum;
if (Math.floor(this.cunt) >= 1) {
n = 1;
}
let show=n + '/' + Math.floor(this.cunt);
cc.find('numStr', this.node).getComponent(cc.Label).string = show;
this.SetItemInfo(goSun, stSonInfo.nItemID, `${CMainPlayerInfo.GetBagItemCnt(stSonInfo.nItemID)}/${this.stFatherItemInfo.nNum * stSonInfo.nNum}`);
this.vecTempB.push(goSun);
index++;
}
this.num_slider.progress=(this.cunt<1 ?0:1);
this.num_bar.progress=(this.cunt<1 ?0:1);
this.resetSendCount();
},
OpenNumPad(e, d) {
if (null == this.stFatherItemInfo)
return;
CPubFunction.FindAndDeleteNode(this.node, 'NumPad');
let goNumPad = SKUIUtil.createSubNode(this.node,cc.v2(177,188), this.NumPad, 'NumPad');
goNumPad.getComponent('NumPad').NumPad_Init((nNum) => {
let nCnt = CPubFunction.ChangeNumToRange(nNum, 1, 10000);
this.SetComposCnt(nCnt);
});
},
SetComposCnt(nCnt) {
if (null == this.stFatherItemInfo)
return;
this.stFatherItemInfo.nNum = nCnt;
this.SetFatherItem(this.btnFatherItem, this.stFatherItemInfo);
},
OnReceiveBagItem() {
this.SetFatherItem(0, this.stFatherItemInfo);
},
OnOK() {
let num = 0;
if (null == this.stFatherItemInfo)
return;
if (Math.floor(this.cunt) == 0) {
num = 1;
} else {
if (this.numSend == null || this.numSend == 0) {
num = 1;
} else {
num = this.numSend;
}
}
GameModel.send('c2s_compose', { nFatherItem: this.stFatherItemInfo.nItemID, nNum: num });
},
});