FriendBattleWindow.ts 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { _decorator, Component, Node, Prefab, instantiate, ProgressBar, Label, Animation, Button } from 'cc';
  2. import { Http } from '../../core/net/Http';
  3. import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
  4. import { WindowManager } from '../../core/ui/window/WindowManager';
  5. import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
  6. import { g } from '../../Data/g';
  7. import { platform } from '../../Data/platform';
  8. import { FriendChallengeItem } from '../../Item/FriendChallengeItem';
  9. const { ccclass, property } = _decorator;
  10. /**好友约战 */
  11. @ccclass('FriendBattleWindow')
  12. export class FriendBattleWindow extends Component {
  13. @property({ tooltip: "宝箱节点", type: Button })
  14. boxButton: Button;
  15. @property({ tooltip: "list节点", type: Node })
  16. listNode: Node;
  17. @property({ tooltip: "item预制体路径" })
  18. itemPrefabUrl = "";
  19. @property({ tooltip: "宝箱进度条", type: ProgressBar })
  20. boxProgress: ProgressBar;
  21. @property({ type: Label, tooltip: "进度文本" })
  22. progressLabel: Label;
  23. @property({ type: Animation, tooltip: "宝箱特效" })
  24. animation: Animation;
  25. @property({ type: Http, tooltip: "Http服务" })
  26. http: Http;
  27. start() {
  28. this.animation.node.active = false;
  29. this.boxButton.enabled = false;
  30. }
  31. update() {
  32. if (g.gameData.hasBattleLogUpdate) {
  33. g.gameData.hasBattleLogUpdate = false;
  34. this.listNode.removeAllChildren();
  35. this.onOpenhandler(true);//刷新数据
  36. }
  37. }
  38. //窗口打开回调
  39. private async onOpenhandler(isUpdate: boolean = false) {
  40. if (g.battleData.friendBattleUpdate || isUpdate) {
  41. g.battleData.friendBattleUpdate = false;
  42. let result = await this.http.send("/api/battle/GetChallenges");//查询挑战信息 20
  43. if (!result.code) {
  44. g.battleData.battleLogs = result.data.logs;
  45. g.battleData.winTimes = result.data.winTimes;
  46. g.battleData.getChallengePrize = result.data.getChallengePrize;
  47. } else {
  48. WindowManager.showTips(g.CodeMsg[result.code]);
  49. }
  50. }
  51. this.progressLabel.string = g.battleData.winTimes + '/5';
  52. this.boxProgress.progress = g.battleData.winTimes / 5;
  53. if (g.battleData.winTimes == 5 && g.battleData.getChallengePrize == 0) {
  54. this.animation.node.active = true;
  55. this.boxButton.enabled = true;
  56. this.animation.play();
  57. } else {
  58. this.animation.node.active = false;
  59. this.boxButton.enabled = false;
  60. }
  61. for (let i = 0; i < g.gameData.myFriendDatas.length; i++) {
  62. let prefabData = await ResourcesUtils.load<Prefab>(this.itemPrefabUrl, null, this.node);
  63. var itemNode = instantiate(prefabData);
  64. itemNode.parent = this.listNode;
  65. let itemData = g.gameData.myFriendDatas[i];
  66. await itemNode.getComponent(FriendChallengeItem).setData(itemData, g.battleData.battleLogs);
  67. }
  68. }
  69. /**打开战斗日志 */
  70. private openBattleLogWindow() {
  71. WindowManager.open("Prefabs/Battle/FriendBattleLogWindow", WindowOpenMode.NotCloseAndAdd, g.battleData.battleLogs);
  72. }
  73. /**领取挑战奖励 */
  74. private async onGetBox() {
  75. if (this.animation.node.active) {//可领取
  76. let result = await this.http.send("/api/battle/GetChallengePrize");//领取挑战奖励21
  77. if (!result.code) {
  78. WindowManager.open("Prefabs/Windows/DialogWindow", WindowOpenMode.NotCloseAndAdd, { num: result.data.addMoney, content: "领取成功,恭喜获得", type: 1 });
  79. g.userData.money += result.data.addMoney;
  80. this.animation.node.active = false;
  81. this.boxButton.enabled = false;
  82. } else {
  83. WindowManager.showTips(g.CodeMsg[result.code]);
  84. }
  85. }
  86. }
  87. /**点击发起挑战 */
  88. public async onInvite() {
  89. let result = await this.http.send("/api/app/share", {});
  90. if (result.code == 0) {
  91. platform.wxShare(result.data.url, result.data.title, result.data.descroption);
  92. } else {
  93. WindowManager.showTips("分享信息获取失败,请稍后再试");
  94. }
  95. }
  96. }