CreateProjectCtrl.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #include <CreateProjectCtrl.h>
  13. #include <ScreensCtrl.h>
  14. #include <PythonBindingsInterface.h>
  15. #include <NewProjectSettingsScreen.h>
  16. #include <ScreenHeaderWidget.h>
  17. #include <GemCatalog/GemCatalogScreen.h>
  18. #include <QDialogButtonBox>
  19. #include <QHBoxLayout>
  20. #include <QVBoxLayout>
  21. #include <QPushButton>
  22. #include <QMessageBox>
  23. #include <QStackedWidget>
  24. #include <QLabel>
  25. #include <QSizePolicy>
  26. namespace O3DE::ProjectManager
  27. {
  28. CreateProjectCtrl::CreateProjectCtrl(QWidget* parent)
  29. : ScreenWidget(parent)
  30. {
  31. QVBoxLayout* vLayout = new QVBoxLayout();
  32. vLayout->setContentsMargins(0,0,0,0);
  33. m_header = new ScreenHeader(this);
  34. m_header->setTitle(tr("Create a New Project"));
  35. m_header->setSubTitle(tr("Enter Project Details"));
  36. connect(m_header->backButton(), &QPushButton::clicked, this, &CreateProjectCtrl::HandleBackButton);
  37. vLayout->addWidget(m_header);
  38. m_stack = new QStackedWidget(this);
  39. m_stack->setObjectName("body");
  40. m_stack->setSizePolicy(QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Expanding));
  41. m_newProjectSettingsScreen = new NewProjectSettingsScreen(this);
  42. m_stack->addWidget(m_newProjectSettingsScreen);
  43. m_gemCatalogScreen = new GemCatalogScreen(this);
  44. m_stack->addWidget(m_gemCatalogScreen);
  45. vLayout->addWidget(m_stack);
  46. QDialogButtonBox* buttons = new QDialogButtonBox();
  47. buttons->setObjectName("footer");
  48. vLayout->addWidget(buttons);
  49. #ifdef TEMPLATE_GEM_CONFIGURATION_ENABLED
  50. connect(m_newProjectSettingsScreen, &ScreenWidget::ChangeScreenRequest, this, &CreateProjectCtrl::OnChangeScreenRequest);
  51. m_secondaryButton = buttons->addButton(tr("Back"), QDialogButtonBox::RejectRole);
  52. m_secondaryButton->setProperty("secondary", true);
  53. m_secondaryButton->setVisible(false);
  54. connect(m_secondaryButton, &QPushButton::clicked, this, &CreateProjectCtrl::HandleSecondaryButton);
  55. Update();
  56. #endif // TEMPLATE_GEM_CONFIGURATION_ENABLED
  57. m_primaryButton = buttons->addButton(tr("Create Project"), QDialogButtonBox::ApplyRole);
  58. connect(m_primaryButton, &QPushButton::clicked, this, &CreateProjectCtrl::HandlePrimaryButton);
  59. setLayout(vLayout);
  60. }
  61. ProjectManagerScreen CreateProjectCtrl::GetScreenEnum()
  62. {
  63. return ProjectManagerScreen::CreateProject;
  64. }
  65. void CreateProjectCtrl::NotifyCurrentScreen()
  66. {
  67. ScreenWidget* currentScreen = reinterpret_cast<ScreenWidget*>(m_stack->currentWidget());
  68. if (currentScreen)
  69. {
  70. currentScreen->NotifyCurrentScreen();
  71. }
  72. }
  73. void CreateProjectCtrl::HandleBackButton()
  74. {
  75. if (m_stack->currentIndex() > 0)
  76. {
  77. #ifdef TEMPLATE_GEM_CONFIGURATION_ENABLED
  78. PreviousScreen();
  79. #endif // TEMPLATE_GEM_CONFIGURATION_ENABLED
  80. }
  81. else
  82. {
  83. emit GotoPreviousScreenRequest();
  84. }
  85. }
  86. #ifdef TEMPLATE_GEM_CONFIGURATION_ENABLED
  87. void CreateProjectCtrl::HandleSecondaryButton()
  88. {
  89. if (m_stack->currentIndex() > 0)
  90. {
  91. // return to Project Settings page
  92. PreviousScreen();
  93. }
  94. else
  95. {
  96. // Configure Gems
  97. NextScreen();
  98. }
  99. }
  100. void CreateProjectCtrl::Update()
  101. {
  102. if (m_stack->currentWidget() == m_gemCatalogScreen)
  103. {
  104. m_header->setSubTitle(tr("Configure project with Gems"));
  105. m_secondaryButton->setVisible(false);
  106. }
  107. else
  108. {
  109. m_header->setSubTitle(tr("Enter Project Details"));
  110. m_secondaryButton->setVisible(true);
  111. m_secondaryButton->setText(tr("Configure Gems"));
  112. }
  113. }
  114. void CreateProjectCtrl::OnChangeScreenRequest(ProjectManagerScreen screen)
  115. {
  116. if (screen == ProjectManagerScreen::GemCatalog)
  117. {
  118. HandleSecondaryButton();
  119. }
  120. else
  121. {
  122. emit ChangeScreenRequest(screen);
  123. }
  124. }
  125. void CreateProjectCtrl::NextScreen()
  126. {
  127. if (m_stack->currentIndex() < m_stack->count())
  128. {
  129. if(CurrentScreenIsValid())
  130. {
  131. m_stack->setCurrentIndex(m_stack->currentIndex() + 1);
  132. QString projectTemplatePath = m_newProjectSettingsScreen->GetProjectTemplatePath();
  133. m_gemCatalogScreen->ReinitForProject(projectTemplatePath + "/Template", /*isNewProject=*/true);
  134. Update();
  135. }
  136. else
  137. {
  138. QMessageBox::warning(this, tr("Invalid project settings"), tr("Please correct the indicated project settings and try again."));
  139. }
  140. }
  141. }
  142. void CreateProjectCtrl::PreviousScreen()
  143. {
  144. // we don't require the current screen to be valid when moving back
  145. if (m_stack->currentIndex() > 0)
  146. {
  147. m_stack->setCurrentIndex(m_stack->currentIndex() - 1);
  148. Update();
  149. }
  150. }
  151. #endif // TEMPLATE_GEM_CONFIGURATION_ENABLED
  152. void CreateProjectCtrl::HandlePrimaryButton()
  153. {
  154. CreateProject();
  155. }
  156. bool CreateProjectCtrl::CurrentScreenIsValid()
  157. {
  158. if (m_stack->currentWidget() == m_newProjectSettingsScreen)
  159. {
  160. return m_newProjectSettingsScreen->Validate();
  161. }
  162. return true;
  163. }
  164. void CreateProjectCtrl::CreateProject()
  165. {
  166. if (m_newProjectSettingsScreen->Validate())
  167. {
  168. ProjectInfo projectInfo = m_newProjectSettingsScreen->GetProjectInfo();
  169. QString projectTemplatePath = m_newProjectSettingsScreen->GetProjectTemplatePath();
  170. auto result = PythonBindingsInterface::Get()->CreateProject(projectTemplatePath, projectInfo);
  171. if (result.IsSuccess())
  172. {
  173. // automatically register the project
  174. PythonBindingsInterface::Get()->AddProject(projectInfo.m_path);
  175. #ifdef TEMPLATE_GEM_CONFIGURATION_ENABLED
  176. m_gemCatalogScreen->EnableDisableGemsForProject(projectInfo.m_path);
  177. #endif // TEMPLATE_GEM_CONFIGURATION_ENABLED
  178. projectInfo.m_needsBuild = true;
  179. emit NotifyBuildProject(projectInfo);
  180. emit ChangeScreenRequest(ProjectManagerScreen::Projects);
  181. }
  182. else
  183. {
  184. QMessageBox::critical(this, tr("Project creation failed"), tr("Failed to create project."));
  185. }
  186. }
  187. else
  188. {
  189. QMessageBox::warning(this, tr("Invalid project settings"), tr("Please correct the indicated project settings and try again."));
  190. }
  191. }
  192. } // namespace O3DE::ProjectManager