Setting.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import Util from "../../../before/util/Util";
  2. import JsbSystem from "../../../mk/system/JsbSystem";
  3. import { DataEventId } from "../../data/GameData";
  4. import Rule from "./Rule";
  5. const { ccclass, property } = cc._decorator;
  6. /**
  7. * 账号设置
  8. * @author 邹勇
  9. */
  10. @ccclass
  11. export default class Setting extends cc.Component {
  12. @property({ type: cc.Sprite, displayName: "头像" })
  13. img_head: cc.Sprite = null;
  14. @property({ type: cc.Label, displayName: "昵称" })
  15. lbl_nickname: cc.Label = null;
  16. @property({ type: cc.Label, displayName: "ID" })
  17. lbl_id: cc.Label = null;
  18. @property({ type: cc.Sprite, displayName: "音乐开关" })
  19. img_music: cc.Sprite = null;
  20. @property({ type: cc.Sprite, displayName: "音效开关" })
  21. img_effect: cc.Sprite = null;
  22. @property({ type: cc.Label, displayName: "版本号" })
  23. lbl_version: cc.Label = null;
  24. @property({ type: cc.Sprite, displayName: "成就名称" })
  25. sp_achieve: cc.Sprite = null;
  26. @property({ type: cc.Label, displayName: '等级' })
  27. lbl_lv: cc.Label = null;
  28. @property({ type: cc.Label, displayName: '红包币' })
  29. lbl_redBagCoin: cc.Label = null;
  30. @property({ type: cc.Label, displayName: '提现金额' })
  31. lbl_value: cc.Label = null;
  32. node_rule: cc.Node = null;
  33. onLoad() {
  34. }
  35. start() {
  36. //mk.ad.showNative(4);
  37. this.initData();
  38. }
  39. private async initData() {
  40. console.log("=== gData.wechatData.unionid", gData.wechatData.unionid);
  41. console.log("=== gData.wechatData.nickName", gData.wechatData.nickName);
  42. this.lbl_id.string = "ID:" + mk.string.getNewLimitStr(gData.wechatData.unionid, 10);// 14
  43. this.lbl_nickname.string = gData.wechatData.nickName;
  44. this.lbl_version.string = gData.appData.appVersion;
  45. this.lbl_lv.string = 'Lv:' + gData.gameData.playerProp.gradeLevel.toString();
  46. this.lbl_redBagCoin.string = (gData.gameData.playerProp.redMoney / 100).toString();
  47. this.lbl_value.string = (gData.gameData.playerProp.redMoney / 1000000).toFixed(3) + '元';
  48. let music = "module/setting/texture/" + (mk.audio.getSwitchMusic() ? "on" : "off");
  49. let effect = "module/setting/texture/" + (mk.audio.getSwitchEffect() ? "on" : "off");
  50. this.img_music.spriteFrame = await mk.loader.load(music, cc.SpriteFrame);
  51. this.img_effect.spriteFrame = await mk.loader.load(effect, cc.SpriteFrame);
  52. this.sp_achieve.spriteFrame = await mk.loader.load('module/gradeReward/texture/name' + gData.gameData.playerProp.farmGradeName, cc.SpriteFrame);
  53. console.log("=== gData.wechatData.avatar", gData.wechatData.avatar);
  54. if (gData.wechatData.avatar != '') {
  55. let result = await mk.loader.loadRemote(gData.wechatData.avatar + "?aaa=aa.jpg", null);
  56. if (result) {
  57. this.img_head.spriteFrame = new cc.SpriteFrame(result);
  58. console.log("=== loadHead:", result);
  59. }
  60. }
  61. }
  62. private clickInviteBtn() {
  63. mk.audio.playEffect("button");
  64. }
  65. clickCopy() {
  66. // //test
  67. // gData.gameData.playerProp.completeFarmTaskTimes++;
  68. // gData.gameData.checkTaskFinishUnLock();
  69. // console.log('gData.gameData.playerProp.completeFarmTaskTimes ', gData.gameData.playerProp.completeFarmTaskTimes);
  70. // return
  71. mk.audio.playEffect("button");
  72. JsbSystem.setClipboard(gData.wechatData.unionid);
  73. mk.tip.pop("复制成功");
  74. }
  75. async clickMusic() {
  76. mk.audio.playEffect("button");
  77. mk.audio.switchMusicFunc();
  78. let music = "module/setting/texture/" + (mk.audio.getSwitchMusic() ? "on" : "off");
  79. this.img_music.spriteFrame = await mk.loader.load(music, cc.SpriteFrame);
  80. }
  81. async clickEffect() {
  82. mk.audio.switchEffectFunc();
  83. mk.audio.playEffect("button");
  84. let effect = "module/setting/texture/" + (mk.audio.getSwitchEffect() ? "on" : "off");
  85. this.img_effect.spriteFrame = await mk.loader.load(effect, cc.SpriteFrame);
  86. }
  87. clickUpdate() {
  88. mk.audio.playEffect("button");
  89. let installVersion = gData.appData.installVersion
  90. let compare = Util.versionCompareHandle(gData.appData.appVersion, installVersion)
  91. if (compare < 0) {
  92. mk.ui.openPanel('module/forceUpdate/forceUpdate');
  93. }
  94. else {
  95. mk.tip.pop('当前已是最新版本')
  96. }
  97. }
  98. /** 点击微信授权 */
  99. onClickWxAuth() {
  100. if (!gData.loginData.isAuth) {
  101. // mk.ui.closePanel(this.node.name);
  102. // JsbSystem.WxAuth();
  103. gData.gameData.authUIType = 2;
  104. mk.ui.openPanel('module/authUI/authUI');
  105. // this.onClickClose();
  106. }
  107. }
  108. /**点击分享 */
  109. public onClickShare() {
  110. mk.data.sendDataEvent(DataEventId.button_click, "邀请icon");
  111. if (!gData.loginData.isAuth) {
  112. // JsbSystem.WxAuth();
  113. gData.gameData.authUIType = 1;
  114. mk.ui.openPanel('module/authUI/authUI');
  115. return;
  116. }
  117. JsbSystem.shareInviteUrl(gData.gameData.shareUrl, gData.gameData.shareTitle, gData.gameData.shareDes, gData.gameData.shareImgUrl);
  118. }
  119. async clickRule(data) {
  120. gData.setting.rule_type = parseInt(data);
  121. }
  122. update() {
  123. if (gData.gameData.init_head) {
  124. this.initData();
  125. }
  126. }
  127. onDestroy() {
  128. }
  129. onClickClose() {
  130. //mk.audio.playEffect("closeButton");
  131. mk.ad.destroyNativeAd();
  132. }
  133. }