MarshalSkillPage.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { _decorator, Component, Node, Prefab, Label, Sprite, instantiate } from 'cc';
  2. import { DataSystem } from '../../core/data/DataSystem';
  3. import { Http } from '../../core/net/Http';
  4. import { NoviceGuideData } from '../../guide/NoviceGuideData';
  5. import { UserHeroData } from '../../hero/UserHeroData';
  6. import { MarshalData } from '../MarshalData';
  7. import { MarshalSkillItem } from './MarshalSkillItem';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('MarshalSkillPage')
  10. export class MarshalSkillPage extends Component {
  11. @property({ type: Sprite, displayName: "进度_总星数", tooltip: "进度_总星数" }) sliderTotalStars: Sprite = null;
  12. @property({ type: Label, displayName: "文本进度_总星数", tooltip: "文本进度_总星数" }) txtTotalStars: Label = null;
  13. @property({ type: Node, displayName: "技能内容节点", tooltip: "技能内容节点" }) contentSkill: Node = null;
  14. @property({ type: Prefab, displayName: "技能预制体", tooltip: "技能预制体" }) skillItemPrefab: Prefab = null;
  15. /**是否初始化过技能页*/
  16. private isInitedSkillPanel: boolean = false;
  17. /**技能item数组*/
  18. private skillItems: MarshalSkillItem[];
  19. public async onShow() {
  20. this.node.active = true;
  21. this.updateSkillPanel();
  22. DataSystem.getData(NoviceGuideData).openMarshalSkill = true;
  23. }
  24. public async onHide() {
  25. this.node.active = false;
  26. }
  27. /**更新技能页*/
  28. private async updateSkillPanel() {
  29. let marshalData = DataSystem.getData(MarshalData);
  30. if (!this.isInitedSkillPanel) {
  31. this.isInitedSkillPanel = true;
  32. let tempKeys = marshalData.marshalSkillData.lvNeedStarsMap.keys();
  33. this.skillItems = [];
  34. for (let id of tempKeys) {
  35. let tempNode = instantiate(this.skillItemPrefab);
  36. tempNode.active = true;
  37. this.contentSkill.addChild(tempNode);
  38. let scr = tempNode.getComponent(MarshalSkillItem);
  39. scr.updateInfo(id, marshalData.marshalSkillData.lvMarshalSkill.get(id));
  40. this.skillItems.push(scr);
  41. }
  42. } else {
  43. for (let t of this.skillItems) {
  44. t.updateInfo(t.skillId, marshalData.marshalSkillData.lvMarshalSkill.get(t.skillId));
  45. }
  46. }
  47. let cur = await this.getTotalStars();
  48. let total = (DataSystem.getData(UserHeroData).haveHeros.length + DataSystem.getData(UserHeroData).notHavetHeros.length) * 7;
  49. this.txtTotalStars.string = cur + "/" + total;
  50. this.sliderTotalStars.fillRange = cur / total;
  51. }
  52. /**获取所有星数*/
  53. getTotalStars() {
  54. let num = 0;
  55. let userHeroData = DataSystem.getData(UserHeroData);
  56. //await userHeroData.pull(this.getComponent(Http));
  57. for (let id of userHeroData.haveHeros) {
  58. let tempHero = userHeroData.get(id);
  59. num += tempHero.server.star;
  60. }
  61. return num;
  62. }
  63. }