SelectTroopsBottom.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { _decorator, Button, Component, director, find, Node, resources, Sprite, SpriteFrame } from 'cc';
  2. import { GameInfo } from '../../GameInfo';
  3. import { UIMgr } from '../../Frames/UIManager';
  4. import { GameMgr } from '../GameFrameWork/GameMgr';
  5. import { BattleSceneTop } from '../UI/BattleSceneTop';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('SelectTroopsBottom')
  8. export class SelectTroopsBottom extends Component {
  9. private _btnNext: Node = null;
  10. private _characterSlot: Node = null;
  11. private _names: string[] = [];
  12. protected onLoad(): void {
  13. this._btnNext = this.node.getChildByName("BtnNext");
  14. this._characterSlot = this.node.getChildByName("CharacterSlot");
  15. }
  16. start() {
  17. this._btnNext.getComponent(Button).node.on(Button.EventType.CLICK, this._onBtnNext, this);
  18. }
  19. private _onBtnNext() {
  20. this._names = this._getNames();
  21. if (this._names) {
  22. GameInfo.Instance.setRoleImgNames(this._names);
  23. GameInfo.Instance.getGameOverReward().clear();
  24. director.loadScene("GameScene");
  25. }
  26. }
  27. private _getNames(): string[] {
  28. for (const element of this._characterSlot.children) {
  29. const name: SpriteFrame = element.getChildByName("Sprite").getComponent(Sprite).spriteFrame;
  30. if (name) {
  31. this._names.push(name.name)
  32. }
  33. }
  34. return this._names;
  35. }
  36. }