HomeSence.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. var WxCommon = require("../WxCommon")
  2. var QQCommon = require("../QQCommon")
  3. var cfg = require("Configure")
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. gamebgMusic: {
  8. default: null,
  9. type: cc.AudioClip
  10. },
  11. buttonAudio: {
  12. default: null,
  13. type: cc.AudioClip
  14. },
  15. SignAtlas: {
  16. default: null,
  17. type: cc.SpriteAtlas,
  18. },
  19. ShareStrategyNode: { //游戏攻略图片节点
  20. default: null,
  21. type: cc.Node
  22. },
  23. GuideNode: {
  24. default: null,
  25. type: cc.Node
  26. },
  27. feiendtex: null,
  28. otherGamesIndex: 0,
  29. skinIndex: 0,
  30. showGuideValue: 0
  31. },
  32. // LIFE-CYCLE CALLBACKS:
  33. onLoad() {
  34. cc.audioEngine.playMusic(this.gamebgMusic, true);
  35. if(CC_QQPLAY && window.GameStatusInfo) {
  36. GameStatusInfo.startMs = ((new Date()).getTime()).toString()
  37. }
  38. // let path = 'GameSandBox://qrcode2.png'
  39. // BK.QRCode.makeQRCodeToFileSync({
  40. // path: path,
  41. // content: 'hello world',
  42. // config: {
  43. // width: 256,
  44. // height: 256
  45. // }
  46. // });
  47. // new BK.Game({
  48. // onShare: function(app) {
  49. // var shareInfo = {
  50. // summary: '分享正文',
  51. // localPicPath: path,
  52. // picUrl: 'https://pub.dwstatic.com/wxgame/budingGame/share/shareImage.jpg',
  53. // gameName: '游戏名称'
  54. // }
  55. // return shareInfo
  56. // }
  57. // })
  58. this.showGuideValue = UserInfo.getItem('showGuide') || false;
  59. if (CC_QQPLAY) {
  60. // this.QQLogin();
  61. // this.initShare();
  62. UserInfo.showIndexBanner();
  63. try{
  64. BK.Script.errorAlertOpen = false;
  65. } catch(e) {}
  66. }
  67. },
  68. start() {
  69. this.feiendtex = new cc.Texture2D();
  70. this.PHB = cc.find("Canvas/PHB")
  71. this.rankScene = this.PHB.getComponent("RankScene");
  72. this.rankNode = this.PHB.getChildByName("Rank")
  73. this.myRankNode = this.PHB.getChildByName('MyRank')
  74. this.worldContentNode = this.rankNode.getChildByName('WorldContent')
  75. this.friendContentNode = this.rankNode.getChildByName('FriendContent')
  76. },
  77. QQLogin() {
  78. if(window.GameStatusInfo && window.GameStatusInfo.openId) {
  79. BK.Console.log('登录成功')
  80. }
  81. },
  82. // initShare(data) {
  83. // let datavalue = UserInfo.getString('allscore');
  84. // let key = UserInfo.getCurWeekScoreValue();
  85. // if (UserInfo.IsEmpty(datavalue)) {
  86. // UserInfo.setString('allscore', key);
  87. // return;
  88. // }
  89. // let datalist = datavalue.split('*');
  90. // let removeIndex = -1;
  91. // for (let index = 0; index < datalist.length; ++index) {
  92. // if (key == datalist[index]) {
  93. // // UserInfo.removeString(datalist[index]);
  94. // removeIndex = index;
  95. // }
  96. // }
  97. // if (removeIndex != -1) {
  98. // datalist.splice(removeIndex, 1);
  99. // }
  100. // // WxCommon.RemoveUserCloudStorage(datalist, this, this.RemoveScoreKey);
  101. // // this.RemoveScoreKey(datalist, true);
  102. // },
  103. // listenGame() {
  104. // // var date = UserInfo.GetNowFormatDate();
  105. // this.OnUpdateGame();
  106. // WxCommon.SetEnableDebug(false);
  107. // WxCommon.OnShow(null, this, null);
  108. // WxCommon.ShowShareMenu();
  109. // WxCommon.OnShareAppMessage(null, this, this.shareCallback);
  110. // WxCommon.GetSystemInfo(null, this, null);
  111. // },
  112. // OnUpdateGame() {
  113. // const updateManager = wx.getUpdateManager()
  114. // updateManager.onCheckForUpdate(function (res) {
  115. // // 请求完新版本信息的回调
  116. // console.log(res.hasUpdate)
  117. // })
  118. // updateManager.onUpdateReady(function () {
  119. // wx.showModal({
  120. // title: '更新提示',
  121. // content: '新版本已经准备好,是否重启应用?',
  122. // success: function (res) {
  123. // if (res.confirm) {
  124. // // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  125. // updateManager.applyUpdate()
  126. // }
  127. // }
  128. // })
  129. // })
  130. // updateManager.onUpdateFailed(function () {
  131. // // 新的版本下载失败
  132. // })
  133. // },
  134. onRankBtn: function (event, optData) {
  135. cc.find("Canvas/PHB").getChildByName("BtnPHBClose").active = (optData == "true");
  136. cc.find("Canvas/PHB").getChildByName("emptyBtn").active = (optData == "true");
  137. cc.find("Canvas/PHB").getChildByName("bg").active = (optData == "true");
  138. if (this.node.active) {
  139. if ("true" == optData) {
  140. UserInfo.destroyIndexBanner();
  141. // this.rankScene.status = 1;
  142. this.showRank();
  143. }
  144. if ("false" == optData) {
  145. UserInfo.showIndexBanner();
  146. cc.find("Canvas/PHB").active = false;
  147. }
  148. } else {
  149. cc.find("Canvas/PHB").active = false;
  150. // window.accountBanner.show();
  151. }
  152. },
  153. showRank() {
  154. this.myRankNode.active = false;
  155. // if (this.rankScene.status == 1) {
  156. // let openDataContext = wx.getOpenDataContext();
  157. // let sharedCanvas = openDataContext.canvas;
  158. // this.feiendtex.initWithElement(sharedCanvas);
  159. // this.feiendtex.handleLoadedTexture();
  160. // this.friendContentNode.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(this.feiendtex);
  161. // var scale = Math.min(750 / this.feiendtex.width, 1334 / this.feiendtex.height);
  162. // this.friendContentNode.setContentSize(this.feiendtex.width * scale, this.feiendtex.height * scale);
  163. // }
  164. this.PHB.active = true;
  165. this.rankNode.active = true;
  166. },
  167. update: function () {
  168. },
  169. onGameStartBtn: function () {
  170. this.node.parent.getChildByName("SkinNode").active = false;
  171. UserInfo.destroyIndexBanner();
  172. if (!this.showGuideValue) {
  173. this.GuideNode.active = true;
  174. this.showGuideValue = 1;
  175. UserInfo.setItem('showGuide', '1')
  176. return false;
  177. } else {
  178. this.GuideNode && this.GuideNode.destroy();
  179. }
  180. if (this.skinIndex != UserInfo.getSkinIndex()) {
  181. UserInfo.setSkinIndex(this.skinIndex);
  182. }
  183. if (this.node.active) {
  184. // cc.audioEngine.stopMusic(this.gamebgMusic);
  185. this.node.parent.getComponent("SenceManager").enterSence("Home", "Game");
  186. } else {
  187. this.node.parent.getChildByName("Game").getComponent("GameSence").onRestartBtn();
  188. }
  189. },
  190. onSkinBtn: function (event, optData) {
  191. if (optData == "true") {
  192. this.node.parent.getChildByName("SkinNode").active = true;
  193. this.skinIndex = UserInfo.getSkinIndex();
  194. var sumScoreLabel = this.node.parent.getChildByName("SkinNode").getChildByName("SumScoreSp").getChildByName("SumScoreLabel");
  195. sumScoreLabel.getComponent("cc.Label").string = UserInfo.getTotalGold();
  196. this.updateSkinNode();
  197. UserInfo.destroyIndexBanner();
  198. } else if (optData == "false") {
  199. this.node.parent.getChildByName("SkinNode").active = false;
  200. UserInfo.showIndexBanner();
  201. }
  202. },
  203. updateSkinNode: function () {
  204. var skinNode = this.node.parent.getChildByName("SkinNode");
  205. if (this.skinIndex == 0) {
  206. skinNode.getChildByName("RightBtn").active = true;
  207. skinNode.getChildByName("LeftBtn").active = false;
  208. } else if (this.skinIndex == cfg.skinTypePath.length - 1) {
  209. skinNode.getChildByName("RightBtn").active = false;
  210. skinNode.getChildByName("LeftBtn").active = true;
  211. } else {
  212. skinNode.getChildByName("RightBtn").active = true;
  213. skinNode.getChildByName("LeftBtn").active = true;
  214. }
  215. var skSpine = skinNode.getChildByName("skSprite");
  216. skSpine.getComponent("sp.Skeleton").setSkin("p" + (this.skinIndex + 1));
  217. //var self = this;
  218. //cc.loader.loadRes(cfg.skinTypePath[self.skinIndex],cc.SpriteFrame,function(err,spriteFrame){
  219. //var skinsp = skinNode.getChildByName("SkinSp");
  220. //skinsp.getComponent("cc.Sprite").spriteFrame = spriteFrame;
  221. var condition1 = skinNode.getChildByName("Condition1");
  222. var condition2 = skinNode.getChildByName("Condition2");
  223. var lockerSp = skinNode.getChildByName("LockerSp");
  224. var playBtn = skinNode.getChildByName("PlayBtn");
  225. var unlockSp = skinNode.getChildByName("UnlockSp");
  226. UserInfo.getUserGameData((data) => {
  227. var historyScore = data.maxScore || UserInfo.getItem('score');
  228. if (this.skinIndex > 0) {
  229. if (cfg.skinCondition[this.skinIndex].scoreType == 0) {
  230. if (historyScore >= cfg.skinCondition[this.skinIndex].score) {
  231. condition1.active = false;
  232. condition2.active = false;
  233. unlockSp.active = true;
  234. lockerSp.active = false;
  235. playBtn.active = true;
  236. } else {
  237. condition1.active = true;
  238. condition2.active = false;
  239. unlockSp.active = false;
  240. lockerSp.active = true;
  241. playBtn.active = false;
  242. condition1.getChildByName("ConditionLabel").getComponent("cc.Label").string = historyScore + "." + cfg.skinCondition[this.skinIndex].score;
  243. }
  244. } else if (cfg.skinCondition[this.skinIndex].scoreType == 1) {
  245. var sumScore = UserInfo.getTotalGold();
  246. if (sumScore >= cfg.skinCondition[this.skinIndex].score) {
  247. condition1.active = false;
  248. condition2.active = false;
  249. unlockSp.active = true;
  250. lockerSp.active = false;
  251. playBtn.active = true;
  252. } else {
  253. condition1.active = false;
  254. condition2.active = true;
  255. unlockSp.active = false;
  256. lockerSp.active = true;
  257. playBtn.active = false;
  258. condition2.getChildByName("ConditionLabel").getComponent("cc.Label").string = cfg.skinCondition[this.skinIndex].score;
  259. }
  260. }
  261. } else {
  262. condition1.active = false;
  263. condition2.active = false;
  264. lockerSp.active = false;
  265. playBtn.active = true;
  266. unlockSp.active = true;
  267. }
  268. })
  269. },
  270. onGuideBtn: function (event) {
  271. this.node.parent.getChildByName("Guide").active = false;
  272. // UserInfo.showIndexBanner();
  273. },
  274. onNextBtn: function (event, optData) {
  275. if (optData == "right") {
  276. this.skinIndex++;
  277. } else if (optData = "left") {
  278. this.skinIndex--;
  279. }
  280. this.updateSkinNode();
  281. },
  282. onHonourBtn: function () {
  283. },
  284. onMoreBtn: function (event, optData) {
  285. if (CC_WECHATGAME) {
  286. // objSdk.openGameCenter();
  287. // wx.navigateToMiniProgram({
  288. // appId: "wx582548bc3a843fed",
  289. // path: "pages/index",
  290. // extraData: {
  291. // fromGame: "budinggame"
  292. // }
  293. // })
  294. } else {
  295. if (this.node.active) {
  296. this.node.getChildByName("GameStartBtn").getComponent("cc.Button").interactable = (optData == "false");
  297. this.node.getChildByName("SkinBtn").getComponent("cc.Button").interactable = (optData == "false");
  298. this.node.getChildByName("HonourBtn").getComponent("cc.Button").interactable = (optData == "false");
  299. this.node.getChildByName("RankBtn").getComponent("cc.Button").interactable = (optData == "false");
  300. this.node.getChildByName("MoreBtn").getComponent("cc.Button").interactable = (optData == "false");
  301. } else {
  302. this.node.parent.getChildByName("Game").getComponent("GameSence").onMoreGameBtn(optData);
  303. }
  304. this.ShareStrategyNode.active = (optData == "true");
  305. if (optData == "true") {
  306. this.createTimer();
  307. }
  308. }
  309. },
  310. onShareBtn: function () {
  311. if (CC_QQPLAY) {
  312. var data = {
  313. titleData: UserInfo.shareDesc,
  314. imgurlData: UserInfo.shareUrl
  315. }
  316. QQCommon.ShareAppMessage(data, null);
  317. }
  318. },
  319. createTimer: function () {
  320. var self = this;
  321. var updateOtherGames = function () {
  322. self.otherGamesIndex = (self.otherGamesIndex + 1 + WxCommon.otherGameCount) % WxCommon.otherGameCount;
  323. self.ShareStrategyNode.getChildByName("OtherGameBtn").getComponent(cc.Sprite).spriteFrame = self.SignAtlas.getSpriteFrame('games' + self.otherGamesIndex);
  324. self.createTimer();
  325. };
  326. if (this.ShareStrategyNode.active == true) {
  327. this.timerid = setTimeout(updateOtherGames, 2000);
  328. }
  329. },
  330. onShowOtherGame: function () {
  331. if (CC_WECHATGAME) {
  332. var path = WxCommon.otherGameMap.get(this.otherGamesIndex);
  333. WxCommon.PreviewImage(path, this, this.hideNode);
  334. }
  335. },
  336. killTimer: function () {
  337. if (this.timerid != null) {
  338. clearTimeout(this.timerid);
  339. this.timerid = null;
  340. }
  341. },
  342. hideNode: function () {
  343. if (this.ShareStrategyNode.active) {
  344. this.killTimer();
  345. this.ShareStrategyNode.active = false;
  346. if (this.node.active) {
  347. this.node.getChildByName("GameStartBtn").getComponent("cc.Button").interactable = true;
  348. this.node.getChildByName("SkinBtn").getComponent("cc.Button").interactable = true;
  349. this.node.getChildByName("HonourBtn").getComponent("cc.Button").interactable = true;
  350. this.node.getChildByName("RankBtn").getComponent("cc.Button").interactable = true;
  351. this.node.getChildByName("MoreBtn").getComponent("cc.Button").interactable = true;
  352. } else {
  353. this.node.parent.getChildByName("Game").getComponent("GameSence").onMoreGameBtn("false");
  354. }
  355. }
  356. },
  357. onBtnAudio: function () {
  358. cc.audioEngine.playEffect(this.buttonAudio);
  359. }
  360. // update (dt) {},
  361. });