GetAward.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. var UIHelper = require("UIHelper");
  2. var propConfig = require("propConfig");
  3. //var byDefine = require("BYDefine");
  4. var Global = require("Global");
  5. var BaseDefine = require("BaseDefine");
  6. var LanguageKey = require("LanguageKey");
  7. var topTipMsg = require("topTipMsg")
  8. cc.Class({
  9. extends: cc.Component,
  10. properties: {
  11. _moreFun:null,
  12. _backCallFun:null,
  13. },
  14. // LIFE-CYCLE CALLBACKS:
  15. onLoad () {
  16. UIHelper.addButtonListener(this.node.getChildByName("Mask"), this.node, "GetAward", "hideAward");
  17. UIHelper.addButtonListener(this.node.getChildByName("btnMore"), this.node, "GetAward", "onClickMore");
  18. UIHelper.addButtonListener(this.node.getChildByName("MaskEX").getChildByName("btn_IKnow"), this.node, "GetAward", "onClickIKnow");
  19. UIHelper.addButtonListener(this.node.getChildByName("MaskEX").getChildByName("btn_guidance"), this.node, "GetAward", "onClickGuidance");
  20. this.node.getChildByName("MaskEX").active = false;
  21. },
  22. showAward: function(kPropList, backCallFun, moreFun, noGoldAdd, bOnlyShow) {
  23. this.node.getChildByName("MaskEX").active = false;
  24. if(!kPropList || kPropList.length<=0)
  25. {
  26. this.node.active = false;
  27. return;
  28. }
  29. var rootNode = this.node.getChildByName("rootNode");
  30. rootNode.removeAllChildren();
  31. var isRedEnvelopes = false;//奖励是红包
  32. var hasMatchProp = false;
  33. let awardListStr = LanguageKey.t(LanguageKey.Public.getAward);
  34. for (let index = 0; index < kPropList.length; index++) {
  35. const element = kPropList[index];
  36. if (element.dwPropID >= 100000 && element.dwPropID < 102010) {//比赛道具
  37. // var node = cc.instantiate(this.node.getChildByName("Spr"));
  38. // node.active = true;
  39. // rootNode.addChild(node);
  40. // node.getChildByName("icon").getComponent("urlSpriteFrame").setUrl(BaseDefine.MATCH_PROP_IMG_URL + element.dwPropID + ".png");
  41. if (element.dwPropID >= 100000 && element.dwPropID < 101000 ) {
  42. // node.getChildByName("AwardLabel").getComponent(cc.Label).string = "现金券×1";
  43. awardListStr += " 现金券×1";
  44. }else if (element.dwPropID >= 101000 && element.dwPropID < 102000 ) {
  45. // node.getChildByName("AwardLabel").getComponent(cc.Label).string = "代金券×1";
  46. awardListStr += " 代金券×1";
  47. }else if (element.dwPropID >= 102000 && element.dwPropID < 102010 ) {
  48. // node.getChildByName("AwardLabel").getComponent(cc.Label).string = "入场券×1";
  49. awardListStr += " 入场券×1";
  50. }
  51. hasMatchProp = true;
  52. } else {
  53. //awardType : 10000: 鲜花饼, 30000:金豆, 200000:实物, 40000:红包券 50000:现金红包
  54. var prop = propConfig.getPropConfig(element.dwPropID);
  55. if (prop.type == propConfig.propType.Prop_Type_Object) {
  56. continue;
  57. }
  58. if (!bOnlyShow) {
  59. if (prop.type != propConfig.propType.Prop_Type_Gold) {
  60. cc.vv.globalUserInfo.addUserProp(element.dwPropID, element.dwPropNum);
  61. }else {
  62. if (element.dwPropID == propConfig.propID.Prop_Id_Gold) {
  63. if (!noGoldAdd) {
  64. var score = cc.vv.globalUserInfo.getUserScore();
  65. Global.print("cc.vv.globalUserInfo.setUserScore showAward::" + score)
  66. cc.vv.globalUserInfo.setUserScore((parseFloat(score) + element.dwPropNum));
  67. }
  68. }else if (element.dwPropID == propConfig.propID.Prop_Id_Card) {
  69. var revenue = cc.vv.globalUserInfo.getUserInsure();
  70. cc.vv.globalUserInfo.setUserInsure(revenue + element.dwPropNum);
  71. }else if (element.dwPropID == propConfig.propID.Prop_Id_Red) {
  72. var insure = cc.vv.globalUserInfo.getRevenue();
  73. cc.vv.globalUserInfo.setRevenue(insure + element.dwPropNum);
  74. }
  75. }
  76. }
  77. // var node = cc.instantiate(this.node.getChildByName("Spr"));
  78. // node.active = true;
  79. // UIHelper.setSpriteFrameByUrl(node.getChildByName("icon").getComponent(cc.Sprite), "Hall/prop/prop_bag_" + element.dwPropID);
  80. // node.getChildByName("AwardLabel").getComponent(cc.Label).string = prop.name + "×" + element.dwPropNum;
  81. // rootNode.addChild(node);
  82. awardListStr += " " + prop.name + "×" + Global.formatString2Score(element.dwPropNum);
  83. if(prop.id == propConfig.propID.Prop_Id_RedEnvelopes)//红包
  84. {
  85. // this.node.getChildByName("MaskEX").active = true;
  86. // node.getChildByName("AwardLabel").getComponent(cc.Label).string = prop.name + "×" + element.dwPropNum + "元";
  87. awardListStr += " " + prop.name + "×" + element.dwPropNum + "元";
  88. isRedEnvelopes = true;
  89. }
  90. }
  91. }
  92. // if (rootNode.childrenCount <= 0) {
  93. // return ;
  94. // }
  95. if (hasMatchProp) {
  96. cc.vv.globalUserInfo.reqMatchProp();
  97. }
  98. var self = this;
  99. // this.node.active = true;
  100. UIHelper.playButtonEffect("award");
  101. // var spb = this.node.getChildByName("SpBg").getChildByName("sp").getComponent(sp.Skeleton);
  102. this.node.getChildByName("Mask").getComponent(cc.Button).interactable = false;
  103. this.node.getChildByName("TouchTip").active = false;
  104. // this.node.getChildByName("Spr").getComponent(cc.Animation).play();
  105. //this.node.getChildByName("AwardLabel").active = false;
  106. // spb.animation = "a1";
  107. // spb.loop = false;
  108. // spb.setCompleteListener(function() {
  109. // self.node.getChildByName("Mask").getComponent(cc.Button).interactable = true;
  110. // if(!isRedEnvelopes){
  111. // self.node.getChildByName("TouchTip").active = true;
  112. // }
  113. // //self.node.getChildByName("AwardLabel").active = true;
  114. // spb.animation = "a2";
  115. // spb.loop = true;
  116. // });
  117. topTipMsg.showTopTipMsg(awardListStr);
  118. this._moreFun = null;
  119. this.node.getChildByName("btnMore").active = false;
  120. if (moreFun) {
  121. this._moreFun = moreFun;
  122. this.node.getChildByName("btnMore").active = true;
  123. }
  124. this._backCallFun = null;
  125. if (backCallFun) {
  126. this._backCallFun = backCallFun;
  127. }
  128. },
  129. showAwardLucky: function(kProp) {
  130. var rootNode = this.node.getChildByName("rootNode");
  131. rootNode.removeAllChildren();
  132. //awardType : 10000: 鲜花饼, 30000:金豆, 200000:实物, 40000:红包券 50000:现金红包
  133. var node = cc.instantiate(this.node.getChildByName("Spr"));
  134. node.active = true;
  135. var imgGoods = node.getChildByName("icon");
  136. cc.assetManager.loadRemote(kProp.dwPropURL, function (err, tex) {
  137. if (err) {
  138. Global.print(err);
  139. } else {
  140. imgGoods.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(tex);
  141. }
  142. });
  143. node.getChildByName("AwardLabel").getComponent(cc.Label).string = Global.gbk2Utf8(kProp.dwPropName);
  144. rootNode.addChild(node);
  145. if (rootNode.childrenCount <= 0) {
  146. return ;
  147. }
  148. var self = this;
  149. this.node.active = true;
  150. UIHelper.playButtonEffect("award");
  151. var spb = this.node.getChildByName("SpBg").getChildByName("sp").getComponent(sp.Skeleton);
  152. this.node.getChildByName("Mask").getComponent(cc.Button).interactable = false;
  153. this.node.getChildByName("TouchTip").active = false;
  154. this.node.getChildByName("Spr").getComponent(cc.Animation).play();
  155. //this.node.getChildByName("AwardLabel").active = false;
  156. spb.setTrackCompleteListener(spb.setAnimation(0, "a1", false), function() {
  157. self.node.getChildByName("Mask").getComponent(cc.Button).interactable = true;
  158. self.node.getChildByName("TouchTip").active = true;
  159. //self.node.getChildByName("AwardLabel").active = true;
  160. spb.setAnimation(0, "a2", true);
  161. });
  162. },
  163. hideAward: function() {
  164. if (cc.director.getScene().name == "byScene") {
  165. } else {
  166. UIHelper.playButtonEffect("close");
  167. }
  168. this.node.active = false;
  169. cc.vv.shareType = "";
  170. if (this._backCallFun) {
  171. this._backCallFun(false);
  172. this._backCallFun = null;
  173. }
  174. },
  175. onClickMore: function() {
  176. if (BaseDefine.GAME_PLATFORM == BaseDefine.WEB_H5_PLATFORM) {
  177. this.onShareSucc();
  178. }
  179. },
  180. onShareSucc: function() {
  181. // if (cc.vv.shareType == "taskwxpyq") {
  182. // if (this._moreFun) {
  183. // this._moreFun(true);
  184. // this._moreFun = null;
  185. // }
  186. // this.node.active = false;
  187. // }
  188. },
  189. onClickIKnow:function(){
  190. this.hideAward();
  191. },
  192. onClickGuidance:function(){
  193. UIHelper.playButtonEffect("open");
  194. },
  195. });