PythonEditorEventsBus.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #pragma once
  2. /*
  3. * Copyright (c) Contributors to the Open 3D Engine Project.
  4. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. *
  6. * SPDX-License-Identifier: Apache-2.0 OR MIT
  7. *
  8. */
  9. #pragma once
  10. #include <AzCore/IO/Path/Path.h>
  11. #include <AzCore/std/any.h>
  12. namespace AzToolsFramework
  13. {
  14. /**
  15. * This bus can be used to send commands to the editor.
  16. */
  17. class EditorLayerPythonRequests
  18. : public AZ::ComponentBus
  19. {
  20. public:
  21. /*
  22. * Gets a CVar value as a string.
  23. */
  24. virtual const char* GetCVar(const char* pName) = 0;
  25. /*
  26. * Sets a CVar value from any simple value.
  27. */
  28. virtual void SetCVar(const char* pName, const AZStd::any& value) = 0;
  29. /*
  30. * Sets a CVar value from a string.
  31. */
  32. virtual void SetCVarFromString(const char* pName, const char* pValue) = 0;
  33. /*
  34. * Sets a CVar value from an integer.
  35. */
  36. virtual void SetCVarFromInteger(const char* pName, int pValue) = 0;
  37. /*
  38. * Sets a CVar value from a float.
  39. */
  40. virtual void SetCVarFromFloat(const char* pName, float pValue) = 0;
  41. /*
  42. * Runs a console command.
  43. */
  44. virtual void PyRunConsole(const char* text) = 0;
  45. /*
  46. * Enters the editor game mode.
  47. */
  48. virtual void EnterGameMode() = 0;
  49. /*
  50. * Queries if it's in the game mode or not.
  51. */
  52. virtual bool IsInGameMode() = 0;
  53. /*
  54. * Exits the editor game mode.
  55. */
  56. virtual void ExitGameMode() = 0;
  57. /*
  58. * Enters the editor AI/Physics simulation mode.
  59. */
  60. virtual void EnterSimulationMode() = 0;
  61. /*
  62. * Queries if the editor is currently in the AI/Physics simulation mode or not.
  63. */
  64. virtual bool IsInSimulationMode() = 0;
  65. /*
  66. * Exits the editor AI/Physics simulation mode.
  67. */
  68. virtual void ExitSimulationMode() = 0;
  69. /*
  70. * Runs a script file. A relative path from the editor user folder or an absolute path should be given as an argument.
  71. */
  72. virtual void RunFile(const char* pFile) = 0;
  73. /*
  74. * Runs a script file with parameters. A relative path from the editor user folder or an absolute path should be given as an argument. The arguments should be separated by whitespace.
  75. */
  76. virtual void RunFileParameters(const char* pFile, const char* pArguments) = 0;
  77. /*
  78. * Executes a given string as an editor command.
  79. */
  80. virtual void ExecuteCommand(const char* cmdline) = 0;
  81. /*
  82. * Shows a confirmation message box with ok|cancel and shows a custom message.
  83. */
  84. virtual bool MessageBoxOkCancel(const char* pMessage) = 0;
  85. /*
  86. * Shows a confirmation message box with yes|no and shows a custom message.
  87. */
  88. virtual bool MessageBoxYesNo(const char* pMessage) = 0;
  89. /*
  90. * Shows a confirmation message box with only ok and shows a custom message.
  91. */
  92. virtual bool MessageBoxOk(const char* pMessage) = 0;
  93. /*
  94. * Shows an edit box and returns the value as string.
  95. */
  96. virtual AZStd::string EditBox(AZStd::string_view pTitle) = 0;
  97. /*
  98. * Shows an edit box and checks the custom value to use the return value with other functions correctly.
  99. */
  100. virtual AZStd::any EditBoxCheckDataType(const char* pTitle) = 0;
  101. /*
  102. * Shows an open file box and returns the selected file path and name.
  103. */
  104. virtual AZStd::string OpenFileBox() = 0;
  105. /*
  106. * Gets axis.
  107. */
  108. virtual const char* GetAxisConstraint() = 0;
  109. /*
  110. * Sets axis.
  111. */
  112. virtual void SetAxisConstraint(AZStd::string_view pConstrain) = 0;
  113. /*
  114. * Finds a pak file name for a given file.
  115. */
  116. virtual AZ::IO::Path GetPakFromFile(const char* filename) = 0;
  117. /*
  118. * Prints the message to the editor console window.
  119. */
  120. virtual void Log(const char* pMessage) = 0;
  121. /*
  122. * Undoes the last operation.
  123. */
  124. virtual void Undo() = 0;
  125. /*
  126. * Redoes the last undone operation.
  127. */
  128. virtual void Redo() = 0;
  129. /*
  130. * Shows a 2d label on the screen at the given position and given color.
  131. */
  132. virtual void DrawLabel(int x, int y, float size, float r, float g, float b, float a, const char* pLabel) = 0;
  133. /*
  134. * Shows a combo box listing each value passed in, returns string value selected by the user.
  135. */
  136. virtual AZStd::string ComboBox(AZStd::string title, AZStd::vector<AZStd::string> values, int selectedIdx = 0) = 0;
  137. };
  138. using EditorLayerPythonRequestBus = AZ::EBus<EditorLayerPythonRequests>;
  139. }