SetUp.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { _decorator, Component, Node, Button, tween, Widget, UITransform, Vec3, Label, Sprite, ImageAsset, SpriteFrame, Texture2D, JsonAsset } from 'cc';
  2. import { Http } from '../core/net/Http';
  3. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  4. import { Sound } from '../core/sound/Sound';
  5. import { WindowManager } from '../core/ui/window/WindowManager';
  6. import { ConfigData } from '../Data/ConfigData';
  7. import { g } from '../Data/g';
  8. import { ISJSB, platform } from '../Data/platform';
  9. import { SoundSystem } from './SoundSystem';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('SetUp')
  12. export class SetUp extends Component {
  13. @property({ tooltip: "设置开启按钮", type: Button }) public setUpBtn: Button;
  14. @property({ tooltip: "设置界面", type: Node }) public setUpWindow: Node;
  15. @property({ tooltip: "设置界面背景", type: Node }) public setUpBg: Node;
  16. @property({ tooltip: "音效设置按键", type: Node }) public setUpSoundBtn: Node;
  17. @property({ tooltip: "玩家昵称", type: Label }) public nameTxt: Label;
  18. @property({ tooltip: "玩家UID", type: Label }) public IDTxt: Label;
  19. @property({ tooltip: "玩家等级", type: Label }) public lvTxt: Label;
  20. @property({ tooltip: "玩家头像", type: Sprite }) public avator: Sprite;
  21. @property({ tooltip: "背景", type: Button }) public bg: Button;
  22. @property({ tooltip: "http服务", type: Http }) public http: Http;
  23. @property({ tooltip: "声音开启显示文本(深)", type: Node }) public soundOpenTxt: Node;
  24. @property({ tooltip: "声音开启显示文本(浅)", type: Node }) public soundOpenTxt0: Node;
  25. @property({ tooltip: "声音关闭显示文本(深)", type: Node }) public soundCloseTxt: Node;
  26. @property({ tooltip: "声音关闭显示文本(浅)", type: Node }) public soundCloseTxt0: Node;
  27. private lvConfig;
  28. start() {
  29. this.initUI();
  30. }
  31. public async initUI() {
  32. this.nameTxt.string = g.userData.nickName;
  33. this.IDTxt.string = "UID:" + g.userData.id;
  34. this.lvConfig = ConfigData.configMap.get("generalBase");
  35. // this.lvConfig = await (await ResourcesUtils.load<JsonAsset>("Configs/generalBase", JsonAsset, this.node)).json;//测试
  36. this.initLv();
  37. if (ISJSB && g.userData.avator) {
  38. let img = await ResourcesUtils.loadRemote<ImageAsset>(g.userData.avator, { ext: ".png" }, this);
  39. const spriteFrame = new SpriteFrame();
  40. const texture = new Texture2D();
  41. texture.image = img;
  42. spriteFrame.texture = texture;
  43. this.avator.spriteFrame = spriteFrame;
  44. }
  45. }
  46. //重置等级
  47. public initLv() {
  48. let _lv = "";
  49. if (g.userData.lv >= 1) {
  50. _lv = this.lvConfig["" + g.userData.lv].name;
  51. }
  52. this.lvTxt.string = "LV." + g.userData.lv + _lv;
  53. }
  54. //打开设置窗口
  55. public setUpBtnEven() {
  56. this.initLv();
  57. this.setUpBtn.interactable = false;
  58. this.bg.interactable = false;
  59. let endX = this.setUpBg.active ? 0 : this.setUpWindow.getComponent(UITransform).width;
  60. this.setUpBg.active = false;
  61. let t = tween(this.setUpWindow);
  62. t.to(0.2, { position: new Vec3(endX) })
  63. .call(() => {
  64. this.bg.interactable = true;
  65. this.setUpBtn.interactable = true;
  66. this.setUpBg.active = this.setUpWindow.position.x == 0 ? false : true;
  67. })
  68. .start();
  69. }
  70. //设置音效
  71. public setUpSound() {
  72. if (Sound.volumeScale == 0) {
  73. Sound.volumeScale = 1;
  74. SoundSystem.setVolume(1);
  75. this.setUpSoundBtn.setPosition(new Vec3(-30));
  76. this.initSoundTxt(true);
  77. } else {
  78. Sound.volumeScale = 0;
  79. SoundSystem.setVolume(0)
  80. this.setUpSoundBtn.setPosition(new Vec3(33));
  81. this.initSoundTxt(false);
  82. }
  83. }
  84. public initSoundTxt(isOpen: boolean) {
  85. this.soundOpenTxt.active = isOpen;
  86. this.soundOpenTxt0.active = !isOpen;
  87. this.soundCloseTxt.active = !isOpen;
  88. this.soundCloseTxt0.active = isOpen;
  89. }
  90. public async onInvite() {
  91. //邀请
  92. let result = await this.http.send("/api/app/share", {});
  93. if (result.code == 0) {
  94. platform.wxShare(result.data.url, result.data.title, result.data.descroption);
  95. } else {
  96. WindowManager.showTips("分享信息获取失败,请稍后再试");
  97. }
  98. }
  99. }