BuildSettingsWindow.ts 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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("ui/EditorUI");
  23. import ModalWindow = require("../ModalWindow");
  24. import ProgressModal = require("../ProgressModal");
  25. import WindowsSettingsWidget = require("./platforms/WindowsSettingsWidget");
  26. import MacSettingsWidget = require("./platforms/MacSettingsWidget");
  27. import AndroidSettingsWidget = require("./platforms/AndroidSettingsWidget");
  28. import IOSSettingsWidget = require("./platforms/IOSSettingsWidget");
  29. import WebSettingsWidget = require("./platforms/WebSettingsWidget");
  30. import LinuxSettingsWidget = require("./platforms/LinuxSettingsWidget");
  31. export interface BuildSettingsWidget {
  32. storeValues();
  33. }
  34. export class BuildSettingsWindow extends ModalWindow {
  35. constructor() {
  36. super();
  37. this.init("Build Settings", "AtomicEditor/editor/ui/buildsettings.tb.txt");
  38. this.settingsContainer = <Atomic.UILayout>this.getWidget("settingscontainer");
  39. var platformcontainer = <Atomic.UILayout>this.getWidget("platformcontainer");
  40. this.platformIndicator = <Atomic.UISkinImage>this.getWidget("current_platform_indicator");
  41. var platformSelect = this.platformSelect = new Atomic.UISelectList();
  42. var platformSource = new Atomic.UISelectItemSource();
  43. platformSource.addItem(new Atomic.UISelectItem("Windows", "WindowsBuildSettings", "LogoWindows"));
  44. platformSource.addItem(new Atomic.UISelectItem("Mac", "MacBuildSettings", "LogoMac"));
  45. platformSource.addItem(new Atomic.UISelectItem("Android", "AndroidBuildSettings", "LogoAndroid"));
  46. platformSource.addItem(new Atomic.UISelectItem("iOS", "iOSBuildSettings", "LogoIOS"));
  47. platformSource.addItem(new Atomic.UISelectItem("WebGL", "WebGLBuildSettings", "LogoHTML5"));
  48. platformSource.addItem(new Atomic.UISelectItem("Linux", "LinuxBuildSettings", "LogoLinux"));
  49. platformSelect.setSource(platformSource);
  50. var lp = new Atomic.UILayoutParams();
  51. var myh = 74 * platformSource.getItemCount(); // 74 pixels per platform icon
  52. lp.minWidth = 160;
  53. lp.minHeight = myh;
  54. lp.maxHeight = myh;
  55. platformSelect.layoutParams = lp;
  56. platformSelect.gravity = Atomic.UI_GRAVITY.UI_GRAVITY_ALL;
  57. platformcontainer.addChild(platformSelect);
  58. this.addPlatformWidget("WINDOWS", new WindowsSettingsWidget(), "LogoWindows", 0);
  59. this.addPlatformWidget("MAC", new MacSettingsWidget(), "LogoMac", 1);
  60. this.addPlatformWidget("ANDROID", new AndroidSettingsWidget(), "LogoAndroid", 2);
  61. this.addPlatformWidget("IOS", new IOSSettingsWidget(), "LogoIOS", 3);
  62. this.addPlatformWidget("WEB", new WebSettingsWidget(), "LogoHTML5", 4);
  63. this.addPlatformWidget("LINUX", new LinuxSettingsWidget(), "LogoLinux", 5);
  64. var currentPlatform = ToolCore.toolSystem.currentPlatform;
  65. this.setDisplayPlatform(currentPlatform);
  66. this.platformIndicator.skinBg = this.platformInfo[currentPlatform.name].logo;
  67. this.resizeToFitContent();
  68. this.center();
  69. this.subscribeToEvent(ToolCore.PlatformChangedEvent((ev: ToolCore.PlatformChangedEvent) => {
  70. this.platformIndicator.skinBg = this.platformInfo[ev.platform.name].logo;
  71. }));
  72. this.subscribeToEvent(this, Atomic.UIWidgetEvent((ev) => this.handleWidgetEvent(ev)));
  73. }
  74. commitBuildSettings() {
  75. for (var name in this.platformInfo) {
  76. <BuildSettingsWidget>(this.platformInfo[name].widget).storeValues();
  77. }
  78. ToolCore.toolSystem.project.saveBuildSettings();
  79. }
  80. handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
  81. if (ev.type == Atomic.UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK) {
  82. var toolSystem = ToolCore.toolSystem;
  83. if (ev.target.id == "cancel") {
  84. this.hide();
  85. return true;
  86. }
  87. if (ev.target.id == "ok") {
  88. this.commitBuildSettings();
  89. this.hide();
  90. return true;
  91. }
  92. if (ev.target.id == "build") {
  93. this.commitBuildSettings();
  94. this.hide();
  95. EditorUI.getModelOps().showBuild();
  96. return true;
  97. }
  98. if (ev.target.id == "set_current_platform") {
  99. var index = this.platformSelect.value;
  100. var showMessage = function(target, title, message) {
  101. var window = new Atomic.UIMessageWindow(target, "modal_error");
  102. window.show(title, message, Atomic.UI_MESSAGEWINDOW_SETTINGS.UI_MESSAGEWINDOW_SETTINGS_OK, true, 640, 260);
  103. };
  104. for (var name in this.platformInfo) {
  105. var info: { widget: Atomic.UIWidget, index: number, logo: string } = this.platformInfo[name];
  106. if (info.index == index) {
  107. var platform = toolSystem.getPlatformByName(name);
  108. // Do we have a C# project?
  109. if (ToolCore.netProjectSystem.solutionAvailable) {
  110. if (platform.platformID == ToolCore.PlatformID.PLATFORMID_WEB) {
  111. showMessage(this, "Platform Info", "\nThe web platform is not available when using C# at this time\n\n");
  112. return true;
  113. }
  114. if (platform.platformID == ToolCore.PlatformID.PLATFORMID_IOS || platform.platformID == ToolCore.PlatformID.PLATFORMID_ANDROID) {
  115. var ide = Atomic.platform == "Windows" ? "Visual Studio" : "Xamarin Studio";
  116. var message = `Please open the following solution in ${ide}:\n\n ${ToolCore.netProjectSystem.solutionPath}\n\n`;
  117. message += "HINT: You can open the solution by clicking on any C# script in the project or from the Developer->Plugins->AtomicNET menu\n";
  118. showMessage(this, "IDE Deployment Required", message);
  119. return true;
  120. }
  121. } else {
  122. if (platform.platformID == ToolCore.PlatformID.PLATFORMID_IOS) {
  123. if (Atomic.platform == "Windows") {
  124. showMessage(this, "MacOSX Required", "\niOS Deployment requires running the Atomic Editor on MacOSX\n\n");
  125. return true;
  126. }
  127. }
  128. }
  129. toolSystem.setCurrentPlatform(platform.platformID);
  130. return true;
  131. }
  132. }
  133. return true;
  134. }
  135. if (ev.refid == "WindowsBuildSettings") {
  136. this.setDisplayPlatform(toolSystem.getPlatformByName("WINDOWS"));
  137. return true;
  138. }
  139. if (ev.refid == "MacBuildSettings") {
  140. this.setDisplayPlatform(toolSystem.getPlatformByName("MAC"));
  141. return true;
  142. }
  143. if (ev.refid == "AndroidBuildSettings") {
  144. this.setDisplayPlatform(toolSystem.getPlatformByName("ANDROID"));
  145. return true;
  146. }
  147. if (ev.refid == "iOSBuildSettings") {
  148. this.setDisplayPlatform(toolSystem.getPlatformByName("IOS"));
  149. return true;
  150. }
  151. if (ev.refid == "WebGLBuildSettings") {
  152. this.setDisplayPlatform(toolSystem.getPlatformByName("WEB"));
  153. return true;
  154. }
  155. if (ev.refid == "LinuxBuildSettings") {
  156. this.setDisplayPlatform(toolSystem.getPlatformByName("LINUX"));
  157. return true;
  158. }
  159. }
  160. return false;
  161. }
  162. addPlatformWidget(name: string, widget: Atomic.UIWidget, logo: string, index: number) {
  163. this.platformInfo[name] = { widget: widget, index: index, logo: logo };
  164. this.settingsContainer.addChild(widget);
  165. }
  166. setDisplayPlatform(platform: ToolCore.Platform) {
  167. for (var name in this.platformInfo) {
  168. this.platformInfo[name].widget.visibility = Atomic.UI_WIDGET_VISIBILITY.UI_WIDGET_VISIBILITY_GONE;
  169. }
  170. if (!platform) return;
  171. var info: { widget: Atomic.UIWidget, index: number, logo: string } = this.platformInfo[platform.name];
  172. info.widget.visibility = Atomic.UI_WIDGET_VISIBILITY.UI_WIDGET_VISIBILITY_VISIBLE;
  173. if (this.platformSelect.value != info.index)
  174. this.platformSelect.value = info.index;
  175. }
  176. platformInfo: {} = {};
  177. settingsContainer: Atomic.UILayout;
  178. platformSelect: Atomic.UISelectList;
  179. platformIndicator: Atomic.UISkinImage;
  180. }