SwitchSkillItem.ts 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { _decorator, Component, Node, Sprite, RichText, SpriteFrame } from 'cc';
  2. import { DataSystem } from '../../core/data/DataSystem';
  3. import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
  4. import { StringUtils } from '../../core/utils/StringUtils';
  5. import { Hero_Client } from '../../hero/UserHeroData';
  6. import { MarshalData } from '../MarshalData';
  7. import { MarshalDataTool } from '../MarshalDataTool';
  8. import { MarshalSkillSystem } from '../MarshalSkillSystem';
  9. import { GrayEffectNode } from './GrayEffectNode';
  10. const { ccclass, property } = _decorator;
  11. /**
  12. * 统帅技能切换item
  13. * @author 郑聂华
  14. */
  15. @ccclass('SwitchSkillItem')
  16. export class SwitchSkillItem extends Component {
  17. @property({ type: ResourceLoader, displayName: "资源加载组件", tooltip: "资源加载组件" }) res: ResourceLoader = null;
  18. @property({ type: GrayEffectNode, displayName: "置灰脚本", tooltip: "置灰脚本" }) grayScr: GrayEffectNode = null;
  19. @property({ type: Node, displayName: "选中节点", tooltip: "选中节点" }) selectNode: Node = null;
  20. @property({ type: Sprite, displayName: "技能图标", tooltip: "技能图标" }) imgSkill: Sprite = null;
  21. @property({ type: RichText, displayName: "文本_技能名称", tooltip: "文本_技能名称" }) txtRichName: RichText = null;
  22. @property({ type: RichText, displayName: "文本_技能介绍", tooltip: "文本_技能介绍" }) txtRichDes: RichText = null;
  23. @property({ type: Node, displayName: "锁", tooltip: "锁" }) lock: Node = null;
  24. //public marshalDataTool: MarshalDataTool;
  25. private skillId: number;
  26. /**技能状态 1 未解锁 2 已解锁 3 Max最高级*/
  27. private skillstatus: number;
  28. /**更新信息
  29. * @param hero 武将
  30. * @param skillId 技能id
  31. * @param lv 技能等级
  32. */
  33. public async updateInfo(hero: Hero_Client, skillId: number, lv: number) {
  34. this.node.active = lv > 0;
  35. this.skillId = skillId;
  36. let tempLv = lv < 0 ? 1 : lv;
  37. let marshalData = DataSystem.getData(MarshalData);
  38. let skillData = marshalData.skillData[skillId];
  39. if (lv < 0) this.skillstatus = 1;
  40. else if (lv < skillData.skillValue.length) this.skillstatus = 2;
  41. else this.skillstatus = 3;
  42. this.txtRichName.string = `<color=#4E301B> ${skillData.name} </c><color=#E6181A>Lv.${tempLv}${tempLv == 3 ? "(Max)" : ""}</color>`;
  43. let addStr = MarshalSkillSystem.getSkillAddValueStr(skillData, tempLv, hero);
  44. let skillValueStr = MarshalSkillSystem.getSkillValueStr(skillData, tempLv);
  45. let totalSkillStr = `${skillValueStr}(+${addStr})`;
  46. let desStr = StringUtils.format(skillData.des, totalSkillStr);
  47. desStr = StringUtils.getRichText(desStr);
  48. this.txtRichDes.string = desStr;
  49. this.lock.active = lv <= 0;
  50. this.setDefaultState(marshalData.defaultId == skillData.id ? 1 : 0);
  51. lv < 0 && this.grayScr.setGray();
  52. this.imgSkill.spriteFrame = await this.res.load<SpriteFrame>("images/skill/" + skillData.icon + "/spriteFrame", SpriteFrame);
  53. }
  54. update() {
  55. DataSystem.watch(MarshalData, "defaultId") && this.updateDefaultSkill();
  56. }
  57. /**更新默认技能显示*/
  58. updateDefaultSkill() {
  59. let marshalData = DataSystem.getData(MarshalData);
  60. this.setDefaultState(marshalData.defaultId == this.skillId ? 1 : 0);
  61. }
  62. /**
  63. * 设置默认技能
  64. * @param type 1 默认技能 0 不是默认技能
  65. */
  66. private setDefaultState(type: number) {
  67. this.selectNode.active = type == 1 && this.skillstatus != 1;
  68. }
  69. private onClickDefaultBtn() {
  70. if (this.skillstatus != 1) {
  71. let marshalData = DataSystem.getData(MarshalData);
  72. if (marshalData.defaultId != this.skillId) {
  73. marshalData.defaultId = this.skillId;
  74. this.setDefaultState(1);
  75. }
  76. } else {
  77. console.log("this skill has default skill");
  78. }
  79. }
  80. }