ScriptCanvasApplication.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "ScriptCanvasApplication.h"
  9. #include "Document/ScriptCanvasDocument.h"
  10. #include <AzFramework/Network/IRemoteTools.h>
  11. #include <AzFramework/Script/ScriptRemoteDebuggingConstants.h>
  12. #include <QApplication>
  13. #include <QIcon>
  14. #if defined(EXTERNAL_CRASH_REPORTING)
  15. #include <ToolsCrashHandler.h>
  16. #endif
  17. // This has to live outside of any namespaces due to issues on Linux with calls to Q_INIT_RESOURCE if they are inside a namespace
  18. void InitScriptCanvasApplicationResources()
  19. {
  20. Q_INIT_RESOURCE(ScriptCanvasApplicationResources);
  21. }
  22. namespace ScriptCanvas
  23. {
  24. static const char* GetBuildTargetName()
  25. {
  26. #if !defined(LY_CMAKE_TARGET)
  27. #error "LY_CMAKE_TARGET must be defined in order to add this source file to a CMake executable target"
  28. #endif
  29. return LY_CMAKE_TARGET;
  30. }
  31. ScriptCanvasApplication::ScriptCanvasApplication(int* argc, char*** argv)
  32. : Base(GetBuildTargetName(), argc, argv)
  33. {
  34. #if defined(EXTERNAL_CRASH_REPORTING)
  35. CrashHandler::ToolsCrashHandler::InitCrashHandler(GetBuildTargetName(), {});
  36. #endif
  37. InitScriptCanvasApplicationResources();
  38. QApplication::setOrganizationName("O3DE");
  39. QApplication::setApplicationName("O3DE Script Canvas");
  40. QApplication::setWindowIcon(QIcon(":/Resources/application.svg"));
  41. AzToolsFramework::EditorWindowRequestBus::Handler::BusConnect();
  42. AtomToolsFramework::AtomToolsDocumentNotificationBus::Handler::BusConnect(m_toolId);
  43. }
  44. ScriptCanvasApplication::~ScriptCanvasApplication()
  45. {
  46. AtomToolsFramework::AtomToolsDocumentNotificationBus::Handler::BusDisconnect();
  47. AzToolsFramework::EditorWindowRequestBus::Handler::BusDisconnect();
  48. }
  49. void ScriptCanvasApplication::Reflect(AZ::ReflectContext* context)
  50. {
  51. Base::Reflect(context);
  52. ScriptCanvasDocument::Reflect(context);
  53. }
  54. void ScriptCanvasApplication::StartCommon(AZ::Entity* systemEntity)
  55. {
  56. Base::StartCommon(systemEntity);
  57. auto documentTypeInfo = ScriptCanvasDocument::BuildDocumentTypeInfo();
  58. AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Event(
  59. m_toolId, &AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Handler::RegisterDocumentType, documentTypeInfo);
  60. #if defined(ENABLE_REMOTE_TOOLS)
  61. if (auto* remoteToolsInterface = AzFramework::RemoteToolsInterface::Get())
  62. {
  63. remoteToolsInterface->RegisterToolingServiceHost(
  64. AzFramework::ScriptCanvasToolsKey, AzFramework::ScriptCanvasToolsName, AzFramework::ScriptCanvasToolsPort);
  65. }
  66. #endif
  67. InitMainWindow();
  68. }
  69. void ScriptCanvasApplication::Destroy()
  70. {
  71. m_window.reset();
  72. Base::Destroy();
  73. }
  74. QWidget* ScriptCanvasApplication::GetAppMainWindow()
  75. {
  76. return m_window.get();
  77. }
  78. void ScriptCanvasApplication::InitMainWindow()
  79. {
  80. m_window.reset(aznew ScriptCanvasEditor::MainWindow(m_toolId));
  81. m_window->show();
  82. }
  83. } // namespace ScriptCanvas