BuildSettingsWindow.ts 9.8 KB

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