Setting.ts 5.0 KB

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