Add an option to hide toasts

- Added an option to hide ModMenuModule::ToastManager toasts trough ModMenuModule::SeukomodOptionsMenu
This commit is contained in:
izawartka 2026-08-16 18:40:28 +02:00
parent 7c83760e1b
commit 49ca1a082d
4 changed files with 44 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include "../root.h"
#include "menu-controls-menu.h"
#include "version-menu.h"
#include "../../../converters/enabled-disabled.h"
ModMenuModule::SeukomodOptionsMenu::SeukomodOptionsMenu()
{
@ -24,6 +25,22 @@ bool ModMenuModule::SeukomodOptionsMenu::Attach()
m_menuController->CreateItem<UiModule::Text>(vertCont, L"Menu controls", options.textSize);
m_menuController->CreateItem<UiModule::Text>(vertCont, L"Version details", options.textSize);
// toasts
ToastManager* toastManager = ToastManager::GetInstance();
UiModule::Text* toastsVisibleText = m_menuController->CreateItem<UiModule::Text>(vertCont, L"", options.textSize);
m_toastsVisibleController = m_menuController->CreateLatestItemController<UiModule::VarTextSelectController<bool, bool>>(
toastsVisibleText,
[toastManager]() -> bool {
return toastManager->GetToastsVisible();
},
UiModule::VarTextSelectOptionList<bool>{ false, true },
UiModule::VarTextSelectControllerOptions{ L"Toasts: #", L"#" }
);
m_toastsVisibleController->SetConverter<EnabledDisabledConverter>();
m_toastsVisibleController->SetCustomSaveCallback([toastManager](bool newValue) {
toastManager->SetToastsVisible(newValue);
});
SetPreviousSelectedIndex();
return true;

View File

@ -12,5 +12,7 @@ namespace ModMenuModule {
virtual bool Attach() override;
void OnMenuAction(UiModule::Selectable* item, UiModule::MenuItemId id) override;
UiModule::VarTextSelectController<bool, bool>* m_toastsVisibleController = nullptr;
};
}

View File

@ -1,6 +1,8 @@
#include "toast-manager.h"
#include "root.h"
static const char TOASTS_VISIBLE_PERSISTENCE_KEY[] = "ModMenu_ToastManager_ToastsVisible";
ModMenuModule::ToastManager* ModMenuModule::ToastManager::m_instance = nullptr;
ModMenuModule::ToastManager* ModMenuModule::ToastManager::GetInstance() {
@ -26,12 +28,21 @@ void ModMenuModule::ToastManager::Show(const Toast& toast) {
m_toasts.emplace_back(toast);
}
void ModMenuModule::ToastManager::SetToastsVisible(bool isHidden)
{
m_toastsVisible = isHidden;
UpdateToastsVisible();
}
void ModMenuModule::ToastManager::Attach() {
const auto& options = ModMenuModule::RootModule::GetInstance()->GetOptions();
UiModule::RootModule* uiRoot = UiModule::RootModule::GetInstance();
m_mainContainer = uiRoot->AddComponent<UiModule::OverridePos>(nullptr, std::nullopt, options.toastPadding);
m_toastListContainer = uiRoot->AddComponent<UiModule::VertCont>(m_mainContainer);
PersistenceModule::PersistenceManager* persistence = PersistenceModule::PersistenceManager::GetInstance();
m_toastsVisible = persistence->Load<bool>(TOASTS_VISIBLE_PERSISTENCE_KEY, true);
AddEventListener<UiModule::PreUpdateUIEvent>(&ToastManager::OnPreUpdateUI);
AddEventListener<GameEndEvent>(&ToastManager::OnGameEnd);
}
@ -45,6 +56,9 @@ void ModMenuModule::ToastManager::Detach() {
uiRoot->RemoveComponent(m_mainContainer, true);
m_mainContainer = nullptr;
m_toastListContainer = nullptr;
PersistenceModule::PersistenceManager* persistence = PersistenceModule::PersistenceManager::GetInstance();
persistence->Save<bool>(TOASTS_VISIBLE_PERSISTENCE_KEY, m_toastsVisible);
}
void ModMenuModule::ToastManager::OnPreUpdateUI(UiModule::PreUpdateUIEvent& event) {
@ -115,3 +129,9 @@ void ModMenuModule::ToastManager::Update() {
);
}
}
void ModMenuModule::ToastManager::UpdateToastsVisible()
{
if (!m_toastListContainer) return;
m_toastListContainer->SetVisible(m_toastsVisible);
}

View File

@ -22,6 +22,9 @@ namespace ModMenuModule {
void Show(const Toast& toast);
void SetToastsVisible(bool isHidden);
bool GetToastsVisible() const { return m_toastsVisible; }
private:
friend class RootModule;
ToastManager();
@ -38,6 +41,7 @@ namespace ModMenuModule {
void OnGameEnd(GameEndEvent& event);
static short GetToastTypeRemap(ToastType type);
void Update();
void UpdateToastsVisible();
struct ToastItem : public Toast {
UiModule::HorCentered* container = nullptr;
@ -51,5 +55,6 @@ namespace ModMenuModule {
std::vector<ToastItem> m_toasts = {};
UiModule::OverridePos* m_mainContainer = nullptr;
UiModule::VertCont* m_toastListContainer = nullptr;
bool m_toastsVisible = false;
};
}