| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import { _decorator, Component, Node, Prefab, Label, Sprite, instantiate } from 'cc';
- import { DataSystem } from '../../core/data/DataSystem';
- import { Http } from '../../core/net/Http';
- import { NoviceGuideData } from '../../guide/NoviceGuideData';
- import { UserHeroData } from '../../hero/UserHeroData';
- import { MarshalData } from '../MarshalData';
- import { MarshalSkillItem } from './MarshalSkillItem';
- const { ccclass, property } = _decorator;
- @ccclass('MarshalSkillPage')
- export class MarshalSkillPage extends Component {
- @property({ type: Sprite, displayName: "进度_总星数", tooltip: "进度_总星数" }) sliderTotalStars: Sprite = null;
- @property({ type: Label, displayName: "文本进度_总星数", tooltip: "文本进度_总星数" }) txtTotalStars: Label = null;
- @property({ type: Node, displayName: "技能内容节点", tooltip: "技能内容节点" }) contentSkill: Node = null;
- @property({ type: Prefab, displayName: "技能预制体", tooltip: "技能预制体" }) skillItemPrefab: Prefab = null;
- /**是否初始化过技能页*/
- private isInitedSkillPanel: boolean = false;
- /**技能item数组*/
- private skillItems: MarshalSkillItem[];
- public async onShow() {
- this.node.active = true;
- this.updateSkillPanel();
- DataSystem.getData(NoviceGuideData).openMarshalSkill = true;
- }
- public async onHide() {
- this.node.active = false;
- }
- /**更新技能页*/
- private async updateSkillPanel() {
- let marshalData = DataSystem.getData(MarshalData);
- if (!this.isInitedSkillPanel) {
- this.isInitedSkillPanel = true;
- let tempKeys = marshalData.marshalSkillData.lvNeedStarsMap.keys();
- this.skillItems = [];
- for (let id of tempKeys) {
- let tempNode = instantiate(this.skillItemPrefab);
- tempNode.active = true;
- this.contentSkill.addChild(tempNode);
- let scr = tempNode.getComponent(MarshalSkillItem);
- scr.updateInfo(id, marshalData.marshalSkillData.lvMarshalSkill.get(id));
- this.skillItems.push(scr);
- }
- } else {
- for (let t of this.skillItems) {
- t.updateInfo(t.skillId, marshalData.marshalSkillData.lvMarshalSkill.get(t.skillId));
- }
- }
- let cur = await this.getTotalStars();
- let total = (DataSystem.getData(UserHeroData).haveHeros.length + DataSystem.getData(UserHeroData).notHavetHeros.length) * 7;
- this.txtTotalStars.string = cur + "/" + total;
- this.sliderTotalStars.fillRange = cur / total;
- }
- /**获取所有星数*/
- getTotalStars() {
- let num = 0;
- let userHeroData = DataSystem.getData(UserHeroData);
- //await userHeroData.pull(this.getComponent(Http));
- for (let id of userHeroData.haveHeros) {
- let tempHero = userHeroData.get(id);
- num += tempHero.server.star;
- }
- return num;
- }
- }
|