EditorUI.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import EditorEvents = require("../editor/EditorEvents");
  2. import MainFrame = require("../ui/MainFrame");
  3. import ModalOps = require("./modal/ModalOps");
  4. import Shortcuts = require("./Shortcuts");
  5. // this is designed with public get functions to solve
  6. // circular dependency issues in TS
  7. var editorUI:EditorUI;
  8. export function getMainFrame():MainFrame {
  9. return editorUI.mainframe;
  10. }
  11. export function getModelOps():ModalOps {
  12. return editorUI.modalOps;
  13. }
  14. export function getView():Atomic.UIView {
  15. return editorUI.view;
  16. }
  17. export function getShortcuts():Shortcuts {
  18. return editorUI.shortcuts;
  19. }
  20. export function initialize() {
  21. editorUI = new EditorUI();
  22. }
  23. export function shutdown() {
  24. editorUI.mainframe.shutdown();
  25. var view = editorUI.view;
  26. view.deleteAllChildren();
  27. view.parent.removeChild(view);
  28. }
  29. export function showModalError(windowText:string, message:string) {
  30. editorUI.showModalError(windowText, message);
  31. }
  32. class EditorUI extends Atomic.ScriptObject {
  33. constructor() {
  34. super();
  35. var graphics = Atomic.getGraphics();
  36. this.view = new Atomic.UIView();
  37. this.mainframe = new MainFrame();
  38. this.view.addChild(this.mainframe);
  39. // set initial size
  40. this.mainframe.setSize(graphics.width, graphics.height);
  41. this.modalOps = new ModalOps();
  42. this.shortcuts = new Shortcuts();
  43. this.subscribeToEvent(EditorEvents.ModalError, (event:EditorEvents.ModalErrorEvent) => {
  44. this.showModalError(event.title, event.message);
  45. })
  46. }
  47. showModalError(windowText:string, message:string)
  48. {
  49. var window = new Atomic.UIMessageWindow(this.view, "modal_error");
  50. window.show(windowText, message, 640, 360);
  51. }
  52. view: Atomic.UIView;
  53. mainframe: MainFrame;
  54. modalOps: ModalOps;
  55. shortcuts: Shortcuts;
  56. }