From 8e1a3bc0731a23023eb308035d5c0fa80e05bc5d Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Tue, 16 Nov 2021 11:52:52 -0800 Subject: [PATCH] Removes CVarMenu from Code/Editor Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- Code/Editor/CVarMenu.cpp | 186 ----------------------------- Code/Editor/CVarMenu.h | 65 ---------- Code/Editor/MainWindow.cpp | 1 - Code/Editor/MainWindow.h | 1 - Code/Editor/editor_lib_files.cmake | 2 - 5 files changed, 255 deletions(-) delete mode 100644 Code/Editor/CVarMenu.cpp delete mode 100644 Code/Editor/CVarMenu.h diff --git a/Code/Editor/CVarMenu.cpp b/Code/Editor/CVarMenu.cpp deleted file mode 100644 index 6449be9b3c..0000000000 --- a/Code/Editor/CVarMenu.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -#include "EditorDefs.h" - -#include "CVarMenu.h" - -CVarMenu::CVarMenu(QWidget* parent) - : QMenu(parent) -{ -} - -void CVarMenu::AddCVarToggleItem(CVarToggle cVarToggle) -{ - // Add CVar toggle action - QAction* action = addAction(cVarToggle.m_displayName); - connect(action, &QAction::triggered, [this, cVarToggle](bool checked) - { - // Update the CVar's value based on the action's new checked state - ICVar* cVar = gEnv->pConsole->GetCVar(cVarToggle.m_cVarName.toUtf8().data()); - if (cVar) - { - SetCVar(cVar, checked ? cVarToggle.m_onValue : cVarToggle.m_offValue); - } - }); - action->setCheckable(true); - - // Initialize the action's checked state based on the associated CVar's value - ICVar* cVar = gEnv->pConsole->GetCVar(cVarToggle.m_cVarName.toUtf8().data()); - bool checked = (cVar && cVar->GetFVal() == cVarToggle.m_onValue); - action->setChecked(checked); -} - -void CVarMenu::AddCVarValuesItem(QString cVarName, - QString displayName, - CVarDisplayNameValuePairs availableCVarValues, - float offValue) -{ - // Add a submenu offering multiple values for one CVar - QMenu* menu = addMenu(displayName); - QActionGroup* group = new QActionGroup(menu); - group->setExclusive(true); - - ICVar* cVar = gEnv->pConsole->GetCVar(cVarName.toUtf8().data()); - float cVarValue = cVar ? cVar->GetFVal() : 0.0f; - for (const auto& availableCVarValue : availableCVarValues) - { - QAction* action = menu->addAction(availableCVarValue.first); - action->setCheckable(true); - group->addAction(action); - - float availableOnValue = availableCVarValue.second; - connect(action, &QAction::triggered, [this, action, cVarName, availableOnValue, offValue](bool checked) - { - ICVar* cVar = gEnv->pConsole->GetCVar(cVarName.toUtf8().data()); - if (cVar) - { - if (!checked) - { - SetCVar(cVar, offValue); - } - else - { - // Toggle the CVar and update the action's checked state to - // allow none of the items to be checked in the exclusive group. - // Otherwise we could have just used the action's currently checked - // state and updated the CVar's value only - bool cVarOn = (cVar->GetFVal() == availableOnValue); - checked = !cVarOn; - SetCVar(cVar, checked ? availableOnValue : offValue); - action->setChecked(checked); - } - } - }); - - // Initialize the action's checked state based on the CVar's current value - bool checked = (cVarValue == availableOnValue); - action->setChecked(checked); - } -} - -void CVarMenu::AddUniqueCVarsItem(QString displayName, - AZStd::vector availableCVars) -{ - // Add a submenu of actions offering values for unique CVars - QMenu* menu = addMenu(displayName); - QActionGroup* group = new QActionGroup(menu); - group->setExclusive(true); - - for (const CVarToggle& availableCVar : availableCVars) - { - QAction* action = menu->addAction(availableCVar.m_displayName); - action->setCheckable(true); - group->addAction(action); - - connect(action, &QAction::triggered, [this, action, availableCVar, availableCVars](bool checked) - { - ICVar* cVar = gEnv->pConsole->GetCVar(availableCVar.m_cVarName.toUtf8().data()); - if (cVar) - { - if (!checked) - { - SetCVar(cVar, availableCVar.m_offValue); - } - else - { - // Toggle the CVar and update the action's checked state to - // allow none of the items to be checked in the exclusive group. - // Otherwise we could have just used the action's currently checked - // state and updated the CVar's value only - bool cVarOn = (cVar->GetFVal() == availableCVar.m_onValue); - bool cVarChecked = !cVarOn; - SetCVar(cVar, cVarChecked ? availableCVar.m_onValue : availableCVar.m_offValue); - action->setChecked(cVarChecked); - if (cVarChecked) - { - // Set the rest of the CVars in the group to their off values - SetCVarsToOffValue(availableCVars, availableCVar); - } - } - } - }); - - // Initialize the action's checked state based on its associated CVar's current value - ICVar* cVar = gEnv->pConsole->GetCVar(availableCVar.m_cVarName.toUtf8().data()); - bool cVarChecked = (cVar && cVar->GetFVal() == availableCVar.m_onValue); - action->setChecked(cVarChecked); - if (cVarChecked) - { - // Set the rest of the CVars in the group to their off values - SetCVarsToOffValue(availableCVars, availableCVar); - } - } -} - -void CVarMenu::AddResetCVarsItem() -{ - QAction* action = addAction(tr("Reset to Default")); - connect(action, &QAction::triggered, this, [this]() - { - for (auto it : m_originalCVarValues) - { - ICVar* cVar = gEnv->pConsole->GetCVar(it.first.c_str()); - if (cVar) - { - cVar->Set(it.second); - } - } - }); -} - -void CVarMenu::SetCVarsToOffValue(const AZStd::vector& cVarToggles, const CVarToggle& excludeCVarToggle) -{ - // Set all but the specified CVars to their off values - for (const CVarToggle& cVarToggle : cVarToggles) - { - if (cVarToggle.m_cVarName != excludeCVarToggle.m_cVarName - || cVarToggle.m_onValue != excludeCVarToggle.m_onValue) - { - ICVar* cVar = gEnv->pConsole->GetCVar(cVarToggle.m_cVarName.toUtf8().data()); - if (cVar) - { - SetCVar(cVar, cVarToggle.m_offValue); - } - } - } -} - -void CVarMenu::SetCVar(ICVar* cVar, float newValue) -{ - float oldValue = cVar->GetFVal(); - cVar->Set(newValue); - - // Store original value for CVar if not already in the list - m_originalCVarValues.emplace(AZStd::string(cVar->GetName()), oldValue); -} - -void CVarMenu::AddSeparator() -{ - addSeparator(); -} diff --git a/Code/Editor/CVarMenu.h b/Code/Editor/CVarMenu.h deleted file mode 100644 index 5195bd99d7..0000000000 --- a/Code/Editor/CVarMenu.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -#pragma once - -#include -#include - -#include -#include -#include -#include - -struct ICVar; - -class CVarMenu - : public QMenu -{ - Q_OBJECT -public: - // CVar that can be toggled on and off - struct CVarToggle - { - QString m_cVarName; - QString m_displayName; - float m_onValue; - float m_offValue; - }; - - // List of a CVar's available values and their descriptions - using CVarDisplayNameValuePairs = AZStd::vector>; - - CVarMenu(QWidget* parent = nullptr); - - // Add an action that turns a CVar on/off - void AddCVarToggleItem(CVarToggle cVarToggle); - - // Add a submenu of actions for a CVar that offers multiple values for exclusive selection - void AddCVarValuesItem(QString cVarName, - QString displayName, - CVarDisplayNameValuePairs availableCVarValues, - float offValue); - - // Add a submenu of actions for exclusively turning unique CVars on/off - void AddUniqueCVarsItem(QString displayName, - AZStd::vector availableCVars); - - // Add an action to reset all CVars to their original values before they - // were modified by this menu - void AddResetCVarsItem(); - - void AddSeparator(); - -private: - void SetCVarsToOffValue(const AZStd::vector& cVarToggles, const CVarToggle& excludeCVarToggle); - void SetCVar(ICVar* cVar, float newValue); - - // Original CVar values before they were modified by this menu - AZStd::unordered_map m_originalCVarValues; -}; diff --git a/Code/Editor/MainWindow.cpp b/Code/Editor/MainWindow.cpp index bbebac96a3..dca6de4fc3 100644 --- a/Code/Editor/MainWindow.cpp +++ b/Code/Editor/MainWindow.cpp @@ -77,7 +77,6 @@ AZ_POP_DISABLE_WARNING #include "ToolbarManager.h" #include "Core/QtEditorApplication.h" #include "UndoDropDown.h" -#include "CVarMenu.h" #include "EditorViewportSettings.h" #include "KeyboardCustomizationSettings.h" diff --git a/Code/Editor/MainWindow.h b/Code/Editor/MainWindow.h index 1e375b08f2..5adf9a8036 100644 --- a/Code/Editor/MainWindow.h +++ b/Code/Editor/MainWindow.h @@ -49,7 +49,6 @@ class ToolbarCustomizationDialog; class QWidgetAction; class ActionManager; class ShortcutDispatcher; -class CVarMenu; namespace AzQtComponents { diff --git a/Code/Editor/editor_lib_files.cmake b/Code/Editor/editor_lib_files.cmake index 758143ac8d..270c5293a7 100644 --- a/Code/Editor/editor_lib_files.cmake +++ b/Code/Editor/editor_lib_files.cmake @@ -249,8 +249,6 @@ set(FILES CryEditPy.cpp CryEdit.cpp CryEdit.h - CVarMenu.cpp - CVarMenu.h EditorToolsApplication.cpp EditorToolsApplication.h EditorToolsApplicationAPI.h