mainframe.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. var graphics = Atomic.getGraphics();
  2. var UI = Atomic.UI;
  3. var UIWidget = Atomic.UIWidget;
  4. var UIMenuWindow = Atomic.UIMenuWindow;
  5. var editorStrings = require("./editorStrings");
  6. var utils = require("./utils");
  7. var ui = require("./ui");
  8. // Create the main frame
  9. var mainframe = exports.mainframe = new UIWidget();
  10. ui.view.addChild(mainframe);
  11. // Set it to be the size of the entire window
  12. mainframe.setSize(graphics.width, graphics.height);
  13. // load the UI
  14. mainframe.load("AtomicEditor/editor/ui/mainframe.tb.txt");
  15. // Subscribe to graphics subsystems screen mode switching, so we can adjust the widget size
  16. mainframe.subscribeToEvent(graphics, "ScreenMode", function(data) {
  17. mainframe.setSize(data.width, data.height);
  18. });
  19. mainframe.handleMenuAtomicEditor = function(data) {
  20. var target = data.target;
  21. if (target && target.id == "menu atomic editor popup") {
  22. if (data.refid == "quit") {
  23. // todo, send a request for file saves, etc
  24. Atomic.getEngine().exit();
  25. return true;
  26. }
  27. }
  28. if (target && target.id == "menu edit popup") {
  29. if (data.refid == "edit play") {
  30. new ToolCore.PlayCmd().run();
  31. return true;
  32. }
  33. }
  34. }
  35. mainframe.handleMenuBarEvent = function(data) {
  36. if (data.type == UI.EVENT_TYPE_CLICK) {
  37. if (mainframe.handleMenuAtomicEditor(data)) return true;
  38. var target = data.target;
  39. var src = srcLookup[target.id];
  40. if (src) {
  41. var menu = new UIMenuWindow(target, target.id + " popup");
  42. menu.show(src);
  43. return true;
  44. }
  45. }
  46. return false;
  47. }
  48. mainframe.subscribeToEvent(mainframe, "WidgetEvent", function(data) {
  49. if (mainframe.handleMenuBarEvent(data)) return true;
  50. return false;
  51. });
  52. var srcLookup = {};
  53. var editorItems = {
  54. "About Atomic Editor": "about atomic editor",
  55. "-1" : null,
  56. "Manage License" : "manage license",
  57. "-2" : null,
  58. "Check for Updates" : "check update",
  59. "-3" : null,
  60. "Quit" : "quit"
  61. };
  62. var editItems = {
  63. "Undo" : ["edit undo", editorStrings.ShortcutUndo],
  64. "Redo" : ["edit redo", editorStrings.ShortcutRedo],
  65. "-1" : null,
  66. "Cut" : ["edit cut", editorStrings.ShortcutCut],
  67. "Copy" : ["edit copy", editorStrings.ShortcutCopy],
  68. "Paste" : ["edit paste", editorStrings.ShortcutPaste],
  69. "Select All" : ["edit select all", editorStrings.ShortcutSelectAll],
  70. "-2" : null,
  71. "Find" : ["edit find", editorStrings.ShortcutFind],
  72. "Find Next" : ["edit find next", editorStrings.ShortcutFindNext],
  73. "Find Prev" : ["edit find prev", editorStrings.ShortcutFindPrev],
  74. "-3" : null,
  75. "Format Code" : ["edit format code", editorStrings.ShortcutBeautify],
  76. "-4" : null,
  77. "Play" : ["edit play", editorStrings.ShortcutPlay]
  78. };
  79. var fileItems = {
  80. "New Project" : "new project",
  81. "Open Project" : "open project",
  82. "Save Project" : "save project",
  83. "-1" : null,
  84. "Close Project" : "close project",
  85. "-2" : null,
  86. "Save File" : ["save file", editorStrings.ShortcutSaveFile],
  87. "Close File" : ["close file", editorStrings.ShortcutCloseFile],
  88. };
  89. var buildItems = {
  90. "Build" : ["build project", editorStrings.ShortcutBuild],
  91. "-1" : null,
  92. "Build Settings" : ["build project settings", editorStrings.ShortcutBuildSettings],
  93. };
  94. var toolsItems = {
  95. "Tiled Map Editor" : "tools tiles"
  96. };
  97. var helpItems = {
  98. "API Documentation" : "help api",
  99. "-1" : null,
  100. "Forums" : "help forums",
  101. "-2" : null,
  102. "Atomic Game Engine on GitHub" : "help github"
  103. };
  104. var developerItems = {
  105. "Set 1920x1080 Resolution" : "developer resolution"
  106. };
  107. srcLookup["menu atomic editor"] = utils.createMenuItemSource(editorItems);
  108. srcLookup["menu file"] = utils.createMenuItemSource(fileItems);
  109. srcLookup["menu edit"] = utils.createMenuItemSource(editItems);
  110. srcLookup["menu build"] = utils.createMenuItemSource(buildItems);
  111. srcLookup["menu tools"] = utils.createMenuItemSource(toolsItems);
  112. srcLookup["menu help"] = utils.createMenuItemSource(helpItems);
  113. srcLookup["menu developer"] = utils.createMenuItemSource(developerItems);