EditorUI.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import EditorEvents = require("editor/EditorEvents");
  2. import MainFrame = require("./frames/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. this.subscribeToEvent("ScreenMode", (ev:Atomic.ScreenModeEvent) => {
  40. this.mainframe.setSize(ev.width, ev.height);
  41. });
  42. // set initial size
  43. this.mainframe.setSize(graphics.width, graphics.height);
  44. this.modalOps = new ModalOps();
  45. this.shortcuts = new Shortcuts();
  46. this.subscribeToEvent(EditorEvents.ModalError, (event:EditorEvents.ModalErrorEvent) => {
  47. this.showModalError(event.title, event.message);
  48. })
  49. }
  50. showModalError(windowText:string, message:string)
  51. {
  52. var window = new Atomic.UIMessageWindow(this.view, "modal_error");
  53. window.show(windowText, message, Atomic.UI_MESSAGEWINDOW_SETTINGS_OK, true, 640, 360);
  54. }
  55. view: Atomic.UIView;
  56. mainframe: MainFrame;
  57. modalOps: ModalOps;
  58. shortcuts: Shortcuts;
  59. }