ShenTaiRole.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { _decorator, Component, Node, Sprite, Label, Animation, SystemEventType, SpriteFrame, ImageAsset, Texture2D } from 'cc';
  2. import { Http } from '../../core/net/Http';
  3. import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
  4. import { OpenWindow } from '../../core/ui/window/OpenWindow';
  5. import { WindowManager } from '../../core/ui/window/WindowManager';
  6. import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
  7. import { g } from '../../Data/g';
  8. import { ISJSB, platform } from '../../Data/platform';
  9. import { FsUtils } from '../../FsUtils/FsUtils';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('ShenTaiRole')
  12. export class ShenTaiRole extends Component {
  13. @property({ type: Sprite, tooltip: "神将图片" })
  14. roleImg: Sprite;
  15. @property({ type: Node, tooltip: "好友头像组" })
  16. headGroup: Node;
  17. @property({ type: Sprite, tooltip: "好友头像" })
  18. friendHead: Sprite;
  19. @property({ type: Label, tooltip: "好友名称" })
  20. friendName: Label;
  21. @property({ type: Label, tooltip: "好友贡献" })
  22. contribute: Label;
  23. @property({ type: Node, tooltip: "奖励信息组" })
  24. giftGroup: Node;
  25. @property({ type: Label, tooltip: "奖励信息" })
  26. giftNum: Label;
  27. @property({ type: Animation, tooltip: "神将台动画" })
  28. animation: Animation;
  29. @property({ tooltip: "是否播放动画" })
  30. isPlayAaimation: Boolean = true;
  31. userInfoWin: OpenWindow;
  32. @property({ type: Http, tooltip: "消息控制" })
  33. http: Http;
  34. public data: any;
  35. private friednLv: number = 0;
  36. start() {
  37. if (this.isPlayAaimation) {
  38. this.scheduleOnce(() => {
  39. this.animation.play();
  40. }, Math.random());
  41. }
  42. }
  43. public async onInvite() {
  44. //邀请
  45. let result = await this.http.send("/api/app/share", {});
  46. if (result.code == 0) {
  47. platform.wxShare(result.data.url, result.data.title, result.data.descroption);
  48. } else {
  49. WindowManager.showTips("分享信息获取失败,请稍后再试");
  50. }
  51. }
  52. public async selectFriendInfo() {
  53. WindowManager.open("Prefabs/Friend/FriendInfoWindow", WindowOpenMode.NotCloseAndAdd, { friednLv: this.friednLv, data: this.data });
  54. }
  55. public async setData(data?: any, friendLv?: number) {
  56. if (data) {
  57. this.friednLv = friendLv;
  58. this.data = data;
  59. this.headGroup.active = true;
  60. this.contribute.node.active = true;
  61. this.roleImg.node.active = true;
  62. this.data.totalRevenueAmount = this.data.totalRevenueAmount || 0;
  63. this.contribute.string = '总贡献:' + this.data.totalRevenueAmount.toFixed(0);
  64. this.giftGroup.active = this.data.revenueAmount > 0;
  65. this.data.revenueAmount = this.data.revenueAmount || 0;
  66. this.giftNum.string = this.data.revenueAmount.toFixed(0);
  67. let lv = this.data.lv ? this.data.lv : 1;
  68. this.friendName.string = this.data.nickname;
  69. this.roleImg.spriteFrame = await ResourcesUtils.load(`Roles/${lv}/spriteFrame`, SpriteFrame, this.node);
  70. if (ISJSB && data.avatar) {
  71. let img = await ResourcesUtils.loadRemote<ImageAsset>(data.avatar, { ext: ".png" }, this);
  72. const spriteFrame = new SpriteFrame();
  73. const texture = new Texture2D();
  74. texture.image = img;
  75. spriteFrame.texture = texture;
  76. this.friendHead.spriteFrame = spriteFrame;
  77. }
  78. } else {
  79. this.headGroup.active = false;
  80. this.contribute.node.active = false;
  81. }
  82. }
  83. //领取贡献
  84. private async getContribute() {
  85. let result = await this.http.send("/api/fission/ReceiveFission", { receiveUserID: this.data.userID });
  86. if (!result.code) {//
  87. g.userData.contribution += result.data.addTotalContribution;
  88. g.gameData.updateMyFessiongDatas([{ userID: this.data.userID }], false);
  89. WindowManager.showTips('贡献领取成功');
  90. this.giftGroup.active = false;
  91. } else {
  92. WindowManager.showTips(g.CodeMsg[result.code]);
  93. }
  94. }
  95. }