TouchCharacterSlot.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { _decorator, math, Node, Rect, UITransform } from 'cc';
  2. import { TouchMgr } from './TouchMgr';
  3. import { CharacterSlotMgr } from './CharacterSlotMgr';
  4. import { UIMgr } from '../../Frames/UIManager';
  5. import { UIType } from '../GameFrameWork/UIBase';
  6. import { PopupUIDataConfig } from './GameScene/Data/PopupUIDataConfig';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('TouchCharacterSlot')
  9. export class TouchCharacterSlot extends TouchMgr {
  10. private _characterSlot: Node = null;
  11. private unLock: Node = null;
  12. protected onLoad(): void {
  13. this._characterSlot = this.node.parent.getChildByName("CharacterSlot");
  14. }
  15. func(pos: math.Vec2): void {
  16. this.node.parent.getChildByName("CharacterSlot").getComponent(CharacterSlotMgr).removeCardImg(pos);
  17. for (const node of this._characterSlot.children) {
  18. if (node.getChildByName("Label").active) {
  19. const box: Rect = node.getComponent(UITransform).getBoundingBoxToWorld();
  20. if (box.contains(pos)) {
  21. this.unLock = node;
  22. PopupUIDataConfig.Instance.setUIName("解锁");
  23. PopupUIDataConfig.Instance.setTypeImg("Lock");
  24. PopupUIDataConfig.Instance.setTypeMoney("Gold");
  25. PopupUIDataConfig.Instance.setLabel(
  26. `可用卡槽:${PopupUIDataConfig.Instance.getAvailableCardSlot()}`,
  27. `下一级:${PopupUIDataConfig.Instance.getAvailableCardSlot() + 1}`,
  28. `耗费:`, `2000`);
  29. PopupUIDataConfig.Instance.setFunction(() => {
  30. this.closeNode();
  31. })
  32. UIMgr.openUI("PopupUI", UIType.WIDGET);
  33. }
  34. }
  35. }
  36. }
  37. closeNode() {
  38. if (this.unLock) {
  39. this.unLock.getChildByName("Lock").active = false;
  40. this.unLock.getChildByName("Label").active = false;
  41. PopupUIDataConfig.Instance.setAvailableCardSlot(PopupUIDataConfig.Instance.getAvailableCardSlot() + 1)
  42. const indexNext: number = this.unLock.getSiblingIndex();
  43. if (indexNext === this.unLock.parent.children.length - 1) return;
  44. const nodeNext = this.unLock.parent.children[indexNext + 1];
  45. nodeNext.getChildByName("Lock").active = true;
  46. nodeNext.getChildByName("Label").active = true;
  47. }
  48. }
  49. }