BsScriptGUISceneTreeView.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Wrappers/GUI/BsScriptGUISceneTreeView.h"
  4. #include "BsScriptMeta.h"
  5. #include "BsMonoClass.h"
  6. #include "BsMonoMethod.h"
  7. #include "BsMonoManager.h"
  8. #include "BsMonoUtil.h"
  9. #include "GUI/BsGUISceneTreeView.h"
  10. #include "GUI/BsGUIOptions.h"
  11. #include "BsScriptGameObjectManager.h"
  12. #include "Wrappers/BsScriptSceneObject.h"
  13. using namespace std::placeholders;
  14. namespace bs
  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", (void*)&ScriptGUISceneTreeView::internal_createInstance);
  33. metaData.scriptClass->addInternalCall("Internal_Update", (void*)&ScriptGUISceneTreeView::internal_update);
  34. metaData.scriptClass->addInternalCall("Internal_CutSelection", (void*)&ScriptGUISceneTreeView::internal_cutSelection);
  35. metaData.scriptClass->addInternalCall("Internal_CopySelection", (void*)&ScriptGUISceneTreeView::internal_copySelection);
  36. metaData.scriptClass->addInternalCall("Internal_PasteToSelection", (void*)&ScriptGUISceneTreeView::internal_pasteToSelection);
  37. metaData.scriptClass->addInternalCall("Internal_DuplicateSelection", (void*)&ScriptGUISceneTreeView::internal_duplicateSelection);
  38. metaData.scriptClass->addInternalCall("Internal_DeleteSelection", (void*)&ScriptGUISceneTreeView::internal_deleteSelection);
  39. metaData.scriptClass->addInternalCall("Internal_RenameSelection", (void*)&ScriptGUISceneTreeView::internal_renameSelection);
  40. onModifiedThunk = (OnModifiedThunkDef)metaData.scriptClass->getMethod("Internal_DoOnModified", 0)->getThunk();
  41. onResourceDroppedThunk = (OnResourceDroppedThunkDef)metaData.scriptClass->getMethod("Internal_DoOnResourceDropped", 2)->getThunk();
  42. }
  43. void ScriptGUISceneTreeView::sceneModified()
  44. {
  45. MonoUtil::invokeThunk(onModifiedThunk, getManagedInstance());
  46. }
  47. void ScriptGUISceneTreeView::resourceDropped(const HSceneObject& parent, const Vector<Path>& resourcePaths)
  48. {
  49. MonoObject* sceneMonoObject = nullptr;
  50. if (parent != nullptr)
  51. {
  52. ScriptSceneObject* scriptSceneObject = ScriptGameObjectManager::instance().getOrCreateScriptSceneObject(parent);
  53. sceneMonoObject = scriptSceneObject->getManagedInstance();
  54. }
  55. UINT32 numPaths = (UINT32)resourcePaths.size();
  56. ScriptArray array = ScriptArray::create<String>(numPaths);
  57. for (UINT32 i = 0; i < numPaths; i++)
  58. array.set(i, resourcePaths[i].toString());
  59. MonoUtil::invokeThunk(onResourceDroppedThunk, getManagedInstance(), sceneMonoObject, array.getInternal());
  60. }
  61. void ScriptGUISceneTreeView::internal_createInstance(MonoObject* instance, MonoString* style, MonoArray* guiOptions)
  62. {
  63. GUIOptions options;
  64. ScriptArray scriptArray(guiOptions);
  65. UINT32 arrayLen = scriptArray.size();
  66. for (UINT32 i = 0; i < arrayLen; i++)
  67. options.addOption(scriptArray.get<GUIOption>(i));
  68. String styleName = MonoUtil::monoToString(style);
  69. GUISceneTreeView* treeView = GUISceneTreeView::create(options);
  70. new (bs_alloc<ScriptGUISceneTreeView>()) ScriptGUISceneTreeView(instance, treeView);
  71. }
  72. void ScriptGUISceneTreeView::internal_update(ScriptGUISceneTreeView* thisPtr)
  73. {
  74. if (thisPtr->mIsDestroyed)
  75. return;
  76. GUISceneTreeView* treeView = static_cast<GUISceneTreeView*>(thisPtr->getGUIElement());
  77. treeView->_update();
  78. }
  79. void ScriptGUISceneTreeView::internal_cutSelection(ScriptGUISceneTreeView* thisPtr)
  80. {
  81. GUISceneTreeView* treeView = static_cast<GUISceneTreeView*>(thisPtr->getGUIElement());
  82. treeView->cutSelection();
  83. }
  84. void ScriptGUISceneTreeView::internal_copySelection(ScriptGUISceneTreeView* thisPtr)
  85. {
  86. GUISceneTreeView* treeView = static_cast<GUISceneTreeView*>(thisPtr->getGUIElement());
  87. treeView->copySelection();
  88. }
  89. void ScriptGUISceneTreeView::internal_pasteToSelection(ScriptGUISceneTreeView* thisPtr)
  90. {
  91. GUISceneTreeView* treeView = static_cast<GUISceneTreeView*>(thisPtr->getGUIElement());
  92. treeView->paste();
  93. }
  94. void ScriptGUISceneTreeView::internal_duplicateSelection(ScriptGUISceneTreeView* thisPtr)
  95. {
  96. GUISceneTreeView* treeView = static_cast<GUISceneTreeView*>(thisPtr->getGUIElement());
  97. treeView->duplicateSelection();
  98. }
  99. void ScriptGUISceneTreeView::internal_deleteSelection(ScriptGUISceneTreeView* thisPtr)
  100. {
  101. GUISceneTreeView* treeView = static_cast<GUISceneTreeView*>(thisPtr->getGUIElement());
  102. treeView->deleteSelection();
  103. }
  104. void ScriptGUISceneTreeView::internal_renameSelection(ScriptGUISceneTreeView* thisPtr)
  105. {
  106. GUISceneTreeView* treeView = static_cast<GUISceneTreeView*>(thisPtr->getGUIElement());
  107. treeView->renameSelected();
  108. }
  109. }