UIBuild.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 "Resources/AEResourceOps.h"
  11. #include "AEPreferences.h"
  12. #include "AEEditor.h"
  13. #include "AEEvents.h"
  14. #include "Project/AEProject.h"
  15. #include "Project/ProjectUtils.h"
  16. #include "UIBuild.h"
  17. namespace AtomicEditor
  18. {
  19. // UIBuildSettings------------------------------------------------
  20. UIBuild::UIBuild(Context* context):
  21. UIModalOpWindow(context)
  22. , buildPathField_(0)
  23. {
  24. Editor* editor = GetSubsystem<Editor>();
  25. Project* project = editor->GetProject();
  26. UI* tbui = GetSubsystem<UI>();
  27. window_->SetText("Build Player");
  28. tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/build.tb.txt");
  29. buildPathField_ = delegate_->GetWidgetByIDAndType<TBTextField>(TBIDC("build_path"));
  30. assert(buildPathField_);
  31. String buildPath = project->GetLastBuildPath();
  32. buildPathField_->SetText(buildPath.CString());
  33. window_->ResizeToFitContent();
  34. Center();
  35. AEEditorPlatform platform = editor->GetCurrentPlatform();
  36. TBSkinImage* platformIndicator = window_->GetContentRoot()->GetWidgetByIDAndType<TBSkinImage>(TBIDC("current_platform_indicator"));
  37. assert(platformIndicator);
  38. if (platform == AE_PLATFORM_MAC)
  39. platformIndicator->SetSkinBg(TBIDC("LogoMac"));
  40. else if (platform == AE_PLATFORM_WINDOWS)
  41. platformIndicator->SetSkinBg(TBIDC("LogoWindows"));
  42. else if (platform == AE_PLATFORM_ANDROID)
  43. platformIndicator->SetSkinBg(TBIDC("LogoAndroid"));
  44. else if (platform == AE_PLATFORM_HTML5)
  45. platformIndicator->SetSkinBg(TBIDC("LogoHTML5"));
  46. else if (platform == AE_PLATFORM_IOS)
  47. platformIndicator->SetSkinBg(TBIDC("LogoIOS"));
  48. }
  49. UIBuild::~UIBuild()
  50. {
  51. }
  52. bool UIBuild::OnEvent(const TBWidgetEvent &ev)
  53. {
  54. UIModalOps* ops = GetSubsystem<UIModalOps>();
  55. ProjectUtils* utils = context_->GetSubsystem<ProjectUtils>();
  56. if (ev.type == EVENT_TYPE_CLICK)
  57. {
  58. if (ev.target->GetID() == TBIDC("choose_path"))
  59. {
  60. String buildPath = utils->GetBuildPath("");
  61. if (buildPath.Length())
  62. buildPathField_->SetText(buildPath.CString());
  63. return true;
  64. }
  65. else if (ev.target->GetID() == TBIDC("build"))
  66. {
  67. // we're going to be hiding this modal
  68. // and chaining the program output modal
  69. // potentially, but we want this modal to
  70. // survive, this needs to be refactored
  71. // until the end of this call
  72. SharedPtr<UIModalOpWindow> keepAlive(this);
  73. TBStr str;
  74. buildPathField_->GetText(str);
  75. String buildPath = str.CStr();
  76. if (buildPath.Length())
  77. {
  78. Editor* editor = GetSubsystem<Editor>();
  79. Project* project = editor->GetProject();
  80. project->SetLastBuildPath(buildPath);
  81. project->Save();
  82. using namespace EditorBuild;
  83. VariantMap neventData;
  84. AEEditorPlatform platform = editor->GetCurrentPlatform();
  85. if (platform == AE_PLATFORM_ANDROID)
  86. neventData[P_PLATFORM] = "Android";
  87. else if (platform == AE_PLATFORM_WINDOWS)
  88. neventData[P_PLATFORM] = "Windows";
  89. else if (platform == AE_PLATFORM_MAC)
  90. neventData[P_PLATFORM] = "Mac";
  91. else if (platform == AE_PLATFORM_HTML5)
  92. neventData[P_PLATFORM] = "HTML5";
  93. else if (platform == AE_PLATFORM_IOS)
  94. neventData[P_PLATFORM] = "IOS";
  95. ops->Hide();
  96. neventData[P_BUILDPATH] = buildPath;
  97. SendEvent(E_EDITORBUILD, neventData);
  98. }
  99. return true;
  100. }
  101. else if (ev.target->GetID() == TBIDC("cancel"))
  102. {
  103. ops->Hide();
  104. return true;
  105. }
  106. }
  107. return false;
  108. }
  109. }