BsScriptGUISceneTreeView.cpp 5.1 KB

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