updates to viewport ui switcher id and usage

This commit is contained in:
hultonha
2021-04-24 18:35:24 +01:00
parent cc4d69f279
commit b27daeead5
13 changed files with 164 additions and 135 deletions
@@ -441,11 +441,11 @@ namespace AzToolsFramework
clusterId);
}
static void RemoveTestSwitcher(const ViewportUi::ClusterId clusterId)
static void RemoveTestSwitcher(const ViewportUi::SwitcherId switcherId)
{
ViewportUi::ViewportUiRequestBus::Event(
ViewportUi::DefaultViewportId, &ViewportUi::ViewportUiRequestBus::Events::RemoveCluster,
clusterId);
ViewportUi::DefaultViewportId, &ViewportUi::ViewportUiRequestBus::Events::RemoveSwitcher,
switcherId);
}
static void SetViewportUiClusterVisible(ViewportUi::ClusterId clusterId, bool visible)
@@ -476,12 +476,12 @@ namespace AzToolsFramework
}
static ViewportUi::ButtonId RegisterSwitcherButton(
ViewportUi::ClusterId clusterId, const char* iconName, const char* buttonName)
ViewportUi::SwitcherId switcherId, const char* iconName, const char* buttonName)
{
ViewportUi::ButtonId buttonId;
ViewportUi::ViewportUiRequestBus::EventResult(
buttonId, ViewportUi::DefaultViewportId,
&ViewportUi::ViewportUiRequestBus::Events::CreateSwitcherButton, clusterId,
&ViewportUi::ViewportUiRequestBus::Events::CreateSwitcherButton, switcherId,
AZStd::string::format("Editor/Icons/Switcher/%s.svg", iconName), buttonName);
return buttonId;
@@ -2624,7 +2624,7 @@ namespace AzToolsFramework
m_testSwitcherHandler = AZ::Event<ViewportUi::ButtonId>::Handler(onButtonClicked);
ViewportUi::ViewportUiRequestBus::Event(
ViewportUi::DefaultViewportId, &ViewportUi::ViewportUiRequestBus::Events::RegisterClusterEventHandler, m_testSwitcherId,
ViewportUi::DefaultViewportId, &ViewportUi::ViewportUiRequestBus::Events::RegisterSwitcherEventHandler, m_testSwitcherId,
m_testSwitcherHandler);
}
@@ -285,7 +285,7 @@ namespace AzToolsFramework
//! Create the Viewport UI Switcher. TEST
void CreateTestSwitcher();
ViewportUi::ClusterId m_testSwitcherId;
ViewportUi::SwitcherId m_testSwitcherId;
ViewportUi::ButtonId m_boxShapeButtonId;
ViewportUi::ButtonId m_physxColliderButtonId;
ViewportUi::ButtonId m_transformButtonId;
@@ -18,33 +18,23 @@
namespace AzToolsFramework::ViewportUi::Internal
{
Cluster::Cluster()
ButtonGroup::ButtonGroup()
: m_buttons()
, m_buttonTriggeredEvent()
{
}
void Cluster::SetViewportUiElementId(const ViewportUiElementId id)
void ButtonGroup::SetViewportUiElementId(const ViewportUiElementId id)
{
m_viewportUiId = id;
}
ViewportUiElementId Cluster::GetViewportUiElementId() const
ViewportUiElementId ButtonGroup::GetViewportUiElementId() const
{
return m_viewportUiId;
}
void Cluster::SetClusterId(const ClusterId clusterId)
{
m_clusterId = clusterId;
}
ClusterId Cluster::GetClusterId() const
{
return m_clusterId;
}
void Cluster::SetHighlightedButton(ButtonId buttonId)
void ButtonGroup::SetHighlightedButton(ButtonId buttonId)
{
if (auto buttonEntry = m_buttons.find(buttonId); buttonEntry != m_buttons.end())
{
@@ -56,7 +46,7 @@ namespace AzToolsFramework::ViewportUi::Internal
}
}
ButtonId Cluster::AddButton(const AZStd::string& icon, const AZStd::string& name)
ButtonId ButtonGroup::AddButton(const AZStd::string& icon, const AZStd::string& name)
{
auto buttonId = ButtonId(m_buttons.size() + 1);
@@ -71,7 +61,7 @@ namespace AzToolsFramework::ViewportUi::Internal
return buttonId;
}
Button* Cluster::GetButton(ButtonId buttonId)
Button* ButtonGroup::GetButton(ButtonId buttonId)
{
if (auto buttonEntry = m_buttons.find(buttonId); buttonEntry != m_buttons.end())
{
@@ -80,7 +70,7 @@ namespace AzToolsFramework::ViewportUi::Internal
return nullptr;
}
AZStd::vector<Button*> Cluster::GetButtons()
AZStd::vector<Button*> ButtonGroup::GetButtons()
{
auto buttons = AZStd::vector<Button*>();
for (const auto& button : m_buttons)
@@ -90,11 +80,11 @@ namespace AzToolsFramework::ViewportUi::Internal
return buttons;
}
void Cluster::ConnectEventHandler(AZ::Event<ButtonId>::Handler& handler) {
void ButtonGroup::ConnectEventHandler(AZ::Event<ButtonId>::Handler& handler) {
handler.Connect(m_buttonTriggeredEvent);
}
void Cluster::PressButton(ButtonId buttonId)
void ButtonGroup::PressButton(ButtonId buttonId)
{
m_buttonTriggeredEvent.Signal(buttonId);
}
@@ -20,20 +20,17 @@ namespace AzToolsFramework::ViewportUi::Internal
//! Data class for a cluster on the Viewport UI. A cluster is defined as a group of buttons with icons
//! each of which can be clicked to trigger an event e.g. toggling between modes.
class Cluster
class ButtonGroup
{
public:
Cluster();
~Cluster() = default;
ButtonGroup();
~ButtonGroup() = default;
void SetHighlightedButton(ButtonId buttonId);
void SetViewportUiElementId(ViewportUiElementId id);
ViewportUiElementId GetViewportUiElementId() const;
void SetClusterId(ClusterId id);
ClusterId GetClusterId() const;
ButtonId AddButton(const AZStd::string& icon, const AZStd::string& name = AZStd::string());
Button* GetButton(ButtonId buttonId);
AZStd::vector<Button*> GetButtons();
@@ -44,7 +41,6 @@ namespace AzToolsFramework::ViewportUi::Internal
private:
AZ::Event<ButtonId> m_buttonTriggeredEvent;
ViewportUiElementId m_viewportUiId;
ClusterId m_clusterId;
AZStd::unordered_map<ButtonId, AZStd::unique_ptr<Button>> m_buttons;
};
} // namespace AzToolsFramework::ViewportUi::Internal
@@ -16,14 +16,14 @@
namespace AzToolsFramework::ViewportUi::Internal
{
ViewportUiCluster::ViewportUiCluster(AZStd::shared_ptr<Cluster> cluster)
ViewportUiCluster::ViewportUiCluster(AZStd::shared_ptr<ButtonGroup> buttonGroup)
: QToolBar(nullptr)
, m_cluster(cluster)
, m_buttonGroup(buttonGroup)
{
setOrientation(Qt::Orientation::Vertical);
setStyleSheet("background: black;");
const AZStd::vector<Button*> buttons = cluster->GetButtons();
const AZStd::vector<Button*> buttons = buttonGroup->GetButtons();
for (auto button : buttons)
{
RegisterButton(button);
@@ -39,7 +39,7 @@ namespace AzToolsFramework::ViewportUi::Internal
AddClusterAction(
action,
[this, button]() {
m_cluster->PressButton(button->m_buttonId);
m_buttonGroup->PressButton(button->m_buttonId);
},
[button](QAction* action) {
action->setChecked(button->m_state == Button::State::Selected);
@@ -18,10 +18,10 @@
#include <AzToolsFramework/ViewportUi/ViewportUiWidgetCallbacks.h>
#include <QToolBar>
class Cluster;
namespace AzToolsFramework::ViewportUi::Internal
{
class ButtonGroup;
//! Helper class to make clusters (toolbars) for display in Viewport UI.
class ViewportUiCluster
: public QToolBar
@@ -29,7 +29,7 @@ namespace AzToolsFramework::ViewportUi::Internal
Q_OBJECT
public:
ViewportUiCluster(AZStd::shared_ptr<Cluster> cluster);
ViewportUiCluster(AZStd::shared_ptr<ButtonGroup> buttonGroup);
~ViewportUiCluster() = default;
//! Adds a new button to the cluster.
@@ -49,7 +49,7 @@ namespace AzToolsFramework::ViewportUi::Internal
//! Removes an action from the Viewport UI Cluster.
void RemoveClusterAction(QAction* action);
AZStd::shared_ptr<Cluster> m_cluster; //!< Data structure which the cluster will be displaying to the Viewport UI.
AZStd::shared_ptr<ButtonGroup> m_buttonGroup; //!< Data structure which the cluster will be displaying to the Viewport UI.
AZStd::unordered_map<ButtonId, QPointer<QAction>> m_buttonActionMap; //!< Map for buttons to their corresponding actions.
ViewportUiWidgetCallbacks m_widgetCallbacks; //!< Registers actions and manages updates.
};
@@ -56,16 +56,16 @@ namespace AzToolsFramework::ViewportUi::Internal
UnparentWidgets(m_viewportUiElements);
}
void ViewportUiDisplay::AddCluster(AZStd::shared_ptr<Cluster> cluster)
void ViewportUiDisplay::AddCluster(AZStd::shared_ptr<ButtonGroup> buttonGroup)
{
if (!cluster.get())
if (!buttonGroup.get())
{
return;
}
auto viewportUiCluster = AZStd::make_shared<ViewportUiCluster>(cluster);
auto viewportUiCluster = AZStd::make_shared<ViewportUiCluster>(buttonGroup);
auto id = AddViewportUiElement(viewportUiCluster);
cluster->SetViewportUiElementId(id);
buttonGroup->SetViewportUiElementId(id);
PositionViewportUiElementAnchored(id, Qt::AlignTop | Qt::AlignLeft);
}
@@ -94,16 +94,16 @@ namespace AzToolsFramework::ViewportUi::Internal
}
}
void ViewportUiDisplay::AddSwitcher(AZStd::shared_ptr<Cluster> cluster, ButtonId currMode)
void ViewportUiDisplay::AddSwitcher(AZStd::shared_ptr<ButtonGroup> buttonGroup, ButtonId currMode)
{
if (!cluster.get())
if (!buttonGroup.get())
{
return;
}
auto viewportUiSwitcher = AZStd::make_shared<ViewportUiSwitcher>(cluster, currMode);
auto viewportUiSwitcher = AZStd::make_shared<ViewportUiSwitcher>(buttonGroup, currMode);
auto id = AddViewportUiElement(viewportUiSwitcher);
cluster->SetViewportUiElementId(id);
buttonGroup->SetViewportUiElementId(id);
PositionViewportUiElementAnchored(id, Qt::AlignTop | Qt::AlignLeft);
}
@@ -56,12 +56,12 @@ namespace AzToolsFramework::ViewportUi::Internal
ViewportUiDisplay(QWidget* parent, QWidget* renderOverlay);
~ViewportUiDisplay();
void AddCluster(AZStd::shared_ptr<Cluster> cluster);
void AddCluster(AZStd::shared_ptr<ButtonGroup> buttonGroup);
void AddClusterButton(ViewportUiElementId clusterId, Button* button);
void RemoveClusterButton(ViewportUiElementId clusterId, ButtonId buttonId);
void UpdateCluster(const ViewportUiElementId clusterId);
void AddSwitcher(AZStd::shared_ptr<Cluster> cluster, ButtonId currMode);
void AddSwitcher(AZStd::shared_ptr<ButtonGroup> buttonGroup, ButtonId currMode);
void AddSwitcherButton(ViewportUiElementId clusterId, Button* button);
void RemoveSwitcherButton(ViewportUiElementId clusterId, ButtonId buttonId);
void UpdateSwitcher(const ViewportUiElementId clusterId);
@@ -32,55 +32,64 @@ namespace AzToolsFramework::ViewportUi
const ClusterId ViewportUiManager::CreateCluster()
{
auto cluster = AZStd::make_shared<Internal::Cluster>();
m_viewportUi->AddCluster(cluster);
auto buttonGroup = AZStd::make_shared<Internal::ButtonGroup>();
m_viewportUi->AddCluster(buttonGroup);
return RegisterNewCluster(cluster);
return RegisterNewCluster(buttonGroup);
}
const ClusterId ViewportUiManager::CreateSwitcher(ButtonId currMode)
const SwitcherId ViewportUiManager::CreateSwitcher(ButtonId currMode)
{
auto cluster = AZStd::make_shared<Internal::Cluster>();
m_viewportUi->AddSwitcher(cluster, currMode);
auto buttonGroup = AZStd::make_shared<Internal::ButtonGroup>();
m_viewportUi->AddSwitcher(buttonGroup, currMode);
return RegisterNewCluster(cluster);
return RegisterNewSwitcher(buttonGroup);
}
void ViewportUiManager::SetClusterActiveButton(const ClusterId clusterId, const ButtonId buttonId)
{
if (auto clusterEntry = m_clusters.find(clusterId); clusterEntry != m_clusters.end())
if (auto clusterIt = m_clusterButtonGroups.find(clusterId); clusterIt != m_clusterButtonGroups.end())
{
auto cluster = clusterEntry->second;
auto cluster = clusterIt->second;
cluster->SetHighlightedButton(buttonId);
UpdateClusterUi(cluster.get());
UpdateButtonGroupUi(cluster.get());
}
}
void ViewportUiManager::SetSwitcherActiveButton(const ClusterId clusterId, const ButtonId buttonId)
void ViewportUiManager::SetSwitcherActiveButton(const SwitcherId switcherId, const ButtonId buttonId)
{
if (auto clusterEntry = m_clusters.find(clusterId); clusterEntry != m_clusters.end())
if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end())
{
auto cluster = clusterEntry->second;
cluster->SetHighlightedButton(buttonId);
m_viewportUi->SetSwitcherActiveMode(cluster->GetViewportUiElementId(), buttonId);
UpdateSwitcherUi(cluster.get());
auto switcher = switcherIt->second;
switcher->SetHighlightedButton(buttonId);
m_viewportUi->SetSwitcherActiveMode(switcher->GetViewportUiElementId(), buttonId);
UpdateButtonGroupUi(switcher.get());
}
}
void ViewportUiManager::RegisterClusterEventHandler(const ClusterId clusterId, AZ::Event<ButtonId>::Handler& handler)
{
if (auto clusterEntry = m_clusters.find(clusterId); clusterEntry != m_clusters.end())
if (auto clusterIt = m_clusterButtonGroups.find(clusterId); clusterIt != m_clusterButtonGroups.end())
{
auto cluster = clusterEntry->second;
auto cluster = clusterIt->second;
cluster->ConnectEventHandler(handler);
}
}
void ViewportUiManager::RegisterSwitcherEventHandler(SwitcherId switcherId, AZ::Event<ButtonId>::Handler& handler)
{
if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end())
{
auto switcher = switcherIt->second;
switcher->ConnectEventHandler(handler);
}
}
const ButtonId ViewportUiManager::CreateClusterButton(const ClusterId clusterId, const AZStd::string& icon)
{
if (auto clusterEntry = m_clusters.find(clusterId); clusterEntry != m_clusters.end())
if (auto clusterIt = m_clusterButtonGroups.find(clusterId); clusterIt != m_clusterButtonGroups.end())
{
auto cluster = clusterEntry->second;
auto cluster = clusterIt->second;
auto newId = cluster->AddButton(icon);
m_viewportUi->AddClusterButton(cluster->GetViewportUiElementId(), cluster->GetButton(newId));
@@ -90,13 +99,13 @@ namespace AzToolsFramework::ViewportUi
return ButtonId(0);
}
const ButtonId ViewportUiManager::CreateSwitcherButton(const ClusterId clusterId, const AZStd::string& icon, const AZStd::string& name)
const ButtonId ViewportUiManager::CreateSwitcherButton(const SwitcherId switcherId, const AZStd::string& icon, const AZStd::string& name)
{
if (auto clusterEntry = m_clusters.find(clusterId); clusterEntry != m_clusters.end())
if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end())
{
auto cluster = clusterEntry->second;
auto newId = cluster->AddButton(icon, name);
m_viewportUi->AddSwitcherButton(cluster->GetViewportUiElementId(), cluster->GetButton(newId));
auto switcher = switcherIt->second;
auto newId = switcher->AddButton(icon, name);
m_viewportUi->AddSwitcherButton(switcher->GetViewportUiElementId(), switcher->GetButton(newId));
return newId;
}
@@ -106,10 +115,19 @@ namespace AzToolsFramework::ViewportUi
void ViewportUiManager::RemoveCluster(const ClusterId clusterId)
{
if (auto clusterEntry = m_clusters.find(clusterId); clusterEntry != m_clusters.end())
if (auto clusterIt = m_clusterButtonGroups.find(clusterId); clusterIt != m_clusterButtonGroups.end())
{
m_clusters.erase(clusterEntry);
m_viewportUi->RemoveViewportUiElement(clusterEntry->second->GetViewportUiElementId());
m_clusterButtonGroups.erase(clusterIt);
m_viewportUi->RemoveViewportUiElement(clusterIt->second->GetViewportUiElementId());
}
}
void ViewportUiManager::RemoveSwitcher(SwitcherId switcherId)
{
if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end())
{
m_switcherButtonGroups.erase(switcherIt);
m_viewportUi->RemoveViewportUiElement(switcherIt->second->GetViewportUiElementId());
}
}
@@ -128,7 +146,7 @@ namespace AzToolsFramework::ViewportUi
void ViewportUiManager::SetClusterVisible(ClusterId clusterId, bool visible)
{
if (auto clusterEntry = m_clusters.find(clusterId); clusterEntry != m_clusters.end())
if (auto clusterEntry = m_clusterButtonGroups.find(clusterId); clusterEntry != m_clusterButtonGroups.end())
{
auto cluster = clusterEntry->second;
SetViewportUiElementVisible(m_viewportUi.get(), cluster->GetViewportUiElementId(), visible);
@@ -206,13 +224,22 @@ namespace AzToolsFramework::ViewportUi
void ViewportUiManager::PressButton(ClusterId clusterId, ButtonId buttonId)
{
// Find cluster using ID and cluster map
if (auto clusterEntry = m_clusters.find(clusterId);
clusterEntry != m_clusters.end())
if (auto clusterEntry = m_clusterButtonGroups.find(clusterId);
clusterEntry != m_clusterButtonGroups.end())
{
clusterEntry->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())
{
switcherEntry->second->PressButton(buttonId);
}
}
void ViewportUiManager::InitializeViewportUi(QWidget* parent, QWidget* renderOverlay)
{
if (m_viewportUi)
@@ -229,9 +256,13 @@ namespace AzToolsFramework::ViewportUi
{
m_viewportUi->Update();
for (auto clusterEntry : m_clusters)
for (auto buttonGroup : m_clusterButtonGroups)
{
UpdateClusterUi(clusterEntry.second.get());
UpdateButtonGroupUi(buttonGroup.second.get());
}
for (auto buttonGroup : m_switcherButtonGroups)
{
UpdateButtonGroupUi(buttonGroup.second.get());
}
for (auto textFieldEntry : m_textFields)
{
@@ -239,11 +270,18 @@ namespace AzToolsFramework::ViewportUi
}
}
ClusterId ViewportUiManager::RegisterNewCluster(AZStd::shared_ptr<Internal::Cluster>& cluster)
ClusterId ViewportUiManager::RegisterNewCluster(AZStd::shared_ptr<Internal::ButtonGroup>& buttonGroup)
{
ClusterId newId = ClusterId(m_clusters.size() + 1);
cluster->SetClusterId(newId);
m_clusters.insert({ newId, cluster });
ClusterId newId = ClusterId(m_clusterButtonGroups.size() + 1);
m_clusterButtonGroups.insert({ newId, buttonGroup });
return newId;
}
SwitcherId ViewportUiManager::RegisterNewSwitcher(AZStd::shared_ptr<Internal::ButtonGroup>& buttonGroup)
{
SwitcherId newId = SwitcherId(m_switcherButtonGroups.size() + 1);
m_switcherButtonGroups.insert({newId, buttonGroup});
return newId;
}
@@ -257,14 +295,9 @@ namespace AzToolsFramework::ViewportUi
return newId;
}
void ViewportUiManager::UpdateClusterUi(Internal::Cluster* cluster)
void ViewportUiManager::UpdateButtonGroupUi(Internal::ButtonGroup* buttonGroup)
{
m_viewportUi->UpdateCluster(cluster->GetViewportUiElementId());
}
void ViewportUiManager::UpdateSwitcherUi(Internal::Cluster* cluster)
{
m_viewportUi->UpdateSwitcher(cluster->GetViewportUiElementId());
m_viewportUi->UpdateCluster(buttonGroup->GetViewportUiElementId());
}
void ViewportUiManager::UpdateTextFieldUi(Internal::TextField* textField)
@@ -32,13 +32,15 @@ namespace AzToolsFramework::ViewportUi
// ViewportUiRequestBus ...
const ClusterId CreateCluster() override;
const ClusterId CreateSwitcher(ButtonId currMode) override;
const SwitcherId CreateSwitcher(ButtonId currMode) override;
void SetClusterActiveButton(ClusterId clusterId, ButtonId buttonId) override;
void SetSwitcherActiveButton(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(ClusterId clusterId, 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<ButtonId>::Handler& handler) override;
void RegisterSwitcherEventHandler(SwitcherId switcherId, AZ::Event<ButtonId>::Handler& handler) override;
void RemoveCluster(ClusterId clusterId) override;
void RemoveSwitcher(SwitcherId switcherId) override;
void SetClusterVisible(ClusterId clusterId, bool visible);
void SetClusterGroupVisible(const AZStd::vector<ClusterId>& clusterGroup, bool visible) override;
const TextFieldId CreateTextField(
@@ -51,7 +53,9 @@ namespace AzToolsFramework::ViewportUi
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;
//! Connects to the correct viewportId bus address.
void ConnectViewportUiBus(const int viewportId);
@@ -63,19 +67,22 @@ namespace AzToolsFramework::ViewportUi
void Update();
protected:
AZStd::unordered_map<ClusterId, AZStd::shared_ptr<Internal::Cluster>> m_clusters; //!< A map of all registered clusters.
AZStd::unordered_map<ClusterId, AZStd::shared_ptr<Internal::ButtonGroup>> m_clusterButtonGroups; //!< A map of all registered clusters.
AZStd::unordered_map<SwitcherId, AZStd::shared_ptr<Internal::ButtonGroup>> m_switcherButtonGroups; //!< A map of all registered clusters.
AZStd::unordered_map<TextFieldId, AZStd::shared_ptr<Internal::TextField>> m_textFields; //!< A map of all registered textFields.
AZStd::unique_ptr<Internal::ViewportUiDisplay> m_viewportUi; //!< The lower level graphical API for Viewport UI.
private:
//! Register a new cluster and return its id.
ClusterId RegisterNewCluster(AZStd::shared_ptr<Internal::Cluster>& cluster);
ClusterId RegisterNewCluster(AZStd::shared_ptr<Internal::ButtonGroup>& buttonGroup);
//! Register a new cluster and return its id.
SwitcherId RegisterNewSwitcher(AZStd::shared_ptr<Internal::ButtonGroup>& buttonGroup);
//! Register a new text field and return its id.
TextFieldId RegisterNewTextField(AZStd::shared_ptr<Internal::TextField>& textField);
//! Update the corresponding ui element for the given cluster.
void UpdateClusterUi(Internal::Cluster* cluster);
//! Update the corresponding ui element for the given cluster.
void UpdateSwitcherUi(Internal::Cluster* cluster);
void UpdateButtonGroupUi(Internal::ButtonGroup* buttonGroup);
//! Update the corresponding ui element for the given text field.
void UpdateTextFieldUi(Internal::TextField* textField);
};
@@ -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
@@ -23,11 +23,13 @@ namespace AzToolsFramework::ViewportUi
using ViewportUiElementId = IdType<struct ViewportUiIdType>;
using ButtonId = IdType<struct ButtonIdType>;
using ClusterId = IdType<struct ClusterIdType>;
using SwitcherId = IdType<struct SwitcherIdType>;
using TextFieldId = IdType<struct TextFieldIdType>;
inline const ViewportUiElementId InvalidViewportUiElementId = ViewportUiElementId(0);
inline const ButtonId InvalidButtonId = ButtonId(0);
inline const ClusterId InvalidClusterId = ClusterId(0);
inline const SwitcherId InvalidSwitcherId = SwitcherId(0);
inline const int DefaultViewportId = 0;
@@ -47,33 +49,36 @@ namespace AzToolsFramework::ViewportUi
//! Creates and registers a cluster with the Viewport UI system.
virtual const ClusterId CreateCluster() = 0;
//! Creates and registers a switcher with the Viewport UI system.
virtual const ClusterId CreateSwitcher(ButtonId currMode) = 0;
virtual const SwitcherId CreateSwitcher(ButtonId currMode) = 0;
//! Sets the active button of the cluster. This is the button which will display as highlighted.
virtual void SetClusterActiveButton(ClusterId clusterId, ButtonId buttonId) = 0;
//! Sets the active button of the switcher. This is the button which will display as highlighted.
//! Maybe update this comment
virtual void SetSwitcherActiveButton(ClusterId clusterId, ButtonId buttonId) = 0;
virtual void SetSwitcherActiveButton(SwitcherId clusterId, ButtonId buttonId) = 0;
//! Registers a new button onto a cluster.
virtual const ButtonId CreateClusterButton(const ClusterId clusterId, const AZStd::string& icon) = 0;
//! Registers a new button onto a switcher.
virtual const ButtonId CreateSwitcherButton(const ClusterId clusterId, const AZStd::string& icon, const AZStd::string& name = AZStd::string()) = 0;
virtual const ButtonId CreateSwitcherButton(
const SwitcherId switcherId, const AZStd::string& icon, const AZStd::string& name = AZStd::string()) = 0;
//! Registers an event handler to handle events from the cluster.
virtual void RegisterClusterEventHandler(ClusterId clusterId, AZ::Event<ButtonId>::Handler& handler) = 0;
//! Registers an event handler to handle events from the cluster.
virtual void RegisterSwitcherEventHandler(SwitcherId switcherId, AZ::Event<ButtonId>::Handler& handler) = 0;
//! Removes a cluster from the Viewport UI system.
virtual void RemoveCluster(ClusterId clusterId) = 0;
//!
virtual void RemoveSwitcher(SwitcherId switcherId) = 0;
//! Sets the visibility of the cluster.
virtual void SetClusterVisible(ClusterId clusterId, bool visible) = 0;
//! Sets the visibility of multiple clusters.
virtual void SetClusterGroupVisible(const AZStd::vector<ClusterId>& clusterGroup, bool visible) = 0;
//! Creates and registers a text field with the Viewport UI system.
virtual const TextFieldId CreateTextField(
const AZStd::string& labelText, const AZStd::string& textFieldDefaultText,
TextFieldValidationType validationType) = 0;
const AZStd::string& labelText, const AZStd::string& textFieldDefaultText, TextFieldValidationType validationType) = 0;
//! Set the text that will go inside the text field.
virtual void SetTextFieldText(TextFieldId textFieldId, const AZStd::string& text) = 0;
//! Register an event handler to handle when the text field text changes.
virtual void RegisterTextFieldCallback(
TextFieldId textFieldId, AZ::Event<AZStd::string>::Handler& handler) = 0;
virtual void RegisterTextFieldCallback(TextFieldId textFieldId, AZ::Event<AZStd::string>::Handler& handler) = 0;
//! Removes a text field from the Viewport UI system.
virtual void RemoveTextField(TextFieldId textFieldId) = 0;
//! Sets the visibility of the text field.
@@ -84,11 +89,12 @@ namespace AzToolsFramework::ViewportUi
virtual void RemoveComponentModeBorder() = 0;
//! Invoke a button press in a cluster.
virtual void PressButton(ClusterId clusterId, ButtonId buttonId) = 0;
//!
virtual void PressButton(SwitcherId switcherId, ButtonId buttonId) = 0;
};
/// The EBusTraits for ViewportInteractionRequests.
class ViewportUiBusTraits
: public AZ::EBusTraits
class ViewportUiBusTraits : public AZ::EBusTraits
{
public:
using BusIdType = int; ///< ViewportId - used to address requests to this EBus.
@@ -3,8 +3,8 @@
namespace AzToolsFramework::ViewportUi::Internal
{
ViewportUiSwitcher::ViewportUiSwitcher(AZStd::shared_ptr<Cluster> switcher, ButtonId currentMode)
: m_switcher(switcher)
ViewportUiSwitcher::ViewportUiSwitcher(AZStd::shared_ptr<ButtonGroup> buttonGroup, ButtonId currentMode)
: m_buttonGroup(buttonGroup)
, m_currentMode(currentMode)
{
setOrientation(Qt::Orientation::Horizontal);
@@ -12,7 +12,7 @@ namespace AzToolsFramework::ViewportUi::Internal
"QToolButton {background-color: #464646; border: outset; border-color: white; border-radius: 7px; "
"border-width: 2px; padding: 7px; color: white;}"));
const AZStd::vector<Button*> buttons = switcher->GetButtons();
const AZStd::vector<Button*> buttons = buttonGroup->GetButtons();
for (auto button : buttons)
{
@@ -63,7 +63,7 @@ namespace AzToolsFramework::ViewportUi::Internal
// resize to fit new action with minimum extra space
resize(minimumSizeHint());
const AZStd::function<void()>&callback = [this, button]() { m_switcher->PressButton(button->m_buttonId); };
const AZStd::function<void()>& callback = [this, button]() { m_buttonGroup->PressButton(button->m_buttonId); };
const AZStd::function<void(QAction*)>& updateCallback = [button](QAction* action) {
action->setChecked(button->m_state == Button::State::Selected);
};
@@ -94,8 +94,8 @@ namespace AzToolsFramework::ViewportUi::Internal
void ViewportUiSwitcher::SetActiveMode(ButtonId buttonId)
{
// Change the toolbutton's name and icon to that button
const AZStd::vector<Button*> buttons = m_switcher->GetButtons();
// Change the tool button's name and icon to that button
const AZStd::vector<Button*> buttons = m_buttonGroup->GetButtons();
for (auto button : buttons)
{
if (button->m_buttonId == buttonId)
@@ -9,18 +9,17 @@
#include <QToolBar>
#include <QToolButton>
class Cluster;
namespace AzToolsFramework::ViewportUi::Internal
{
class ButtonGroup;
//! Helper class to make switchers (toolbars) for display in Viewport UI.
class ViewportUiSwitcher : public QToolBar
{
Q_OBJECT
public:
ViewportUiSwitcher(AZStd::shared_ptr<Cluster> switcher, ButtonId currentMode);
ViewportUiSwitcher(AZStd::shared_ptr<ButtonGroup> buttonGroup, ButtonId currentMode);
~ViewportUiSwitcher();
//! Adds a new button to the cluster.
void AddButton(Button* button);
@@ -32,10 +31,8 @@ namespace AzToolsFramework::ViewportUi::Internal
private:
QToolButton* m_activeButton;
ButtonId m_currentMode;
AZStd::shared_ptr<Cluster> m_switcher; //!< Data structure which the cluster will be displaying to the Viewport UI.
AZStd::shared_ptr<ButtonGroup> m_buttonGroup; //!< Data structure which the cluster will be displaying to the Viewport UI.
AZStd::unordered_map<ButtonId, QPointer<QAction>> m_buttonActionMap; //!< Map for buttons to their corresponding actions.
ViewportUiWidgetCallbacks m_widgetCallbacks; //!< Registers actions and manages updates.
};
} // namespace AzToolsFramework::ViewportUi::Internal