UINewProject.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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/UI.h>
  10. #include "License/AELicenseSystem.h"
  11. #include "Resources/AEResourceOps.h"
  12. #include "AEPreferences.h"
  13. #include "AEEditor.h"
  14. #include "AEEvents.h"
  15. #include "Project/AEProject.h"
  16. #include "Project/ProjectUtils.h"
  17. #include "UINewProject.h"
  18. namespace AtomicEditor
  19. {
  20. UINewProject::UINewProject(Context* context):
  21. UIModalOpWindow(context)
  22. {
  23. Editor* editor = GetSubsystem<Editor>();
  24. Project* project = editor->GetProject();
  25. UI* tbui = GetSubsystem<UI>();
  26. window_->SetText("Project Type");
  27. tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/newproject.tb.txt");
  28. window_->ResizeToFitContent();
  29. Center();
  30. }
  31. UINewProject::~UINewProject()
  32. {
  33. }
  34. bool UINewProject::Create2DProject(const String& projectPath, const String& filename)
  35. {
  36. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  37. #ifdef ATOMIC_PLATFORM_OSX
  38. String templateSourceDir = fileSystem->GetAppBundleResourceFolder();
  39. #else
  40. String templateSourceDir = fileSystem->GetProgramDir();
  41. #endif
  42. templateSourceDir += "/ProjectTemplates/Project2D";
  43. fileSystem->CopyDir(templateSourceDir + "/Resources", projectPath + "/Resources");
  44. File file(context_, projectPath + "/" + filename + ".atomic", FILE_WRITE);
  45. file.Close();
  46. return true;
  47. }
  48. bool UINewProject::CreateEmptyProject(const String& projectPath, const String &filename)
  49. {
  50. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  51. #ifdef ATOMIC_PLATFORM_OSX
  52. String templateSourceDir = fileSystem->GetAppBundleResourceFolder();
  53. #else
  54. String templateSourceDir = fileSystem->GetProgramDir();
  55. #endif
  56. templateSourceDir += "/ProjectTemplates/EmptyProject";
  57. fileSystem->CopyDir(templateSourceDir + "/Resources", projectPath + "/Resources");
  58. File file(context_, projectPath + "/" + filename + ".atomic", FILE_WRITE);
  59. file.Close();
  60. return true;
  61. }
  62. bool UINewProject::Create3DProject(const String& projectPath, const String &filename)
  63. {
  64. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  65. #ifdef ATOMIC_PLATFORM_OSX
  66. String templateSourceDir = fileSystem->GetAppBundleResourceFolder();
  67. #else
  68. String templateSourceDir = fileSystem->GetProgramDir();
  69. #endif
  70. templateSourceDir += "/ProjectTemplates/Project3D";
  71. fileSystem->CopyDir(templateSourceDir + "/Resources", projectPath + "/Resources");
  72. File file(context_, projectPath + "/" + filename + ".atomic", FILE_WRITE);
  73. file.Close();
  74. return true;
  75. }
  76. bool UINewProject::OnEvent(const TBWidgetEvent &ev)
  77. {
  78. Editor* editor = GetSubsystem<Editor>();
  79. UIModalOps* ops = GetSubsystem<UIModalOps>();
  80. if (ev.type == EVENT_TYPE_CLICK)
  81. {
  82. if (ev.target->GetID() == TBIDC("cancel"))
  83. {
  84. ops->Hide();
  85. return true;
  86. }
  87. int projectType = -1;
  88. if (ev.target->GetID() == TBIDC("project_empty"))
  89. {
  90. projectType = 0;
  91. }
  92. else if (ev.target->GetID() == TBIDC("project_2d"))
  93. {
  94. projectType = 1;
  95. }
  96. else if (ev.target->GetID() == TBIDC("project_3d"))
  97. {
  98. // BEGIN LICENSE MANAGEMENT
  99. LicenseSystem* licenseSystem = GetSubsystem<LicenseSystem>();
  100. if (licenseSystem->IsStandardLicense())
  101. {
  102. SharedPtr<UINewProject> keepAlive(this);
  103. UIModalOps* ops = GetSubsystem<UIModalOps>();
  104. ops->Hide();
  105. ops->ShowInfoModule3D();
  106. return true;
  107. }
  108. // END LICENSE MANAGEMENT
  109. projectType = 2;
  110. }
  111. if (projectType != -1)
  112. {
  113. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  114. #ifdef ATOMIC_PLATFORM_OSX
  115. String templateSourceDir = fileSystem->GetAppBundleResourceFolder();
  116. #else
  117. String templateSourceDir = fileSystem->GetProgramDir();
  118. #endif
  119. if (projectType == 0)
  120. templateSourceDir += "/ProjectTemplates/EmptyProject";
  121. else if (projectType == 1)
  122. templateSourceDir += "/ProjectTemplates/Project2D";
  123. else
  124. templateSourceDir += "/ProjectTemplates/Project3D";
  125. SharedPtr<UINewProject> keepAlive(this);
  126. UIModalOps* ops = GetSubsystem<UIModalOps>();
  127. ops->Hide();
  128. ops->ShowCreateProject(templateSourceDir);
  129. return true;
  130. }
  131. }
  132. return false;
  133. }
  134. }