import { Label } from 'cc'; import { Button } from 'cc'; import { Sprite } from 'cc'; import { _decorator, Component, Node } from 'cc'; import { SkillInfo } from '../../global/GameInterface'; import { UmLog } from '../../../../cc-common/cc-util/UmLog'; import { GameDefine } from '../../config/GameDefine'; import { GameGlobalData } from '../../global/GameGlobalData'; const { ccclass, property } = _decorator; @ccclass('SkillRewardItemUI') export class SkillRewardItemUI extends Component { @property(Sprite) spIcon: Sprite = null!; @property(Label) txtName: Label = null!; @property(Label) txtInfo: Label = null!; @property(Button) btnSelect: Button = null!; @property(Label) txtLevel: Label = null!; selectCallback = null; skillData: SkillInfo = null; protected onLoad(): void { this.btnSelect?.node.on(Button.EventType.CLICK, this.onBtnSelectClicked, this); } public setData(skillData: SkillInfo, selectCallback) { this.skillData = skillData; this.txtName.string = skillData.skillName; this.selectCallback = selectCallback; var infoStr = ""; if (GameGlobalData.Instance.isActiveSkill(skillData.skillName)) { var asCollected = GameGlobalData.Instance.userDataSaver.activeSkillCollected; var targetLevel = 1; if (asCollected.hasOwnProperty(skillData.skillName)) { targetLevel += asCollected[skillData.skillName]; } var skillConfig = GameGlobalData.Instance.gameDataConfig.getActiveSkillDataByNameAndLevel(skillData.skillName, targetLevel); this.txtName.string += (": " + skillConfig.Visual_Name); infoStr += `\nDMG: ~> ${skillConfig.DMG}`; infoStr += `\nMana: ~> ${skillConfig.Mana}`; infoStr += `\nRange: ~> ${skillConfig.Range}`; } else { var psCollected = GameGlobalData.Instance.passiveSkillCollected; var targetLevel = 1; if (psCollected.hasOwnProperty(skillData.skillName)) { targetLevel += psCollected[skillData.skillName]; } var skillConfig = GameGlobalData.Instance.gameDataConfig.getPassiveSkillDataByNameAndLevel(skillData.skillName, targetLevel); infoStr = `${skillConfig.visualname}: +${skillConfig.value}`; } this.txtInfo.string = infoStr; this.txtLevel.string = targetLevel.toString(); } onBtnSelectClicked() { UmLog.log("onBtnSelectClicked => ", this.skillData.skillName); this.selectCallback?.(this.skillData); } }