Skip to content

Commit

Permalink
automatic shutdown via ShutdownController
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Oct 20, 2024
1 parent 1cce932 commit 856ddce
Show file tree
Hide file tree
Showing 29 changed files with 142 additions and 77 deletions.
5 changes: 4 additions & 1 deletion source/Gui/AlienWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@

#include "StyleRepository.h"
#include "WindowController.h"
#include "ShutdownController.h"

AlienWindow::AlienWindow(std::string const& title, std::string const& settingsNode, bool defaultOn)
: _title(title)
, _settingsNode(settingsNode)
{
_on = GlobalSettings::get().getBool(settingsNode + ".active", defaultOn);
ShutdownController::get().registerObject(this);
}

AlienWindow::~AlienWindow()
void AlienWindow::shutdown()
{
GlobalSettings::get().setBool(_settingsNode + ".active", _on);
shutdownIntern();
}

void AlienWindow::process()
Expand Down
8 changes: 6 additions & 2 deletions source/Gui/AlienWindow.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#pragma once

#include "Definitions.h"
#include "ShutdownInterface.h"

class AlienWindow
class AlienWindow : public ShutdownInterface
{
public:
AlienWindow(std::string const& title, std::string const& settingsNode, bool defaultOn);
virtual ~AlienWindow();

void process();

bool isOn() const;
void setOn(bool value);

protected:
virtual void shutdownIntern() {};
virtual void processIntern() = 0;
virtual void processBackground() {}
virtual void processActivated() {}
Expand All @@ -22,4 +23,7 @@ class AlienWindow
bool _on = false;
std::string _title;
std::string _settingsNode;

private:
void shutdown() override;
};
3 changes: 3 additions & 0 deletions source/Gui/AutosaveController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "DelayedExecutionController.h"
#include "OverlayMessageController.h"
#include "SerializationHelperService.h"
#include "ShutdownController.h"

namespace
{
Expand All @@ -22,6 +23,8 @@ void AutosaveController::init(SimulationFacade const& simulationFacade)
_simulationFacade = simulationFacade;
_startTimePoint = std::chrono::steady_clock::now();
_on = GlobalSettings::get().getBool("controllers.auto save.active", true);

ShutdownController::get().registerObject(this);
}

void AutosaveController::shutdown()
Expand Down
6 changes: 4 additions & 2 deletions source/Gui/AutosaveController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
#include "EngineInterface/Definitions.h"

#include "Definitions.h"
#include "ShutdownInterface.h"

class AutosaveController
class AutosaveController : public ShutdownInterface
{
MAKE_SINGLETON(AutosaveController);

public:
void init(SimulationFacade const& simulationFacade);
void shutdown();

bool isOn() const;
void setOn(bool value);

void process();

private:
void shutdown() override;

void onSave();

SimulationFacade _simulationFacade;
Expand Down
2 changes: 1 addition & 1 deletion source/Gui/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void BrowserWindow::init(SimulationFacade const& simulationFacade, PersisterFaca
_lastSessionData.load(getAllRawTOs());
}

void BrowserWindow::shutdown()
void BrowserWindow::shutdownIntern()
{
auto& settings = GlobalSettings::get();
settings.setInt("windows.browser.resource type", _currentWorkspace.resourceType);
Expand Down
3 changes: 2 additions & 1 deletion source/Gui/BrowserWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class BrowserWindow : public AlienWindow

public:
void init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade);
void shutdown();

void onRefresh();
WorkspaceType getCurrentWorkspaceType() const;
Expand All @@ -33,6 +32,8 @@ class BrowserWindow : public AlienWindow
private:
BrowserWindow();

void shutdownIntern() override;

struct WorkspaceId
{
NetworkResourceType resourceType;
Expand Down
7 changes: 5 additions & 2 deletions source/Gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,15 @@ PUBLIC
ResizeWorldDialog.h
SelectionWindow.cpp
SelectionWindow.h
SerializationHelperService.cpp
SerializationHelperService.h
Shader.cpp
Shader.h
ShaderWindow.cpp
ShaderWindow.h
SerializationHelperService.cpp
SerializationHelperService.h
ShutdownController.cpp
ShutdownController.h
ShutdownInterface.h
SimulationInteractionController.cpp
SimulationInteractionController.h
SimulationParametersWindow.cpp
Expand Down
3 changes: 1 addition & 2 deletions source/Gui/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class UiController;

class AutosaveController;

class _GettingStartedWindow;
using GettingStartedWindow = std::shared_ptr<_GettingStartedWindow>;
class GettingStartedWindow;

class _DisplaySettingsDialog;
using DisplaySettingsDialog = std::shared_ptr<_DisplaySettingsDialog>;
Expand Down
3 changes: 3 additions & 0 deletions source/Gui/EditorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "GenomeEditorWindow.h"
#include "MessageDialog.h"
#include "OverlayMessageController.h"
#include "ShutdownController.h"

namespace
{
Expand All @@ -33,6 +34,8 @@ void EditorController::init(SimulationFacade const& simulationFacade)
_patternEditorWindow = std::make_shared<_PatternEditorWindow>(_editorModel, _simulationFacade);
_creatorWindow = std::make_shared<_CreatorWindow>(_editorModel, _simulationFacade);
_multiplierWindow = std::make_shared<_MultiplierWindow>(_editorModel, _simulationFacade);

ShutdownController::get().registerObject(this);
}

void EditorController::shutdown()
Expand Down
6 changes: 3 additions & 3 deletions source/Gui/EditorController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
#include "EngineInterface/Descriptions.h"

#include "Definitions.h"
#include "ShutdownInterface.h"

class EditorController
class EditorController : public ShutdownInterface
{
MAKE_SINGLETON(EditorController);

public:
void init(SimulationFacade const& simulationFacade);
void shutdown();

bool isOn() const;
void setOn(bool value);
Expand Down Expand Up @@ -50,9 +50,9 @@ class EditorController
void onAccelerateSelectedObjects(RealVector2D const& viewPos, RealVector2D const& prevWorldPos);

private:
void shutdown() override;
void processInspectorWindows();

private:
EditorModel _editorModel;
SelectionWindow _selectionWindow;
PatternEditorWindow _patternEditorWindow;
Expand Down
24 changes: 12 additions & 12 deletions source/Gui/GettingStartedWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
#include <windows.h>
#endif

void _GettingStartedWindow::init()
void GettingStartedWindow::init()
{
_showAfterStartup = _on;
}


void _GettingStartedWindow::shutdown()
GettingStartedWindow::GettingStartedWindow()
: AlienWindow("Getting started", "windows.getting started", true)
{}

void GettingStartedWindow::shutdownIntern()
{
_on = _showAfterStartup;
}

_GettingStartedWindow::_GettingStartedWindow()
: AlienWindow("Getting started", "windows.getting started", true)
{}

void _GettingStartedWindow::processIntern()
void GettingStartedWindow::processIntern()
{
drawTitle();

Expand Down Expand Up @@ -405,7 +405,7 @@ void _GettingStartedWindow::processIntern()
AlienImGui::ToggleButton(AlienImGui::ToggleButtonParameters().name("Show after startup"), _showAfterStartup);
}

void _GettingStartedWindow::drawTitle()
void GettingStartedWindow::drawTitle()
{
ImGui::PushStyleColor(ImGuiCol_Text, (ImU32)Const::HeadlineColor);

Expand Down Expand Up @@ -456,7 +456,7 @@ void _GettingStartedWindow::drawTitle()
AlienImGui::Separator();
}

void _GettingStartedWindow::drawHeading1(std::string const& text)
void GettingStartedWindow::drawHeading1(std::string const& text)
{
AlienImGui::Separator();
ImGui::PushStyleColor(ImGuiCol_Text, (ImU32)Const::HeadlineColor);
Expand All @@ -465,20 +465,20 @@ void _GettingStartedWindow::drawHeading1(std::string const& text)
AlienImGui::Separator();
}

void _GettingStartedWindow::drawHeading2(std::string const& text)
void GettingStartedWindow::drawHeading2(std::string const& text)
{
ImGui::Spacing();
AlienImGui::BoldText(text);
}

void _GettingStartedWindow::drawItemText(std::string const& text)
void GettingStartedWindow::drawItemText(std::string const& text)
{
ImGui::Text(ICON_FA_CHEVRON_RIGHT);
ImGui::SameLine();
AlienImGui::Text(text);
}

void _GettingStartedWindow::drawParagraph(std::string const& text)
void GettingStartedWindow::drawParagraph(std::string const& text)
{
AlienImGui::Text(text);
}
Expand Down
9 changes: 5 additions & 4 deletions source/Gui/GettingStartedWindow.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#pragma once

#include "Base/Singleton.h"
#include "EngineInterface/Definitions.h"

#include "Definitions.h"
#include "AlienWindow.h"

class _GettingStartedWindow : public AlienWindow
class GettingStartedWindow : public AlienWindow
{
MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(_GettingStartedWindow);
MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(GettingStartedWindow);

public:
void init();
void shutdown();

private:
_GettingStartedWindow();
GettingStartedWindow();

void shutdownIntern() override;
void processIntern() override;

void drawTitle();
Expand Down
10 changes: 5 additions & 5 deletions source/Gui/LogWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ void LogWindow::init(GuiLogger const& logger)
_verbose = GlobalSettings::get().getBool("windows.log.verbose", false);
}

void LogWindow::shutdown()
{
GlobalSettings::get().setBool("windows.log.verbose", _verbose);
}

LogWindow::LogWindow()
: AlienWindow("Log", "windows.log", false)
{}

void LogWindow::shutdownIntern()
{
GlobalSettings::get().setBool("windows.log.verbose", _verbose);
}

void LogWindow::processIntern()
{
auto& styleRepository = StyleRepository::get();
Expand Down
4 changes: 2 additions & 2 deletions source/Gui/LogWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class LogWindow : public AlienWindow

public:
void init(GuiLogger const& logger);
void shutdown();

private:
LogWindow();

void processIntern();
void shutdownIntern() override;
void processIntern() override;

bool _verbose = false;

Expand Down
5 changes: 4 additions & 1 deletion source/Gui/LoginController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#include "EngineInterface/SimulationFacade.h"
#include "PersisterInterface/LoginRequestData.h"
#include "PersisterInterface/SenderInfo.h"
#include "PersisterInterface/TaskProcessor.h"

#include "MessageDialog.h"
#include "ActivateUserDialog.h"
#include "BrowserWindow.h"
#include "PersisterInterface/TaskProcessor.h"
#include "ShutdownController.h"

void LoginController::init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade)
{
Expand All @@ -26,6 +27,8 @@ void LoginController::init(SimulationFacade const& simulationFacade, PersisterFa
_password = settings.getString("dialogs.login.password", "");
onLogin();
}

ShutdownController::get().registerObject(this);
}

void LoginController::shutdown()
Expand Down
9 changes: 6 additions & 3 deletions source/Gui/LoginController.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#pragma once

#include "Base/Singleton.h"
#include "Definitions.h"
#include "PersisterInterface/PersisterFacade.h"

class LoginController
#include "Definitions.h"
#include "ShutdownInterface.h"

class LoginController : public ShutdownInterface
{
MAKE_SINGLETON(LoginController);
public:

void init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade);
void shutdown();

void onLogin();

Expand All @@ -33,6 +34,8 @@ class LoginController
UserInfo getUserInfo();

private:
void shutdown() override;

SimulationFacade _simulationFacade;
PersisterFacade _persisterFacade;

Expand Down
Loading

0 comments on commit 856ddce

Please sign in to comment.