diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp index da771d9ff8..4d981e3d34 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp @@ -448,7 +448,7 @@ namespace AzToolsFramework switcherId); } - static void SetViewportUiClusterVisible(ViewportUi::ClusterId clusterId, bool visible) + static void SetViewportUiClusterVisible(const ViewportUi::ClusterId clusterId, const bool visible) { ViewportUi::ViewportUiRequestBus::Event( ViewportUi::DefaultViewportId, @@ -456,7 +456,7 @@ namespace AzToolsFramework clusterId, visible); } - static void SetViewportUiClusterActiveButton(ViewportUi::ClusterId clusterId, ViewportUi::ButtonId buttonId) + static void SetViewportUiClusterActiveButton(const ViewportUi::ClusterId clusterId, const ViewportUi::ButtonId buttonId) { ViewportUi::ViewportUiRequestBus::Event( ViewportUi::DefaultViewportId, @@ -464,7 +464,7 @@ namespace AzToolsFramework clusterId, buttonId); } - static ViewportUi::ButtonId RegisterClusterButton(ViewportUi::ClusterId clusterId, const char* iconName) + static ViewportUi::ButtonId RegisterClusterButton(const ViewportUi::ClusterId clusterId, const char* iconName) { ViewportUi::ButtonId buttonId; ViewportUi::ViewportUiRequestBus::EventResult( @@ -476,7 +476,7 @@ namespace AzToolsFramework } static ViewportUi::ButtonId RegisterSwitcherButton( - ViewportUi::SwitcherId switcherId, const char* iconName, const char* buttonName) + const ViewportUi::SwitcherId switcherId, const char* iconName, const char* buttonName) { ViewportUi::ButtonId buttonId; ViewportUi::ViewportUiRequestBus::EventResult( diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/Cluster.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/Cluster.h index ab97c03212..9b4977b58c 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/Cluster.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/Cluster.h @@ -18,8 +18,9 @@ namespace AzToolsFramework::ViewportUi::Internal { class Button; - //! Data class for a cluster on the Viewport UI. A cluster is defined as a group of buttons with icons + //! Data class for a button group on the Viewport UI. A button group is defined as a group of buttons with icons //! each of which can be clicked to trigger an event e.g. toggling between modes. + //! @note This can be used with either a Cluster or a Switcher with slightly different visuals for each. class ButtonGroup { public: diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiManager.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiManager.cpp index 694ef83c7c..f572607981 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiManager.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiManager.cpp @@ -76,7 +76,7 @@ namespace AzToolsFramework::ViewportUi } } - void ViewportUiManager::RegisterSwitcherEventHandler(SwitcherId switcherId, AZ::Event::Handler& handler) + void ViewportUiManager::RegisterSwitcherEventHandler(const SwitcherId switcherId, AZ::Event::Handler& handler) { if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end()) { @@ -146,13 +146,22 @@ namespace AzToolsFramework::ViewportUi void ViewportUiManager::SetClusterVisible(ClusterId clusterId, bool visible) { - if (auto clusterEntry = m_clusterButtonGroups.find(clusterId); clusterEntry != m_clusterButtonGroups.end()) + if (auto clusterIt = m_clusterButtonGroups.find(clusterId); clusterIt != m_clusterButtonGroups.end()) { - auto cluster = clusterEntry->second; + auto cluster = clusterIt->second; SetViewportUiElementVisible(m_viewportUi.get(), cluster->GetViewportUiElementId(), visible); } } + void ViewportUiManager::SetSwitcherVisible(SwitcherId switcherId, bool visible) + { + if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end()) + { + auto switcher = switcherIt->second; + SetViewportUiElementVisible(m_viewportUi.get(), switcher->GetViewportUiElementId(), visible); + } + } + void ViewportUiManager::SetClusterGroupVisible(const AZStd::vector& clusterGroup, bool visible) { for (auto clusterId : clusterGroup) @@ -174,9 +183,9 @@ namespace AzToolsFramework::ViewportUi void ViewportUiManager::SetTextFieldText(TextFieldId textFieldId, const AZStd::string& text) { - if (auto textFieldEntry = m_textFields.find(textFieldId); textFieldEntry != m_textFields.end()) + if (auto textFieldIt = m_textFields.find(textFieldId); textFieldIt != m_textFields.end()) { - auto textField = textFieldEntry->second; + auto textField = textFieldIt->second; textField->m_fieldText = text; UpdateTextFieldUi(textField.get()); } @@ -185,27 +194,27 @@ namespace AzToolsFramework::ViewportUi void ViewportUiManager::RegisterTextFieldCallback( TextFieldId textFieldId, AZ::Event::Handler& handler) { - if (auto textFieldEntry = m_textFields.find(textFieldId); textFieldEntry != m_textFields.end()) + if (auto textFieldIt = m_textFields.find(textFieldId); textFieldIt != m_textFields.end()) { - auto textField = textFieldEntry->second; + auto textField = textFieldIt->second; textField->ConnectEventHandler(handler); } } void ViewportUiManager::RemoveTextField(TextFieldId textFieldId) { - if (auto textFieldEntry = m_textFields.find(textFieldId); textFieldEntry != m_textFields.end()) + if (auto textFieldIt = m_textFields.find(textFieldId); textFieldIt != m_textFields.end()) { - m_textFields.erase(textFieldEntry); - m_viewportUi->RemoveViewportUiElement(textFieldEntry->second->m_viewportId); + m_textFields.erase(textFieldIt); + m_viewportUi->RemoveViewportUiElement(textFieldIt->second->m_viewportId); } } void ViewportUiManager::SetTextFieldVisible(TextFieldId textFieldId, bool visible) { - if (auto textFieldEntry = m_textFields.find(textFieldId); textFieldEntry != m_textFields.end()) + if (auto textFieldIt = m_textFields.find(textFieldId); textFieldIt != m_textFields.end()) { - auto textField = textFieldEntry->second; + auto textField = textFieldIt->second; SetViewportUiElementVisible(m_viewportUi.get(), textField->m_viewportId, visible); } } @@ -224,19 +233,19 @@ namespace AzToolsFramework::ViewportUi void ViewportUiManager::PressButton(ClusterId clusterId, ButtonId buttonId) { // Find cluster using ID and cluster map - if (auto clusterEntry = m_clusterButtonGroups.find(clusterId); - clusterEntry != m_clusterButtonGroups.end()) + if (auto clusterIt = m_clusterButtonGroups.find(clusterId); + clusterIt != m_clusterButtonGroups.end()) { - clusterEntry->second->PressButton(buttonId); + clusterIt->second->PressButton(buttonId); } } void ViewportUiManager::PressButton(SwitcherId switcherId, ButtonId buttonId) { // Find cluster using ID and cluster map - if (auto switcherEntry = m_switcherButtonGroups.find(switcherId); switcherEntry != m_switcherButtonGroups.end()) + if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end()) { - switcherEntry->second->PressButton(buttonId); + switcherIt->second->PressButton(buttonId); } } @@ -264,9 +273,9 @@ namespace AzToolsFramework::ViewportUi { UpdateButtonGroupUi(buttonGroup.second.get()); } - for (auto textFieldEntry : m_textFields) + for (auto textField : m_textFields) { - UpdateTextFieldUi(textFieldEntry.second.get()); + UpdateTextFieldUi(textField.second.get()); } } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiManager.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiManager.h index de3b52c620..dd79b2c0d3 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiManager.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiManager.h @@ -1,14 +1,14 @@ /* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ #pragma once @@ -29,31 +29,30 @@ namespace AzToolsFramework::ViewportUi public: ViewportUiManager() = default; ~ViewportUiManager() = default; - + // ViewportUiRequestBus ... const ClusterId CreateCluster() override; const SwitcherId CreateSwitcher(ButtonId currMode) override; void SetClusterActiveButton(ClusterId clusterId, ButtonId buttonId) override; void SetSwitcherActiveButton(SwitcherId switcherId, ButtonId buttonId) override; const ButtonId CreateClusterButton(ClusterId clusterId, const AZStd::string& icon) override; - const ButtonId CreateSwitcherButton(SwitcherId switcherId, const AZStd::string& icon, const AZStd::string& name = AZStd::string()) override; + const ButtonId CreateSwitcherButton( + SwitcherId switcherId, const AZStd::string& icon, const AZStd::string& name = AZStd::string()) override; void RegisterClusterEventHandler(ClusterId clusterId, AZ::Event::Handler& handler) override; void RegisterSwitcherEventHandler(SwitcherId switcherId, AZ::Event::Handler& handler) override; void RemoveCluster(ClusterId clusterId) override; void RemoveSwitcher(SwitcherId switcherId) override; void SetClusterVisible(ClusterId clusterId, bool visible); + void SetSwitcherVisible(SwitcherId switcherId, bool visible); void SetClusterGroupVisible(const AZStd::vector& clusterGroup, bool visible) override; const TextFieldId CreateTextField( - const AZStd::string& labelText, const AZStd::string& textFieldDefaultText, - TextFieldValidationType validationType) override; + const AZStd::string& labelText, const AZStd::string& textFieldDefaultText, TextFieldValidationType validationType) override; void SetTextFieldText(TextFieldId textFieldId, const AZStd::string& text) override; - void RegisterTextFieldCallback( - TextFieldId textFieldId, AZ::Event::Handler& handler) override; + void RegisterTextFieldCallback(TextFieldId textFieldId, AZ::Event::Handler& handler) override; void RemoveTextField(TextFieldId textFieldId) override; void SetTextFieldVisible(TextFieldId textFieldId, bool visible) override; void CreateComponentModeBorder(const AZStd::string& borderTitle) override; void RemoveComponentModeBorder() override; - void PressButton(ClusterId clusterId, ButtonId buttonId) override; void PressButton(SwitcherId switcherId, ButtonId buttonId) override; @@ -67,21 +66,22 @@ namespace AzToolsFramework::ViewportUi void Update(); protected: - AZStd::unordered_map> m_clusterButtonGroups; //!< A map of all registered clusters. - AZStd::unordered_map> m_switcherButtonGroups; //!< A map of all registered clusters. + AZStd::unordered_map> + m_clusterButtonGroups; //!< A map of all registered Clusters. + AZStd::unordered_map> + m_switcherButtonGroups; //!< A map of all registered Switchers. + AZStd::unordered_map> m_textFields; //!< A map of all registered TextFields. - AZStd::unordered_map> m_textFields; //!< A map of all registered textFields. AZStd::unique_ptr m_viewportUi; //!< The lower level graphical API for Viewport UI. private: - //! Register a new cluster and return its id. + //! Register a new Cluster and return its id. ClusterId RegisterNewCluster(AZStd::shared_ptr& buttonGroup); - //! Register a new cluster and return its id. + //! Register a new Switcher and return its id. SwitcherId RegisterNewSwitcher(AZStd::shared_ptr& buttonGroup); - //! Register a new text field and return its id. TextFieldId RegisterNewTextField(AZStd::shared_ptr& textField); - //! Update the corresponding ui element for the given cluster. + //! Update the corresponding ui element for the given button group. void UpdateButtonGroupUi(Internal::ButtonGroup* buttonGroup); //! Update the corresponding ui element for the given text field. void UpdateTextFieldUi(Internal::TextField* textField);