ModalOps.ts 7.2 KB

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