EditorUI.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. import EditorEvents = require("editor/EditorEvents");
  8. import MainFrame = require("./frames/MainFrame");
  9. import ModalOps = require("./modal/ModalOps");
  10. import Shortcuts = require("./Shortcuts");
  11. // this is designed with public get functions to solve
  12. // circular dependency issues in TS
  13. var editorUI:EditorUI;
  14. export function getMainFrame():MainFrame {
  15. return editorUI.mainframe;
  16. }
  17. export function getModelOps():ModalOps {
  18. return editorUI.modalOps;
  19. }
  20. export function getView():Atomic.UIView {
  21. return editorUI.view;
  22. }
  23. export function getShortcuts():Shortcuts {
  24. return editorUI.shortcuts;
  25. }
  26. export function initialize() {
  27. editorUI = new EditorUI();
  28. }
  29. export function shutdown() {
  30. editorUI.mainframe.shutdown();
  31. var view = editorUI.view;
  32. view.deleteAllChildren();
  33. view.parent.removeChild(view);
  34. }
  35. export function showModalError(windowText:string, message:string) {
  36. editorUI.showModalError(windowText, message);
  37. }
  38. export function getCurrentResourceEditor():Editor.ResourceEditor {
  39. return getMainFrame().resourceframe.currentResourceEditor;
  40. }
  41. class EditorUI extends Atomic.ScriptObject {
  42. constructor() {
  43. super();
  44. var graphics = Atomic.getGraphics();
  45. this.view = new Atomic.UIView();
  46. this.mainframe = new MainFrame();
  47. this.view.addChild(this.mainframe);
  48. this.subscribeToEvent("ScreenMode", (ev:Atomic.ScreenModeEvent) => {
  49. this.mainframe.setSize(ev.width, ev.height);
  50. });
  51. // set initial size
  52. this.mainframe.setSize(graphics.width, graphics.height);
  53. this.modalOps = new ModalOps();
  54. this.shortcuts = new Shortcuts();
  55. this.subscribeToEvent(EditorEvents.ModalError, (event:EditorEvents.ModalErrorEvent) => {
  56. this.showModalError(event.title, event.message);
  57. })
  58. }
  59. showModalError(windowText:string, message:string)
  60. {
  61. var window = new Atomic.UIMessageWindow(this.view, "modal_error");
  62. window.show(windowText, message, Atomic.UI_MESSAGEWINDOW_SETTINGS_OK, true, 640, 360);
  63. }
  64. view: Atomic.UIView;
  65. mainframe: MainFrame;
  66. modalOps: ModalOps;
  67. shortcuts: Shortcuts;
  68. }