BsScriptHandleManager.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEditorPrerequisites.h"
  5. #include "Handles/BsHandleManager.h"
  6. namespace bs
  7. {
  8. /** @addtogroup EditorScript
  9. * @{
  10. */
  11. /**
  12. * Renders, updates and manipulates handles declared in managed code. Managed code handles have a [CustomHandle]
  13. * attribute and must implement bs.Editor.Handle.
  14. */
  15. class BS_SCR_BED_EXPORT ScriptHandleManager : public HandleManager
  16. {
  17. /** Contains data about a manage type that draws and handles interaction with a custom handle. */
  18. struct CustomHandleData
  19. {
  20. MonoClass* handleType;
  21. MonoClass* componentType;
  22. MonoMethod* ctor;
  23. };
  24. /**
  25. * Data about an active instance of a managed custom handle object. Active handle means its scene object is
  26. * currently selected and the handle is displayed and can be interacted with.
  27. */
  28. struct ActiveCustomHandleData
  29. {
  30. MonoObject* object;
  31. uint32_t gcHandle;
  32. };
  33. /**
  34. * Data about all active managed custom handle objects for a specific scene object. Active handle means its
  35. * scene object is currently selected and the handle is displayed and can be interacted with.
  36. */
  37. struct ActiveCustomHandles
  38. {
  39. HSceneObject selectedObject;
  40. Vector<ActiveCustomHandleData> handles;
  41. };
  42. public:
  43. ScriptHandleManager(ScriptAssemblyManager& scriptObjectManager);
  44. ~ScriptHandleManager();
  45. protected:
  46. /** @copydoc HandleManager::triggerPreInput */
  47. void triggerPreInput() override;
  48. /** @copydoc HandleManager::triggerPostInput */
  49. void triggerPostInput() override;
  50. /** @copydoc HandleManager::queueDrawCommands */
  51. void queueDrawCommands() override;
  52. /** Creates or destroys handle objects depending on the current selection. */
  53. void updateHandles();
  54. /**
  55. * Clears references to all managed types and objects. Must be called before loadAssemblyData() if
  56. * loadAssemblyData() was called previously.
  57. */
  58. void clearAssemblyData();
  59. /**
  60. * Loads internal managed assembly types and finds all custom handle classes. Must be called after construction and
  61. * after assembly reload.
  62. */
  63. void loadAssemblyData();
  64. /**
  65. * Checks is the provided type a valid custom handle class. Custom handles must have a [CustomHandle] attribute and
  66. * must implement BansheeEditor.Handle.
  67. *
  68. * @param[in] type Type to check.
  69. * @param[in] componentType Component type for which the handle should be displayed for. Handle will not
  70. * be displayed unless a component of this type is selected. Only valid if method
  71. * returns true.
  72. * @param[in] ctor Constructor method for the handle type. Only valid if method returns true.
  73. * @return True if the type is a valid custom handle type.
  74. */
  75. bool isValidHandleType(MonoClass* type, MonoClass*& componentType, MonoMethod*& ctor) const;
  76. /**
  77. * Triggers the PreInput method on the provided Handle object. Pre input happens before any handles are selected
  78. * or moved and allows you to position the handles or prepare them in some other way.
  79. */
  80. void callPreInput(MonoObject* instance);
  81. /**
  82. * Triggers the PostInput method on the provided Handle object. Post input happens after we know in what way has the
  83. * user interacted with the handles this frame.
  84. */
  85. void callPostInput(MonoObject* instance);
  86. /**
  87. * Triggers the Draw method on the provided Handle object. Draw allows you to draw the visual representation of the
  88. * handles. Called after PostInput.
  89. */
  90. void callDraw(MonoObject* instance);
  91. /**
  92. * Triggers the Destroy method on the provided Handle object. Destroy is called when the handle is no longer being
  93. * displayed.
  94. */
  95. void callDestroy(MonoObject* instance);
  96. ScriptAssemblyManager& mScriptObjectManager;
  97. HEvent mDomainUnloadConn;
  98. HEvent mDomainLoadConn;
  99. Map<String, CustomHandleData> mHandles;
  100. ActiveCustomHandles mActiveHandleData;
  101. Vector<MonoClass*> mGlobalHandlesToCreate;
  102. Vector<ActiveCustomHandleData> mActiveGlobalHandles;
  103. MonoObject* mDefaultHandleManager = nullptr;
  104. uint32_t mDefaultHandleManagerGCHandle = 0;
  105. MonoClass* mCustomHandleAttribute = nullptr;
  106. MonoField* mTypeField = nullptr;
  107. MonoClass* mHandleBaseClass = nullptr;
  108. MonoClass* mDefaultHandleManagerClass = nullptr;
  109. typedef void(BS_THUNKCALL *DestroyThunkDef) (MonoObject*, MonoException**);
  110. MonoMethod* mPreInputMethod;
  111. MonoMethod* mPostInputMethod;
  112. MonoMethod* mDrawMethod;
  113. DestroyThunkDef mDestroyThunk;
  114. };
  115. /** @} */
  116. }