DebugUI.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. var Global = require("Global");
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. CardPrefab:cc.Node,
  6. LibraryCardsNode:cc.Node,
  7. HandCardsNode:cc.Node,
  8. selectCard:null,
  9. callFun:null,
  10. },
  11. onLoad () {
  12. },
  13. start () {
  14. },
  15. show:function(data,callFun){
  16. Global.print("DebugUI show " + JSON.stringify(data));
  17. if(!data){
  18. this.node.active = false;
  19. return;
  20. }
  21. this.callFun = callFun;
  22. var HandCardsArray = [];
  23. for(let i = 0;i< data.cbHandCardCount;i++){
  24. HandCardsArray.push(data.cbHandCardsData[i]);
  25. }
  26. var LibraryCardsArray = [];
  27. for(let i = 0;i<data.cbLibraryCardCount;i++){
  28. if(data.cbLibraryCardsData[i] == 0) {continue}
  29. LibraryCardsArray.push(data.cbLibraryCardsData[i]);
  30. }
  31. LibraryCardsArray.reverse();
  32. this.HandCardsNode.removeAllChildren();
  33. for(let i = 0;i<HandCardsArray.length;i++){
  34. var card = cc.instantiate(this.CardPrefab);
  35. card.active = true;
  36. card.getComponent("Card").setId(HandCardsArray[i]);
  37. this.HandCardsNode.addChild(card);
  38. }
  39. this.LibraryCardsNode.removeAllChildren();
  40. for(let i = 0;i<LibraryCardsArray.length;i++){
  41. var card = cc.instantiate(this.CardPrefab);
  42. card.active = true;
  43. card.getComponent("Card").setId(LibraryCardsArray[i]);
  44. this.LibraryCardsNode.addChild(card);
  45. }
  46. this.node.active = true;
  47. },
  48. onBtnClose:function(event,opt){
  49. this.node.active = false;
  50. },
  51. onBtnSure:function(event,opt){
  52. var handCardsData = [];
  53. for(let i = 0;i<this.HandCardsNode.childrenCount;i++){
  54. let cardId = this.HandCardsNode.children[i].getComponent("Card").cardId();
  55. handCardsData.push(cardId);
  56. }
  57. var libraryCardsData = [];
  58. for(let i = 0;i<this.LibraryCardsNode.childrenCount;i++){
  59. let cardId = this.LibraryCardsNode.children[i].getComponent("Card").cardId();
  60. libraryCardsData.push(cardId);
  61. }
  62. libraryCardsData.reverse();
  63. Global.print("RUMMY Debug onBtnSure handCardsData " + JSON.stringify(handCardsData));
  64. Global.print("RUMMY Debug onBtnSure libraryCardsData " + JSON.stringify(libraryCardsData));
  65. var data = {};
  66. data.cbHandCardCount = this.HandCardsNode.childrenCount;
  67. data.cbHandCardsData = handCardsData;
  68. data.cbLibraryCardCount = this.LibraryCardsNode.childrenCount;
  69. data.cbLibraryCardsData = libraryCardsData;
  70. if(this.callFun){
  71. this.callFun(data);
  72. }
  73. this.onBtnClose();
  74. },
  75. onBtnCard:function(event,opt){
  76. if(this.selectCard){
  77. var card = event.target;
  78. var cardId = card.getComponent("Card").cardId();
  79. var selectCardId = this.selectCard.getComponent("Card").cardId();
  80. card.getComponent("Card").setId(selectCardId);
  81. this.selectCard.getComponent("Card").setId(cardId);
  82. this.selectCard.color = cc.color(255,255,255);
  83. this.selectCard = null;
  84. }else{
  85. this.selectCard = event.target;
  86. this.selectCard.color = cc.color(150,150,150);
  87. }
  88. },
  89. });