NavBarController.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { _decorator, Color, Component, Node, Sprite } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('NavBarController')
  4. export class NavBarController extends Component {
  5. @property({ type: [Node] }) panels: Node[] = []; // 依次给 Main、Shop、Upgrade、Skill
  6. @property({ type: [Node] }) buttons: Node[] = []; // 依次给 Battle、Shop、Upgrade、Skill
  7. private normalColor = new Color(255, 255, 255, 255);
  8. private activeColor = new Color(255, 0, 0, 255); // 红色
  9. start () {
  10. // 默认打开 MainUI
  11. this.switchTo(0);
  12. }
  13. onBattleClick () { this.switchTo(0); }
  14. onUpgradeClick () { this.switchTo(1); }
  15. onShopClick () { this.switchTo(2); }
  16. onSkillClick () {
  17. this.switchTo(3);
  18. // 注意:滚动功能现在由SkillNodeGenerator组件通过装饰器直接处理
  19. }
  20. private switchTo (index: number) {
  21. // 显示对应面板
  22. this.panels.forEach((p, i) => p.active = i === index);
  23. // 设置按钮颜色
  24. this.buttons.forEach((btn, i) => {
  25. const sp = btn.getComponent(Sprite);
  26. if (sp) sp.color = (i === index) ? this.activeColor : this.normalColor;
  27. });
  28. }
  29. }