BattleInfoWindow.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { _decorator, Component, Node, RichText, SpriteFrame, Label, Sprite } from 'cc';
  2. import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
  3. import { WindowManager } from '../../core/ui/window/WindowManager';
  4. import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
  5. import { g } from '../../Data/g';
  6. import { FsUtils } from '../../FsUtils/FsUtils';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('BattleInfoWindow')
  9. export class BattleInfoWindow extends Component {
  10. @property({ type: Node, tooltip: "复仇按钮" })
  11. avengeButton: Node;
  12. @property({ type: RichText, tooltip: "玩家文本" })
  13. userNameLabel: RichText;
  14. @property({ type: Sprite, tooltip: "金币图标" })
  15. iconSprite: Sprite;
  16. @property({ type: Label, tooltip: "数量文本" })
  17. numLabel: Label;
  18. @property({ type: Label, tooltip: "损失信息文本" })
  19. infoLabel: Label;
  20. start() {
  21. this.openHandler();
  22. }
  23. public async openHandler() {
  24. let data = g.gameData.beAttackDatas[0];
  25. if (data) {
  26. this.userNameLabel.string = `<color=#d1240e>${FsUtils.beautySub(data.attackUserName, 4)}</color><color=#8f5748>攻击了你的队伍</color>`;
  27. if (data.beAttackLossType == 3) {//损失物品类型(1money,2diamond,3general)
  28. this.numLabel.string = '';
  29. this.iconSprite.node.active = false;
  30. this.infoLabel.string = `你损失了1个${data.beAttackLossNum}级神将`;
  31. } else {
  32. this.iconSprite.node.active = true;
  33. this.numLabel.string = FsUtils.moneyFormat(Number(data.beAttackLossNum));
  34. let img: SpriteFrame;
  35. if (data.beAttackLossType == 1) {
  36. img = await ResourcesUtils.load("Images/Money/moneyIcon/spriteFrame", SpriteFrame, this.node);
  37. } else if (data.beAttackLossType == 2) {
  38. img = await ResourcesUtils.load("Images/Money/goldIcon/spriteFrame", SpriteFrame, this.node);
  39. }
  40. this.iconSprite.spriteFrame = img;
  41. }
  42. }
  43. }
  44. public onCloseButton() {
  45. g.gameData.beAttackDatas.splice(0, 1);
  46. WindowManager.close();
  47. }
  48. public onAvengeButton() {
  49. g.gameData.beAttackDatas = [];
  50. WindowManager.open("Prefabs/Battle/BattleUIWindow", WindowOpenMode.CloseAndCover, { tabIndex: 1 });//打开复仇面板
  51. WindowManager.close();
  52. }
  53. }