TouchCharacterSlot-001.ts 2.4 KB

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