BuildSettingsWindow.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. 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. platformSelect.setSource(platformSource);
  49. var lp = new Atomic.UILayoutParams();
  50. lp.minWidth = 160;
  51. lp.minHeight = 370;
  52. lp.maxHeight = 370;
  53. platformSelect.layoutParams = lp;
  54. platformSelect.gravity = Atomic.UI_GRAVITY_ALL;
  55. platformcontainer.addChild(platformSelect);
  56. this.addPlatformWidget("WINDOWS", new WindowsSettingsWidget(), "LogoWindows", 0);
  57. this.addPlatformWidget("MAC", new MacSettingsWidget(), "LogoMac", 1);
  58. this.addPlatformWidget("ANDROID", new AndroidSettingsWidget(), "LogoAndroid", 2);
  59. this.addPlatformWidget("IOS", new IOSSettingsWidget(), "LogoIOS", 3);
  60. this.addPlatformWidget("WEB", new WebSettingsWidget(), "LogoHTML5", 4);
  61. var currentPlatform = ToolCore.toolSystem.currentPlatform;
  62. this.setDisplayPlatform(currentPlatform);
  63. this.platformIndicator.skinBg = this.platformInfo[currentPlatform.name].logo;
  64. this.resizeToFitContent();
  65. this.center();
  66. this.subscribeToEvent("PlatformChanged", (ev: ToolCore.PlatformChangedEvent) => {
  67. this.platformIndicator.skinBg = this.platformInfo[ev.platform.name].logo;
  68. });
  69. this.subscribeToEvent(this, "WidgetEvent", (ev) => this.handleWidgetEvent(ev));
  70. }
  71. commitBuildSettings() {
  72. for (var name in this.platformInfo) {
  73. <BuildSettingsWidget>(this.platformInfo[name].widget).storeValues();
  74. }
  75. ToolCore.toolSystem.project.saveBuildSettings();
  76. }
  77. handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
  78. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  79. var toolSystem = ToolCore.toolSystem;
  80. if (ev.target.id == "cancel") {
  81. this.hide();
  82. return true;
  83. }
  84. if (ev.target.id == "ok") {
  85. this.commitBuildSettings();
  86. this.hide();
  87. return true;
  88. }
  89. if (ev.target.id == "build") {
  90. this.commitBuildSettings();
  91. this.hide();
  92. EditorUI.getModelOps().showBuild();
  93. return true;
  94. }
  95. if (ev.target.id == "set_current_platform") {
  96. var index = this.platformSelect.value;
  97. for (var name in this.platformInfo) {
  98. var info: { widget: Atomic.UIWidget, index: number, logo: string } = this.platformInfo[name];
  99. if (info.index == index) {
  100. var platform = toolSystem.getPlatformByName(name);
  101. if (platform.platformID == ToolCore.PLATFORMID_IOS) {
  102. if (Atomic.platform == "Windows") {
  103. var message = "\niOS Deployment requires running the Atomic Editor on MacOSX\n\n";
  104. new Atomic.UIMessageWindow(this, "modal_error").show("MacOSX Required", message, Atomic.UI_MESSAGEWINDOW_SETTINGS_OK, true, 640, 260);
  105. return true;
  106. }
  107. }
  108. toolSystem.setCurrentPlatform(platform.platformID);
  109. return true;
  110. }
  111. }
  112. return true;
  113. }
  114. if (ev.refid == "WindowsBuildSettings") {
  115. this.setDisplayPlatform(toolSystem.getPlatformByName("WINDOWS"));
  116. return true;
  117. }
  118. if (ev.refid == "MacBuildSettings") {
  119. this.setDisplayPlatform(toolSystem.getPlatformByName("MAC"));
  120. return true;
  121. }
  122. if (ev.refid == "AndroidBuildSettings") {
  123. this.setDisplayPlatform(toolSystem.getPlatformByName("ANDROID"));
  124. return true;
  125. }
  126. if (ev.refid == "iOSBuildSettings") {
  127. this.setDisplayPlatform(toolSystem.getPlatformByName("IOS"));
  128. return true;
  129. }
  130. if (ev.refid == "WebGLBuildSettings") {
  131. this.setDisplayPlatform(toolSystem.getPlatformByName("WEB"));
  132. return true;
  133. }
  134. }
  135. return false;
  136. }
  137. addPlatformWidget(name: string, widget: Atomic.UIWidget, logo: string, index: number) {
  138. this.platformInfo[name] = { widget: widget, index: index, logo: logo };
  139. this.settingsContainer.addChild(widget);
  140. }
  141. setDisplayPlatform(platform: ToolCore.Platform) {
  142. for (var name in this.platformInfo) {
  143. this.platformInfo[name].widget.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  144. }
  145. if (!platform) return;
  146. var info: { widget: Atomic.UIWidget, index: number, logo: string } = this.platformInfo[platform.name];
  147. info.widget.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  148. if (this.platformSelect.value != info.index)
  149. this.platformSelect.value = info.index;
  150. }
  151. platformInfo: {} = {};
  152. settingsContainer: Atomic.UILayout;
  153. platformSelect: Atomic.UISelectList;
  154. platformIndicator: Atomic.UISkinImage;
  155. }