ProjectsScreen.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <ProjectsScreen.h>
  9. #include <ProjectManagerDefs.h>
  10. #include <ProjectButtonWidget.h>
  11. #include <PythonBindingsInterface.h>
  12. #include <ProjectUtils.h>
  13. #include <ProjectBuilderController.h>
  14. #include <ScreensCtrl.h>
  15. #include <SettingsInterface.h>
  16. #include <AzQtComponents/Components/FlowLayout.h>
  17. #include <AzCore/Platform.h>
  18. #include <AzCore/IO/SystemFile.h>
  19. #include <AzFramework/AzFramework_Traits_Platform.h>
  20. #include <AzFramework/Process/ProcessCommon.h>
  21. #include <AzFramework/Process/ProcessWatcher.h>
  22. #include <AzCore/Utils/Utils.h>
  23. #include <QVBoxLayout>
  24. #include <QHBoxLayout>
  25. #include <QLabel>
  26. #include <QPushButton>
  27. #include <QMenu>
  28. #include <QListView>
  29. #include <QSpacerItem>
  30. #include <QListWidget>
  31. #include <QListWidgetItem>
  32. #include <QScrollArea>
  33. #include <QStackedWidget>
  34. #include <QFrame>
  35. #include <QIcon>
  36. #include <QPixmap>
  37. #include <QSettings>
  38. #include <QMessageBox>
  39. #include <QTimer>
  40. #include <QQueue>
  41. #include <QDir>
  42. #include <QGuiApplication>
  43. #include <QFileSystemWatcher>
  44. namespace O3DE::ProjectManager
  45. {
  46. ProjectsScreen::ProjectsScreen(QWidget* parent)
  47. : ScreenWidget(parent)
  48. {
  49. QVBoxLayout* vLayout = new QVBoxLayout();
  50. vLayout->setAlignment(Qt::AlignTop);
  51. vLayout->setContentsMargins(s_contentMargins, 0, s_contentMargins, 0);
  52. setLayout(vLayout);
  53. m_fileSystemWatcher = new QFileSystemWatcher(this);
  54. connect(m_fileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &ProjectsScreen::HandleProjectDirectoryChanged);
  55. m_stack = new QStackedWidget(this);
  56. m_firstTimeContent = CreateFirstTimeContent();
  57. m_stack->addWidget(m_firstTimeContent);
  58. m_projectsContent = CreateProjectsContent();
  59. m_stack->addWidget(m_projectsContent);
  60. vLayout->addWidget(m_stack);
  61. connect(reinterpret_cast<ScreensCtrl*>(parent), &ScreensCtrl::NotifyBuildProject, this, &ProjectsScreen::SuggestBuildProject);
  62. // Will focus whatever button it finds so the Project tab is not focused on start-up
  63. QTimer::singleShot(0, this, [this]
  64. {
  65. QPushButton* foundButton = m_stack->currentWidget()->findChild<QPushButton*>();
  66. if (foundButton)
  67. {
  68. foundButton->setFocus();
  69. }
  70. });
  71. }
  72. ProjectsScreen::~ProjectsScreen()
  73. {
  74. }
  75. QFrame* ProjectsScreen::CreateFirstTimeContent()
  76. {
  77. QFrame* frame = new QFrame(this);
  78. frame->setObjectName("firstTimeContent");
  79. {
  80. QVBoxLayout* layout = new QVBoxLayout();
  81. layout->setContentsMargins(0, 0, 0, 0);
  82. layout->setAlignment(Qt::AlignTop);
  83. frame->setLayout(layout);
  84. QLabel* titleLabel = new QLabel(tr("Ready? Set. Create!"), this);
  85. titleLabel->setObjectName("titleLabel");
  86. layout->addWidget(titleLabel);
  87. QLabel* introLabel = new QLabel(this);
  88. introLabel->setObjectName("introLabel");
  89. introLabel->setText(tr("Welcome to O3DE! Start something new by creating a project."));
  90. layout->addWidget(introLabel);
  91. QHBoxLayout* buttonLayout = new QHBoxLayout();
  92. buttonLayout->setAlignment(Qt::AlignLeft);
  93. buttonLayout->setSpacing(s_spacerSize);
  94. // use a newline to force the text up
  95. QPushButton* createProjectButton = new QPushButton(tr("Create a Project\n"), this);
  96. createProjectButton->setObjectName("createProjectButton");
  97. buttonLayout->addWidget(createProjectButton);
  98. QPushButton* addProjectButton = new QPushButton(tr("Add a Project\n"), this);
  99. addProjectButton->setObjectName("addProjectButton");
  100. buttonLayout->addWidget(addProjectButton);
  101. connect(createProjectButton, &QPushButton::clicked, this, &ProjectsScreen::HandleNewProjectButton);
  102. connect(addProjectButton, &QPushButton::clicked, this, &ProjectsScreen::HandleAddProjectButton);
  103. layout->addLayout(buttonLayout);
  104. }
  105. return frame;
  106. }
  107. QFrame* ProjectsScreen::CreateProjectsContent()
  108. {
  109. QFrame* frame = new QFrame(this);
  110. frame->setObjectName("projectsContent");
  111. {
  112. QVBoxLayout* layout = new QVBoxLayout();
  113. layout->setAlignment(Qt::AlignTop);
  114. layout->setContentsMargins(0, 0, 0, 0);
  115. frame->setLayout(layout);
  116. QFrame* header = new QFrame(frame);
  117. QHBoxLayout* headerLayout = new QHBoxLayout();
  118. {
  119. QLabel* titleLabel = new QLabel(tr("My Projects"), this);
  120. titleLabel->setObjectName("titleLabel");
  121. headerLayout->addWidget(titleLabel);
  122. QMenu* newProjectMenu = new QMenu(this);
  123. m_createNewProjectAction = newProjectMenu->addAction("Create New Project");
  124. m_addExistingProjectAction = newProjectMenu->addAction("Add Existing Project");
  125. connect(m_createNewProjectAction, &QAction::triggered, this, &ProjectsScreen::HandleNewProjectButton);
  126. connect(m_addExistingProjectAction, &QAction::triggered, this, &ProjectsScreen::HandleAddProjectButton);
  127. QPushButton* newProjectMenuButton = new QPushButton(tr("New Project..."), this);
  128. newProjectMenuButton->setObjectName("newProjectButton");
  129. newProjectMenuButton->setMenu(newProjectMenu);
  130. newProjectMenuButton->setDefault(true);
  131. headerLayout->addWidget(newProjectMenuButton);
  132. }
  133. header->setLayout(headerLayout);
  134. layout->addWidget(header);
  135. QScrollArea* projectsScrollArea = new QScrollArea(this);
  136. QWidget* scrollWidget = new QWidget();
  137. m_projectsFlowLayout = new FlowLayout(0, s_spacerSize, s_spacerSize);
  138. scrollWidget->setLayout(m_projectsFlowLayout);
  139. projectsScrollArea->setWidget(scrollWidget);
  140. projectsScrollArea->setWidgetResizable(true);
  141. ResetProjectsContent();
  142. layout->addWidget(projectsScrollArea);
  143. }
  144. return frame;
  145. }
  146. ProjectButton* ProjectsScreen::CreateProjectButton(const ProjectInfo& project)
  147. {
  148. ProjectButton* projectButton = new ProjectButton(project, this);
  149. m_projectButtons.insert(QDir::toNativeSeparators(project.m_path), projectButton);
  150. m_projectsFlowLayout->addWidget(projectButton);
  151. connect(projectButton, &ProjectButton::OpenProject, this, &ProjectsScreen::HandleOpenProject);
  152. connect(projectButton, &ProjectButton::EditProject, this, &ProjectsScreen::HandleEditProject);
  153. connect(projectButton, &ProjectButton::EditProjectGems, this, &ProjectsScreen::HandleEditProjectGems);
  154. connect(projectButton, &ProjectButton::CopyProject, this, &ProjectsScreen::HandleCopyProject);
  155. connect(projectButton, &ProjectButton::RemoveProject, this, &ProjectsScreen::HandleRemoveProject);
  156. connect(projectButton, &ProjectButton::DeleteProject, this, &ProjectsScreen::HandleDeleteProject);
  157. connect(projectButton, &ProjectButton::BuildProject, this, &ProjectsScreen::QueueBuildProject);
  158. connect(projectButton, &ProjectButton::OpenCMakeGUI, this,
  159. [this](const ProjectInfo& projectInfo)
  160. {
  161. AZ::Outcome result = ProjectUtils::OpenCMakeGUI(projectInfo.m_path);
  162. if (!result)
  163. {
  164. QMessageBox::critical(this, tr("Failed to open CMake GUI"), result.GetError(), QMessageBox::Ok);
  165. }
  166. });
  167. return projectButton;
  168. }
  169. void ProjectsScreen::ResetProjectsContent()
  170. {
  171. RemoveInvalidProjects();
  172. // Get all projects and create a vertical scrolling list of them
  173. // Sort building and queued projects first
  174. auto projectsResult = PythonBindingsInterface::Get()->GetProjects();
  175. if (projectsResult.IsSuccess() && !projectsResult.GetValue().isEmpty())
  176. {
  177. QVector<ProjectInfo> projectsVector = projectsResult.GetValue();
  178. // If a project path is in this set then the button for it will be kept
  179. QSet<QString> keepProject;
  180. for (const ProjectInfo& project : projectsVector)
  181. {
  182. keepProject.insert(QDir::toNativeSeparators(project.m_path));
  183. }
  184. // Clear flow and delete buttons for removed projects
  185. auto projectButtonsIter = m_projectButtons.begin();
  186. while (projectButtonsIter != m_projectButtons.end())
  187. {
  188. m_projectsFlowLayout->removeWidget(projectButtonsIter.value());
  189. if (!keepProject.contains(projectButtonsIter.key()))
  190. {
  191. projectButtonsIter.value()->deleteLater();
  192. projectButtonsIter = m_projectButtons.erase(projectButtonsIter);
  193. }
  194. else
  195. {
  196. ++projectButtonsIter;
  197. }
  198. }
  199. QString buildProjectPath = "";
  200. if (m_currentBuilder)
  201. {
  202. buildProjectPath = QDir::toNativeSeparators(m_currentBuilder->GetProjectInfo().m_path);
  203. }
  204. // Put currently building project in front, then queued projects, then sorts alphabetically
  205. std::sort(projectsVector.begin(), projectsVector.end(), [buildProjectPath, this](const ProjectInfo& arg1, const ProjectInfo& arg2)
  206. {
  207. if (arg1.m_path == buildProjectPath)
  208. {
  209. return true;
  210. }
  211. else if (arg2.m_path == buildProjectPath)
  212. {
  213. return false;
  214. }
  215. bool arg1InBuildQueue = BuildQueueContainsProject(arg1.m_path);
  216. bool arg2InBuildQueue = BuildQueueContainsProject(arg2.m_path);
  217. if (arg1InBuildQueue && !arg2InBuildQueue)
  218. {
  219. return true;
  220. }
  221. else if (!arg1InBuildQueue && arg2InBuildQueue)
  222. {
  223. return false;
  224. }
  225. else
  226. {
  227. return arg1.m_displayName.toLower() < arg2.m_displayName.toLower();
  228. }
  229. });
  230. // Add any missing project buttons and restore buttons to default state
  231. for (const ProjectInfo& project : projectsVector)
  232. {
  233. ProjectButton* currentButton = nullptr;
  234. if (!m_projectButtons.contains(QDir::toNativeSeparators(project.m_path)))
  235. {
  236. currentButton = CreateProjectButton(project);
  237. m_projectButtons.insert(QDir::toNativeSeparators(project.m_path), currentButton);
  238. m_fileSystemWatcher->addPath(QDir::toNativeSeparators(project.m_path + '/'));
  239. }
  240. else
  241. {
  242. auto projectButtonIter = m_projectButtons.find(QDir::toNativeSeparators(project.m_path));
  243. if (projectButtonIter != m_projectButtons.end())
  244. {
  245. currentButton = projectButtonIter.value();
  246. currentButton->SetState(ProjectButtonState::ReadyToLaunch);
  247. }
  248. }
  249. // Check whether project manager has successfully built the project
  250. if (currentButton)
  251. {
  252. m_projectsFlowLayout->addWidget(currentButton);
  253. bool projectBuiltSuccessfully = false;
  254. SettingsInterface::Get()->GetProjectBuiltSuccessfully(projectBuiltSuccessfully, project);
  255. if (!projectBuiltSuccessfully)
  256. {
  257. currentButton->SetState(ProjectButtonState::NeedsToBuild);
  258. }
  259. }
  260. }
  261. // Setup building button again
  262. auto buildProjectIter = m_projectButtons.find(buildProjectPath);
  263. if (buildProjectIter != m_projectButtons.end())
  264. {
  265. m_currentBuilder->SetProjectButton(buildProjectIter.value());
  266. }
  267. for (const ProjectInfo& project : m_buildQueue)
  268. {
  269. auto projectIter = m_projectButtons.find(QDir::toNativeSeparators(project.m_path));
  270. if (projectIter != m_projectButtons.end())
  271. {
  272. projectIter.value()->SetProjectButtonAction(
  273. tr("Cancel queued build"),
  274. [this, project]
  275. {
  276. UnqueueBuildProject(project);
  277. SuggestBuildProjectMsg(project, false);
  278. });
  279. }
  280. }
  281. for (const ProjectInfo& project : m_requiresBuild)
  282. {
  283. auto projectIter = m_projectButtons.find(QDir::toNativeSeparators(project.m_path));
  284. if (projectIter != m_projectButtons.end())
  285. {
  286. if (project.m_buildFailed)
  287. {
  288. projectIter.value()->SetBuildLogsLink(project.m_logUrl);
  289. projectIter.value()->SetState(ProjectButtonState::BuildFailed);
  290. }
  291. else
  292. {
  293. projectIter.value()->SetState(ProjectButtonState::NeedsToBuild);
  294. }
  295. }
  296. }
  297. }
  298. m_stack->setCurrentWidget(m_projectsContent);
  299. m_projectsFlowLayout->update();
  300. }
  301. void ProjectsScreen::HandleProjectDirectoryChanged(const QString& /*path*/)
  302. {
  303. // QFileWatcher automatically stops watching the path if it was removed so we will just refresh our view
  304. ResetProjectsContent();
  305. }
  306. ProjectManagerScreen ProjectsScreen::GetScreenEnum()
  307. {
  308. return ProjectManagerScreen::Projects;
  309. }
  310. bool ProjectsScreen::IsTab()
  311. {
  312. return true;
  313. }
  314. QString ProjectsScreen::GetTabText()
  315. {
  316. return tr("Projects");
  317. }
  318. void ProjectsScreen::paintEvent([[maybe_unused]] QPaintEvent* event)
  319. {
  320. // we paint the background here because qss does not support background cover scaling
  321. QPainter painter(this);
  322. const QSize winSize = size();
  323. const float pixmapRatio = (float)m_background.width() / m_background.height();
  324. const float windowRatio = (float)winSize.width() / winSize.height();
  325. QRect backgroundRect;
  326. if (pixmapRatio > windowRatio)
  327. {
  328. const int newWidth = (int)(winSize.height() * pixmapRatio);
  329. const int offset = (newWidth - winSize.width()) / -2;
  330. backgroundRect = QRect(offset, 0, newWidth, winSize.height());
  331. }
  332. else
  333. {
  334. const int newHeight = (int)(winSize.width() / pixmapRatio);
  335. backgroundRect = QRect(0, 0, winSize.width(), newHeight);
  336. }
  337. // Draw the background image.
  338. painter.drawPixmap(backgroundRect, m_background);
  339. // Draw a semi-transparent overlay to darken down the colors.
  340. // Use SourceOver, DestinationIn will make background transparent on Mac
  341. painter.setCompositionMode (QPainter::CompositionMode_SourceOver);
  342. const float overlayTransparency = 0.3f;
  343. painter.fillRect(backgroundRect, QColor(0, 0, 0, static_cast<int>(255.0f * overlayTransparency)));
  344. }
  345. void ProjectsScreen::HandleNewProjectButton()
  346. {
  347. emit ResetScreenRequest(ProjectManagerScreen::CreateProject);
  348. emit ChangeScreenRequest(ProjectManagerScreen::CreateProject);
  349. }
  350. void ProjectsScreen::HandleAddProjectButton()
  351. {
  352. if (ProjectUtils::AddProjectDialog(this))
  353. {
  354. emit ChangeScreenRequest(ProjectManagerScreen::Projects);
  355. }
  356. }
  357. void ProjectsScreen::HandleOpenProject(const QString& projectPath)
  358. {
  359. if (!projectPath.isEmpty())
  360. {
  361. if (!WarnIfInBuildQueue(projectPath))
  362. {
  363. AZ::IO::FixedMaxPath fixedProjectPath = projectPath.toUtf8().constData();
  364. AZ::IO::FixedMaxPath editorExecutablePath = ProjectUtils::GetEditorExecutablePath(fixedProjectPath);
  365. if (editorExecutablePath.empty())
  366. {
  367. AZ_Error("ProjectManager", false, "Failed to locate editor");
  368. QMessageBox::critical(
  369. this, tr("Error"), tr("Failed to locate the Editor, please verify that it is built."));
  370. return;
  371. }
  372. AzFramework::ProcessLauncher::ProcessLaunchInfo processLaunchInfo;
  373. processLaunchInfo.m_commandlineParameters = AZStd::vector<AZStd::string>{
  374. editorExecutablePath.String(),
  375. AZStd::string::format(R"(--regset="/Amazon/AzCore/Bootstrap/project_path=%s")", fixedProjectPath.c_str())
  376. };
  377. ;
  378. bool launchSucceeded = AzFramework::ProcessLauncher::LaunchUnwatchedProcess(processLaunchInfo);
  379. if (!launchSucceeded)
  380. {
  381. AZ_Error("ProjectManager", false, "Failed to launch editor");
  382. QMessageBox::critical(
  383. this, tr("Error"), tr("Failed to launch the Editor, please verify the project settings are valid."));
  384. }
  385. else
  386. {
  387. // prevent the user from accidentally pressing the button while the editor is launching
  388. // and let them know what's happening
  389. ProjectButton* button = qobject_cast<ProjectButton*>(sender());
  390. if (button)
  391. {
  392. button->SetState(ProjectButtonState::Launching);
  393. }
  394. // enable the button after 3 seconds
  395. constexpr int waitTimeInMs = 3000;
  396. QTimer::singleShot(
  397. waitTimeInMs, this,
  398. [button]
  399. {
  400. if (button)
  401. {
  402. button->SetState(ProjectButtonState::ReadyToLaunch);
  403. }
  404. });
  405. }
  406. }
  407. }
  408. else
  409. {
  410. AZ_Error("ProjectManager", false, "Cannot open editor because an empty project path was provided");
  411. QMessageBox::critical( this, tr("Error"), tr("Failed to launch the Editor because the project path is invalid."));
  412. }
  413. }
  414. void ProjectsScreen::HandleEditProject(const QString& projectPath)
  415. {
  416. if (!WarnIfInBuildQueue(projectPath))
  417. {
  418. emit NotifyCurrentProject(projectPath);
  419. emit ChangeScreenRequest(ProjectManagerScreen::UpdateProject);
  420. }
  421. }
  422. void ProjectsScreen::HandleEditProjectGems(const QString& projectPath)
  423. {
  424. if (!WarnIfInBuildQueue(projectPath))
  425. {
  426. emit NotifyCurrentProject(projectPath);
  427. emit ChangeScreenRequest(ProjectManagerScreen::GemCatalog);
  428. }
  429. }
  430. void ProjectsScreen::HandleCopyProject(const ProjectInfo& projectInfo)
  431. {
  432. if (!WarnIfInBuildQueue(projectInfo.m_path))
  433. {
  434. ProjectInfo newProjectInfo(projectInfo);
  435. // Open file dialog and choose location for copied project then register copy with O3DE
  436. if (ProjectUtils::CopyProjectDialog(projectInfo.m_path, newProjectInfo, this))
  437. {
  438. emit NotifyBuildProject(newProjectInfo);
  439. emit ChangeScreenRequest(ProjectManagerScreen::Projects);
  440. }
  441. }
  442. }
  443. void ProjectsScreen::HandleRemoveProject(const QString& projectPath)
  444. {
  445. if (!WarnIfInBuildQueue(projectPath))
  446. {
  447. // Unregister Project from O3DE and reload projects
  448. if (ProjectUtils::UnregisterProject(projectPath))
  449. {
  450. emit ChangeScreenRequest(ProjectManagerScreen::Projects);
  451. }
  452. }
  453. }
  454. void ProjectsScreen::HandleDeleteProject(const QString& projectPath)
  455. {
  456. if (!WarnIfInBuildQueue(projectPath))
  457. {
  458. QMessageBox::StandardButton warningResult = QMessageBox::warning(this,
  459. tr("Delete Project"),
  460. tr("Are you sure?\nProject will be unregistered from O3DE and project directory will be deleted from your disk."),
  461. QMessageBox::No | QMessageBox::Yes);
  462. if (warningResult == QMessageBox::Yes)
  463. {
  464. QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
  465. // Remove project from O3DE and delete from disk
  466. HandleRemoveProject(projectPath);
  467. ProjectUtils::DeleteProjectFiles(projectPath);
  468. QGuiApplication::restoreOverrideCursor();
  469. }
  470. }
  471. }
  472. void ProjectsScreen::SuggestBuildProjectMsg(const ProjectInfo& projectInfo, bool showMessage)
  473. {
  474. if (RequiresBuildProjectIterator(projectInfo.m_path) == m_requiresBuild.end() || projectInfo.m_buildFailed)
  475. {
  476. m_requiresBuild.append(projectInfo);
  477. }
  478. ResetProjectsContent();
  479. if (showMessage)
  480. {
  481. QMessageBox::information(this,
  482. tr("Project Should be rebuilt."),
  483. projectInfo.GetProjectDisplayName() + tr(" project likely needs to be rebuilt."));
  484. }
  485. }
  486. void ProjectsScreen::SuggestBuildProject(const ProjectInfo& projectInfo)
  487. {
  488. SuggestBuildProjectMsg(projectInfo, true);
  489. }
  490. void ProjectsScreen::QueueBuildProject(const ProjectInfo& projectInfo)
  491. {
  492. auto requiredIter = RequiresBuildProjectIterator(projectInfo.m_path);
  493. if (requiredIter != m_requiresBuild.end())
  494. {
  495. m_requiresBuild.erase(requiredIter);
  496. }
  497. if (!BuildQueueContainsProject(projectInfo.m_path))
  498. {
  499. if (m_buildQueue.empty() && !m_currentBuilder)
  500. {
  501. StartProjectBuild(projectInfo);
  502. // Projects Content is already reset in function
  503. }
  504. else
  505. {
  506. m_buildQueue.append(projectInfo);
  507. ResetProjectsContent();
  508. }
  509. }
  510. }
  511. void ProjectsScreen::UnqueueBuildProject(const ProjectInfo& projectInfo)
  512. {
  513. m_buildQueue.removeAll(projectInfo);
  514. ResetProjectsContent();
  515. }
  516. void ProjectsScreen::NotifyCurrentScreen()
  517. {
  518. if (ShouldDisplayFirstTimeContent())
  519. {
  520. m_background.load(":/Backgrounds/FtueBackground.jpg");
  521. m_stack->setCurrentWidget(m_firstTimeContent);
  522. }
  523. else
  524. {
  525. m_background.load(":/Backgrounds/DefaultBackground.jpg");
  526. ResetProjectsContent();
  527. }
  528. }
  529. bool ProjectsScreen::ShouldDisplayFirstTimeContent()
  530. {
  531. auto projectsResult = PythonBindingsInterface::Get()->GetProjects();
  532. if (!projectsResult.IsSuccess() || projectsResult.GetValue().isEmpty())
  533. {
  534. return true;
  535. }
  536. QSettings settings;
  537. bool displayFirstTimeContent = settings.value("displayFirstTimeContent", true).toBool();
  538. if (displayFirstTimeContent)
  539. {
  540. settings.setValue("displayFirstTimeContent", false);
  541. }
  542. return displayFirstTimeContent;
  543. }
  544. bool ProjectsScreen::RemoveInvalidProjects()
  545. {
  546. return PythonBindingsInterface::Get()->RemoveInvalidProjects();
  547. }
  548. bool ProjectsScreen::StartProjectBuild(const ProjectInfo& projectInfo)
  549. {
  550. if (ProjectUtils::FindSupportedCompiler(this))
  551. {
  552. QMessageBox::StandardButton buildProject = QMessageBox::information(
  553. this,
  554. tr("Building \"%1\"").arg(projectInfo.GetProjectDisplayName()),
  555. tr("Ready to build \"%1\"?").arg(projectInfo.GetProjectDisplayName()),
  556. QMessageBox::No | QMessageBox::Yes);
  557. if (buildProject == QMessageBox::Yes)
  558. {
  559. m_currentBuilder = new ProjectBuilderController(projectInfo, nullptr, this);
  560. ResetProjectsContent();
  561. connect(m_currentBuilder, &ProjectBuilderController::Done, this, &ProjectsScreen::ProjectBuildDone);
  562. connect(m_currentBuilder, &ProjectBuilderController::NotifyBuildProject, this, &ProjectsScreen::SuggestBuildProject);
  563. m_currentBuilder->Start();
  564. }
  565. else
  566. {
  567. SuggestBuildProjectMsg(projectInfo, false);
  568. return false;
  569. }
  570. return true;
  571. }
  572. return false;
  573. }
  574. void ProjectsScreen::ProjectBuildDone(bool success)
  575. {
  576. ProjectInfo currentBuilderProject;
  577. if (!success)
  578. {
  579. currentBuilderProject = m_currentBuilder->GetProjectInfo();
  580. }
  581. delete m_currentBuilder;
  582. m_currentBuilder = nullptr;
  583. if (!success)
  584. {
  585. SuggestBuildProjectMsg(currentBuilderProject, false);
  586. }
  587. if (!m_buildQueue.empty())
  588. {
  589. while (!StartProjectBuild(m_buildQueue.front()) && m_buildQueue.size() > 1)
  590. {
  591. m_buildQueue.pop_front();
  592. }
  593. m_buildQueue.pop_front();
  594. }
  595. ResetProjectsContent();
  596. }
  597. QList<ProjectInfo>::iterator ProjectsScreen::RequiresBuildProjectIterator(const QString& projectPath)
  598. {
  599. QString nativeProjPath(QDir::toNativeSeparators(projectPath));
  600. auto projectIter = m_requiresBuild.begin();
  601. for (; projectIter != m_requiresBuild.end(); ++projectIter)
  602. {
  603. if (QDir::toNativeSeparators(projectIter->m_path) == nativeProjPath)
  604. {
  605. break;
  606. }
  607. }
  608. return projectIter;
  609. }
  610. bool ProjectsScreen::BuildQueueContainsProject(const QString& projectPath)
  611. {
  612. QString nativeProjPath(QDir::toNativeSeparators(projectPath));
  613. for (const ProjectInfo& project : m_buildQueue)
  614. {
  615. if (QDir::toNativeSeparators(project.m_path) == nativeProjPath)
  616. {
  617. return true;
  618. }
  619. }
  620. return false;
  621. }
  622. bool ProjectsScreen::WarnIfInBuildQueue(const QString& projectPath)
  623. {
  624. if (BuildQueueContainsProject(projectPath))
  625. {
  626. QMessageBox::warning(
  627. this,
  628. tr("Action Temporarily Disabled!"),
  629. tr("Action not allowed on projects in build queue."));
  630. return true;
  631. }
  632. return false;
  633. }
  634. } // namespace O3DE::ProjectManager