UIManageLicense.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. // BEGIN LICENSE MANAGEMENT
  5. #include "AtomicEditor.h"
  6. #include <TurboBadger/tb_window.h>
  7. #include <TurboBadger/tb_select.h>
  8. #include <TurboBadger/tb_editfield.h>
  9. #include <TurboBadger/tb_message_window.h>
  10. #include <Atomic/Core/Context.h>
  11. #include <Atomic/UI/UI.h>
  12. #include "Resources/AEResourceOps.h"
  13. #include "AEPreferences.h"
  14. #include "AEEditor.h"
  15. #include "AEEvents.h"
  16. #include "Project/AEProject.h"
  17. #include "Project/ProjectUtils.h"
  18. #include "AELicenseSystem.h"
  19. #include "UIManageLicense.h"
  20. namespace AtomicEditor
  21. {
  22. // UIBuildSettings------------------------------------------------
  23. UIManageLicense::UIManageLicense(Context* context):
  24. UIModalOpWindow(context)
  25. {
  26. Editor* editor = GetSubsystem<Editor>();
  27. Project* project = editor->GetProject();
  28. UI* tbui = GetSubsystem<UI>();
  29. window_->SetText("Manage License");
  30. tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/managelicense.tb.txt");
  31. window_->ResizeToFitContent();
  32. Center();
  33. progressModal_ = new ProgressModal(context_, "Manage License", "");
  34. }
  35. UIManageLicense::~UIManageLicense()
  36. {
  37. progressModal_->Hide();
  38. }
  39. bool UIManageLicense::OnEvent(const TBWidgetEvent &ev)
  40. {
  41. Editor* editor = GetSubsystem<Editor>();
  42. LicenseSystem* licenseSystem = GetSubsystem<LicenseSystem>();
  43. if (ev.type == EVENT_TYPE_CLICK)
  44. {
  45. if (ev.target->GetID() == TBIDC("ok"))
  46. {
  47. UIModalOps* ops = GetSubsystem<UIModalOps>();
  48. ops->Hide();
  49. return true;
  50. }
  51. if (ev.target->GetID() == TBIDC("confirm_license_return"))
  52. {
  53. if (ev.ref_id == TBIDC("TBMessageWindow.ok"))
  54. {
  55. request_ = licenseSystem->Deactivate();
  56. SubscribeToEvent(request_, E_CURLCOMPLETE, HANDLER(UIManageLicense, HandleCurlComplete));
  57. progressModal_->SetMessage("Returning license, please wait...");
  58. progressModal_->Show();
  59. }
  60. }
  61. if (ev.target->GetID() == TBIDC("return_activation"))
  62. {
  63. if (editor->IsProjectLoaded())
  64. {
  65. editor->PostModalError("Close Project", "Please close the current project before deactivating license");
  66. }
  67. else
  68. {
  69. TBMessageWindow *msg_win = new TBMessageWindow(window_, TBIDC("confirm_license_return"));
  70. TBMessageWindowSettings settings(TB_MSG_OK_CANCEL, TBID(uint32(0)));
  71. settings.dimmer = true;
  72. settings.styling = true;
  73. msg_win->Show("Return License", "Are you sure you want to return the installed license?", &settings, 300, 140);
  74. }
  75. return true;
  76. }
  77. }
  78. return false;
  79. }
  80. void UIManageLicense::HandleCurlComplete(StringHash eventType, VariantMap& eventData)
  81. {
  82. progressModal_->Hide();
  83. }
  84. }
  85. // END LICENSE MANAGEMENT