UIModalOps.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. isHiding_ = false;
  83. }
  84. void UIModalOps::ShowCreateComponent(const String& resourcePath)
  85. {
  86. assert(opWindow_.Null());
  87. resourcePath_ = resourcePath;
  88. Show();
  89. opWindow_ = new UICreateComponent(context_);
  90. }
  91. void UIModalOps::ShowCreateScript(const String& resourcePath)
  92. {
  93. assert(opWindow_.Null());
  94. resourcePath_ = resourcePath;
  95. Show();
  96. opWindow_ = new UICreateScript(context_);
  97. }
  98. void UIModalOps::ShowResourceDelete(const String& resourcePath)
  99. {
  100. assert(opWindow_.Null());
  101. resourcePath_ = resourcePath;
  102. Show();
  103. opWindow_ = new UIResourceDelete(context_);
  104. }
  105. void UIModalOps::ShowNewFolder(const String& resourcePath)
  106. {
  107. assert(opWindow_.Null());
  108. resourcePath_ = resourcePath;
  109. Show();
  110. opWindow_ = new UINewFolder(context_);
  111. }
  112. void UIModalOps::ShowBuildSettings()
  113. {
  114. assert(opWindow_.Null());
  115. Show();
  116. opWindow_ = new UIBuildSettings(context_);
  117. }
  118. void UIModalOps::ShowBuild()
  119. {
  120. assert(opWindow_.Null());
  121. Show();
  122. // BEGIN LICENSE MANAGEMENT
  123. LicenseSystem* licenseSystem = GetSubsystem<LicenseSystem>();
  124. if (licenseSystem->HasPlatformLicense())
  125. opWindow_ = new UIBuild(context_);
  126. else
  127. opWindow_ = new PlatformsInfo(context_);
  128. // END LICENSE MANAGEMENT
  129. }
  130. void UIModalOps::ShowNewProject()
  131. {
  132. assert(opWindow_.Null());
  133. Show();
  134. opWindow_ = new UINewProject(context_);
  135. }
  136. void UIModalOps::SetProgramOutputSubprocess(Object* subprocess)
  137. {
  138. if (opWindow_.Null())
  139. return;
  140. if (opWindow_->GetType() != UIProgramOutput::GetTypeStatic())
  141. return;
  142. UIProgramOutput* output = (UIProgramOutput*)(opWindow_.Get());
  143. output->SetSubprocess(subprocess);
  144. }
  145. void UIModalOps::ShowProgramOutput(Object *subprocess)
  146. {
  147. assert(opWindow_.Null());
  148. Show();
  149. UIProgramOutput* output = new UIProgramOutput(context_);
  150. output->SetSubprocess(subprocess);
  151. opWindow_ = output;
  152. }
  153. void UIModalOps::ShowActivation()
  154. {
  155. assert(opWindow_.Null());
  156. Show();
  157. opWindow_ = new UIActivation(context_);
  158. }
  159. void UIModalOps::ShowActivationSuccess()
  160. {
  161. assert(opWindow_.Null());
  162. Show();
  163. opWindow_ = new UIActivationSuccess(context_);
  164. }
  165. void UIModalOps::ShowAbout()
  166. {
  167. assert(opWindow_.Null());
  168. Show();
  169. opWindow_ = new UIAbout(context_);
  170. }
  171. void UIModalOps::ShowManageLicense()
  172. {
  173. assert(opWindow_.Null());
  174. Show();
  175. opWindow_ = new UIManageLicense(context_);
  176. }
  177. void UIModalOps::ShowPlatformsInfo()
  178. {
  179. assert(opWindow_.Null());
  180. Show();
  181. opWindow_ = new PlatformsInfo(context_);
  182. }
  183. void UIModalOps::ShowEulaAgreement()
  184. {
  185. assert(opWindow_.Null());
  186. Show();
  187. opWindow_ = new UIEulaAgreement(context_);
  188. }
  189. void UIModalOps::OnWidgetDelete(TBWidget *widget)
  190. {
  191. if (isHiding_)
  192. return;
  193. if (opWindow_)
  194. {
  195. if (widget == opWindow_->GetWindow())
  196. Hide();
  197. }
  198. }
  199. bool UIModalOps::OnWidgetDying(TBWidget *widget)
  200. {
  201. return false;
  202. }
  203. UIModalOps::~UIModalOps()
  204. {
  205. TBWidgetListener::RemoveGlobalListener(this);
  206. }
  207. bool UIModalOps::OnEvent(const TBWidgetEvent &ev)
  208. {
  209. return false;
  210. }
  211. }