Popup.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import BasicObject from "../../Basic/BasicObject";
  2. import BasicView from "../../Basic/BasicView";
  3. import Tool from "../../Tool/Tool";
  4. /**弹窗计数 */
  5. let PopupCount: number = 0;
  6. /**
  7. * 弹窗组件 - 表现层
  8. */
  9. export default class Popup extends BasicObject {
  10. /**视窗 */
  11. private view: BasicView;
  12. /**底层遮罩 */
  13. private cover: fgui.GComponent;
  14. /**弹窗 */
  15. private window: fgui.GComponent;
  16. /**关闭按钮 */
  17. private closeButton: fgui.GComponent;
  18. /**关闭方法 */
  19. private closeFunction: Function;
  20. constructor (view: BasicView, cover: fgui.GComponent, window: fgui.GComponent, closeButton: fgui.GComponent, closeFunction: Function) {
  21. super();
  22. view.node.zIndex += PopupCount;
  23. PopupCount++;
  24. this.view = view;
  25. this.cover = cover;
  26. this.window = window;
  27. this.closeFunction = closeFunction;
  28. this.window.on(cc.Node.EventType.TOUCH_END, () => {
  29. });
  30. this.cover.on(cc.Node.EventType.TOUCH_END, () => {
  31. this.hide();
  32. });
  33. this.closeButton = closeButton;
  34. Tool.Tool2D.Button.addEvent(this.closeButton, {
  35. "touchend": () => {
  36. this.hide();
  37. }
  38. }, this.view.fgui.id);
  39. this.window.setScale(0.3, 0.3);
  40. }
  41. /**显示 */
  42. public show (): void {
  43. this.window.setScale(0.3, 0.3);
  44. Tool.Tween.tweenTo(this.window, cc.tween(this.window)
  45. .to(0.1, {scaleX: 1, scaleY: 1}, cc.easeBackOut())
  46. .start()
  47. );
  48. }
  49. /**隐藏 */
  50. public hide (): void {
  51. Tool.Tween.tweenTo(this.window, cc.tween(this.window)
  52. .to(0.1, {scaleX: 0.3, scaleY: 0.3})
  53. .call(() => {
  54. this.closeFunction && this.closeFunction();
  55. })
  56. .start()
  57. );
  58. }
  59. _destroy () {
  60. Tool.Tween.destroy(this.window.id);
  61. super._destroy();
  62. }
  63. }