PVPResult.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { _decorator, Component, Node, Label, SystemEvent, Sprite, SpriteFrame } from 'cc';
  2. import { DataSystem } from '../core/data/DataSystem';
  3. import { ResourceLoader } from '../core/resourceManager/ResourceLoader';
  4. import { Sound } from '../core/sound/Sound';
  5. import { UserData } from '../data/UserData';
  6. import { FightData } from '../fight/FightData';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('PVPResult')
  9. export class PVPResult extends Component {
  10. @property({ type: Node, tooltip: "关闭节点" }) mask: Node;
  11. @property({ type: [Node], tooltip: "结算显示节点集合" }) nodesList: Array<Node> = [];
  12. @property({ type: Label, tooltip: "失败昵称" }) failName: Label;
  13. @property({ type: Node, tooltip: "胜利奖励显示" }) winShowNode: Node;
  14. @property({ type: Label, tooltip: "失败数量" }) failCount: Label;
  15. @property({ type: Label, tooltip: "胜利昵称" }) winName: Label;
  16. @property({ type: Label, tooltip: "胜利数量" }) winCount: Label;
  17. @property({ type: Sprite, tooltip: "奖励道具图标" }) winIconSprite: Sprite;
  18. @property({ type: Sprite, tooltip: "奖励道具图标" }) lossIconSprite: Sprite;
  19. public closehandler: Function;
  20. private sound: Sound;
  21. start() {
  22. this.mask.on(SystemEvent.EventType.TOUCH_END, () => {
  23. this.node.destroy();
  24. }, this);
  25. }
  26. onDestroy() {
  27. this.winShowNode.active = true;
  28. this.closehandler && this.closehandler();
  29. }
  30. public async setData(data: any) {
  31. let icon = 5;
  32. if (data.rewardType == 'money') {
  33. icon = 5;
  34. } else if (data.rewardType == 'diamond') {
  35. icon = 7;
  36. } else if (data.rewardType == 'bonus') {
  37. icon = 2;
  38. } else {
  39. icon = 8;
  40. }
  41. let img = await this.getComponent(ResourceLoader).load<SpriteFrame>("image/icons/icon" + icon + "/spriteFrame", SpriteFrame);
  42. this.nodesList[0].active = this.nodesList[1].active = this.nodesList[2].active = false;
  43. this.sound = this.getComponent(Sound);
  44. if (data.isWin) {
  45. data.type == 3 && (this.winShowNode.active = false);
  46. this.nodesList[2].active = true;
  47. this.winName.string = data.bonus.nickName;
  48. this.winIconSprite.spriteFrame = img;
  49. this.winCount.string = "x" + (!data.rewardNum ? "0" : data.rewardNum + "");
  50. if (this.sound) {
  51. this.sound.play(0);
  52. }
  53. if (data.type == 2) {
  54. DataSystem.getData(FightData).revengeSuccessEnemyId = data.bonus.enemyID;
  55. } else if (data.type == 3) {
  56. DataSystem.getData(FightData).challengeSuccessFriendId = data.bonus.enemyID;
  57. }
  58. } else {
  59. if (data.type == 2) {
  60. this.nodesList[0].active = true;
  61. } else {
  62. this.nodesList[1].active = true;
  63. this.failName.string = data.bonus.nickName;
  64. this.lossIconSprite.spriteFrame = img;
  65. this.failCount.string = "x" + (!data.rewardNum ? "0" : data.rewardNum + "");
  66. }
  67. if (this.sound) {
  68. this.sound.play(1);
  69. }
  70. }
  71. DataSystem.getData(UserData)[data.rewardType] += data.rewardNum;
  72. data.bonus.key != "0" && DataSystem.getData(FightData).attackBonusList.push(data.bonus);
  73. }
  74. }