UIModalOps.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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/UI.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 "UICreateProject.h"
  23. #include "UIAbout.h"
  24. #include "UIPlatformsInfo.h"
  25. #include "UIInfoModule3D.h"
  26. #include "License/UIActivation.h"
  27. #include "License/UIActivationSuccess.h"
  28. #include "License/UIManageLicense.h"
  29. #include "License/AELicenseSystem.h"
  30. #include "License/UIEulaAgreement.h"
  31. #include "Player/UIPlayer.h"
  32. namespace AtomicEditor
  33. {
  34. // UIModalOpWindow------------------------------------------------
  35. UIModalOpWindow::UIModalOpWindow(Context* context):
  36. AEWidget(context)
  37. {
  38. window_ = new TBWindow();
  39. UI* tbui = GetSubsystem<UI>();
  40. TBWidget* root = tbui->GetRootWidget();
  41. root->AddChild(delegate_);
  42. // start with full screen as size
  43. delegate_->SetRect(TBRect(0, 0, root->GetRect().w, root->GetRect().h));
  44. delegate_->AddChild(window_);
  45. delegate_->SetFocus(WIDGET_FOCUS_REASON_UNKNOWN);
  46. }
  47. UIModalOpWindow::~UIModalOpWindow()
  48. {
  49. }
  50. bool UIModalOpWindow::OnEvent(const TBWidgetEvent &ev)
  51. {
  52. return false;
  53. }
  54. void UIModalOpWindow::Center()
  55. {
  56. UI* tbui = GetSubsystem<UI>();
  57. TBRect rect = window_->GetRect();
  58. TBWidget* root = tbui->GetRootWidget();
  59. TBRect bounds(0, 0, root->GetRect().w, root->GetRect().h);
  60. window_->SetRect(rect.CenterIn(bounds).MoveIn(bounds).Clip(bounds));
  61. delegate_->SetRect(bounds);
  62. }
  63. // UIModalOps------------------------------------------------
  64. UIModalOps::UIModalOps(Context* context) :
  65. AEWidget(context),
  66. dimmer_(0),
  67. isHiding_(false)
  68. {
  69. TBWidgetListener::AddGlobalListener(this);
  70. context->RegisterSubsystem(this);
  71. dimmer_ = new TBDimmer();
  72. SubscribeToEvent(E_EDITORSHUTDOWN, HANDLER(UIModalOps, HandleEditorShutdown));
  73. }
  74. void UIModalOps::Show()
  75. {
  76. assert(!dimmer_->GetParent());
  77. UI* tbui = GetSubsystem<UI>();
  78. TBWidget* root = tbui->GetRootWidget();
  79. root->AddChild(dimmer_);
  80. }
  81. void UIModalOps::Hide()
  82. {
  83. isHiding_ = true;
  84. if (dimmer_->GetParent())
  85. dimmer_->GetParent()->RemoveChild(dimmer_);
  86. opWindow_ = NULL;
  87. UI* tbui = GetSubsystem<UI>();
  88. tbui->GetRootWidget()->SetFocusRecursive(WIDGET_FOCUS_REASON_UNKNOWN);
  89. isHiding_ = false;
  90. }
  91. void UIModalOps::ShowCreateComponent(const String& resourcePath)
  92. {
  93. assert(opWindow_.Null());
  94. resourcePath_ = resourcePath;
  95. Show();
  96. opWindow_ = new UICreateComponent(context_);
  97. }
  98. void UIModalOps::ShowCreateModule(const String& resourcePath)
  99. {
  100. assert(opWindow_.Null());
  101. resourcePath_ = resourcePath;
  102. Show();
  103. opWindow_ = new UICreateModule(context_);
  104. }
  105. void UIModalOps::ShowCreate2DLevel(const String& resourcePath)
  106. {
  107. assert(opWindow_.Null());
  108. resourcePath_ = resourcePath;
  109. Show();
  110. opWindow_ = new UICreate2DLevel(context_);
  111. }
  112. void UIModalOps::ShowCreateScript(const String& resourcePath)
  113. {
  114. assert(opWindow_.Null());
  115. resourcePath_ = resourcePath;
  116. Show();
  117. opWindow_ = new UICreateScript(context_);
  118. }
  119. void UIModalOps::ShowResourceDelete(const String& resourcePath)
  120. {
  121. assert(opWindow_.Null());
  122. resourcePath_ = resourcePath;
  123. Show();
  124. opWindow_ = new UIResourceDelete(context_);
  125. }
  126. void UIModalOps::ShowNewFolder(const String& resourcePath)
  127. {
  128. assert(opWindow_.Null());
  129. resourcePath_ = resourcePath;
  130. Show();
  131. opWindow_ = new UINewFolder(context_);
  132. }
  133. void UIModalOps::ShowBuildSettings()
  134. {
  135. assert(opWindow_.Null());
  136. Show();
  137. opWindow_ = new UIBuildSettings(context_);
  138. }
  139. void UIModalOps::ShowBuild()
  140. {
  141. assert(opWindow_.Null());
  142. Show();
  143. // BEGIN LICENSE MANAGEMENT
  144. LicenseSystem* licenseSystem = GetSubsystem<LicenseSystem>();
  145. /*
  146. if (licenseSystem->HasPlatformLicense())
  147. */
  148. opWindow_ = new UIBuild(context_);
  149. //else
  150. // opWindow_ = new PlatformsInfo(context_);
  151. // END LICENSE MANAGEMENT
  152. }
  153. void UIModalOps::ShowNewProject()
  154. {
  155. assert(opWindow_.Null());
  156. Show();
  157. opWindow_ = new UINewProject(context_);
  158. }
  159. void UIModalOps::ShowCreateProject(const String &templateFolder, const String &imagePath)
  160. {
  161. assert(opWindow_.Null());
  162. Show();
  163. opWindow_ = new UICreateProject(context_, templateFolder, imagePath);
  164. }
  165. void UIModalOps::SetProgramOutputSubprocess(Object* subprocess)
  166. {
  167. if (opWindow_.Null())
  168. return;
  169. if (opWindow_->GetType() != UIProgramOutput::GetTypeStatic())
  170. return;
  171. UIProgramOutput* output = (UIProgramOutput*)(opWindow_.Get());
  172. output->SetSubprocess(subprocess);
  173. }
  174. void UIModalOps::PrintToProgramOutput(const String& text)
  175. {
  176. if (opWindow_.Null())
  177. return;
  178. if (opWindow_->GetType() != UIProgramOutput::GetTypeStatic())
  179. return;
  180. UIProgramOutput* output = (UIProgramOutput*)(opWindow_.Get());
  181. output->OutputText(text);
  182. }
  183. void UIModalOps::ShowProgramOutput(Object *subprocess)
  184. {
  185. assert(opWindow_.Null());
  186. Show();
  187. UIProgramOutput* output = new UIProgramOutput(context_);
  188. output->SetSubprocess(subprocess);
  189. opWindow_ = output;
  190. }
  191. void UIModalOps::ShowActivation()
  192. {
  193. assert(opWindow_.Null());
  194. Show();
  195. opWindow_ = new UIActivation(context_);
  196. }
  197. void UIModalOps::ShowActivationSuccess()
  198. {
  199. assert(opWindow_.Null());
  200. Show();
  201. opWindow_ = new UIActivationSuccess(context_);
  202. }
  203. void UIModalOps::ShowAbout()
  204. {
  205. assert(opWindow_.Null());
  206. Show();
  207. opWindow_ = new UIAbout(context_);
  208. }
  209. void UIModalOps::ShowManageLicense()
  210. {
  211. assert(opWindow_.Null());
  212. Show();
  213. opWindow_ = new UIManageLicense(context_);
  214. }
  215. void UIModalOps::ShowPlatformsInfo()
  216. {
  217. assert(opWindow_.Null());
  218. Show();
  219. opWindow_ = new PlatformsInfo(context_);
  220. }
  221. void UIModalOps::ShowEulaAgreement()
  222. {
  223. assert(opWindow_.Null());
  224. Show();
  225. opWindow_ = new UIEulaAgreement(context_);
  226. }
  227. void UIModalOps::ShowPlayer()
  228. {
  229. assert(opWindow_.Null());
  230. Show();
  231. opWindow_ = new UIPlayer(context_);
  232. }
  233. void UIModalOps::ShowInfoModule3D(const String &exampleFolder, const String &exampleScreenshot)
  234. {
  235. assert(opWindow_.Null());
  236. Show();
  237. opWindow_ = new InfoModule3D(context_, exampleFolder, exampleScreenshot);
  238. }
  239. void UIModalOps::OnWidgetDelete(TBWidget *widget)
  240. {
  241. if (isHiding_)
  242. return;
  243. if (opWindow_)
  244. {
  245. if (widget == opWindow_->GetWindow())
  246. Hide();
  247. }
  248. }
  249. bool UIModalOps::OnWidgetDying(TBWidget *widget)
  250. {
  251. return false;
  252. }
  253. UIModalOps::~UIModalOps()
  254. {
  255. TBWidgetListener::RemoveGlobalListener(this);
  256. }
  257. bool UIModalOps::OnEvent(const TBWidgetEvent &ev)
  258. {
  259. return false;
  260. }
  261. void UIModalOps::HandleEditorShutdown(StringHash eventType, VariantMap& eventData)
  262. {
  263. context_->RemoveSubsystem(GetType());
  264. }
  265. }