diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp index c16d60d658..651edf4501 100644 --- a/interface/src/scripting/SelectionScriptingInterface.cpp +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -83,38 +83,56 @@ bool SelectionScriptingInterface::enableListHighlight(const QString& listName, c auto highlightStyle = _highlightedListMap.find(listName); if (highlightStyle == _highlightedListMap.end()) { highlightStyle = _highlightedListMap.insert(listName, SelectionHighlightStyle()); - doSetupHandler = true; + } if (!(*highlightStyle).isBoundToList()) { - GameplayObjects currentList = _selectedItemsListMap.value(listName); - if (!currentList.getContainsData()) { - _selectedItemsListMap.insert(listName, currentList); - doSetupHandler = true; + auto currentList = _selectedItemsListMap.find(listName); + if (currentList == _selectedItemsListMap.end()) { + _selectedItemsListMap.insert(listName, GameplayObjects()); + setupHandler(listName); + // doSetupHandler = true; } (*highlightStyle).setBoundToList(true); } (*highlightStyle).fromVariantMap(highlightStyleValues); - if (doSetupHandler) { +/* if (doSetupHandler) { setupHandler(listName); + }*/ + + auto mainScene = qApp->getMain3DScene(); + if (mainScene) { + render::Transaction transaction; + transaction.resetSelectionHighlight(listName.toStdString(), (*highlightStyle).getStyle()); + mainScene->enqueueTransaction(transaction); + } + else { + qWarning() << "SelectionToSceneHandler::highlightStyleChanged(), Unexpected null scene, possibly during application shutdown"; } - emit highlightStyleChanged(listName); return true; } bool SelectionScriptingInterface::disableListHighlight(const QString& listName) { auto highlightStyle = _highlightedListMap.find(listName); if (highlightStyle != _highlightedListMap.end()) { - if ((*highlightStyle).isBoundToList()) { - GameplayObjects currentList = _selectedItemsListMap.value(listName); - if (currentList.getContainsData()) { - } + // if ((*highlightStyle).isBoundToList()) { _highlightedListMap.erase(highlightStyle); - emit selectedItemsListChanged(listName); - } + + auto mainScene = qApp->getMain3DScene(); + if (mainScene) { + render::Transaction transaction; + transaction.removeHighlightFromSelection(listName.toStdString()); + mainScene->enqueueTransaction(transaction); + } + else { + qWarning() << "SelectionToSceneHandler::highlightStyleChanged(), Unexpected null scene, possibly during application shutdown"; + } + // emit highlightStyleRemoved(listName); + + // } } return true; @@ -126,7 +144,7 @@ QVariantMap SelectionScriptingInterface::getListHighlightStyle(const QString& li render::HighlightStyle SelectionScriptingInterface::getHighlightStyle(const QString& listName) const { auto highlightStyle = _highlightedListMap.find(listName); - if (highlightStyle != _highlightedListMap.end()) { + if (highlightStyle == _highlightedListMap.end()) { return render::HighlightStyle(); } else { return (*highlightStyle).getStyle(); @@ -196,14 +214,6 @@ bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { } } -void SelectionScriptingInterface::onSelectedItemsListChanged(const QString& listName) { - emit selectedItemsListChanged(listName); -} - -void SelectionScriptingInterface::onHighlightStyleChanged(const QString& listName) { - emit onHighlightStyleChanged(listName); -} - void SelectionScriptingInterface::setupHandler(const QString& selectionName) { auto handler = _handlerMap.find(selectionName); if (handler == _handlerMap.end()) { @@ -223,14 +233,9 @@ void SelectionToSceneHandler::initialize(const QString& listName) { _listName = listName; connect(&(*DependencyManager::get()), &SelectionScriptingInterface::selectedItemsListChanged, this, &SelectionToSceneHandler::selectedItemsListChanged); - connect(&(*DependencyManager::get()), &SelectionScriptingInterface::highlightStyleChanged, this, &SelectionToSceneHandler::highlightStyleChanged); + // connect(&(*DependencyManager::get()), &SelectionScriptingInterface::highlightStyleChanged, this, &SelectionToSceneHandler::highlightStyleChanged); + // connect(&(*DependencyManager::get()), &SelectionScriptingInterface::highlightStyleRemoved, this, &SelectionToSceneHandler::highlightStyleRemoved); - auto mainScene = qApp->getMain3DScene(); - if (mainScene) { - render::Transaction transaction; - transaction.resetSelectionHighlight(listName.toStdString(), DependencyManager::get()->getHighlightStyle(listName)); - mainScene->enqueueTransaction(transaction); - } } void SelectionToSceneHandler::selectedItemsListChanged(const QString& listName) { @@ -284,25 +289,36 @@ void SelectionToSceneHandler::updateSceneFromSelectedList() { qWarning() << "SelectionToSceneHandler::updateRendererSelectedList(), Unexpected null scene, possibly during application shutdown"; } } - +/* void SelectionToSceneHandler::highlightStyleChanged(const QString& listName) { if (listName == _listName) { auto mainScene = qApp->getMain3DScene(); if (mainScene) { auto thisStyle = DependencyManager::get()->getHighlightStyle(listName); render::Transaction transaction; - render::ItemIDs finalList; - transaction.resetSelectionHighlight(listName.toStdString(), thisStyle); - mainScene->enqueueTransaction(transaction); } else { - qWarning() << "SelectionToSceneHandler::updateRendererSelectedList(), Unexpected null scene, possibly during application shutdown"; + qWarning() << "SelectionToSceneHandler::highlightStyleChanged(), Unexpected null scene, possibly during application shutdown"; } } } +void SelectionToSceneHandler::highlightStyleRemoved(const QString& listName) { + if (listName == _listName) { + auto mainScene = qApp->getMain3DScene(); + if (mainScene) { + render::Transaction transaction; + transaction.removeHighlightFromSelection(listName.toStdString()); + mainScene->enqueueTransaction(transaction); + } + else { + qWarning() << "SelectionToSceneHandler::highlightStyleRemoved(), Unexpected null scene, possibly during application shutdown"; + } + } +} +*/ bool SelectionHighlightStyle::fromVariantMap(const QVariantMap& properties) { auto outlineColor = properties["outlineColor"]; if (outlineColor.isValid()) { diff --git a/interface/src/scripting/SelectionScriptingInterface.h b/interface/src/scripting/SelectionScriptingInterface.h index e27946c2fd..96cc71906f 100644 --- a/interface/src/scripting/SelectionScriptingInterface.h +++ b/interface/src/scripting/SelectionScriptingInterface.h @@ -59,7 +59,8 @@ public: public slots: void selectedItemsListChanged(const QString& listName); - void highlightStyleChanged(const QString& listName); + // void highlightStyleChanged(const QString& listName); + // void highlightStyleRemoved(const QString& listName); private: QString _listName{ "" }; @@ -137,12 +138,10 @@ public: render::HighlightStyle getHighlightStyle(const QString& listName) const; - void onSelectedItemsListChanged(const QString& listName); - void onHighlightStyleChanged(const QString& listName); - signals: void selectedItemsListChanged(const QString& listName); - void highlightStyleChanged(const QString& listName); + // void highlightStyleChanged(const QString& listName); + // void highlightStyleRemoved(const QString& listName); private: QMap _selectedItemsListMap; @@ -154,6 +153,8 @@ private: template bool removeFromGameplayObjects(const QString& listName, T idToRemove); void setupHandler(const QString& selectionName); + + }; #endif // hifi_SelectionScriptingInterface_h diff --git a/interface/src/ui/overlays/ContextOverlayInterface.cpp b/interface/src/ui/overlays/ContextOverlayInterface.cpp index cd55fa33a3..81896e7a94 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.cpp +++ b/interface/src/ui/overlays/ContextOverlayInterface.cpp @@ -70,14 +70,6 @@ ContextOverlayInterface::ContextOverlayInterface() { { _selectionScriptingInterface->enableListHighlight("contextOverlayHighlightList", QVariantMap()); - /* render::Transaction transaction; - initializeSelectionToSceneHandler(_selectionToSceneHandlers[0], "contextOverlayHighlightList", transaction); - for (auto i = 1; i < MAX_SELECTION_COUNT; i++) { - auto selectionName = QString("highlightList") + QString::number(i); - initializeSelectionToSceneHandler(_selectionToSceneHandlers[i], selectionName, transaction); - } - const render::ScenePointer& scene = qApp->getMain3DScene(); - scene->enqueueTransaction(transaction);*/ } auto nodeList = DependencyManager::get(); @@ -86,12 +78,6 @@ ContextOverlayInterface::ContextOverlayInterface() { _challengeOwnershipTimeoutTimer.setSingleShot(true); } -void ContextOverlayInterface::initializeSelectionToSceneHandler(SelectionToSceneHandler& handler, const QString& selectionName, render::Transaction& transaction) { - handler.initialize(selectionName); - connect(_selectionScriptingInterface.data(), &SelectionScriptingInterface::selectedItemsListChanged, &handler, &SelectionToSceneHandler::selectedItemsListChanged); - transaction.resetSelectionHighlight(selectionName.toStdString()); -} - static const uint32_t MOUSE_HW_ID = 0; static const uint32_t LEFT_HAND_HW_ID = 1; static const xColor CONTEXT_OVERLAY_COLOR = { 255, 255, 255 }; diff --git a/interface/src/ui/overlays/ContextOverlayInterface.h b/interface/src/ui/overlays/ContextOverlayInterface.h index 81e398e15d..990a7fe599 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.h +++ b/interface/src/ui/overlays/ContextOverlayInterface.h @@ -96,9 +96,6 @@ private: void disableEntityHighlight(const EntityItemID& entityItemID); void deletingEntity(const EntityItemID& entityItemID); - void initializeSelectionToSceneHandler(SelectionToSceneHandler& handler, const QString& selectionName, render::Transaction& transaction); - - SelectionToSceneHandler _selectionToSceneHandlers[MAX_SELECTION_COUNT]; Q_INVOKABLE void startChallengeOwnershipTimer(); QTimer _challengeOwnershipTimeoutTimer;