Game.ts 9.6 KB

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