| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- import GamePlay from "../../before/GamePlay";
- import JsbSystem from "../../mk/system/JsbSystem";
- import { DataEventId, GameProp, VideoAdType } from "../data/GameData";
- import FunBtns from "./FunBtns";
- const { ccclass, property } = cc._decorator;
- @ccclass("RedPoinNode")
- export class RedPoinNode {
- @property({ type: cc.Node, displayName: "签到" })
- node_sign: cc.Node = null;
- @property({ type: cc.Node, displayName: "存钱罐" })
- node_pigbank: cc.Node = null;
- @property({ type: cc.Node, displayName: "红包提现" })
- node_redbagCash: cc.Node = null;
- @property({ type: cc.Node, displayName: "福袋" })
- node_blessingBag: cc.Node = null;
- @property({ type: cc.Node, displayName: "转盘" })
- node_turnable: cc.Node = null;
- @property({ type: cc.Node, displayName: "福利礼包" })
- node_redeem: cc.Node = null;
- }
- @ccclass
- export default class Game extends cc.Component {
- @property({ type: cc.Node, displayName: "游戏核心玩法" })
- node_gameplay: cc.Node = null;
- @property({ type: cc.Node, displayName: "功能按钮" })
- node_btn: cc.Node = null;
- @property({ type: cc.Sprite, displayName: "头像" })
- img_head: cc.Sprite = null;
- @property({ type: cc.Label, displayName: "红包币" })
- lbl_redMoney: cc.Label = null;
- @property({ type: cc.Label, displayName: "金猪币" })
- lbl_rmb: cc.Label = null;
- @property({ type: cc.Sprite, displayName: "红包提现" })
- btn_cashOutNormal: cc.Sprite = null;
- @property({ type: cc.Sprite, displayName: "金猪提现" })
- btn_cashOutGold: cc.Sprite = null;
- @property({ type: cc.Node, displayName: "气泡红包1" })
- btn_getRed1: cc.Node = null;
- @property({ type: cc.Node, displayName: "气泡红包2" })
- btn_getRed2: cc.Node = null;
- @property({ type: cc.Node, displayName: "气泡红包3" })
- btn_getRed3: cc.Node = null;
- @property({ type: cc.Button, displayName: "开始游戏" })
- btn_start: cc.Button = null;
- @property({ type: cc.Node, displayName: "红包币图标" })
- icon_hb: cc.Node = null;
- @property({ type: cc.Node, displayName: "金猪币图标" })
- icon_zb: cc.Node = null;
- @property({ type: cc.Node, displayName: "顶部ui组" })
- node_top_ui: cc.Node = null;
- @property({ type: RedPoinNode, displayName: "红点组" })
- nodeRedPoint: RedPoinNode = null;
- onLoad() {
- gData.gameData.gameStyle = this;
- mk.ui.closePanel("login");
- }
- start() {
- this.initMusic();
- this.initBtns();
- this.initQiPaos();
- this.initInfo();
- this.autoOpenPanel();
- this.runGuideWeak();
- mk.guide.open(1);
- // // 测试代码
- // this.schedule(() => {
- // let data = {
- // videoRedMoney: {
- // videoRewardList: [
- // {
- // rewardType: 1,
- // rewardNum: 500
- // },
- // {
- // rewardType: 2,
- // rewardNum: 0
- // },
- // {
- // rewardType: 3,
- // rewardNum: 0
- // }
- // ]
- // }
- // };
- // gData.reward.adData = data;
- // mk.ui.openPanel('module/reward/reward')
- // }, 3)
- }
- update() {
- if (gData.gameData.updatePiggyBankValue) {
- this.updatePiggyBankValue();
- gData.gameData.updatePiggyBankValue = false;
- }
- if (gData.gameData.init_coin) {
- this.changeInfo();
- }
- if (gData.gameData.init_head) {
- this.initHead();
- }
- if (gData.gameData.init_red_point) {
- this.initRedPoint();
- }
- }
- lateUpdate() {
- gData.gameData.init_head = false;
- }
- private initMusic() {
- mk.audio.playMusic("bgm");
- }
- /**
- * 根据配置,添加开启的功能按钮
- */
- private initBtns() {
- let sc = this.node_btn.getComponent(FunBtns) as FunBtns;
- // sc.init();
- }
- private initQiPaos() {
- mk.tween.scale(this.btn_getRed1, 0.6, 0, 1, null, 'backOut');
- mk.tween.scale(this.btn_getRed2, 0.6, 0, 1, null, 'backOut');
- mk.tween.scale(this.btn_getRed3, 0.6, 0, 1, null, 'backOut');
- let easing_type = '';//sineInOut
- cc.tween(this.btn_getRed1).to(1.2, { y: 100 }, { easing: easing_type }).to(1.2, { y: 50 }, { easing: easing_type }).union().repeatForever().start();
- 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();
- 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();
- }
- private initInfo() {
- this.lbl_redMoney.string = gData.gameData.gameData.redMoney + "";
- // this.lbl_rmb.string = gData.gameData.gameData.piggyBank + "";
- const new_count = gData.gameData.gameData.piggyBank / 100;
- this.lbl_rmb.string = new_count.toFixed(2);
- gData.gameData.init_coin = false;
- }
- private changeInfo() {
- this.lbl_redMoney.node.getComponent(mk.component.numberAnim).setValue(gData.gameData.gameData.redMoney);
- // this.lbl_rmb.node.getComponent('NumberAnim').setValue(gData.gameData.gameData.piggyBank);
- const new_count = gData.gameData.gameData.piggyBank / 100;
- if (parseInt(this.lbl_rmb.string) == 0 && new_count != 0 || parseInt(this.lbl_rmb.string) != 0 && new_count == 0) {
- if (this.lbl_rmb.string != new_count.toFixed(2)) {
- this.lbl_rmb.node.getComponent(mk.component.numberAnim).setValue(parseFloat(new_count.toFixed(2)), 2);
- }
- }
- gData.gameData.init_coin = false;
- }
- private async initHead() {
- let result = await mk.loader.loadRemote(gData.wechatData.avatar + "?aaa=aa.jpg", null);
- this.img_head.spriteFrame = new cc.SpriteFrame(result);
- }
- private updatePiggyBankValue() {
- this.lbl_rmb.string = (gData.gameData.gameData.piggyBank / 100).toFixed(2);
- gData.gameData.updatePiggyBankValue = false;
- }
- /**
- * 初始化红点
- */
- private initRedPoint() {
- this.nodeRedPoint.node_sign.active = gData.sign.redPoint();
- this.nodeRedPoint.node_pigbank.active = gData.pigbank.redPoint();
- this.nodeRedPoint.node_redbagCash.active = gData.redBagCash.redPoint();
- this.nodeRedPoint.node_turnable.active = gData.turnable.redPoint();
- this.nodeRedPoint.node_blessingBag.active = gData.blessingBag.redPoint();
- this.nodeRedPoint.node_redeem.active = gData.redeem.redPoint();
- gData.gameData.init_red_point = false;
- // if ((!GamePlay.Inst || (GamePlay.Inst && !GamePlay.Inst.node.active)) && this.nodeRedPoint.node_redbagCash.active) {
- // let state = mk.guide.open(2);
- // if (state) {
- // mk.ui.closeAllUI();
- // }
- // }
- if (this.nodeRedPoint.node_redbagCash.active) {
- let state = mk.guide.open(2);
- if (state) {
- mk.ui.closeAllUI();
- }
- }
- }
- /**
- * 自动打开面板
- * - isAutoOpenPanel 1自动开 2不自动开 其他不处理
- */
- private autoOpenPanel() {
- if (!gData.gameData.isNewPlayer()) {
- mk.ui.openPanel('module/pigBank/pigBank');
- gData.gameData.setProp(GameProp.isAutoOpenPanel, 1)
- }
- }
- /**
- * 开始运行弱引导
- */
- private runGuideWeak() {
- gData.guideWeakData.enable = true;
- }
- //测试道具获取效果
- private testFly() {
- mk.fly.PlayCoinAnim(1, 20, cc.v2(0, -300), cc.v2(0, 0));
- // mk.fly.PlayCoinAnim(2, 20, cc.v2(0, -300), 'Canvas/界面层/game/功能按钮/右侧按钮/btn2');
- }
- /** 点击开始 */
- public onClickStart(a, b) {
- mk.data.sendDataEvent(DataEventId.button_click, "开始游戏icon");
- this.node_gameplay.active = true;
- }
- /** 点击互推 */
- public onClickHuTui() {
- mk.data.sendDataEvent(DataEventId.button_click, "互推icon");
- }
- /** 点击福利礼包 */
- public onClickFuli() {
- mk.data.sendDataEvent(DataEventId.button_click, "福利礼包icon");
- }
- /** 点击气泡红包 */
- public onClickQipaoRedBag() {
- mk.ad.videoAdType = VideoAdType.StartQiPaoRedBag;
- mk.data.sendDataEvent(DataEventId.button_click, "气泡红包icon");
- }
- /** 点击红包提现 */
- public onClickRedBagCash() {
- mk.data.sendDataEvent(DataEventId.button_click, "常规提现-提现icon");
- }
- /**点击金猪提现 */
- public onClickGoldPigCash() {
- mk.data.sendDataEvent(DataEventId.button_click, "金猪现金-提现icon");
- }
- /** 点击金猪存钱罐 */
- public onClickPigBank() {
- mk.data.sendDataEvent(DataEventId.button_click, "存钱罐icon");
- }
- /** */
- public onClickTurntable() {
- mk.data.sendDataEvent(DataEventId.button_click, "转盘icon");
- }
- /** 点击签到 */
- public onClickSign() {
- mk.data.sendDataEvent(DataEventId.button_click, "签到icon");
- }
- /** 点击福袋 */
- public onClickFudai() {
- mk.data.sendDataEvent(DataEventId.button_click, "福袋icon");
- }
- /**点击分享 */
- public onClickShare() {
- mk.data.sendDataEvent(DataEventId.button_click, "邀请icon");
- if (!gData.loginData.isAuth) {
- // mk.tip.pop("请先点击头像,在设置界面授权");
- JsbSystem.WxAuth();
- return;
- }
- JsbSystem.sharePic();
- }
- /** 点击富翁银行 */
- public onClickSafeDepositBox() {
- mk.data.sendDataEvent(DataEventId.button_click, "富翁银行icon");
- }
- public onClickGuideToWx() {
- let state = mk.storage.getStorage('onClickGuideToWx');
- if (!state) {
- mk.storage.setStorage('onClickGuideToWx', 1);
- mk.data.sendDataEvent(DataEventId.button_click, "加我送钱icon");
- mk.data.sendXYEvent('onClickGuideToWx', '加我送钱');
- }
- }
- }
|