ModalOps.ts 6.7 KB

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