propBagJS.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. import CGPPropBagMission from 'CGPPropBagMission'
  2. var UIHelper = require("UIHelper");
  3. var topTipMsg = require("topTipMsg");
  4. var Global = require("Global");
  5. var propConfig = require("propConfig");
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. listPropContent: {
  10. default: null,
  11. type: cc.Node,
  12. },
  13. },
  14. // LIFE-CYCLE CALLBACKS:
  15. onLoad () {
  16. this._propBagMission = new CGPPropBagMission({ URL: cc.vv.config.Address, Port: cc.vv.config.Port });
  17. this._propBagMission.setMissionSink(this);
  18. },
  19. start () {
  20. UIHelper.addButtonListener(this.node.getChildByName("rootNode").getChildByName("btnClose"), this.node, "propBagJS", "onClickClose");
  21. UIHelper.addButtonListener(this.node.getChildByName("ChatNode").getChildByName("rootNode").getChildByName("btnClose"), this.node, "propBagJS", "onClickChatClose");
  22. UIHelper.addButtonListener(this.node.getChildByName("infoNode").getChildByName("rootNode").getChildByName("btnGO"), this.node, "propBagJS", "onClickUseProp");
  23. UIHelper.addButtonListener(this.node.getChildByName("ChatNode").getChildByName("rootNode").getChildByName("btnSendMsg"), this.node, "propBagJS", "onClickSendMsg");
  24. UIHelper.addButtonListener(this.node.getChildByName("ChatNode").getChildByName("rootNode").getChildByName("btnResetMsg"), this.node, "propBagJS", "onClickResetMsg");
  25. var gameTab = this.node.getChildByName("rootNode").getChildByName("tab").getChildByName("gameTab");
  26. gameTab.on("toggle", this.onSelectToggle, this);
  27. var matchTab = this.node.getChildByName("rootNode").getChildByName("tab").getChildByName("matchTab");
  28. matchTab.on("toggle", this.onSelectToggle, this);
  29. },
  30. onClickClose(event, opt) { //关闭背包界面
  31. UIHelper.playButtonEffect("close");
  32. this.node.active = false;
  33. },
  34. onClickChatClose(event, opt) { //关闭喇叭界面
  35. this.node.getChildByName("ChatNode").active = false;
  36. },
  37. onSelectToggle: function(event, opt) {
  38. var tab = this.node.getChildByName("rootNode").getChildByName("tab");
  39. if (!tab.active) {
  40. return;
  41. }
  42. // var gameTab = tab.getChildByName("gameTab");
  43. // if (gameTab.getComponent(cc.Toggle).isChecked) {
  44. // }
  45. // var matchTab = tab.getChildByName("matchTab");
  46. // if (matchTab.getComponent(cc.Toggle).isChecked) {
  47. // }
  48. var kList = cc.vv.globalUserInfo.getUserPropList();
  49. this.refreshPropItem(kList);
  50. },
  51. onClickUseProp(event, opt) { //使用道具
  52. var propInfo = this.node.getChildByName("infoNode").getComponent("propItemInfoJS").getInfo();
  53. if (propInfo && propInfo.data) {
  54. switch (propInfo.info.type) {
  55. case propConfig.propType.Prop_Type_Gold:
  56. case propConfig.propType.Prop_Type_Object:
  57. break;
  58. case propConfig.propType.Prop_Type_Game: {
  59. this.node.getChildByName("infoNode").active = false;
  60. cc.find("Canvas").getComponent("homeStart").goGoldGameByName("NoAssign", {name:""});
  61. this.node.active = false;
  62. break;
  63. }
  64. default:
  65. break;
  66. }
  67. }
  68. },
  69. onClickPropItem(event, opt) { //点击背包道具
  70. Global.print("propBagJS onClickPropItem 查看信息 datastr = ");
  71. var propInfo = event.target.getComponent("propItemJS").getPropInfo();
  72. if (propInfo.info) {
  73. this.node.getChildByName("infoNode").getComponent("propItemInfoJS").showInfo(propInfo);
  74. }
  75. },
  76. hasMatchProp: function(kList) {
  77. for (let index = 0; index < kList.length; index++) {
  78. if (kList[index].dwPropNum > 0) {
  79. const id = kList[index].dwPropID;
  80. var prop = propConfig.getPropConfig(id);
  81. }
  82. }
  83. return false;
  84. },
  85. show: function() { //展示背包
  86. this.node.active = true;
  87. var kList = cc.vv.globalUserInfo.getUserPropList();
  88. var tab = this.node.getChildByName("rootNode").getChildByName("tab");
  89. tab.active = this.hasMatchProp(kList);
  90. this.refreshPropItem(kList);
  91. var ani = this.node.getComponent(cc.Animation);
  92. ani.play("ShowRootNode");
  93. },
  94. getPropItem(index) { //得到单个道具实例
  95. if (!this.listPropContent) {
  96. return null;
  97. }
  98. var items = null;
  99. if (index < this.listPropContent.childrenCount) {
  100. items = this.listPropContent.children[index];
  101. }else {
  102. if (this.listPropContent.childrenCount > 0) {
  103. items = cc.instantiate(this.listPropContent.children[0]);
  104. this.listPropContent.addChild(items);
  105. }
  106. }
  107. var js = items.getComponent("propItemJS");
  108. if (!js) {
  109. js = items.addComponent("propItemJS");
  110. }
  111. UIHelper.addButtonListener(items, this.node, "propBagJS", "onClickPropItem");
  112. items.active = true;
  113. return items;
  114. },
  115. getRefreshPropType: function() {
  116. var tab = this.node.getChildByName("rootNode").getChildByName("tab");
  117. if (!tab.active) {
  118. return 0;
  119. }
  120. var gameTab = tab.getChildByName("gameTab");
  121. if (gameTab.getComponent(cc.Toggle).isChecked) {
  122. return 0;
  123. }
  124. var matchTab = tab.getChildByName("matchTab");
  125. if (matchTab.getComponent(cc.Toggle).isChecked) {
  126. return 1;
  127. }
  128. return 0;
  129. },
  130. refreshPropItem(kList) { //刷新背包状态
  131. if (!this.listPropContent) {
  132. return;
  133. }
  134. for (var index = 0; index < this.listPropContent.childrenCount; index++) {
  135. const items = this.listPropContent.children[index];
  136. var js = items.getComponent("propItemJS");
  137. if (js) {
  138. js.hideItem();
  139. }
  140. }
  141. var type = this.getRefreshPropType();
  142. var cnt = 0;
  143. for (var index = 0; index < kList.length; index++) {
  144. if (kList[index].dwPropNum > 0) {
  145. const id = kList[index].dwPropID;
  146. var prop = propConfig.getPropConfig(id);
  147. Global.print("**** kList[index] = " + JSON.stringify(kList[index]));
  148. Global.print("**** kList[index] hasOwnProperty = " + kList[index].hasOwnProperty("info"));
  149. if (prop) {
  150. if (type == 0) {
  151. continue;
  152. }
  153. if (type == 1) {
  154. continue;
  155. }
  156. if(prop.id >= 501 && prop.id <= 506){//1-6级保险箱
  157. continue;
  158. }
  159. var items = this.getPropItem(cnt);
  160. items.active = true;
  161. var js = items.getComponent("propItemJS");
  162. if(kList[index].info)
  163. {
  164. js.setItemInfo({name:kList[index].strPropName, type:kList[index].info.type}, kList[index]);
  165. }else
  166. {
  167. js.setItemInfo(prop, kList[index]);
  168. }
  169. cnt++;
  170. }else if ((!prop) && (kList[index].hasOwnProperty("info"))) {
  171. }
  172. }
  173. }
  174. if (cnt > 8) {
  175. if((cnt % 4) != 0) {
  176. var num = 0;
  177. for (var index = 0; index < 4 - cnt; index++) {
  178. var items = this.getPropItem(cnt + num);
  179. var js = items.getComponent("propItemJS");
  180. js.setItemInfo(null, null);
  181. items.active = true;
  182. num++;
  183. }
  184. }
  185. }else if (cnt < 8) {
  186. var num = 0;
  187. for (var index = 0; index < 8 - cnt; index++) {
  188. var items = this.getPropItem(cnt + num);
  189. items.active = true;
  190. var js = items.getComponent("propItemJS");
  191. js.setItemInfo(null, null);
  192. num++;
  193. }
  194. }
  195. },
  196. onQueryUsePropItemNet: function(data) { //使用道具返回
  197. var datastr = JSON.stringify(data);
  198. Global.print("propBagJS onQueryUsePropItemNet 使用道具 datastr = " + datastr);
  199. if (data.nResultCode == 0) {
  200. this.node.getChildByName("infoNode").active = false;
  201. } else {
  202. topTipMsg.showTopTipMsg(Global.gbk2Utf8(data.sDescribeString));
  203. }
  204. },
  205. onClickSendMsg: function(event, opt) { //喇叭发送消息
  206. var chatNode = this.node.getChildByName("ChatNode").getChildByName("rootNode");
  207. this.onClickChatClose();
  208. topTipMsg.showTopTipMsg("消息已广播给所有游戏中的玩家");
  209. this._propBagMission.queryUseTrumpet(cc.vv.globalUserInfo.getUserID(), 4, chatNode.getChildByName("EditBox").getComponent(cc.EditBox).string);
  210. },
  211. onClickResetMsg: function(event, opt) { //重置喇叭消息输入
  212. var chatNode = this.node.getChildByName("ChatNode").getChildByName("rootNode");
  213. chatNode.getChildByName("EditBox").getComponent(cc.EditBox).string = "";
  214. },
  215. onEditboxChange:function(event,opt) {
  216. var chatNode = this.node.getChildByName("ChatNode").getChildByName("rootNode");
  217. chatNode.getChildByName("EditBox").getComponent(cc.EditBox).string = event.replace(/[\r\n\s]/g, "");
  218. },
  219. // update (dt) {},
  220. });