EditorUI.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. // this is designed with public get functions to solve
  27. // circular dependency issues in TS
  28. var editorUI:EditorUI;
  29. export function getMainFrame():MainFrame {
  30. return editorUI.mainframe;
  31. }
  32. export function getModelOps():ModalOps {
  33. return editorUI.modalOps;
  34. }
  35. export function getView():Atomic.UIView {
  36. return editorUI.view;
  37. }
  38. export function getShortcuts():Shortcuts {
  39. return editorUI.shortcuts;
  40. }
  41. export function initialize() {
  42. editorUI = new EditorUI();
  43. }
  44. export function shutdown() {
  45. editorUI.mainframe.shutdown();
  46. var view = editorUI.view;
  47. view.deleteAllChildren();
  48. view.parent.removeChild(view);
  49. }
  50. export function showModalError(windowText:string, message:string) {
  51. editorUI.showModalError(windowText, message);
  52. }
  53. export function getCurrentResourceEditor():Editor.ResourceEditor {
  54. return getMainFrame().resourceframe.currentResourceEditor;
  55. }
  56. class EditorUI extends Atomic.ScriptObject {
  57. constructor() {
  58. super();
  59. var graphics = Atomic.getGraphics();
  60. this.view = new Atomic.UIView();
  61. this.mainframe = new MainFrame();
  62. this.view.addChild(this.mainframe);
  63. this.subscribeToEvent("ScreenMode", (ev:Atomic.ScreenModeEvent) => {
  64. this.mainframe.setSize(ev.width, ev.height);
  65. });
  66. // set initial size
  67. this.mainframe.setSize(graphics.width, graphics.height);
  68. this.modalOps = new ModalOps();
  69. this.shortcuts = new Shortcuts();
  70. this.subscribeToEvent(EditorEvents.ModalError, (event:EditorEvents.ModalErrorEvent) => {
  71. this.showModalError(event.title, event.message);
  72. });
  73. }
  74. showModalError(windowText:string, message:string) {
  75. var window = new Atomic.UIMessageWindow(this.view, "modal_error");
  76. window.show(windowText, message, Atomic.UI_MESSAGEWINDOW_SETTINGS_OK, true, 640, 360);
  77. }
  78. view: Atomic.UIView;
  79. mainframe: MainFrame;
  80. modalOps: ModalOps;
  81. shortcuts: Shortcuts;
  82. }