From 17a79daad89afe48b8d03df852c99eedcc887e9d Mon Sep 17 00:00:00 2001 From: sphrose <82213493+sphrose@users.noreply.github.com> Date: Mon, 12 Jul 2021 16:07:52 +0100 Subject: [PATCH 1/2] Add clear console when starting gamemode setting. Signed-off-by: sphrose <82213493+sphrose@users.noreply.github.com> --- Code/Editor/Controls/ConsoleSCB.cpp | 4 ++++ Code/Editor/Controls/ConsoleSCB.h | 2 ++ Code/Editor/EditorPreferencesPageGeneral.cpp | 5 +++++ Code/Editor/EditorPreferencesPageGeneral.h | 1 + Code/Editor/GameEngine.cpp | 6 ++++++ Code/Editor/Settings.cpp | 5 +++++ Code/Editor/Settings.h | 1 + 7 files changed, 24 insertions(+) diff --git a/Code/Editor/Controls/ConsoleSCB.cpp b/Code/Editor/Controls/ConsoleSCB.cpp index 32ec6506b1..32731b7317 100644 --- a/Code/Editor/Controls/ConsoleSCB.cpp +++ b/Code/Editor/Controls/ConsoleSCB.cpp @@ -537,6 +537,10 @@ void CConsoleSCB::AddToPendingLines(const QString& text, bool bNewLine) s_pendingLines.push_back({ text, bNewLine }); } +void CConsoleSCB::ClearText() +{ + ui->textEdit->clear(); +} /** * When a CVar variable is updated, we need to tell alert our console variables * pane so it can update the corresponding row diff --git a/Code/Editor/Controls/ConsoleSCB.h b/Code/Editor/Controls/ConsoleSCB.h index faa8c06124..d561e5f5a6 100644 --- a/Code/Editor/Controls/ConsoleSCB.h +++ b/Code/Editor/Controls/ConsoleSCB.h @@ -174,6 +174,8 @@ public: static void AddToPendingLines(const QString& text, bool bNewLine); // call this function instead of AddToConsole() until an instance of CConsoleSCB exists to prevent messages from getting lost + void ClearText(); + // EditorPreferencesNotificationBus... void OnEditorPreferencesChanged() override; diff --git a/Code/Editor/EditorPreferencesPageGeneral.cpp b/Code/Editor/EditorPreferencesPageGeneral.cpp index 861ef10c23..cf4a430c7e 100644 --- a/Code/Editor/EditorPreferencesPageGeneral.cpp +++ b/Code/Editor/EditorPreferencesPageGeneral.cpp @@ -31,6 +31,7 @@ void CEditorPreferencesPage_General::Reflect(AZ::SerializeContext& serialize) ->Field("PreviewPanel", &GeneralSettings::m_previewPanel) ->Field("ApplyConfigSpec", &GeneralSettings::m_applyConfigSpec) ->Field("EnableSourceControl", &GeneralSettings::m_enableSourceControl) + ->Field("ClearConsole", &GeneralSettings::m_clearConsoleOnGameModeStart) ->Field("ConsoleBackgroundColorTheme", &GeneralSettings::m_consoleBackgroundColorTheme) ->Field("AutoloadLastLevel", &GeneralSettings::m_autoLoadLastLevel) ->Field("ShowTimeInConsole", &GeneralSettings::m_bShowTimeInConsole) @@ -76,6 +77,8 @@ void CEditorPreferencesPage_General::Reflect(AZ::SerializeContext& serialize) ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_previewPanel, "Show Geometry Preview Panel", "Show Geometry Preview Panel") ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_applyConfigSpec, "Hide objects by config spec", "Hide objects by config spec") ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_enableSourceControl, "Enable Source Control", "Enable Source Control") + ->DataElement( + AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_clearConsoleOnGameModeStart, "Clear Console at Game Startup", "Clear Console when Game Mode Starts") ->DataElement(AZ::Edit::UIHandlers::ComboBox, &GeneralSettings::m_consoleBackgroundColorTheme, "Console Background", "Console Background") ->EnumAttribute(AzToolsFramework::ConsoleColorTheme::Light, "Light") ->EnumAttribute(AzToolsFramework::ConsoleColorTheme::Dark, "Dark") @@ -141,6 +144,7 @@ void CEditorPreferencesPage_General::OnApply() gSettings.bPreviewGeometryWindow = m_generalSettings.m_previewPanel; gSettings.bApplyConfigSpecInEditor = m_generalSettings.m_applyConfigSpec; gSettings.enableSourceControl = m_generalSettings.m_enableSourceControl; + gSettings.clearConsoleOnGameModeStart = m_generalSettings.m_clearConsoleOnGameModeStart; gSettings.consoleBackgroundColorTheme = m_generalSettings.m_consoleBackgroundColorTheme; gSettings.bShowTimeInConsole = m_generalSettings.m_bShowTimeInConsole; gSettings.bShowDashboardAtStartup = m_messaging.m_showDashboard; @@ -175,6 +179,7 @@ void CEditorPreferencesPage_General::InitializeSettings() m_generalSettings.m_previewPanel = gSettings.bPreviewGeometryWindow; m_generalSettings.m_applyConfigSpec = gSettings.bApplyConfigSpecInEditor; m_generalSettings.m_enableSourceControl = gSettings.enableSourceControl; + m_generalSettings.m_clearConsoleOnGameModeStart = gSettings.clearConsoleOnGameModeStart; m_generalSettings.m_consoleBackgroundColorTheme = gSettings.consoleBackgroundColorTheme; m_generalSettings.m_bShowTimeInConsole = gSettings.bShowTimeInConsole; m_generalSettings.m_autoLoadLastLevel = gSettings.bAutoloadLastLevelAtStartup; diff --git a/Code/Editor/EditorPreferencesPageGeneral.h b/Code/Editor/EditorPreferencesPageGeneral.h index ca315c2d01..557a9d5bce 100644 --- a/Code/Editor/EditorPreferencesPageGeneral.h +++ b/Code/Editor/EditorPreferencesPageGeneral.h @@ -45,6 +45,7 @@ private: bool m_previewPanel; bool m_applyConfigSpec; bool m_enableSourceControl; + bool m_clearConsoleOnGameModeStart; AzToolsFramework::ConsoleColorTheme m_consoleBackgroundColorTheme; bool m_autoLoadLastLevel; bool m_bShowTimeInConsole; diff --git a/Code/Editor/GameEngine.cpp b/Code/Editor/GameEngine.cpp index a729be9175..e77d44d98e 100644 --- a/Code/Editor/GameEngine.cpp +++ b/Code/Editor/GameEngine.cpp @@ -29,6 +29,7 @@ // Editor #include "IEditorImpl.h" +#include "Controls/ConsoleSCB.h" #include "CryEditDoc.h" #include "Settings.h" @@ -565,6 +566,11 @@ void CGameEngine::SwitchToInGame() streamer->QueueRequest(flush); wait.acquire(); } + + if (gSettings.clearConsoleOnGameModeStart) + { + CConsoleSCB::GetCreatedInstance()->ClearText(); + } GetIEditor()->Notify(eNotify_OnBeginGameMode); diff --git a/Code/Editor/Settings.cpp b/Code/Editor/Settings.cpp index cdd44b5fff..f675116e56 100644 --- a/Code/Editor/Settings.cpp +++ b/Code/Editor/Settings.cpp @@ -188,6 +188,7 @@ SEditorSettings::SEditorSettings() consoleBackgroundColorTheme = AzToolsFramework::ConsoleColorTheme::Dark; bShowTimeInConsole = false; + clearConsoleOnGameModeStart = false; enableSceneInspector = false; @@ -526,6 +527,8 @@ void SEditorSettings::Save() SaveValue("Settings", "ConsoleBackgroundColorThemeV2", (int)consoleBackgroundColorTheme); + SaveValue("Settings", "ClearConsoleOnGameModeStart", clearConsoleOnGameModeStart); + SaveValue("Settings", "ShowTimeInConsole", bShowTimeInConsole); SaveValue("Settings", "EnableSceneInspector", enableSceneInspector); @@ -744,6 +747,8 @@ void SEditorSettings::Load() consoleBackgroundColorTheme = AzToolsFramework::ConsoleColorTheme::Dark; } + LoadValue("Settings", "ClearConsoleOnGameModeStart", clearConsoleOnGameModeStart); + LoadValue("Settings", "ShowTimeInConsole", bShowTimeInConsole); LoadValue("Settings", "EnableSceneInspector", enableSceneInspector); diff --git a/Code/Editor/Settings.h b/Code/Editor/Settings.h index cef77de6a7..ff4252f8d8 100644 --- a/Code/Editor/Settings.h +++ b/Code/Editor/Settings.h @@ -379,6 +379,7 @@ AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING //! Source Control Enabling. bool enableSourceControl; + bool clearConsoleOnGameModeStart; //! Text editor. QString textEditorForScript; From 93cbb7c98186c15427826f639edf8e5abf30499b Mon Sep 17 00:00:00 2001 From: sphrose <82213493+sphrose@users.noreply.github.com> Date: Wed, 14 Jul 2021 10:14:25 +0100 Subject: [PATCH 2/2] Review changes Changed text case, removed ClearText API and added GameStartup motify listening. Signed-off-by: sphrose <82213493+sphrose@users.noreply.github.com> --- Code/Editor/Controls/ConsoleSCB.cpp | 23 ++++++++++++++++---- Code/Editor/Controls/ConsoleSCB.h | 5 +++-- Code/Editor/EditorPreferencesPageGeneral.cpp | 2 +- Code/Editor/GameEngine.cpp | 6 ----- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Code/Editor/Controls/ConsoleSCB.cpp b/Code/Editor/Controls/ConsoleSCB.cpp index 32731b7317..3498476797 100644 --- a/Code/Editor/Controls/ConsoleSCB.cpp +++ b/Code/Editor/Controls/ConsoleSCB.cpp @@ -337,6 +337,8 @@ CConsoleSCB::CConsoleSCB(QWidget* parent) connect(findPreviousAction, &QAction::triggered, this, &CConsoleSCB::findPrevious); ui->findPrevButton->addAction(findPreviousAction); + GetIEditor()->RegisterNotifyListener(this); + connect(ui->button, &QPushButton::clicked, this, &CConsoleSCB::showVariableEditor); connect(ui->findButton, &QPushButton::clicked, this, &CConsoleSCB::toggleConsoleSearch); connect(ui->textEdit, &ConsoleTextEdit::searchBarRequested, this, [this] @@ -375,6 +377,8 @@ CConsoleSCB::~CConsoleSCB() { AzToolsFramework::EditorPreferencesNotificationBus::Handler::BusDisconnect(); + GetIEditor()->UnregisterNotifyListener(this); + s_consoleSCB = nullptr; CLogFile::AttachEditBox(nullptr); } @@ -537,10 +541,6 @@ void CConsoleSCB::AddToPendingLines(const QString& text, bool bNewLine) s_pendingLines.push_back({ text, bNewLine }); } -void CConsoleSCB::ClearText() -{ - ui->textEdit->clear(); -} /** * When a CVar variable is updated, we need to tell alert our console variables * pane so it can update the corresponding row @@ -1355,4 +1355,19 @@ CConsoleSCB* CConsoleSCB::GetCreatedInstance() return s_consoleSCB; } +void CConsoleSCB::OnEditorNotifyEvent(EEditorNotifyEvent event) +{ + switch (event) + { + case eNotify_OnBeginGameMode: + if (gSettings.clearConsoleOnGameModeStart) + { + ui->textEdit->clear(); + } + break; + default: + break; + } +} + #include diff --git a/Code/Editor/Controls/ConsoleSCB.h b/Code/Editor/Controls/ConsoleSCB.h index d561e5f5a6..a62c1009b0 100644 --- a/Code/Editor/Controls/ConsoleSCB.h +++ b/Code/Editor/Controls/ConsoleSCB.h @@ -158,6 +158,7 @@ private: class CConsoleSCB : public QWidget , private AzToolsFramework::EditorPreferencesNotificationBus::Handler + , public IEditorNotifyListener { Q_OBJECT public: @@ -174,8 +175,6 @@ public: static void AddToPendingLines(const QString& text, bool bNewLine); // call this function instead of AddToConsole() until an instance of CConsoleSCB exists to prevent messages from getting lost - void ClearText(); - // EditorPreferencesNotificationBus... void OnEditorPreferencesChanged() override; @@ -188,6 +187,8 @@ private Q_SLOTS: void findNext(); private: + void OnEditorNotifyEvent(EEditorNotifyEvent event) override; + QScopedPointer ui; int m_richEditTextLength; diff --git a/Code/Editor/EditorPreferencesPageGeneral.cpp b/Code/Editor/EditorPreferencesPageGeneral.cpp index cf4a430c7e..046a546f59 100644 --- a/Code/Editor/EditorPreferencesPageGeneral.cpp +++ b/Code/Editor/EditorPreferencesPageGeneral.cpp @@ -78,7 +78,7 @@ void CEditorPreferencesPage_General::Reflect(AZ::SerializeContext& serialize) ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_applyConfigSpec, "Hide objects by config spec", "Hide objects by config spec") ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_enableSourceControl, "Enable Source Control", "Enable Source Control") ->DataElement( - AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_clearConsoleOnGameModeStart, "Clear Console at Game Startup", "Clear Console when Game Mode Starts") + AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_clearConsoleOnGameModeStart, "Clear Console at game startup", "Clear Console when game mode starts") ->DataElement(AZ::Edit::UIHandlers::ComboBox, &GeneralSettings::m_consoleBackgroundColorTheme, "Console Background", "Console Background") ->EnumAttribute(AzToolsFramework::ConsoleColorTheme::Light, "Light") ->EnumAttribute(AzToolsFramework::ConsoleColorTheme::Dark, "Dark") diff --git a/Code/Editor/GameEngine.cpp b/Code/Editor/GameEngine.cpp index e77d44d98e..c4fd38afc9 100644 --- a/Code/Editor/GameEngine.cpp +++ b/Code/Editor/GameEngine.cpp @@ -29,7 +29,6 @@ // Editor #include "IEditorImpl.h" -#include "Controls/ConsoleSCB.h" #include "CryEditDoc.h" #include "Settings.h" @@ -567,11 +566,6 @@ void CGameEngine::SwitchToInGame() wait.acquire(); } - if (gSettings.clearConsoleOnGameModeStart) - { - CConsoleSCB::GetCreatedInstance()->ClearText(); - } - GetIEditor()->Notify(eNotify_OnBeginGameMode); m_pISystem->GetIMovieSystem()->EnablePhysicsEvents(true);