| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import { _decorator, Component, Node, Sprite, RichText, SpriteFrame } from 'cc';
- import { DataSystem } from '../../core/data/DataSystem';
- import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
- import { StringUtils } from '../../core/utils/StringUtils';
- import { Hero_Client } from '../../hero/UserHeroData';
- import { MarshalData } from '../MarshalData';
- import { MarshalDataTool } from '../MarshalDataTool';
- import { MarshalSkillSystem } from '../MarshalSkillSystem';
- import { GrayEffectNode } from './GrayEffectNode';
- const { ccclass, property } = _decorator;
- /**
- * 统帅技能切换item
- * @author 郑聂华
- */
- @ccclass('SwitchSkillItem')
- export class SwitchSkillItem extends Component {
- @property({ type: ResourceLoader, displayName: "资源加载组件", tooltip: "资源加载组件" }) res: ResourceLoader = null;
- @property({ type: GrayEffectNode, displayName: "置灰脚本", tooltip: "置灰脚本" }) grayScr: GrayEffectNode = null;
- @property({ type: Node, displayName: "选中节点", tooltip: "选中节点" }) selectNode: Node = null;
- @property({ type: Sprite, displayName: "技能图标", tooltip: "技能图标" }) imgSkill: Sprite = null;
- @property({ type: RichText, displayName: "文本_技能名称", tooltip: "文本_技能名称" }) txtRichName: RichText = null;
- @property({ type: RichText, displayName: "文本_技能介绍", tooltip: "文本_技能介绍" }) txtRichDes: RichText = null;
- @property({ type: Node, displayName: "锁", tooltip: "锁" }) lock: Node = null;
- //public marshalDataTool: MarshalDataTool;
- private skillId: number;
- /**技能状态 1 未解锁 2 已解锁 3 Max最高级*/
- private skillstatus: number;
- /**更新信息
- * @param hero 武将
- * @param skillId 技能id
- * @param lv 技能等级
- */
- public async updateInfo(hero: Hero_Client, skillId: number, lv: number) {
- this.node.active = lv > 0;
- this.skillId = skillId;
- let tempLv = lv < 0 ? 1 : lv;
- let marshalData = DataSystem.getData(MarshalData);
- let skillData = marshalData.skillData[skillId];
- if (lv < 0) this.skillstatus = 1;
- else if (lv < skillData.skillValue.length) this.skillstatus = 2;
- else this.skillstatus = 3;
- this.txtRichName.string = `<color=#4E301B> ${skillData.name} </c><color=#E6181A>Lv.${tempLv}${tempLv == 3 ? "(Max)" : ""}</color>`;
- let addStr = MarshalSkillSystem.getSkillAddValueStr(skillData, tempLv, hero);
- let skillValueStr = MarshalSkillSystem.getSkillValueStr(skillData, tempLv);
- let totalSkillStr = `${skillValueStr}(+${addStr})`;
- let desStr = StringUtils.format(skillData.des, totalSkillStr);
- desStr = StringUtils.getRichText(desStr);
- this.txtRichDes.string = desStr;
- this.lock.active = lv <= 0;
- this.setDefaultState(marshalData.defaultId == skillData.id ? 1 : 0);
- lv < 0 && this.grayScr.setGray();
- this.imgSkill.spriteFrame = await this.res.load<SpriteFrame>("images/skill/" + skillData.icon + "/spriteFrame", SpriteFrame);
- }
- update() {
- DataSystem.watch(MarshalData, "defaultId") && this.updateDefaultSkill();
- }
- /**更新默认技能显示*/
- updateDefaultSkill() {
- let marshalData = DataSystem.getData(MarshalData);
- this.setDefaultState(marshalData.defaultId == this.skillId ? 1 : 0);
- }
- /**
- * 设置默认技能
- * @param type 1 默认技能 0 不是默认技能
- */
- private setDefaultState(type: number) {
- this.selectNode.active = type == 1 && this.skillstatus != 1;
- }
- private onClickDefaultBtn() {
- if (this.skillstatus != 1) {
- let marshalData = DataSystem.getData(MarshalData);
- if (marshalData.defaultId != this.skillId) {
- marshalData.defaultId = this.skillId;
- this.setDefaultState(1);
- }
- } else {
- console.log("this skill has default skill");
- }
- }
- }
|