Game.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. import GamePlay from "../../before/GamePlay";
  2. import JsbSystem from "../../mk/system/JsbSystem";
  3. import { DataEventId, GameProp, VideoAdType } from "../data/GameData";
  4. import FunBtns from "./FunBtns";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass("RedPoinNode")
  7. export class RedPoinNode {
  8. @property({ type: cc.Node, displayName: "签到" })
  9. node_sign: cc.Node = null;
  10. @property({ type: cc.Node, displayName: "存钱罐" })
  11. node_pigbank: cc.Node = null;
  12. @property({ type: cc.Node, displayName: "红包提现" })
  13. node_redbagCash: cc.Node = null;
  14. @property({ type: cc.Node, displayName: "福袋" })
  15. node_blessingBag: cc.Node = null;
  16. @property({ type: cc.Node, displayName: "转盘" })
  17. node_turnable: cc.Node = null;
  18. @property({ type: cc.Node, displayName: "福利礼包" })
  19. node_redeem: cc.Node = null;
  20. }
  21. @ccclass
  22. export default class Game extends cc.Component {
  23. @property({ type: cc.Node, displayName: "游戏核心玩法" })
  24. node_gameplay: cc.Node = null;
  25. @property({ type: cc.Node, displayName: "功能按钮" })
  26. node_btn: cc.Node = null;
  27. @property({ type: cc.Sprite, displayName: "头像" })
  28. img_head: cc.Sprite = null;
  29. @property({ type: cc.Label, displayName: "红包币" })
  30. lbl_redMoney: cc.Label = null;
  31. @property({ type: cc.Label, displayName: "金猪币" })
  32. lbl_rmb: cc.Label = null;
  33. @property({ type: cc.Sprite, displayName: "红包提现" })
  34. btn_cashOutNormal: cc.Sprite = null;
  35. @property({ type: cc.Sprite, displayName: "金猪提现" })
  36. btn_cashOutGold: cc.Sprite = null;
  37. @property({ type: cc.Node, displayName: "气泡红包1" })
  38. btn_getRed1: cc.Node = null;
  39. @property({ type: cc.Node, displayName: "气泡红包2" })
  40. btn_getRed2: cc.Node = null;
  41. @property({ type: cc.Node, displayName: "气泡红包3" })
  42. btn_getRed3: cc.Node = null;
  43. @property({ type: cc.Button, displayName: "开始游戏" })
  44. btn_start: cc.Button = null;
  45. @property({ type: cc.Node, displayName: "红包币图标" })
  46. icon_hb: cc.Node = null;
  47. @property({ type: cc.Node, displayName: "金猪币图标" })
  48. icon_zb: cc.Node = null;
  49. @property({ type: cc.Node, displayName: "顶部ui组" })
  50. node_top_ui: cc.Node = null;
  51. @property({ type: RedPoinNode, displayName: "红点组" })
  52. nodeRedPoint: RedPoinNode = null;
  53. onLoad() {
  54. gData.gameData.gameStyle = this;
  55. mk.ui.closePanel("login");
  56. }
  57. start() {
  58. this.initMusic();
  59. this.initBtns();
  60. this.initQiPaos();
  61. this.initInfo();
  62. this.autoOpenPanel();
  63. this.runGuideWeak();
  64. mk.guide.open(1);
  65. // // 测试代码
  66. // this.schedule(() => {
  67. // let data = {
  68. // videoRedMoney: {
  69. // videoRewardList: [
  70. // {
  71. // rewardType: 1,
  72. // rewardNum: 500
  73. // },
  74. // {
  75. // rewardType: 2,
  76. // rewardNum: 0
  77. // },
  78. // {
  79. // rewardType: 3,
  80. // rewardNum: 0
  81. // }
  82. // ]
  83. // }
  84. // };
  85. // gData.reward.adData = data;
  86. // mk.ui.openPanel('module/reward/reward')
  87. // }, 3)
  88. }
  89. update() {
  90. if (gData.gameData.updatePiggyBankValue) {
  91. this.updatePiggyBankValue();
  92. gData.gameData.updatePiggyBankValue = false;
  93. }
  94. if (gData.gameData.init_coin) {
  95. this.changeInfo();
  96. }
  97. if (gData.gameData.init_head) {
  98. this.initHead();
  99. }
  100. if (gData.gameData.init_red_point) {
  101. this.initRedPoint();
  102. }
  103. }
  104. lateUpdate() {
  105. gData.gameData.init_head = false;
  106. }
  107. private initMusic() {
  108. mk.audio.playMusic("bgm");
  109. }
  110. /**
  111. * 根据配置,添加开启的功能按钮
  112. */
  113. private initBtns() {
  114. let sc = this.node_btn.getComponent(FunBtns) as FunBtns;
  115. // sc.init();
  116. }
  117. private initQiPaos() {
  118. mk.tween.scale(this.btn_getRed1, 0.6, 0, 1, null, 'backOut');
  119. mk.tween.scale(this.btn_getRed2, 0.6, 0, 1, null, 'backOut');
  120. mk.tween.scale(this.btn_getRed3, 0.6, 0, 1, null, 'backOut');
  121. let easing_type = '';//sineInOut
  122. cc.tween(this.btn_getRed1).to(1.2, { y: 100 }, { easing: easing_type }).to(1.2, { y: 50 }, { easing: easing_type }).union().repeatForever().start();
  123. cc.tween(this.btn_getRed2).delay(0.2).to(1.5, { y: 125 }, { easing: easing_type }).to(1.5, { y: 50 }, { easing: easing_type }).union().repeatForever().start();
  124. cc.tween(this.btn_getRed3).delay(0.4).to(1, { y: 10 }, { easing: easing_type }).to(1, { y: -50 }, { easing: easing_type }).union().repeatForever().start();
  125. }
  126. private initInfo() {
  127. this.lbl_redMoney.string = gData.gameData.gameData.redMoney + "";
  128. // this.lbl_rmb.string = gData.gameData.gameData.piggyBank + "";
  129. const new_count = gData.gameData.gameData.piggyBank / 100;
  130. this.lbl_rmb.string = new_count.toFixed(2);
  131. gData.gameData.init_coin = false;
  132. }
  133. private changeInfo() {
  134. this.lbl_redMoney.node.getComponent(mk.component.numberAnim).setValue(gData.gameData.gameData.redMoney);
  135. // this.lbl_rmb.node.getComponent('NumberAnim').setValue(gData.gameData.gameData.piggyBank);
  136. const new_count = gData.gameData.gameData.piggyBank / 100;
  137. if (parseInt(this.lbl_rmb.string) == 0 && new_count != 0 || parseInt(this.lbl_rmb.string) != 0 && new_count == 0) {
  138. if (this.lbl_rmb.string != new_count.toFixed(2)) {
  139. this.lbl_rmb.node.getComponent(mk.component.numberAnim).setValue(parseFloat(new_count.toFixed(2)), 2);
  140. }
  141. }
  142. gData.gameData.init_coin = false;
  143. }
  144. private async initHead() {
  145. let result = await mk.loader.loadRemote(gData.wechatData.avatar + "?aaa=aa.jpg", null);
  146. this.img_head.spriteFrame = new cc.SpriteFrame(result);
  147. }
  148. private updatePiggyBankValue() {
  149. this.lbl_rmb.string = (gData.gameData.gameData.piggyBank / 100).toFixed(2);
  150. gData.gameData.updatePiggyBankValue = false;
  151. }
  152. /**
  153. * 初始化红点
  154. */
  155. private initRedPoint() {
  156. this.nodeRedPoint.node_sign.active = gData.sign.redPoint();
  157. this.nodeRedPoint.node_pigbank.active = gData.pigbank.redPoint();
  158. this.nodeRedPoint.node_redbagCash.active = gData.redBagCash.redPoint();
  159. this.nodeRedPoint.node_turnable.active = gData.turnable.redPoint();
  160. this.nodeRedPoint.node_blessingBag.active = gData.blessingBag.redPoint();
  161. this.nodeRedPoint.node_redeem.active = gData.redeem.redPoint();
  162. gData.gameData.init_red_point = false;
  163. // if ((!GamePlay.Inst || (GamePlay.Inst && !GamePlay.Inst.node.active)) && this.nodeRedPoint.node_redbagCash.active) {
  164. // let state = mk.guide.open(2);
  165. // if (state) {
  166. // mk.ui.closeAllUI();
  167. // }
  168. // }
  169. if (this.nodeRedPoint.node_redbagCash.active) {
  170. let state = mk.guide.open(2);
  171. if (state) {
  172. mk.ui.closeAllUI();
  173. }
  174. }
  175. }
  176. /**
  177. * 自动打开面板
  178. * - isAutoOpenPanel 1自动开 2不自动开 其他不处理
  179. */
  180. private autoOpenPanel() {
  181. if (!gData.gameData.isNewPlayer()) {
  182. mk.ui.openPanel('module/pigBank/pigBank');
  183. gData.gameData.setProp(GameProp.isAutoOpenPanel, 1)
  184. }
  185. }
  186. /**
  187. * 开始运行弱引导
  188. */
  189. private runGuideWeak() {
  190. gData.guideWeakData.enable = true;
  191. }
  192. //测试道具获取效果
  193. private testFly() {
  194. mk.fly.PlayCoinAnim(1, 20, cc.v2(0, -300), cc.v2(0, 0));
  195. // mk.fly.PlayCoinAnim(2, 20, cc.v2(0, -300), 'Canvas/界面层/game/功能按钮/右侧按钮/btn2');
  196. }
  197. /** 点击开始 */
  198. public onClickStart(a, b) {
  199. mk.data.sendDataEvent(DataEventId.button_click, "开始游戏icon");
  200. this.node_gameplay.active = true;
  201. }
  202. /** 点击互推 */
  203. public onClickHuTui() {
  204. mk.data.sendDataEvent(DataEventId.button_click, "互推icon");
  205. }
  206. /** 点击福利礼包 */
  207. public onClickFuli() {
  208. mk.data.sendDataEvent(DataEventId.button_click, "福利礼包icon");
  209. }
  210. /** 点击气泡红包 */
  211. public onClickQipaoRedBag() {
  212. mk.ad.videoAdType = VideoAdType.StartQiPaoRedBag;
  213. mk.data.sendDataEvent(DataEventId.button_click, "气泡红包icon");
  214. }
  215. /** 点击红包提现 */
  216. public onClickRedBagCash() {
  217. mk.data.sendDataEvent(DataEventId.button_click, "常规提现-提现icon");
  218. }
  219. /**点击金猪提现 */
  220. public onClickGoldPigCash() {
  221. mk.data.sendDataEvent(DataEventId.button_click, "金猪现金-提现icon");
  222. }
  223. /** 点击金猪存钱罐 */
  224. public onClickPigBank() {
  225. mk.data.sendDataEvent(DataEventId.button_click, "存钱罐icon");
  226. }
  227. /** */
  228. public onClickTurntable() {
  229. mk.data.sendDataEvent(DataEventId.button_click, "转盘icon");
  230. }
  231. /** 点击签到 */
  232. public onClickSign() {
  233. mk.data.sendDataEvent(DataEventId.button_click, "签到icon");
  234. }
  235. /** 点击福袋 */
  236. public onClickFudai() {
  237. mk.data.sendDataEvent(DataEventId.button_click, "福袋icon");
  238. }
  239. /**点击分享 */
  240. public onClickShare() {
  241. mk.data.sendDataEvent(DataEventId.button_click, "邀请icon");
  242. if (!gData.loginData.isAuth) {
  243. // mk.tip.pop("请先点击头像,在设置界面授权");
  244. JsbSystem.WxAuth();
  245. return;
  246. }
  247. JsbSystem.sharePic();
  248. }
  249. /** 点击富翁银行 */
  250. public onClickSafeDepositBox() {
  251. mk.data.sendDataEvent(DataEventId.button_click, "富翁银行icon");
  252. }
  253. public onClickGuideToWx() {
  254. let state = mk.storage.getStorage('onClickGuideToWx');
  255. if (!state) {
  256. mk.storage.setStorage('onClickGuideToWx', 1);
  257. mk.data.sendDataEvent(DataEventId.button_click, "加我送钱icon");
  258. mk.data.sendXYEvent('onClickGuideToWx', '加我送钱');
  259. }
  260. }
  261. }