UIBuildSettings.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "AtomicEditor.h"
  5. #include <TurboBadger/tb_window.h>
  6. #include <TurboBadger/tb_select.h>
  7. #include <TurboBadger/tb_editfield.h>
  8. #include <Atomic/Core/Context.h>
  9. #include <Atomic/UI/UI.h>
  10. #include "AEEvents.h"
  11. #include "AEEditor.h"
  12. #include "Resources/AEResourceOps.h"
  13. #include "UIBuildSettings.h"
  14. // BEGIN LICENSE MANAGEMENT
  15. #include "License/AELicenseSystem.h"
  16. // END LICENSE MANAGEMENT
  17. namespace AtomicEditor
  18. {
  19. // UIBuildSettings------------------------------------------------
  20. UIBuildSettings::UIBuildSettings(Context* context):
  21. UIModalOpWindow(context),
  22. windowsSettings_(new UIBuildSettingsWindows(context)),
  23. androidSettings_(new UIBuildSettingsAndroid(context)),
  24. webSettings_(new UIBuildSettingsWeb(context)),
  25. iosSettings_(new UIBuildSettingsIOS(context)),
  26. macSettings_(new UIBuildSettingsMac(context)),
  27. platformIndicator_(0)
  28. {
  29. UI* tbui = GetSubsystem<UI>();
  30. window_->SetText("Atomic Player - Build Settings");
  31. tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/buildsettings.tb.txt");
  32. TBLayout* platformcontainer = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("platformcontainer"));
  33. assert(platformcontainer);
  34. platformSelect_ = new TBSelectList();
  35. platformSelect_->SetSource(&platformSource_);
  36. LayoutParams lp;
  37. lp.min_h = 370;
  38. lp.max_h = 370;
  39. lp.min_w = 160;
  40. platformSelect_->SetLayoutParams(lp);
  41. platformSelect_->SetGravity(WIDGET_GRAVITY_ALL);
  42. TBGenericStringItem* item = new TBGenericStringItem("Windows");
  43. item->SetSkinImage(TBIDC("LogoWindows"));
  44. item->id = TBIDC("WindowsBuildSettings");
  45. platformSource_.AddItem(item);
  46. item = new TBGenericStringItem("Mac");
  47. item->SetSkinImage(TBIDC("LogoMac"));
  48. item->id = TBIDC("MacBuildSettings");
  49. platformSource_.AddItem(item);
  50. item = new TBGenericStringItem("WebGL");
  51. item->SetSkinImage(TBIDC("LogoHTML5"));
  52. item->id = TBIDC("WebGLBuildSettings");
  53. platformSource_.AddItem(item);
  54. item = new TBGenericStringItem("Android");
  55. item->SetSkinImage(TBIDC("LogoAndroid"));
  56. item->id = TBIDC("AndroidBuildSettings");
  57. platformSource_.AddItem(item);
  58. item = new TBGenericStringItem("iOS");
  59. item->SetSkinImage(TBIDC("LogoIOS"));
  60. item->id = TBIDC("iOSBuildSettings");
  61. platformSource_.AddItem(item);
  62. platformSelect_->SetValue(-1);
  63. platformSelect_->SetValue(0);
  64. platformcontainer->AddChild(platformSelect_);
  65. platformIndicator_ = delegate_->GetWidgetByIDAndType<TBSkinImage>(TBIDC("current_platform_indicator"));
  66. assert(platformIndicator_);
  67. RefreshSettings();
  68. Editor* editor = GetSubsystem<Editor>();
  69. AEEditorPlatform platform = editor->GetCurrentPlatform();
  70. UpdateCurrentPlatform(platform);
  71. // windows settings
  72. if (platform == AE_PLATFORM_WINDOWS)
  73. SelectWindowsSettings();
  74. else if (platform == AE_PLATFORM_MAC)
  75. SelectMacSettings();
  76. else if (platform == AE_PLATFORM_ANDROID)
  77. SelectAndroidSettings();
  78. else if (platform == AE_PLATFORM_HTML5)
  79. SelectWebSettings();
  80. else if (platform == AE_PLATFORM_IOS)
  81. SelectIOSSettings();
  82. window_->ResizeToFitContent();
  83. Center();
  84. SubscribeToEvent(E_PLATFORMCHANGE, HANDLER(UIBuildSettings, HandlePlatformChange));
  85. }
  86. void UIBuildSettings::RemoveSettingsWidgets()
  87. {
  88. TBLayout* settingscontainer = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("settingscontainer"));
  89. assert(settingscontainer);
  90. if (windowsSettings_->GetWidgetDelegate()->GetParent() == settingscontainer)
  91. settingscontainer->RemoveChild(windowsSettings_->GetWidgetDelegate());
  92. if (androidSettings_->GetWidgetDelegate()->GetParent() == settingscontainer)
  93. settingscontainer->RemoveChild(androidSettings_->GetWidgetDelegate());
  94. if (webSettings_->GetWidgetDelegate()->GetParent() == settingscontainer)
  95. settingscontainer->RemoveChild(webSettings_->GetWidgetDelegate());
  96. if (iosSettings_->GetWidgetDelegate()->GetParent() == settingscontainer)
  97. settingscontainer->RemoveChild(iosSettings_->GetWidgetDelegate());
  98. if (macSettings_->GetWidgetDelegate()->GetParent() == settingscontainer)
  99. settingscontainer->RemoveChild(macSettings_->GetWidgetDelegate());
  100. }
  101. void UIBuildSettings::SelectWindowsSettings()
  102. {
  103. RemoveSettingsWidgets();
  104. TBLayout* settingscontainer = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("settingscontainer"));
  105. assert(settingscontainer);
  106. settingscontainer->AddChild(windowsSettings_->GetWidgetDelegate());
  107. windowsSettings_->Refresh();
  108. platformSelect_->SetValue(0);
  109. }
  110. void UIBuildSettings::SelectWebSettings()
  111. {
  112. RemoveSettingsWidgets();
  113. TBLayout* settingscontainer = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("settingscontainer"));
  114. assert(settingscontainer);
  115. settingscontainer->AddChild(webSettings_->GetWidgetDelegate());
  116. webSettings_->Refresh();
  117. platformSelect_->SetValue(2);
  118. }
  119. void UIBuildSettings::SelectAndroidSettings()
  120. {
  121. RemoveSettingsWidgets();
  122. TBLayout* settingscontainer = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("settingscontainer"));
  123. assert(settingscontainer);
  124. settingscontainer->AddChild(androidSettings_->GetWidgetDelegate());
  125. androidSettings_->Refresh();
  126. platformSelect_->SetValue(3);
  127. }
  128. void UIBuildSettings::SelectIOSSettings()
  129. {
  130. RemoveSettingsWidgets();
  131. TBLayout* settingscontainer = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("settingscontainer"));
  132. assert(settingscontainer);
  133. settingscontainer->AddChild(iosSettings_->GetWidgetDelegate());
  134. iosSettings_->Refresh();
  135. platformSelect_->SetValue(4);
  136. }
  137. void UIBuildSettings::SelectMacSettings()
  138. {
  139. RemoveSettingsWidgets();
  140. RemoveSettingsWidgets();
  141. TBLayout* settingscontainer = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("settingscontainer"));
  142. assert(settingscontainer);
  143. settingscontainer->AddChild(macSettings_->GetWidgetDelegate());
  144. macSettings_->Refresh();
  145. platformSelect_->SetValue(1);
  146. }
  147. UIBuildSettings::~UIBuildSettings()
  148. {
  149. platformSelect_->SetSource(NULL);
  150. platformSource_.DeleteAllItems();
  151. }
  152. void UIBuildSettings::RequestPlatformChange(TBID id)
  153. {
  154. Editor* editor = GetSubsystem<Editor>();
  155. AEEditorPlatform platform = AE_PLATFORM_UNDEFINED;
  156. if (id == TBIDC("WindowsBuildSettings"))
  157. {
  158. platform = AE_PLATFORM_WINDOWS;
  159. }
  160. else if (id == TBIDC("MacBuildSettings"))
  161. {
  162. platform = AE_PLATFORM_MAC;
  163. }
  164. else if (id == TBIDC("WebGLBuildSettings"))
  165. {
  166. platform = AE_PLATFORM_HTML5;
  167. }
  168. else if (id == TBIDC("AndroidBuildSettings"))
  169. {
  170. platform = AE_PLATFORM_ANDROID;
  171. }
  172. else if (id == TBIDC("iOSBuildSettings"))
  173. {
  174. platform = AE_PLATFORM_IOS;
  175. }
  176. if (platform == AE_PLATFORM_UNDEFINED)
  177. {
  178. #ifdef ATOMIC_PLATFORM_OSX
  179. platform = AE_PLATFORM_MAC;
  180. #else
  181. platform = AE_PLATFORM_WINDOWS;
  182. #endif
  183. }
  184. editor->RequestPlatformChange(platform);
  185. }
  186. void UIBuildSettings::RefreshSettings()
  187. {
  188. androidSettings_->Refresh();
  189. iosSettings_->Refresh();
  190. macSettings_->Refresh();
  191. windowsSettings_->Refresh();
  192. webSettings_->Refresh();
  193. }
  194. void UIBuildSettings::StoreSettings()
  195. {
  196. androidSettings_->StoreSettings();
  197. iosSettings_->StoreSettings();
  198. macSettings_->StoreSettings();
  199. windowsSettings_->StoreSettings();
  200. webSettings_->StoreSettings();
  201. Editor* editor = GetSubsystem<Editor>();
  202. editor->SaveProject();
  203. }
  204. bool UIBuildSettings::OnEvent(const TBWidgetEvent &ev)
  205. {
  206. UIModalOps* ops = GetSubsystem<UIModalOps>();
  207. if (ev.type == EVENT_TYPE_CLICK)
  208. {
  209. if (ev.ref_id == TBIDC("WindowsBuildSettings"))
  210. {
  211. SelectWindowsSettings();
  212. return true;
  213. }
  214. else if (ev.ref_id == TBIDC("AndroidBuildSettings"))
  215. {
  216. SelectAndroidSettings();
  217. return true;
  218. }
  219. else if (ev.ref_id == TBIDC("WebGLBuildSettings"))
  220. {
  221. SelectWebSettings();
  222. return true;
  223. }
  224. else if (ev.ref_id == TBIDC("iOSBuildSettings"))
  225. {
  226. SelectIOSSettings();
  227. return true;
  228. }
  229. else if (ev.ref_id == TBIDC("MacBuildSettings"))
  230. {
  231. SelectMacSettings();
  232. return true;
  233. }
  234. else if (ev.target->GetID() == TBIDC("set_current_platform"))
  235. {
  236. // BEGIN LICENSE MANAGEMENT
  237. TBID id = platformSelect_->GetSelectedItemID();
  238. LicenseSystem* licenseSystem = GetSubsystem<LicenseSystem>();
  239. if (licenseSystem->IsStandardLicense())
  240. {
  241. if (id == TBIDC("WebGLBuildSettings") || id == TBIDC("AndroidBuildSettings") || id == TBIDC("iOSBuildSettings"))
  242. {
  243. SharedPtr<UIBuildSettings> keepAlive(this);
  244. UIModalOps* ops = GetSubsystem<UIModalOps>();
  245. ops->Hide();
  246. ops->ShowPlatformsInfo();
  247. return true;
  248. }
  249. }
  250. #ifdef ATOMIC_PLATFORM_WINDOWS
  251. if (id == TBIDC("iOSBuildSettings"))
  252. {
  253. Editor* editor = GetSubsystem<Editor>();
  254. editor->PostModalInfo("MacOSX Required", "iOS platform requires MacOSX Editor");
  255. return true;
  256. }
  257. #endif
  258. RequestPlatformChange(id);
  259. return true;
  260. // END LICENSE MANAGEMENT
  261. }
  262. else if (ev.target->GetID() == TBIDC("ok"))
  263. {
  264. StoreSettings();
  265. ops->Hide();
  266. return true;
  267. }
  268. else if (ev.target->GetID() == TBIDC("build"))
  269. {
  270. StoreSettings();
  271. SharedPtr<UIBuildSettings> keepAlive(this);
  272. ops->Hide();
  273. ops->ShowBuild();
  274. return true;
  275. }
  276. else if (ev.target->GetID() == TBIDC("cancel"))
  277. {
  278. ops->Hide();
  279. return true;
  280. }
  281. }
  282. return false;
  283. }
  284. void UIBuildSettings::UpdateCurrentPlatform(AEEditorPlatform platform)
  285. {
  286. if (platform == AE_PLATFORM_MAC)
  287. platformIndicator_->SetSkinBg(TBIDC("LogoMac"));
  288. else if (platform == AE_PLATFORM_WINDOWS)
  289. platformIndicator_->SetSkinBg(TBIDC("LogoWindows"));
  290. else if (platform == AE_PLATFORM_ANDROID)
  291. platformIndicator_->SetSkinBg(TBIDC("LogoAndroid"));
  292. else if (platform == AE_PLATFORM_HTML5)
  293. platformIndicator_->SetSkinBg(TBIDC("LogoHTML5"));
  294. else if (platform == AE_PLATFORM_IOS)
  295. platformIndicator_->SetSkinBg(TBIDC("LogoIOS"));
  296. }
  297. void UIBuildSettings::HandlePlatformChange(StringHash eventType, VariantMap& eventData)
  298. {
  299. using namespace PlatformChange;
  300. AEEditorPlatform platform = (AEEditorPlatform) eventData[P_PLATFORM].GetUInt();
  301. UpdateCurrentPlatform(platform);
  302. }
  303. }