UI_Dialog.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { _decorator, Component, Node, tween, v3 } from 'cc';
  2. import { aa, UIElement } from 'db://assets/scripts/aa';
  3. import { GameUILayers } from 'db://assets/scripts/GameUILayers';
  4. import { ani_ui } from '../../util/Customize_Ani';
  5. const { ccclass, property } = _decorator;
  6. export class UI_Dialog extends aa.UIcontroller {
  7. @UIElement()
  8. close_btn: Node
  9. @UIElement({ type: Node, prefix: "" ,path:"bg"})
  10. bg: Node
  11. @UIElement({ type: Node, prefix: "" ,path:"Root"})
  12. Root: Node
  13. private state = 0
  14. public get layer(): number {
  15. return GameUILayers.ALERT
  16. }
  17. protected onCreated(): void {
  18. this.state = 0
  19. if (this.close_btn) {
  20. this.close_btn.on(Node.EventType.TOUCH_END,this.onClose,this)
  21. }
  22. // if (this.bg) {
  23. // this.bg.on(Node.EventType.TOUCH_END, this.onClose, this)
  24. // }
  25. this.start()
  26. this.dlg_Show()
  27. }
  28. start(){
  29. }
  30. onClose() {
  31. this.close()
  32. }
  33. close() {
  34. if (this.state != 0) {
  35. return
  36. }
  37. this.node.off(Node.EventType.TOUCH_END)
  38. this.state = 1
  39. this.dlg_Close(() => {
  40. this.state = 0
  41. super.close()
  42. })
  43. }
  44. dlg_Close(cb?) {
  45. let dlg = this.Root || this.node;
  46. tween(dlg)
  47. .to(0.2, { scale: v3(0, 0, 0) }, { easing: "sineOut" }).call(() => {
  48. cb && cb()
  49. }).start();
  50. }
  51. dlg_Show() {
  52. let dlg = this.Root || this.node;
  53. ani_ui(dlg);
  54. // dlg.scale = v3(0, 0, 0);
  55. // tween(dlg)
  56. // .to(0.15, { scale: v3(1.2, 1.2, 1) }, { easing: "sineOut" })
  57. // .to(0.1, { scale: v3(1, 1, 1) }, { easing: "sineOut" })
  58. // .start();
  59. }
  60. }