123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- import CGPPropBagMission from 'CGPPropBagMission'
- var UIHelper = require("UIHelper");
- var topTipMsg = require("topTipMsg");
- var Global = require("Global");
- var propConfig = require("propConfig");
- cc.Class({
- extends: cc.Component,
- properties: {
- listPropContent: {
- default: null,
- type: cc.Node,
- },
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this._propBagMission = new CGPPropBagMission({ URL: cc.vv.config.Address, Port: cc.vv.config.Port });
- this._propBagMission.setMissionSink(this);
- },
- start () {
- UIHelper.addButtonListener(this.node.getChildByName("rootNode").getChildByName("btnClose"), this.node, "propBagJS", "onClickClose");
- UIHelper.addButtonListener(this.node.getChildByName("ChatNode").getChildByName("rootNode").getChildByName("btnClose"), this.node, "propBagJS", "onClickChatClose");
- UIHelper.addButtonListener(this.node.getChildByName("infoNode").getChildByName("rootNode").getChildByName("btnGO"), this.node, "propBagJS", "onClickUseProp");
-
- UIHelper.addButtonListener(this.node.getChildByName("ChatNode").getChildByName("rootNode").getChildByName("btnSendMsg"), this.node, "propBagJS", "onClickSendMsg");
- UIHelper.addButtonListener(this.node.getChildByName("ChatNode").getChildByName("rootNode").getChildByName("btnResetMsg"), this.node, "propBagJS", "onClickResetMsg");
- var gameTab = this.node.getChildByName("rootNode").getChildByName("tab").getChildByName("gameTab");
- gameTab.on("toggle", this.onSelectToggle, this);
- var matchTab = this.node.getChildByName("rootNode").getChildByName("tab").getChildByName("matchTab");
- matchTab.on("toggle", this.onSelectToggle, this);
- },
- onClickClose(event, opt) { //关闭背包界面
- UIHelper.playButtonEffect("close");
- this.node.active = false;
- },
- onClickChatClose(event, opt) { //关闭喇叭界面
- this.node.getChildByName("ChatNode").active = false;
- },
- onSelectToggle: function(event, opt) {
- var tab = this.node.getChildByName("rootNode").getChildByName("tab");
- if (!tab.active) {
- return;
- }
- // var gameTab = tab.getChildByName("gameTab");
- // if (gameTab.getComponent(cc.Toggle).isChecked) {
- // }
- // var matchTab = tab.getChildByName("matchTab");
- // if (matchTab.getComponent(cc.Toggle).isChecked) {
- // }
-
- var kList = cc.vv.globalUserInfo.getUserPropList();
- this.refreshPropItem(kList);
- },
- onClickUseProp(event, opt) { //使用道具
- var propInfo = this.node.getChildByName("infoNode").getComponent("propItemInfoJS").getInfo();
- if (propInfo && propInfo.data) {
- switch (propInfo.info.type) {
- case propConfig.propType.Prop_Type_Gold:
- case propConfig.propType.Prop_Type_Object:
- break;
- case propConfig.propType.Prop_Type_Game: {
- this.node.getChildByName("infoNode").active = false;
- cc.find("Canvas").getComponent("homeStart").goGoldGameByName("NoAssign", {name:""});
- this.node.active = false;
- break;
- }
- default:
- break;
- }
- }
- },
- onClickPropItem(event, opt) { //点击背包道具
- Global.print("propBagJS onClickPropItem 查看信息 datastr = ");
- var propInfo = event.target.getComponent("propItemJS").getPropInfo();
- if (propInfo.info) {
- this.node.getChildByName("infoNode").getComponent("propItemInfoJS").showInfo(propInfo);
- }
- },
- hasMatchProp: function(kList) {
- for (let index = 0; index < kList.length; index++) {
- if (kList[index].dwPropNum > 0) {
- const id = kList[index].dwPropID;
- var prop = propConfig.getPropConfig(id);
- }
- }
- return false;
- },
-
- show: function() { //展示背包
- this.node.active = true;
- var kList = cc.vv.globalUserInfo.getUserPropList();
- var tab = this.node.getChildByName("rootNode").getChildByName("tab");
- tab.active = this.hasMatchProp(kList);
-
- this.refreshPropItem(kList);
- var ani = this.node.getComponent(cc.Animation);
- ani.play("ShowRootNode");
- },
-
- getPropItem(index) { //得到单个道具实例
- if (!this.listPropContent) {
- return null;
- }
- var items = null;
- if (index < this.listPropContent.childrenCount) {
- items = this.listPropContent.children[index];
- }else {
- if (this.listPropContent.childrenCount > 0) {
- items = cc.instantiate(this.listPropContent.children[0]);
- this.listPropContent.addChild(items);
- }
- }
- var js = items.getComponent("propItemJS");
- if (!js) {
- js = items.addComponent("propItemJS");
- }
- UIHelper.addButtonListener(items, this.node, "propBagJS", "onClickPropItem");
- items.active = true;
- return items;
- },
- getRefreshPropType: function() {
- var tab = this.node.getChildByName("rootNode").getChildByName("tab");
- if (!tab.active) {
- return 0;
- }
- var gameTab = tab.getChildByName("gameTab");
- if (gameTab.getComponent(cc.Toggle).isChecked) {
- return 0;
- }
- var matchTab = tab.getChildByName("matchTab");
- if (matchTab.getComponent(cc.Toggle).isChecked) {
- return 1;
- }
- return 0;
- },
- refreshPropItem(kList) { //刷新背包状态
- if (!this.listPropContent) {
- return;
- }
- for (var index = 0; index < this.listPropContent.childrenCount; index++) {
- const items = this.listPropContent.children[index];
- var js = items.getComponent("propItemJS");
- if (js) {
- js.hideItem();
- }
- }
- var type = this.getRefreshPropType();
- var cnt = 0;
- for (var index = 0; index < kList.length; index++) {
- if (kList[index].dwPropNum > 0) {
- const id = kList[index].dwPropID;
- var prop = propConfig.getPropConfig(id);
- Global.print("**** kList[index] = " + JSON.stringify(kList[index]));
- Global.print("**** kList[index] hasOwnProperty = " + kList[index].hasOwnProperty("info"));
-
- if (prop) {
- if (type == 0) {
- continue;
- }
- if (type == 1) {
- continue;
- }
- if(prop.id >= 501 && prop.id <= 506){//1-6级保险箱
- continue;
- }
- var items = this.getPropItem(cnt);
- items.active = true;
-
- var js = items.getComponent("propItemJS");
- if(kList[index].info)
- {
- js.setItemInfo({name:kList[index].strPropName, type:kList[index].info.type}, kList[index]);
- }else
- {
- js.setItemInfo(prop, kList[index]);
- }
-
-
- cnt++;
- }else if ((!prop) && (kList[index].hasOwnProperty("info"))) {
-
- }
- }
- }
- if (cnt > 8) {
- if((cnt % 4) != 0) {
- var num = 0;
- for (var index = 0; index < 4 - cnt; index++) {
- var items = this.getPropItem(cnt + num);
- var js = items.getComponent("propItemJS");
- js.setItemInfo(null, null);
- items.active = true;
- num++;
- }
- }
- }else if (cnt < 8) {
- var num = 0;
- for (var index = 0; index < 8 - cnt; index++) {
- var items = this.getPropItem(cnt + num);
- items.active = true;
-
- var js = items.getComponent("propItemJS");
- js.setItemInfo(null, null);
- num++;
- }
- }
- },
-
- onQueryUsePropItemNet: function(data) { //使用道具返回
- var datastr = JSON.stringify(data);
- Global.print("propBagJS onQueryUsePropItemNet 使用道具 datastr = " + datastr);
- if (data.nResultCode == 0) {
- this.node.getChildByName("infoNode").active = false;
- } else {
- topTipMsg.showTopTipMsg(Global.gbk2Utf8(data.sDescribeString));
- }
- },
- onClickSendMsg: function(event, opt) { //喇叭发送消息
- var chatNode = this.node.getChildByName("ChatNode").getChildByName("rootNode");
- this.onClickChatClose();
- topTipMsg.showTopTipMsg("消息已广播给所有游戏中的玩家");
- this._propBagMission.queryUseTrumpet(cc.vv.globalUserInfo.getUserID(), 4, chatNode.getChildByName("EditBox").getComponent(cc.EditBox).string);
- },
- onClickResetMsg: function(event, opt) { //重置喇叭消息输入
- var chatNode = this.node.getChildByName("ChatNode").getChildByName("rootNode");
- chatNode.getChildByName("EditBox").getComponent(cc.EditBox).string = "";
- },
-
- onEditboxChange:function(event,opt) {
- var chatNode = this.node.getChildByName("ChatNode").getChildByName("rootNode");
- chatNode.getChildByName("EditBox").getComponent(cc.EditBox).string = event.replace(/[\r\n\s]/g, "");
- },
- // update (dt) {},
- });
|