MarshalSkillLvUpUI.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { _decorator, Component, Node, Sprite, Label, RichText, sp, SpriteFrame, isValid } from 'cc';
  2. import { DataSystem } from '../../core/data/DataSystem';
  3. import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
  4. import { UITween } from '../../core/ui/tween/UITween';
  5. import { Window } from '../../core/ui/window/Window';
  6. import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
  7. import { WindowSystem } from '../../core/ui/window/WindowSystem';
  8. import { StringUtils } from '../../core/utils/StringUtils';
  9. import { MarshalData } from '../MarshalData';
  10. import { MarshalDataTool } from '../MarshalDataTool';
  11. import { MarshalSkillSystem } from '../MarshalSkillSystem';
  12. const { ccclass, property } = _decorator;
  13. /**
  14. * 统帅技能解锁和升级弹窗 只在统帅页显示
  15. * @author 郑聂华
  16. */
  17. @ccclass('MarshalSkillLvUpUI')
  18. export class MarshalSkillLvUpUI extends Component {
  19. @property({ type: ResourceLoader, displayName: "资源加载组件", tooltip: "资源加载组件" }) res: ResourceLoader = null;
  20. @property({ type: Node, displayName: "标题_解锁", tooltip: "标题_解锁" }) titleUnlock: Node = null;
  21. @property({ type: Node, displayName: "标题_升级", tooltip: "标题_升级" }) titleLvup: Node = null;
  22. @property({ type: Sprite, displayName: "技能图", tooltip: "技能图" }) imgSkill: Sprite = null;
  23. @property({ type: Label, displayName: "技能名称", tooltip: "技能名称" }) txtSkillName: Label = null;
  24. @property({ type: Label, displayName: "技能等级", tooltip: "技能等级" }) txtSkillLv: Label = null;
  25. @property({ type: RichText, displayName: "技能描述", tooltip: "技能描述" }) txtRichDes: RichText = null;
  26. @property({ type: Label, displayName: "计时器", tooltip: "计时器" }) txtTime: Label = null;
  27. @property({ type: sp.Skeleton, displayName: "效果_解锁", tooltip: "效果_解锁" }) spineUnlock: sp.Skeleton = null;
  28. @property({ type: sp.Skeleton, displayName: "效果_升级", tooltip: "效果_升级" }) spineLvup: sp.Skeleton = null;
  29. private paramData: { type: number, id: number, lv: number, lastLv: number };
  30. private timer: number = 10;
  31. /**
  32. * 打开页面初始化
  33. * @param param 参数
  34. * {
  35. * type:1, 1 解锁 2 升级
  36. id:110001, 技能id
  37. lv:2, 技能等级
  38. lastLv:1 技能上一级
  39. * }
  40. */
  41. async init(param: { type: number, id: number, lv: number, lastLv: number }) {
  42. this.paramData = param;
  43. this.titleUnlock.active = param.type == 1;
  44. this.titleLvup.active = param.type == 2;
  45. let marshalData = DataSystem.getData(MarshalData);
  46. let skillData = marshalData.skillData[param.id];
  47. this.txtSkillName.string = skillData.name;
  48. this.txtSkillLv.string = "Lv." + (param.type == 1 ? param.lv : param.lastLv);
  49. let totalSkillValueStr = MarshalSkillSystem.getSkillValueStr(skillData, param.type == 1 ? param.lv : param.lastLv);
  50. let des = StringUtils.format(skillData.des, totalSkillValueStr);
  51. this.txtRichDes.string = StringUtils.getRichText(des);
  52. this.schedule(this.closeSchedule, 1);
  53. if (param.type == 1) this.playUnlockEft(); else this.playLvUpEft();
  54. this.imgSkill.spriteFrame = await this.res.load<SpriteFrame>("images/skill/" + skillData.icon + "/spriteFrame", SpriteFrame);
  55. }
  56. /**解锁动画*/
  57. private async playUnlockEft() {
  58. this.imgSkill.grayscale = true;
  59. this.spineUnlock.node.active = true;
  60. this.spineUnlock.setAnimation(0, "None", false);
  61. await new Promise<void>(resolve => { setTimeout(() => resolve(), 1000) });
  62. if (isValid(this.node)) {
  63. this.spineUnlock.setToSetupPose();
  64. this.spineUnlock.setAnimation(0, "animation", false);
  65. await new Promise<void>(resolve => { setTimeout(() => resolve(), (this.spineUnlock.findAnimation("animation").duration + 0.5) * 1000) });
  66. if (isValid(this.node)) {
  67. this.spineUnlock.node.active = false;
  68. this.imgSkill.grayscale = false;
  69. }
  70. }
  71. }
  72. /**升级动画*/
  73. private async playLvUpEft() {
  74. this.imgSkill.grayscale = false;
  75. await new Promise<void>(resolve => { setTimeout(() => resolve(), 1000) });
  76. if (isValid(this.node)) {
  77. this.spineLvup.node.active = true;
  78. this.spineLvup.setAnimation(0, "animation", false);
  79. await new Promise<void>(resolve => { setTimeout(() => resolve(), (this.spineLvup.findAnimation("animation").duration + 0.5) * 1000) });
  80. if (isValid(this.node)) {
  81. this.spineLvup.node.active = true;
  82. let marshalData = DataSystem.getData(MarshalData);
  83. let skillData = marshalData.skillData[this.paramData.id];
  84. this.txtSkillLv.string = "Lv." + this.paramData.lv;
  85. let totalSkillValueStr = MarshalSkillSystem.getSkillValueStr(skillData, this.paramData.lv);
  86. let des = StringUtils.format(skillData.des, totalSkillValueStr);
  87. this.txtRichDes.string = StringUtils.getRichText(des);
  88. this.txtRichDes.node.getComponent(UITween).play();
  89. }
  90. }
  91. }
  92. private closeSchedule() {
  93. this.timer -= 1;
  94. if (this.timer < 0) {
  95. this.unschedule(this.closeSchedule);
  96. this.getComponent(Window).close();
  97. }
  98. this.txtTime.string = this.timer + "秒后自动关闭";
  99. }
  100. onDestroy() {
  101. let marshalData = DataSystem.getData(MarshalData);
  102. marshalData.skillUnlockLvUpQueue.splice(0, 1);
  103. let lenAfter = marshalData.skillUnlockLvUpQueue.length;
  104. if (lenAfter > 0) {
  105. let param = marshalData.skillUnlockLvUpQueue[0];
  106. WindowSystem.open("prefabs/ui/marshalStage/marshalSkillLvUp", WindowOpenMode.NotCloseAndCover, [param]);
  107. }
  108. }
  109. }