BuildSettingsWindow.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. import EditorEvents = require("editor/EditorEvents");
  8. import EditorUI = require("ui/EditorUI");
  9. import ModalWindow = require("../ModalWindow");
  10. import ProgressModal = require("../ProgressModal");
  11. import WindowsSettingsWidget = require("./platforms/WindowsSettingsWidget");
  12. import MacSettingsWidget = require("./platforms/MacSettingsWidget");
  13. import AndroidSettingsWidget = require("./platforms/AndroidSettingsWidget");
  14. import IOSSettingsWidget = require("./platforms/IOSSettingsWidget");
  15. import WebSettingsWidget = require("./platforms/WebSettingsWidget");
  16. export interface BuildSettingsWidget {
  17. storeValues();
  18. }
  19. export class BuildSettingsWindow extends ModalWindow {
  20. constructor() {
  21. super();
  22. this.init("Build Settings", "AtomicEditor/editor/ui/buildsettings.tb.txt");
  23. this.settingsContainer = <Atomic.UILayout>this.getWidget("settingscontainer");
  24. var platformcontainer = <Atomic.UILayout>this.getWidget("platformcontainer");
  25. this.platformIndicator = <Atomic.UISkinImage>this.getWidget("current_platform_indicator");
  26. var platformSelect = this.platformSelect = new Atomic.UISelectList();
  27. var platformSource = new Atomic.UISelectItemSource();
  28. platformSource.addItem(new Atomic.UISelectItem("Windows", "WindowsBuildSettings", "LogoWindows"));
  29. platformSource.addItem(new Atomic.UISelectItem("Mac", "MacBuildSettings", "LogoMac"));
  30. platformSource.addItem(new Atomic.UISelectItem("Android", "AndroidBuildSettings", "LogoAndroid"));
  31. platformSource.addItem(new Atomic.UISelectItem("iOS", "iOSBuildSettings", "LogoIOS"));
  32. platformSource.addItem(new Atomic.UISelectItem("WebGL", "WebGLBuildSettings", "LogoHTML5"));
  33. platformSelect.setSource(platformSource);
  34. var lp = new Atomic.UILayoutParams();
  35. lp.minWidth = 160;
  36. lp.minHeight = 370;
  37. lp.maxHeight = 370;
  38. platformSelect.layoutParams = lp;
  39. platformSelect.gravity = Atomic.UI_GRAVITY_ALL;
  40. platformcontainer.addChild(platformSelect);
  41. this.addPlatformWidget("WINDOWS", new WindowsSettingsWidget(), "LogoWindows", 0);
  42. this.addPlatformWidget("MAC", new MacSettingsWidget(), "LogoMac", 1);
  43. this.addPlatformWidget("ANDROID", new AndroidSettingsWidget(), "LogoAndroid", 2);
  44. this.addPlatformWidget("IOS", new IOSSettingsWidget(), "LogoIOS", 3);
  45. this.addPlatformWidget("WEB", new WebSettingsWidget(), "LogoHTML5", 4);
  46. var currentPlatform = ToolCore.toolSystem.currentPlatform;
  47. this.setDisplayPlatform(currentPlatform);
  48. this.platformIndicator.skinBg = this.platformInfo[currentPlatform.name].logo;
  49. this.resizeToFitContent();
  50. this.center();
  51. this.subscribeToEvent("PlatformChanged", (ev: ToolCore.PlatformChangedEvent) => {
  52. this.platformIndicator.skinBg = this.platformInfo[ev.platform.name].logo;
  53. });
  54. this.subscribeToEvent(this, "WidgetEvent", (ev) => this.handleWidgetEvent(ev));
  55. }
  56. commitBuildSettings() {
  57. for (var name in this.platformInfo) {
  58. <BuildSettingsWidget>(this.platformInfo[name].widget).storeValues();
  59. }
  60. ToolCore.toolSystem.project.saveBuildSettings();
  61. }
  62. handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
  63. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  64. var toolSystem = ToolCore.toolSystem;
  65. if (ev.target.id == "cancel") {
  66. this.hide();
  67. return true;
  68. }
  69. if (ev.target.id == "ok") {
  70. this.commitBuildSettings();
  71. this.hide();
  72. return true;
  73. }
  74. if (ev.target.id == "build") {
  75. this.commitBuildSettings();
  76. this.hide();
  77. EditorUI.getModelOps().showBuild();
  78. return true;
  79. }
  80. if (ev.target.id == "set_current_platform") {
  81. var index = this.platformSelect.value;
  82. for (var name in this.platformInfo) {
  83. var info: { widget: Atomic.UIWidget, index: number, logo: string } = this.platformInfo[name];
  84. if (info.index == index) {
  85. var platform = toolSystem.getPlatformByName(name);
  86. if (platform.platformID == ToolCore.PLATFORMID_IOS) {
  87. if (Atomic.platform == "Windows") {
  88. var message = "\niOS Deployment requires running the Atomic Editor on MacOSX\n\n";
  89. new Atomic.UIMessageWindow(this, "modal_error").show("MacOSX Required", message, Atomic.UI_MESSAGEWINDOW_SETTINGS_OK, true, 640, 260);
  90. return true;
  91. }
  92. }
  93. if (!platform.license) {
  94. this.hide();
  95. EditorUI.getModelOps().showProPlatformWindow();
  96. return true;
  97. }
  98. toolSystem.setCurrentPlatform(platform.platformID);
  99. return true;
  100. }
  101. }
  102. return true;
  103. }
  104. if (ev.refid == "WindowsBuildSettings") {
  105. this.setDisplayPlatform(toolSystem.getPlatformByName("WINDOWS"));
  106. return true;
  107. }
  108. if (ev.refid == "MacBuildSettings") {
  109. this.setDisplayPlatform(toolSystem.getPlatformByName("MAC"));
  110. return true;
  111. }
  112. if (ev.refid == "AndroidBuildSettings") {
  113. this.setDisplayPlatform(toolSystem.getPlatformByName("ANDROID"));
  114. return true;
  115. }
  116. if (ev.refid == "iOSBuildSettings") {
  117. this.setDisplayPlatform(toolSystem.getPlatformByName("IOS"));
  118. return true;
  119. }
  120. if (ev.refid == "WebGLBuildSettings") {
  121. this.setDisplayPlatform(toolSystem.getPlatformByName("WEB"));
  122. return true;
  123. }
  124. }
  125. return false;
  126. }
  127. addPlatformWidget(name: string, widget: Atomic.UIWidget, logo: string, index: number) {
  128. this.platformInfo[name] = { widget: widget, index: index, logo: logo };
  129. this.settingsContainer.addChild(widget);
  130. }
  131. setDisplayPlatform(platform: ToolCore.Platform) {
  132. for (var name in this.platformInfo) {
  133. this.platformInfo[name].widget.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  134. }
  135. if (!platform) return;
  136. var info: { widget: Atomic.UIWidget, index: number, logo: string } = this.platformInfo[platform.name];
  137. info.widget.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  138. if (this.platformSelect.value != info.index)
  139. this.platformSelect.value = info.index;
  140. }
  141. platformInfo: {} = {};
  142. settingsContainer: Atomic.UILayout;
  143. platformSelect: Atomic.UISelectList;
  144. platformIndicator: Atomic.UISkinImage;
  145. }