ShopJS.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. 商城
  3. */
  4. //var planeInfo = require('PlaneInfoJS');
  5. var prisonInfo = require('PrisonerInfo');
  6. var WxCommon = require("../extra/WxCommon")
  7. cc.Class({
  8. extends: cc.Component,
  9. properties: {
  10. sceneManager: {
  11. default: null,
  12. type: cc.Node
  13. },
  14. gold: { //玩家分数
  15. default: null,
  16. type: cc.Label
  17. },
  18. characterName: { //人物名字
  19. default: null,
  20. type: cc.Label
  21. },
  22. price: { //人物价格展示
  23. default: null,
  24. type: cc.Label
  25. },
  26. introduceLabel: { //人物介绍
  27. default: null,
  28. type: cc.Label
  29. },
  30. lockedLabel : { //解锁提示
  31. default: null,
  32. type: cc.Label
  33. },
  34. chaDisplay: { //人物展示图片
  35. default: null,
  36. type: cc.Node
  37. },
  38. buy: { //购买按钮
  39. default: null,
  40. type: cc.Node
  41. },
  42. // lockPlay: { //锁,开始节点
  43. // default: null,
  44. // type: cc.Node
  45. // },
  46. // lockPlaySPFArr: { //锁、开始图片数组
  47. // default: [],
  48. // type: [cc.SpriteFrame]
  49. // },
  50. characrerSPFArr: { //展示人物节点数组
  51. default: [],
  52. type: [cc.Prefab]
  53. },
  54. },
  55. onLoad: function() {
  56. this._planeLevelIndex = UserInfo.getString("isLock1") == "true" ? UserInfo.getCurrentPrison()-1 : 1; //当前选中的飞机下标
  57. this.chaDisplay.removeAllChildren();
  58. var prisonNode = cc.instantiate(this.characrerSPFArr[this._planeLevelIndex]);
  59. this.chaDisplay.addChild(prisonNode);
  60. var prisonersk = prisonNode.getComponent(sp.Skeleton);
  61. prisonersk.setAnimation(0, "a1", true);
  62. this.price.string = prisonInfo[this._planeLevelIndex].price;
  63. this.introduceLabel.string = prisonInfo[this._planeLevelIndex].introduce;
  64. this.gold.string = ""+UserInfo.getGold();
  65. this.characterName.string = prisonInfo[this._planeLevelIndex].name;
  66. this.node.getChildByName("ChaPrice").active = this._planeLevelIndex != 1;
  67. //this.node.getChildByName("ShareTip").active = this._planeLevelIndex == 1;
  68. this.node.getChildByName("ShareTip").active = false;
  69. this.isShowBuyButton();
  70. this.isShowShareButton();
  71. },
  72. onEnable: function() {
  73. this.chaDisplay.removeAllChildren();
  74. var prisonNode = cc.instantiate(this.characrerSPFArr[this._planeLevelIndex]);
  75. this.chaDisplay.addChild(prisonNode);
  76. var prisonersk = prisonNode.getComponent(sp.Skeleton);
  77. prisonersk.setAnimation(0, "a1", true);
  78. this.price.string = prisonInfo[this._planeLevelIndex].price;
  79. this.introduceLabel.string = prisonInfo[this._planeLevelIndex].introduce;
  80. this.gold.string = ""+UserInfo.getGold();
  81. this.characterName.string = prisonInfo[this._planeLevelIndex].name;
  82. this.node.getChildByName("ChaPrice").active = this._planeLevelIndex != 1;
  83. //this.node.getChildByName("ShareTip").active = this._planeLevelIndex == 1;
  84. this.node.getChildByName("ShareTip").active = false;
  85. this.isShowBuyButton();
  86. this.isShowShareButton();
  87. },
  88. onGoMain: function() {
  89. this._planeLevelIndex = UserInfo.getString("isLock1") == "true" ? this._planeLevelIndex : 1;
  90. this.sceneManager.getComponent('SceneManager').changeCanvasByName('Main');
  91. },
  92. onGoGame: function() {
  93. this._planeLevelIndex = UserInfo.getString("isLock1") == "true" ? this._planeLevelIndex : 1;
  94. //this.sceneManager.getComponent('SceneManager').changeCanvasByName('Game');
  95. // if (parseInt(UserInfo.getString("course")) == 1) {
  96. // UserInfo.setString("course", '0');
  97. // this.sceneManager.getComponent('SceneManager').changeCanvasByName('Guide');
  98. // } else {
  99. this.sceneManager.getComponent('SceneManager').changeCanvasByName('Game');
  100. //}
  101. },
  102. onLeft: function() {
  103. this._planeLevelIndex--;
  104. if (this._planeLevelIndex < 0) this._planeLevelIndex = prisonInfo.length-1;
  105. this.chaDisplay.removeAllChildren();
  106. var prisonNode = cc.instantiate(this.characrerSPFArr[this._planeLevelIndex]);
  107. this.chaDisplay.addChild(prisonNode);
  108. var prisonersk = prisonNode.getComponent(sp.Skeleton);
  109. prisonersk.setAnimation(0, "a1", true);
  110. this.price.string = prisonInfo[this._planeLevelIndex].price;
  111. this.characterName.string = prisonInfo[this._planeLevelIndex].name;
  112. this.introduceLabel.string = prisonInfo[this._planeLevelIndex].introduce;
  113. this.node.getChildByName("ChaPrice").active = this._planeLevelIndex != 1;
  114. //this.node.getChildByName("ShareTip").active = this._planeLevelIndex == 1;
  115. this.isShowBuyButton();
  116. this.isShowShareButton();
  117. },
  118. onRight: function() {
  119. this._planeLevelIndex++;
  120. if (this._planeLevelIndex == prisonInfo.length) this._planeLevelIndex = 0;
  121. this.chaDisplay.removeAllChildren();
  122. var prisonNode = cc.instantiate(this.characrerSPFArr[this._planeLevelIndex]);
  123. this.chaDisplay.addChild(prisonNode);
  124. var prisonersk = prisonNode.getComponent(sp.Skeleton);
  125. prisonersk.setAnimation(0, "a1", true);
  126. this.price.string = prisonInfo[this._planeLevelIndex].price;
  127. this.characterName.string = prisonInfo[this._planeLevelIndex].name;
  128. this.introduceLabel.string = prisonInfo[this._planeLevelIndex].introduce;
  129. this.node.getChildByName("ChaPrice").active = this._planeLevelIndex != 1;
  130. //this.node.getChildByName("ShareTip").active = this._planeLevelIndex == 1;
  131. this.isShowBuyButton();
  132. this.isShowShareButton();
  133. },
  134. onBuy: function() {
  135. let playerGold = UserInfo.getGold();
  136. let chaPrice = parseInt(this.price.string);
  137. if (playerGold >= chaPrice) { //够钱买飞机
  138. let lastGold = playerGold - chaPrice;
  139. this.gold.string = ""+lastGold;
  140. UserInfo.setGold(lastGold);
  141. UserInfo.setString("isLock"+this._planeLevelIndex, "true");
  142. this.isShowBuyButton();
  143. this.isShowShareButton();
  144. } else { //不够
  145. if (UserInfo.platform == 1) {
  146. wx.showModal({
  147. title:'温馨提示',
  148. content:'您的金币不足,无法购买',
  149. showCancel:false,
  150. cancelText:'取消',
  151. cancelColor:'#000000',
  152. confirmText:'确认',
  153. confirmColor:'#3cc51f',
  154. success: function(res) {
  155. cc.vv.isAlreadyShow = true;
  156. }
  157. })
  158. }
  159. return;
  160. }
  161. },
  162. isShowBuyButton: function() {
  163. this.node.getChildByName("btnShare").active = false;
  164. this.buy.active = false;
  165. if (this.checkPlaneLock()) {
  166. //this.lockPlay.getComponent(cc.Button).enabled = true;
  167. //this.lockPlay.getComponent(cc.Sprite).spriteFrame = this.lockPlaySPFArr[1];
  168. this.price.node.parent.active = false;
  169. this.lockedLabel.node.active = true;
  170. } else {
  171. this.buy.active = true;
  172. //this.lockPlay.getComponent(cc.Button).enabled = false;
  173. //this.lockPlay.getComponent(cc.Sprite).spriteFrame = this.lockPlaySPFArr[0];
  174. this.price.node.parent.active = true;
  175. this.lockedLabel.node.active = false;
  176. }
  177. //设置开始按钮能否点击
  178. },
  179. isShowShareButton: function() {
  180. // if (this._planeLevelIndex == 1) {
  181. // if (!this.checkPlaneLock()) {
  182. // this.buy.active = false;
  183. // this.node.getChildByName("btnShare").active = false;
  184. // this.node.getChildByName("ChaPrice").active = false;
  185. // this.node.getChildByName("ShareTip").active = false;
  186. // // this.lockPlay.getComponent(cc.Button).enabled = false;
  187. // // this.lockPlay.getComponent(cc.Sprite).spriteFrame = this.lockPlaySPFArr[0];
  188. // } else {
  189. // this.node.getChildByName("ShareTip").active = false;
  190. // this.lockedLabel.node.active = true;
  191. // }
  192. // }
  193. },
  194. onShare: function() {
  195. var self = this;
  196. var Ok = function() {
  197. UserInfo.setString("isLock"+self._planeLevelIndex, "true");
  198. // this.lockPlay.getComponent(cc.Button).enabled = true;
  199. // this.lockPlay.getComponent(cc.Sprite).spriteFrame = this.lockPlaySPFArr[1];
  200. self.isShowBuyButton();
  201. self.isShowShareButton();
  202. }
  203. var data = {titleData:UserInfo.shareDesc,imgurlData:UserInfo.shareUrl,queryData:'pp=pp'}
  204. WxCommon.ShareAppMessage(data, this, Ok);
  205. },
  206. //检测当前选中飞机有没有解锁
  207. checkPlaneLock: function() {
  208. let currentIsLockKey = "isLock"+this._planeLevelIndex;
  209. let isLock = UserInfo.getString(currentIsLockKey);
  210. if (isLock == "true") {//解锁
  211. UserInfo.setCurrentPrison(this._planeLevelIndex+1);
  212. } else {//没有解锁
  213. if (this._planeLevelIndex == 0) { //如果是0号飞机,不需要解锁
  214. isLock = "true";
  215. UserInfo.setString(currentIsLockKey, "true");
  216. }
  217. }
  218. return isLock == "true" ? true : false;
  219. },
  220. });