BsScriptGUISceneTreeView.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "BsScriptGUISceneTreeView.h"
  2. #include "BsScriptMeta.h"
  3. #include "BsMonoClass.h"
  4. #include "BsMonoMethod.h"
  5. #include "BsMonoManager.h"
  6. #include "BsMonoUtil.h"
  7. #include "BsGUISceneTreeView.h"
  8. #include "BsGUIOptions.h"
  9. #include "BsScriptGameObjectManager.h"
  10. #include "BsScriptSceneObject.h"
  11. using namespace std::placeholders;
  12. namespace BansheeEngine
  13. {
  14. ScriptGUISceneTreeView::OnModifiedThunkDef ScriptGUISceneTreeView::onModifiedThunk;
  15. ScriptGUISceneTreeView::OnResourceDroppedThunkDef ScriptGUISceneTreeView::onResourceDroppedThunk;
  16. ScriptGUISceneTreeView::ScriptGUISceneTreeView(MonoObject* instance, GUISceneTreeView* treeView)
  17. :TScriptGUIElement(instance, treeView)
  18. {
  19. mOnModifiedConn = treeView->onModified.connect(std::bind(&ScriptGUISceneTreeView::sceneModified, this));
  20. mOnResourceDroppedConn = treeView->onResourceDropped.connect(
  21. std::bind(&ScriptGUISceneTreeView::resourceDropped, this, _1, _2));
  22. }
  23. ScriptGUISceneTreeView::~ScriptGUISceneTreeView()
  24. {
  25. mOnModifiedConn.disconnect();
  26. mOnResourceDroppedConn.disconnect();
  27. }
  28. void ScriptGUISceneTreeView::initRuntimeData()
  29. {
  30. metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUISceneTreeView::internal_createInstance);
  31. metaData.scriptClass->addInternalCall("Internal_Update", &ScriptGUISceneTreeView::internal_update);
  32. metaData.scriptClass->addInternalCall("Internal_CutSelection", &ScriptGUISceneTreeView::internal_cutSelection);
  33. metaData.scriptClass->addInternalCall("Internal_CopySelection", &ScriptGUISceneTreeView::internal_copySelection);
  34. metaData.scriptClass->addInternalCall("Internal_PasteToSelection", &ScriptGUISceneTreeView::internal_pasteToSelection);
  35. metaData.scriptClass->addInternalCall("Internal_DuplicateSelection", &ScriptGUISceneTreeView::internal_duplicateSelection);
  36. metaData.scriptClass->addInternalCall("Internal_DeleteSelection", &ScriptGUISceneTreeView::internal_deleteSelection);
  37. onModifiedThunk = (OnModifiedThunkDef)metaData.scriptClass->getMethod("Internal_DoOnModified", 0)->getThunk();
  38. onResourceDroppedThunk = (OnResourceDroppedThunkDef)metaData.scriptClass->getMethod("Internal_DoOnResourceDropped", 2)->getThunk();
  39. }
  40. void ScriptGUISceneTreeView::sceneModified()
  41. {
  42. MonoUtil::invokeThunk(onModifiedThunk, getManagedInstance());
  43. }
  44. void ScriptGUISceneTreeView::resourceDropped(const HSceneObject& parent, const Vector<Path>& resourcePaths)
  45. {
  46. MonoObject* sceneMonoObject = nullptr;
  47. if (parent != nullptr)
  48. {
  49. ScriptSceneObject* scriptSceneObject = ScriptGameObjectManager::instance().getOrCreateScriptSceneObject(parent);
  50. sceneMonoObject = scriptSceneObject->getManagedInstance();
  51. }
  52. UINT32 numPaths = (UINT32)resourcePaths.size();
  53. ScriptArray array = ScriptArray::create<WString>(numPaths);
  54. for (UINT32 i = 0; i < numPaths; i++)
  55. array.set(i, resourcePaths[i].toWString());
  56. MonoUtil::invokeThunk(onResourceDroppedThunk, getManagedInstance(), sceneMonoObject, array.getInternal());
  57. }
  58. void ScriptGUISceneTreeView::internal_createInstance(MonoObject* instance, MonoString* style, MonoArray* guiOptions)
  59. {
  60. GUIOptions options;
  61. UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
  62. for (UINT32 i = 0; i < arrayLen; i++)
  63. options.addOption(mono_array_get(guiOptions, GUIOption, i));
  64. String styleName = toString(MonoUtil::monoToWString(style));
  65. GUISceneTreeView* treeView = GUISceneTreeView::create(options);
  66. ScriptGUISceneTreeView* nativeInstance = new (bs_alloc<ScriptGUISceneTreeView>()) ScriptGUISceneTreeView(instance, treeView);
  67. }
  68. void ScriptGUISceneTreeView::internal_update(ScriptGUISceneTreeView* thisPtr)
  69. {
  70. if (thisPtr->mIsDestroyed)
  71. return;
  72. GUISceneTreeView* treeView = static_cast<GUISceneTreeView*>(thisPtr->getGUIElement());
  73. treeView->_update();
  74. }
  75. void ScriptGUISceneTreeView::internal_cutSelection(ScriptGUISceneTreeView* thisPtr)
  76. {
  77. GUISceneTreeView* treeView = static_cast<GUISceneTreeView*>(thisPtr->getGUIElement());
  78. treeView->cutSelection();
  79. }
  80. void ScriptGUISceneTreeView::internal_copySelection(ScriptGUISceneTreeView* thisPtr)
  81. {
  82. GUISceneTreeView* treeView = static_cast<GUISceneTreeView*>(thisPtr->getGUIElement());
  83. treeView->copySelection();
  84. }
  85. void ScriptGUISceneTreeView::internal_pasteToSelection(ScriptGUISceneTreeView* thisPtr)
  86. {
  87. GUISceneTreeView* treeView = static_cast<GUISceneTreeView*>(thisPtr->getGUIElement());
  88. treeView->paste();
  89. }
  90. void ScriptGUISceneTreeView::internal_duplicateSelection(ScriptGUISceneTreeView* thisPtr)
  91. {
  92. GUISceneTreeView* treeView = static_cast<GUISceneTreeView*>(thisPtr->getGUIElement());
  93. treeView->duplicateSelection();
  94. }
  95. void ScriptGUISceneTreeView::internal_deleteSelection(ScriptGUISceneTreeView* thisPtr)
  96. {
  97. GUISceneTreeView* treeView = static_cast<GUISceneTreeView*>(thisPtr->getGUIElement());
  98. treeView->deleteSelection();
  99. }
  100. }