UIBuild.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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/TBUI.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. TBUI* tbui = GetSubsystem<TBUI>();
  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. }
  47. UIBuild::~UIBuild()
  48. {
  49. }
  50. bool UIBuild::OnEvent(const TBWidgetEvent &ev)
  51. {
  52. UIModalOps* ops = GetSubsystem<UIModalOps>();
  53. ProjectUtils* utils = context_->GetSubsystem<ProjectUtils>();
  54. if (ev.type == EVENT_TYPE_CLICK)
  55. {
  56. if (ev.target->GetID() == TBIDC("choose_path"))
  57. {
  58. String buildPath = utils->GetBuildPath("");
  59. if (buildPath.Length())
  60. buildPathField_->SetText(buildPath.CString());
  61. return true;
  62. }
  63. else if (ev.target->GetID() == TBIDC("build"))
  64. {
  65. // we're going to be hiding this modal
  66. // and chaining the program output modal
  67. // potentially, but we want this modal to
  68. // survive, this needs to be refactored
  69. // until the end of this call
  70. SharedPtr<UIModalOpWindow> keepAlive(this);
  71. TBStr str;
  72. buildPathField_->GetText(str);
  73. String buildPath = str.CStr();
  74. if (buildPath.Length())
  75. {
  76. Editor* editor = GetSubsystem<Editor>();
  77. Project* project = editor->GetProject();
  78. project->SetLastBuildPath(buildPath);
  79. project->Save();
  80. using namespace EditorBuild;
  81. VariantMap neventData;
  82. AEEditorPlatform platform = editor->GetCurrentPlatform();
  83. if (platform == AE_PLATFORM_ANDROID)
  84. neventData[P_PLATFORM] = "Android";
  85. else if (platform == AE_PLATFORM_WINDOWS)
  86. neventData[P_PLATFORM] = "Windows";
  87. else if (platform == AE_PLATFORM_MAC)
  88. neventData[P_PLATFORM] = "Mac";
  89. else if (platform == AE_PLATFORM_HTML5)
  90. neventData[P_PLATFORM] = "HTML5";
  91. else if (platform == AE_PLATFORM_IOS)
  92. neventData[P_PLATFORM] = "iOS";
  93. ops->Hide();
  94. neventData[P_BUILDPATH] = buildPath;
  95. SendEvent(E_EDITORBUILD, neventData);
  96. }
  97. return true;
  98. }
  99. else if (ev.target->GetID() == TBIDC("cancel"))
  100. {
  101. ops->Hide();
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107. }