ModalOps.ts 6.5 KB

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