EditorUI.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 showEditorStatus(message:string) {
  58. editorUI.showEditorStatus(message);
  59. }
  60. export function getCurrentResourceEditor():Editor.ResourceEditor {
  61. return getMainFrame().resourceframe.currentResourceEditor;
  62. }
  63. class EditorUI extends Atomic.ScriptObject {
  64. constructor(editor: AtomicEditor) {
  65. super();
  66. var graphics = Atomic.getGraphics();
  67. this.view = new Atomic.UIView();
  68. this.mainframe = new MainFrame();
  69. this.view.addChild(this.mainframe);
  70. this.editor = editor;
  71. this.subscribeToEvent(Atomic.ScreenModeEvent((ev:Atomic.ScreenModeEvent) => {
  72. this.mainframe.setSize(ev.width, ev.height);
  73. }));
  74. // set initial size
  75. this.mainframe.setSize(graphics.width, graphics.height);
  76. this.modalOps = new ModalOps();
  77. this.shortcuts = new Shortcuts();
  78. // Hook the service locator into the event system and give it the ui objects it needs
  79. ServiceLocator.uiServices.init(
  80. this.mainframe,
  81. this.modalOps);
  82. ServiceLocator.subscribeToEvents(this.mainframe);
  83. this.subscribeToEvent(Editor.EditorModalEvent((event:Editor.EditorModalEvent) => {
  84. if (event.type == Editor.EDITOR_MODALERROR)
  85. this.showModalError(event.title, event.message);
  86. else if ( event.type == Editor.EDITOR_MODALINFO)
  87. this.showEditorStatus(event.message);
  88. }));
  89. this.showEditorStatus("Ready.");
  90. }
  91. showModalError(windowText: string, message: string) {
  92. this.modalOps.showError(windowText, message);
  93. }
  94. showEditorStatus(message: string) {
  95. this.mainframe.showStatusText(message);
  96. }
  97. view: Atomic.UIView;
  98. mainframe: MainFrame;
  99. modalOps: ModalOps;
  100. shortcuts: Shortcuts;
  101. editor: AtomicEditor;
  102. }