UIModalOps.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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_widgets_common.h>
  6. #include <TurboBadger/tb_window.h>
  7. #include <TurboBadger/tb_message_window.h>
  8. #include <TurboBadger/tb_editfield.h>
  9. #include <Atomic/Core/Context.h>
  10. #include <Atomic/Graphics/Graphics.h>
  11. #include <Atomic/UI/TBUI.h>
  12. #include "AEEvents.h"
  13. #include "Resources/AEResourceOps.h"
  14. #include "UI/UIMainFrame.h"
  15. #include "UI/UIProjectFrame.h"
  16. #include "UIModalOps.h"
  17. #include "UIResourceOps.h"
  18. #include "UIBuild.h"
  19. #include "UIBuildSettings.h"
  20. #include "UIProgramOutput.h"
  21. #include "UINewProject.h"
  22. #include "UIAbout.h"
  23. #include "UIPlatformsInfo.h"
  24. #include "License/UIActivation.h"
  25. #include "License/UIActivationSuccess.h"
  26. #include "License/UIManageLicense.h"
  27. #include "License/AELicenseSystem.h"
  28. #include "License/UIEulaAgreement.h"
  29. namespace AtomicEditor
  30. {
  31. // UIModalOpWindow------------------------------------------------
  32. UIModalOpWindow::UIModalOpWindow(Context* context):
  33. AEWidget(context)
  34. {
  35. window_ = new TBWindow();
  36. TBUI* tbui = GetSubsystem<TBUI>();
  37. TBWidget* root = tbui->GetRootWidget();
  38. root->AddChild(delegate_);
  39. // start with full screen as size
  40. delegate_->SetRect(TBRect(0, 0, root->GetRect().w, root->GetRect().h));
  41. delegate_->AddChild(window_);
  42. }
  43. UIModalOpWindow::~UIModalOpWindow()
  44. {
  45. }
  46. bool UIModalOpWindow::OnEvent(const TBWidgetEvent &ev)
  47. {
  48. return false;
  49. }
  50. void UIModalOpWindow::Center()
  51. {
  52. TBUI* tbui = GetSubsystem<TBUI>();
  53. TBRect rect = window_->GetRect();
  54. TBWidget* root = tbui->GetRootWidget();
  55. TBRect bounds(0, 0, root->GetRect().w, root->GetRect().h);
  56. window_->SetRect(rect.CenterIn(bounds).MoveIn(bounds).Clip(bounds));
  57. delegate_->SetRect(bounds);
  58. }
  59. // UIModalOps------------------------------------------------
  60. UIModalOps::UIModalOps(Context* context) :
  61. AEWidget(context),
  62. dimmer_(0),
  63. isHiding_(false)
  64. {
  65. TBWidgetListener::AddGlobalListener(this);
  66. context->RegisterSubsystem(this);
  67. dimmer_ = new TBDimmer();
  68. }
  69. void UIModalOps::Show()
  70. {
  71. assert(!dimmer_->GetParent());
  72. TBUI* tbui = GetSubsystem<TBUI>();
  73. TBWidget* root = tbui->GetRootWidget();
  74. root->AddChild(dimmer_);
  75. }
  76. void UIModalOps::Hide()
  77. {
  78. isHiding_ = true;
  79. if (dimmer_->GetParent())
  80. dimmer_->GetParent()->RemoveChild(dimmer_);
  81. opWindow_ = NULL;
  82. TBUI* tbui = GetSubsystem<TBUI>();
  83. tbui->GetRootWidget()->SetFocusRecursive(WIDGET_FOCUS_REASON_UNKNOWN);
  84. isHiding_ = false;
  85. }
  86. void UIModalOps::ShowCreateComponent(const String& resourcePath)
  87. {
  88. assert(opWindow_.Null());
  89. resourcePath_ = resourcePath;
  90. Show();
  91. opWindow_ = new UICreateComponent(context_);
  92. }
  93. void UIModalOps::ShowCreateScript(const String& resourcePath)
  94. {
  95. assert(opWindow_.Null());
  96. resourcePath_ = resourcePath;
  97. Show();
  98. opWindow_ = new UICreateScript(context_);
  99. }
  100. void UIModalOps::ShowResourceDelete(const String& resourcePath)
  101. {
  102. assert(opWindow_.Null());
  103. resourcePath_ = resourcePath;
  104. Show();
  105. opWindow_ = new UIResourceDelete(context_);
  106. }
  107. void UIModalOps::ShowNewFolder(const String& resourcePath)
  108. {
  109. assert(opWindow_.Null());
  110. resourcePath_ = resourcePath;
  111. Show();
  112. opWindow_ = new UINewFolder(context_);
  113. }
  114. void UIModalOps::ShowBuildSettings()
  115. {
  116. assert(opWindow_.Null());
  117. Show();
  118. opWindow_ = new UIBuildSettings(context_);
  119. }
  120. void UIModalOps::ShowBuild()
  121. {
  122. assert(opWindow_.Null());
  123. Show();
  124. // BEGIN LICENSE MANAGEMENT
  125. LicenseSystem* licenseSystem = GetSubsystem<LicenseSystem>();
  126. if (licenseSystem->HasPlatformLicense())
  127. opWindow_ = new UIBuild(context_);
  128. else
  129. opWindow_ = new PlatformsInfo(context_);
  130. // END LICENSE MANAGEMENT
  131. }
  132. void UIModalOps::ShowNewProject()
  133. {
  134. assert(opWindow_.Null());
  135. Show();
  136. opWindow_ = new UINewProject(context_);
  137. }
  138. void UIModalOps::SetProgramOutputSubprocess(Object* subprocess)
  139. {
  140. if (opWindow_.Null())
  141. return;
  142. if (opWindow_->GetType() != UIProgramOutput::GetTypeStatic())
  143. return;
  144. UIProgramOutput* output = (UIProgramOutput*)(opWindow_.Get());
  145. output->SetSubprocess(subprocess);
  146. }
  147. void UIModalOps::ShowProgramOutput(Object *subprocess)
  148. {
  149. assert(opWindow_.Null());
  150. Show();
  151. UIProgramOutput* output = new UIProgramOutput(context_);
  152. output->SetSubprocess(subprocess);
  153. opWindow_ = output;
  154. }
  155. void UIModalOps::ShowActivation()
  156. {
  157. assert(opWindow_.Null());
  158. Show();
  159. opWindow_ = new UIActivation(context_);
  160. }
  161. void UIModalOps::ShowActivationSuccess()
  162. {
  163. assert(opWindow_.Null());
  164. Show();
  165. opWindow_ = new UIActivationSuccess(context_);
  166. }
  167. void UIModalOps::ShowAbout()
  168. {
  169. assert(opWindow_.Null());
  170. Show();
  171. opWindow_ = new UIAbout(context_);
  172. }
  173. void UIModalOps::ShowManageLicense()
  174. {
  175. assert(opWindow_.Null());
  176. Show();
  177. opWindow_ = new UIManageLicense(context_);
  178. }
  179. void UIModalOps::ShowPlatformsInfo()
  180. {
  181. assert(opWindow_.Null());
  182. Show();
  183. opWindow_ = new PlatformsInfo(context_);
  184. }
  185. void UIModalOps::ShowEulaAgreement()
  186. {
  187. assert(opWindow_.Null());
  188. Show();
  189. opWindow_ = new UIEulaAgreement(context_);
  190. }
  191. void UIModalOps::OnWidgetDelete(TBWidget *widget)
  192. {
  193. if (isHiding_)
  194. return;
  195. if (opWindow_)
  196. {
  197. if (widget == opWindow_->GetWindow())
  198. Hide();
  199. }
  200. }
  201. bool UIModalOps::OnWidgetDying(TBWidget *widget)
  202. {
  203. return false;
  204. }
  205. UIModalOps::~UIModalOps()
  206. {
  207. TBWidgetListener::RemoveGlobalListener(this);
  208. }
  209. bool UIModalOps::OnEvent(const TBWidgetEvent &ev)
  210. {
  211. return false;
  212. }
  213. }