| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import { _decorator, Component, Node, Sprite, RichText, Label, SpriteFrame } from 'cc';
- import { DataSystem } from '../../core/data/DataSystem';
- import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
- import { StringUtils } from '../../core/utils/StringUtils';
- import { MarshalData } from '../MarshalData';
- import { MarshalDataTool } from '../MarshalDataTool';
- import { MarshalSkillSystem } from '../MarshalSkillSystem';
- import { GrayEffectNode } from './GrayEffectNode';
- const { ccclass, property } = _decorator;
- /**
- * 统帅技能item
- * @author 郑聂华
- */
- @ccclass('MarshalSkillItem')
- export class MarshalSkillItem extends Component {
- @property({ type: ResourceLoader, displayName: "资源加载组件", tooltip: "资源加载组件" }) res: ResourceLoader = null;
- @property({ type: GrayEffectNode, displayName: "置灰脚本", tooltip: "置灰脚本" }) grayScr: GrayEffectNode = null;
- @property({ type: Node, displayName: "选中节点1", tooltip: "选中节点1" }) nodeSelect1: Node = null;
- @property({ type: Node, displayName: "选中节点2", tooltip: "选中节点2" }) nodeSelect2: Node = null;
- @property({ type: Node, displayName: "下部灰色节点", tooltip: "下部灰色节点" }) imgDwnBg1: Node = null;
- @property({ type: Node, displayName: "下部选中节点", tooltip: "下部选中节点" }) imgDwnBg2: 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;
- @property({ type: Node, displayName: "标题_解锁", tooltip: "标题_解锁" }) tipUnlock: Node = null;
- @property({ type: Node, displayName: "标题_升级", tooltip: "标题_升级" }) tipLvup: Node = null;
- @property({ type: Node, displayName: "条件节点", tooltip: "条件节点" }) conditNode: Node = null;
- @property({ type: Label, displayName: "文本_星数", tooltip: "文本_星数" }) txtStar: Label = null;
- @property({ type: Node, displayName: "默认技能文本", tooltip: "默认技能文本" }) nodeDefaultTip: Node = null;
- @property({ type: Node, displayName: "默认技能按钮", tooltip: "默认技能按钮" }) nodeDefaultBtn: Node = null;
- //public marshalDataTool: MarshalDataTool;
- public skillId: number;
- /**技能状态 1 未解锁 2 已解锁 3 Max最高级*/
- private skillstatus: number;
- /**更新信息
- * @param skillId 技能id
- * @param lv 技能等级
- */
- public async updateInfo(skillId: number, lv: number) {
- 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 next = tempLv < skillData.skillValue.length ? MarshalSkillSystem.getSkillValueStr(skillData, tempLv + 1) : "";
- let totalskillvaluestr = `${MarshalSkillSystem.getSkillValueStr(skillData, tempLv) + (next == "" ? next : "(下一级" + next + ")")}`;
- let des = StringUtils.format(skillData.des, totalskillvaluestr);
- des = StringUtils.getRichText(des);
- //des = des.replace("$0", totalskillvaluestr);
- this.txtRichDes.string = des;
- this.conditNode.active = tempLv != 3;
- this.tipUnlock.active = lv <= 0;
- this.tipLvup.active = lv > 0 && lv < skillData.skillValue.length;
- this.txtStar.string = tempLv != 3 ? marshalData.marshalSkillData.lvNeedStarsMap.get(skillData.id)[lv < 0 ? 0 : lv] + "" : "";
- let posYTip = lv < skillData.skillValue.length ? -100 : -70;
- let posYBtn = lv < skillData.skillValue.length ? -105 : -75;
- this.nodeDefaultTip.setPosition(this.nodeDefaultTip.position.x, posYTip);
- this.nodeDefaultBtn.setPosition(this.nodeDefaultBtn.position.x, posYBtn);
- 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() {
- console.log("default ");
- let marshalData = DataSystem.getData(MarshalData);
- this.setDefaultState(marshalData.defaultId == this.skillId ? 1 : 0);
- }
- /**
- * 设置默认技能
- * @param type 1 默认技能 0 不是默认技能
- */
- private setDefaultState(type: number) {
- this.nodeSelect1.active = type == 1;
- this.nodeSelect2.active = type == 1 && this.skillstatus != 3;
- this.imgDwnBg1.active = this.skillstatus != 3;
- this.imgDwnBg2.active = type == 1 && this.skillstatus != 3;
- this.nodeDefaultTip.active = type == 1 && this.skillstatus != 1;
- this.nodeDefaultBtn.active = type != 1 && this.skillstatus != 1;
- }
- private onClickDefaultBtn() {
- if (this.skillstatus != 1) {
- let marshalData = DataSystem.getData(MarshalData);
- marshalData.defaultId = this.skillId;
- this.setDefaultState(1);
- } else {
- console.log("this skill has default skill");
- }
- }
- }
|