MarshalSkillItem.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { _decorator, Component, Node, Sprite, RichText, Label, 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 { MarshalData } from '../MarshalData';
  6. import { MarshalDataTool } from '../MarshalDataTool';
  7. import { MarshalSkillSystem } from '../MarshalSkillSystem';
  8. import { GrayEffectNode } from './GrayEffectNode';
  9. const { ccclass, property } = _decorator;
  10. /**
  11. * 统帅技能item
  12. * @author 郑聂华
  13. */
  14. @ccclass('MarshalSkillItem')
  15. export class MarshalSkillItem extends Component {
  16. @property({ type: ResourceLoader, displayName: "资源加载组件", tooltip: "资源加载组件" }) res: ResourceLoader = null;
  17. @property({ type: GrayEffectNode, displayName: "置灰脚本", tooltip: "置灰脚本" }) grayScr: GrayEffectNode = null;
  18. @property({ type: Node, displayName: "选中节点1", tooltip: "选中节点1" }) nodeSelect1: Node = null;
  19. @property({ type: Node, displayName: "选中节点2", tooltip: "选中节点2" }) nodeSelect2: Node = null;
  20. @property({ type: Node, displayName: "下部灰色节点", tooltip: "下部灰色节点" }) imgDwnBg1: Node = null;
  21. @property({ type: Node, displayName: "下部选中节点", tooltip: "下部选中节点" }) imgDwnBg2: Node = null;
  22. @property({ type: Sprite, displayName: "技能图", tooltip: "技能图" }) imgSkill: Sprite = null;
  23. @property({ type: RichText, displayName: "技能名称与等级", tooltip: "技能名称与等级" }) txtRichName: RichText = null;
  24. @property({ type: RichText, displayName: "技能描述", tooltip: "技能描述" }) txtRichDes: RichText = null;
  25. @property({ type: Node, displayName: "锁", tooltip: "锁" }) lock: Node = null;
  26. @property({ type: Node, displayName: "标题_解锁", tooltip: "标题_解锁" }) tipUnlock: Node = null;
  27. @property({ type: Node, displayName: "标题_升级", tooltip: "标题_升级" }) tipLvup: Node = null;
  28. @property({ type: Node, displayName: "条件节点", tooltip: "条件节点" }) conditNode: Node = null;
  29. @property({ type: Label, displayName: "文本_星数", tooltip: "文本_星数" }) txtStar: Label = null;
  30. @property({ type: Node, displayName: "默认技能文本", tooltip: "默认技能文本" }) nodeDefaultTip: Node = null;
  31. @property({ type: Node, displayName: "默认技能按钮", tooltip: "默认技能按钮" }) nodeDefaultBtn: Node = null;
  32. //public marshalDataTool: MarshalDataTool;
  33. public skillId: number;
  34. /**技能状态 1 未解锁 2 已解锁 3 Max最高级*/
  35. private skillstatus: number;
  36. /**更新信息
  37. * @param skillId 技能id
  38. * @param lv 技能等级
  39. */
  40. public async updateInfo(skillId: number, lv: number) {
  41. this.skillId = skillId;
  42. let tempLv = lv < 0 ? 1 : lv;
  43. let marshalData = DataSystem.getData(MarshalData);
  44. let skillData = marshalData.skillData[skillId];
  45. if (lv < 0) this.skillstatus = 1;
  46. else if (lv < skillData.skillValue.length) this.skillstatus = 2;
  47. else this.skillstatus = 3;
  48. this.txtRichName.string = `<color=#4E301B>${skillData.name}</c><color=#E6181A>Lv.${tempLv + (tempLv == 3 ? "(Max)" : "")}</color>`;
  49. let next = tempLv < skillData.skillValue.length ? MarshalSkillSystem.getSkillValueStr(skillData, tempLv + 1) : "";
  50. let totalskillvaluestr = `${MarshalSkillSystem.getSkillValueStr(skillData, tempLv) + (next == "" ? next : "(下一级" + next + ")")}`;
  51. let des = StringUtils.format(skillData.des, totalskillvaluestr);
  52. des = StringUtils.getRichText(des);
  53. //des = des.replace("$0", totalskillvaluestr);
  54. this.txtRichDes.string = des;
  55. this.conditNode.active = tempLv != 3;
  56. this.tipUnlock.active = lv <= 0;
  57. this.tipLvup.active = lv > 0 && lv < skillData.skillValue.length;
  58. this.txtStar.string = tempLv != 3 ? marshalData.marshalSkillData.lvNeedStarsMap.get(skillData.id)[lv < 0 ? 0 : lv] + "" : "";
  59. let posYTip = lv < skillData.skillValue.length ? -100 : -70;
  60. let posYBtn = lv < skillData.skillValue.length ? -105 : -75;
  61. this.nodeDefaultTip.setPosition(this.nodeDefaultTip.position.x, posYTip);
  62. this.nodeDefaultBtn.setPosition(this.nodeDefaultBtn.position.x, posYBtn);
  63. this.lock.active = lv <= 0;
  64. this.setDefaultState(marshalData.defaultId == skillData.id ? 1 : 0);
  65. lv <= 0 && this.grayScr.setGray();
  66. this.imgSkill.spriteFrame = await this.res.load<SpriteFrame>("images/skill/" + skillData.icon + "/spriteFrame", SpriteFrame);
  67. }
  68. update() {
  69. DataSystem.watch(MarshalData, "defaultId") && this.updateDefaultSkill();
  70. }
  71. /**更新默认技能显示*/
  72. updateDefaultSkill() {
  73. console.log("default ");
  74. let marshalData = DataSystem.getData(MarshalData);
  75. this.setDefaultState(marshalData.defaultId == this.skillId ? 1 : 0);
  76. }
  77. /**
  78. * 设置默认技能
  79. * @param type 1 默认技能 0 不是默认技能
  80. */
  81. private setDefaultState(type: number) {
  82. this.nodeSelect1.active = type == 1;
  83. this.nodeSelect2.active = type == 1 && this.skillstatus != 3;
  84. this.imgDwnBg1.active = this.skillstatus != 3;
  85. this.imgDwnBg2.active = type == 1 && this.skillstatus != 3;
  86. this.nodeDefaultTip.active = type == 1 && this.skillstatus != 1;
  87. this.nodeDefaultBtn.active = type != 1 && this.skillstatus != 1;
  88. }
  89. private onClickDefaultBtn() {
  90. if (this.skillstatus != 1) {
  91. let marshalData = DataSystem.getData(MarshalData);
  92. marshalData.defaultId = this.skillId;
  93. this.setDefaultState(1);
  94. } else {
  95. console.log("this skill has default skill");
  96. }
  97. }
  98. }