123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- var Global = require("Global");
- cc.Class({
- extends: cc.Component,
- properties: {
- CardPrefab:cc.Node,
- LibraryCardsNode:cc.Node,
- HandCardsNode:cc.Node,
- selectCard:null,
- callFun:null,
- },
- onLoad () {
- },
- start () {
- },
- show:function(data,callFun){
- Global.print("DebugUI show " + JSON.stringify(data));
- if(!data){
- this.node.active = false;
- return;
- }
- this.callFun = callFun;
- var HandCardsArray = [];
- for(let i = 0;i< data.cbHandCardCount;i++){
- HandCardsArray.push(data.cbHandCardsData[i]);
- }
- var LibraryCardsArray = [];
- for(let i = 0;i<data.cbLibraryCardCount;i++){
- if(data.cbLibraryCardsData[i] == 0) {continue}
- LibraryCardsArray.push(data.cbLibraryCardsData[i]);
- }
- LibraryCardsArray.reverse();
- this.HandCardsNode.removeAllChildren();
- for(let i = 0;i<HandCardsArray.length;i++){
- var card = cc.instantiate(this.CardPrefab);
- card.active = true;
- card.getComponent("Card").setId(HandCardsArray[i]);
- this.HandCardsNode.addChild(card);
- }
- this.LibraryCardsNode.removeAllChildren();
- for(let i = 0;i<LibraryCardsArray.length;i++){
- var card = cc.instantiate(this.CardPrefab);
- card.active = true;
- card.getComponent("Card").setId(LibraryCardsArray[i]);
- this.LibraryCardsNode.addChild(card);
- }
- this.node.active = true;
- },
- onBtnClose:function(event,opt){
- this.node.active = false;
- },
- onBtnSure:function(event,opt){
-
- var handCardsData = [];
- for(let i = 0;i<this.HandCardsNode.childrenCount;i++){
- let cardId = this.HandCardsNode.children[i].getComponent("Card").cardId();
- handCardsData.push(cardId);
- }
- var libraryCardsData = [];
- for(let i = 0;i<this.LibraryCardsNode.childrenCount;i++){
- let cardId = this.LibraryCardsNode.children[i].getComponent("Card").cardId();
- libraryCardsData.push(cardId);
- }
- libraryCardsData.reverse();
- Global.print("RUMMY Debug onBtnSure handCardsData " + JSON.stringify(handCardsData));
- Global.print("RUMMY Debug onBtnSure libraryCardsData " + JSON.stringify(libraryCardsData));
- var data = {};
- data.cbHandCardCount = this.HandCardsNode.childrenCount;
- data.cbHandCardsData = handCardsData;
- data.cbLibraryCardCount = this.LibraryCardsNode.childrenCount;
- data.cbLibraryCardsData = libraryCardsData;
- if(this.callFun){
- this.callFun(data);
- }
- this.onBtnClose();
- },
- onBtnCard:function(event,opt){
- if(this.selectCard){
- var card = event.target;
- var cardId = card.getComponent("Card").cardId();
- var selectCardId = this.selectCard.getComponent("Card").cardId();
- card.getComponent("Card").setId(selectCardId);
- this.selectCard.getComponent("Card").setId(cardId);
- this.selectCard.color = cc.color(255,255,255);
- this.selectCard = null;
- }else{
- this.selectCard = event.target;
- this.selectCard.color = cc.color(150,150,150);
- }
- },
- });
|