EditorUI.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. import MainFrame = require("./frames/MainFrame");
  23. import ModalOps = require("./modal/ModalOps");
  24. import Shortcuts = require("./Shortcuts");
  25. import ServiceLocator from "../hostExtensions/ServiceLocator";
  26. import {default as AtomicEditor} from "editor/Editor";
  27. // this is designed with public get functions to solve
  28. // circular dependency issues in TS
  29. var editorUI:EditorUI;
  30. export function getMainFrame():MainFrame {
  31. return editorUI.mainframe;
  32. }
  33. export function getModelOps():ModalOps {
  34. return editorUI.modalOps;
  35. }
  36. export function getView():Atomic.UIView {
  37. return editorUI.view;
  38. }
  39. export function getShortcuts():Shortcuts {
  40. return editorUI.shortcuts;
  41. }
  42. export function initialize(editor: AtomicEditor) {
  43. editorUI = new EditorUI(editor);
  44. }
  45. export function getEditor(): AtomicEditor {
  46. return editorUI.editor;
  47. }
  48. export function shutdown() {
  49. editorUI.mainframe.shutdown();
  50. var view = editorUI.view;
  51. view.deleteAllChildren();
  52. view.parent.removeChild(view);
  53. }
  54. export function showModalError(windowText:string, message:string) {
  55. editorUI.showModalError(windowText, message);
  56. }
  57. export function getCurrentResourceEditor():Editor.ResourceEditor {
  58. return getMainFrame().resourceframe.currentResourceEditor;
  59. }
  60. class EditorUI extends Atomic.ScriptObject {
  61. constructor(editor: AtomicEditor) {
  62. super();
  63. var graphics = Atomic.getGraphics();
  64. this.view = new Atomic.UIView();
  65. this.mainframe = new MainFrame();
  66. this.view.addChild(this.mainframe);
  67. this.editor = editor;
  68. this.subscribeToEvent(Atomic.ScreenModeEvent((ev:Atomic.ScreenModeEvent) => {
  69. this.mainframe.setSize(ev.width, ev.height);
  70. }));
  71. // set initial size
  72. this.mainframe.setSize(graphics.width, graphics.height);
  73. this.modalOps = new ModalOps();
  74. this.shortcuts = new Shortcuts();
  75. // Hook the service locator into the event system and give it the ui objects it needs
  76. ServiceLocator.uiServices.init(
  77. this.mainframe,
  78. this.modalOps);
  79. ServiceLocator.subscribeToEvents(this.mainframe);
  80. this.subscribeToEvent(Editor.EditorModalEvent((event:Editor.EditorModalEvent) => {
  81. this.showModalError(event.title, event.message);
  82. }));
  83. }
  84. showModalError(windowText: string, message: string) {
  85. this.modalOps.showError(windowText, message);
  86. }
  87. view: Atomic.UIView;
  88. mainframe: MainFrame;
  89. modalOps: ModalOps;
  90. shortcuts: Shortcuts;
  91. editor: AtomicEditor;
  92. }