EditorUI.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 EditorEvents = require("editor/EditorEvents");
  23. import MainFrame = require("./frames/MainFrame");
  24. import ModalOps = require("./modal/ModalOps");
  25. import Shortcuts = require("./Shortcuts");
  26. import ServiceLocator from "../hostExtensions/ServiceLocator";
  27. import Editor = require("editor/Editor");
  28. // this is designed with public get functions to solve
  29. // circular dependency issues in TS
  30. var editorUI:EditorUI;
  31. export function getMainFrame():MainFrame {
  32. return editorUI.mainframe;
  33. }
  34. export function getModelOps():ModalOps {
  35. return editorUI.modalOps;
  36. }
  37. export function getView():Atomic.UIView {
  38. return editorUI.view;
  39. }
  40. export function getShortcuts():Shortcuts {
  41. return editorUI.shortcuts;
  42. }
  43. export function initialize(editor: Editor) {
  44. editorUI = new EditorUI(editor);
  45. }
  46. export function getEditor(): Editor {
  47. return editorUI.editor;
  48. }
  49. export function shutdown() {
  50. editorUI.mainframe.shutdown();
  51. var view = editorUI.view;
  52. view.deleteAllChildren();
  53. view.parent.removeChild(view);
  54. }
  55. export function showModalError(windowText:string, message:string) {
  56. editorUI.showModalError(windowText, message);
  57. }
  58. export function getCurrentResourceEditor():Editor.ResourceEditor {
  59. return getMainFrame().resourceframe.currentResourceEditor;
  60. }
  61. class EditorUI extends Atomic.ScriptObject {
  62. constructor(editor: Editor) {
  63. super();
  64. var graphics = Atomic.getGraphics();
  65. this.view = new Atomic.UIView();
  66. this.mainframe = new MainFrame();
  67. this.view.addChild(this.mainframe);
  68. this.editor = editor;
  69. this.subscribeToEvent("ScreenMode", (ev:Atomic.ScreenModeEvent) => {
  70. this.mainframe.setSize(ev.width, ev.height);
  71. });
  72. // set initial size
  73. this.mainframe.setSize(graphics.width, graphics.height);
  74. this.modalOps = new ModalOps();
  75. this.shortcuts = new Shortcuts();
  76. // Hook the service locator into the event system and give it the ui objects it needs
  77. ServiceLocator.uiServices.init(
  78. this.mainframe,
  79. this.modalOps);
  80. ServiceLocator.subscribeToEvents(this.mainframe);
  81. this.subscribeToEvent(EditorEvents.ModalError, (event:EditorEvents.ModalErrorEvent) => {
  82. this.showModalError(event.title, event.message);
  83. });
  84. }
  85. showModalError(windowText: string, message: string) {
  86. this.modalOps.showError(windowText, message);
  87. }
  88. view: Atomic.UIView;
  89. mainframe: MainFrame;
  90. modalOps: ModalOps;
  91. shortcuts: Shortcuts;
  92. editor: Editor;
  93. }