ModalOps.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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 EditorUI = require("../EditorUI");
  23. import ModalWindow = require("./ModalWindow");
  24. import About = require("./About");
  25. import NewProject = require("./NewProject");
  26. import CreateProject = require("./CreateProject");
  27. import EULAWindow = require("./license/EULAWindow");
  28. import BuildWindow = require("./build/BuildWindow");
  29. import BuildOutput = require("./build/BuildOutput");
  30. import BuildSettingsWindow = require("./build/BuildSettingsWindow");
  31. import ResourceSelection = require("./ResourceSelection");
  32. import UIResourceOps = require("./UIResourceOps");
  33. import SnapSettingsWindow = require("./SnapSettingsWindow");
  34. import ExtensionWindow = require("./ExtensionWindow");
  35. import ProjectTemplates = require("../../resources/ProjectTemplates");
  36. import NewBuildWindow = require("./info/NewBuildWindow");
  37. import AtomicNETWindow = require("./info/AtomicNETWindow");
  38. class ModalOps extends Atomic.ScriptObject {
  39. constructor() {
  40. super();
  41. this.dimmer = new Atomic.UIDimmer();
  42. this.subscribeToEvent("WindowClosed", (e) => {
  43. if (e.window == this.opWindow)
  44. {
  45. this.opWindow = null;
  46. if (this.dimmer.parent) {
  47. this.dimmer.parent.removeChild(this.dimmer, false);
  48. }
  49. }
  50. });
  51. }
  52. showCreateProject(projectTemplateDefinition: ProjectTemplates.ProjectTemplateDefinition) {
  53. if (this.show()) {
  54. this.opWindow = new CreateProject(projectTemplateDefinition);
  55. }
  56. }
  57. showCreateFolder(resourcePath: string) {
  58. if (this.show()) {
  59. this.opWindow = new UIResourceOps.CreateFolder(resourcePath);
  60. }
  61. }
  62. showCreateComponent(resourcePath: string) {
  63. if (this.show()) {
  64. this.opWindow = new UIResourceOps.CreateComponent(resourcePath);
  65. }
  66. }
  67. showCreateScript(resourcePath: string) {
  68. if (this.show()) {
  69. this.opWindow = new UIResourceOps.CreateScript(resourcePath);
  70. }
  71. }
  72. showCreateScene(resourcePath: string) {
  73. if (this.show()) {
  74. this.opWindow = new UIResourceOps.CreateScene(resourcePath);
  75. }
  76. }
  77. showCreateMaterial(resourcePath: string) {
  78. if (this.show()) {
  79. this.opWindow = new UIResourceOps.CreateMaterial(resourcePath);
  80. }
  81. }
  82. showResourceDelete(asset: ToolCore.Asset) {
  83. if (this.show()) {
  84. this.opWindow = new UIResourceOps.ResourceDelete(asset);
  85. }
  86. }
  87. showRenameAsset(asset: ToolCore.Asset) {
  88. if (this.show()) {
  89. this.opWindow = new UIResourceOps.RenameAsset(asset);
  90. }
  91. }
  92. showResourceSelection(windowText: string, importerType: string, resourceType: string, callback: (retObject: any, args: any) => void, args: any = undefined) {
  93. if (this.show()) {
  94. this.opWindow = new ResourceSelection(windowText, importerType, resourceType, callback, args);
  95. }
  96. }
  97. showNewProject() {
  98. if (this.show()) {
  99. this.opWindow = new NewProject();
  100. }
  101. }
  102. showEULAWindow() {
  103. if (this.show()) {
  104. this.opWindow = new EULAWindow();
  105. }
  106. }
  107. showNewBuildWindow() {
  108. if (this.show()) {
  109. this.opWindow = new NewBuildWindow();
  110. }
  111. }
  112. showAbout() {
  113. if (this.show()) {
  114. this.opWindow = new About();
  115. }
  116. }
  117. showBuild() {
  118. if (!ToolCore.toolSystem.project)
  119. return;
  120. if (this.show()) {
  121. this.opWindow = new BuildWindow();
  122. }
  123. }
  124. showBuildSettings() {
  125. if (!ToolCore.toolSystem.project)
  126. return;
  127. if (this.show()) {
  128. this.opWindow = new BuildSettingsWindow.BuildSettingsWindow();
  129. }
  130. }
  131. showBuildOutput(buildBase: ToolCore.BuildBase) {
  132. if (this.show()) {
  133. this.opWindow = new BuildOutput(buildBase);
  134. }
  135. }
  136. showSnapSettings() {
  137. // only show snap settings if we have a project loaded
  138. if (!ToolCore.toolSystem.project)
  139. return;
  140. if (this.show()) {
  141. this.opWindow = new SnapSettingsWindow();
  142. }
  143. }
  144. showAtomicNETWindow() {
  145. if (this.show()) {
  146. this.opWindow = new AtomicNETWindow();
  147. }
  148. }
  149. // TODO: standardize to same pattern as other modal windows
  150. showError(windowText: string, message: string) {
  151. var view = EditorUI.getView();
  152. var window = new Atomic.UIMessageWindow(view, "modal_error");
  153. window.show(windowText, message, Atomic.UI_MESSAGEWINDOW_SETTINGS_OK, true, 640, 360);
  154. }
  155. showExtensionWindow(windowText: string, uifilename: string, handleWidgetEventCB: (ev: Atomic.UIWidgetEvent) => void): Editor.Modal.ExtensionWindow {
  156. if (this.show()) {
  157. this.opWindow = new ExtensionWindow(windowText, uifilename, handleWidgetEventCB);
  158. return this.opWindow;
  159. }
  160. }
  161. private show(): boolean {
  162. if (this.dimmer.parent) {
  163. console.log("WARNING: attempting to show modal while dimmer is active");
  164. return false;
  165. }
  166. if (this.opWindow) {
  167. console.log("WARNING: attempting to show modal while another opWindow is active");
  168. return false;
  169. }
  170. var view = EditorUI.getView();
  171. view.addChild(this.dimmer);
  172. return true;
  173. }
  174. hide() {
  175. if (this.opWindow) {
  176. var window = this.opWindow;
  177. this.opWindow = null;
  178. if (window.parent)
  179. window.parent.removeChild(window, false);
  180. var view = EditorUI.getView();
  181. view.setFocusRecursive();
  182. }
  183. if (this.dimmer.parent) {
  184. this.dimmer.parent.removeChild(this.dimmer, false);
  185. }
  186. }
  187. dimmer: Atomic.UIDimmer;
  188. opWindow: ModalWindow;
  189. }
  190. export = ModalOps;