Finalize Pause menu and setup of settings menu.

This commit is contained in:
2025-04-12 16:32:14 -04:00
parent 6f0d7d734f
commit 54eb43044d
8 changed files with 82 additions and 31 deletions

View File

@@ -38,6 +38,9 @@ namespace CaveGame::Client {
class GameSession : public Scene { class GameSession : public Scene {
public: public:
Event<> OnSessionExit;
Event<> RequestToggleSettings;
GameSession() = default; GameSession() = default;
explicit GameSession(bool createNewWorld); explicit GameSession(bool createNewWorld);
void Update(float elapsed) override; void Update(float elapsed) override;

View File

@@ -30,7 +30,9 @@ namespace CaveGame::Client
public: public:
Event<SingleplayerSessionInfo> RequestWorld; Event<SingleplayerSessionInfo> RequestWorld;
Event<> RequestQuit; Event<> RequestQuit;
Event<> RequestShowCredits; Event<> RequestToggleCredits;
Event<> RequestToggleSettings;
MainMenu(); MainMenu();
void Update(float elapsed) override; void Update(float elapsed) override;
void Draw() override; void Draw() override;

View File

@@ -21,7 +21,10 @@ namespace CaveGame::Client
void ChangeScene(Scene* new_scene); void ChangeScene(Scene* new_scene);
Scene* CurrentScene(); Scene* CurrentScene();
protected: protected:
void UpdateSceneState(float elapsed);
protected:
Scene* next_scene = nullptr;
Scene* current_scene = nullptr; Scene* current_scene = nullptr;
private: Scene* prev_scene = nullptr;
}; };
} }

View File

@@ -20,35 +20,53 @@
namespace CaveGame::Client { namespace CaveGame::Client {
// TODO: Analyze behavior of singleton on an object that requires specific initialization, like this. // TODO: Analyze behavior of singleton on an object that requires specific initialization, like this.
class SettingsMenu : public JUI::Window, public Singleton<SettingsMenu> class SettingsMenu : public JUI::Window
{ {
public: public:
SettingsMenu() SettingsMenu()
{ {
SetTitle("Settings");
auto* root_layout = new JUI::VerticalListLayout(this); using namespace JUI::UDimLiterals;
SetTitle("Settings");
Size({400_px, 400_px});
auto* root_layout = new JUI::VerticalListLayout(this->ViewportInstance());
general_section = new JUI::Collapsible(root_layout); general_section = new JUI::Collapsible(root_layout);
general_section->Size({100_percent, 100_px});
general_section->Title("General"); general_section->Title("General");
auto* gen_layout = new JUI::VerticalListLayout(general_section); auto* gen_layout = new JUI::VerticalListLayout(general_section);
sound_section = new JUI::Collapsible(root_layout); sound_section = new JUI::Collapsible(root_layout);
sound_section->Size({100_percent, 100_px});
sound_section->Title("Sound"); sound_section->Title("Sound");
auto* snd_layout = new JUI::VerticalListLayout(sound_section); auto* snd_layout = new JUI::VerticalListLayout(sound_section);
graphics_section = new JUI::Collapsible(root_layout); graphics_section = new JUI::Collapsible(root_layout);
graphics_section->Size({100_percent, 100_px});
graphics_section->Title("Graphics"); graphics_section->Title("Graphics");
auto* gfx_layout = new JUI::VerticalListLayout(graphics_section); auto* gfx_layout = new JUI::VerticalListLayout(graphics_section);
input_section = new JUI::Collapsible(root_layout); input_section = new JUI::Collapsible(root_layout);
input_section->Size({100_percent, 100_px});
input_section->Title("Input"); input_section->Title("Input");
Close();
} }
explicit SettingsMenu(Widget* parent) : SettingsMenu()
{
Parent(parent);
}
protected: protected:
JUI::Collapsible* general_section; JUI::Collapsible* general_section;
JUI::Collapsible* sound_section; JUI::Collapsible* sound_section;

View File

@@ -29,7 +29,7 @@ void CaveGame::Client::GameSession::Load() {
pause_menu = new PauseMenuWidget(hud); pause_menu = new PauseMenuWidget(hud);
pause_menu->OnQuitButtonPressed += [this] (){ SaveAndExit();}; pause_menu->OnQuitButtonPressed += [this] (){ SaveAndExit();};
pause_menu->OnResumeButtonPressed += [this] () { pause_menu->Close(); }; pause_menu->OnResumeButtonPressed += [this] () { pause_menu->Close(); };
pause_menu->OnSettingsButtonPressed += [this] () { Client::SettingsMenu::Instance().Toggle(); }; pause_menu->OnSettingsButtonPressed += [this] () { RequestToggleSettings.Invoke(); };
hotbar = TileHotbar(); hotbar = TileHotbar();
// TODO: Redundant, use the constructor. // TODO: Redundant, use the constructor.
@@ -69,6 +69,7 @@ void CaveGame::Client::GameSession::Draw() {
void CaveGame::Client::GameSession::SaveAndExit() { void CaveGame::Client::GameSession::SaveAndExit() {
world->SaveAndExit(); world->SaveAndExit();
OnSessionExit.Invoke();
} }

View File

@@ -4,6 +4,7 @@
#include "JUI/Widgets/Button.hpp" #include "JUI/Widgets/Button.hpp"
#include "JUI/Widgets/Image.hpp" #include "JUI/Widgets/Image.hpp"
#include "Client/AssetService.hpp" #include "Client/AssetService.hpp"
#include <Client/SettingsMenu.hpp>
CaveGame::Client::MainMenu::MainMenu() : Scene() CaveGame::Client::MainMenu::MainMenu() : Scene()
{ {
@@ -116,19 +117,18 @@ void CaveGame::Client::MainMenu::BuildWidgets() {
}; };
//auto *sp_btn = create_mainmenu_btn("Singleplayer", button_list); auto *settings_btn = create_mainmenu_btn("Settings", button_list);
//sp_btn->OnReleaseEvent += [this](Vector2 pos, MouseButton btn, bool b) { settings_btn->OnReleaseEvent += [this] (Vector2 pos, JUI::MouseButton btn, bool b) mutable {
// if (b) if (b)
// RequestWorld.Invoke({}); RequestToggleSettings.Invoke();
//}; };
auto *mp_btn = create_mainmenu_btn("Multiplayer", button_list);
auto *credits_btn = create_mainmenu_btn("Credits", button_list); auto *credits_btn = create_mainmenu_btn("Credits", button_list);
credits_btn->OnReleaseEvent += [this](Vector2 pos, JUI::MouseButton btn, bool b) { credits_btn->OnReleaseEvent += [this](Vector2 pos, JUI::MouseButton btn, bool b) {
if (b) if (b)
RequestShowCredits.Invoke(); RequestToggleCredits.Invoke();
}; };
// TODO: Replace with IconButton with steam logo // TODO: Replace with IconButton with steam logo

View File

@@ -6,11 +6,31 @@ namespace CaveGame::Client
{ {
void SceneManager::ChangeScene(Scene* new_scene) void SceneManager::ChangeScene(Scene* new_scene)
{ {
if (current_scene != nullptr) next_scene = new_scene;
current_scene->Unload();
current_scene = new_scene; //if (current_scene != nullptr)
current_scene->Load(); // current_scene->Unload();
//current_scene = new_scene;
//current_scene->Load();
}
void SceneManager::UpdateSceneState(float elapsed)
{
if (next_scene != nullptr)
{
if (current_scene != nullptr)
{
current_scene->Unload();
prev_scene = current_scene;
}
current_scene = next_scene;
current_scene->Load();
next_scene = nullptr;
}
} }
Scene* SceneManager::CurrentScene() { return current_scene; } Scene* SceneManager::CurrentScene() { return current_scene; }

View File

@@ -1,6 +1,6 @@
#include <Client/CreditsWindow.hpp> #include <Client/CreditsWindow.hpp>
#include "ClientApp/CaveGameWindow.hpp" #include "ClientApp/CaveGameWindow.hpp"
#include <Client/SettingsMenu.hpp>
#include <bits/random.h> #include <bits/random.h>
#include <Core/Explosion.hpp> #include <Core/Explosion.hpp>
#include <Core/Loggers.hpp> #include <Core/Loggers.hpp>
@@ -46,8 +46,17 @@ namespace CaveGame::ClientApp {
{ {
Logs::Info(std::format("Game session requested.", info.NewWorld)); Logs::Info(std::format("Game session requested.", info.NewWorld));
game_ctx = new CaveGame::Client::GameSession(info.NewWorld); game_ctx = new CaveGame::Client::GameSession(info.NewWorld);
// TODO: Parse Info to construct gameworld files. // TODO: Parse Info to construct gameworld files.
ChangeScene(game_ctx); ChangeScene(game_ctx);
game_ctx->RequestToggleSettings += [&, this] mutable {
settings_window->Toggle();
};
game_ctx->OnSessionExit += [&, this] mutable {
ChangeScene(menu_ctx);
};
} }
void CaveGameWindow::CreateContexts() void CaveGameWindow::CreateContexts()
@@ -56,18 +65,15 @@ namespace CaveGame::ClientApp {
splash_ctx = new CaveGame::Client::Splash(); splash_ctx = new CaveGame::Client::Splash();
Logs::Info("Building main menu."); Logs::Info("Building main menu.");
menu_ctx = new CaveGame::Client::MainMenu(); menu_ctx = new CaveGame::Client::MainMenu();
game_ctx = new CaveGame::Client::GameSession();
menu_ctx->RequestWorld += [this](Client::SingleplayerSessionInfo info) { menu_ctx->RequestWorld += [this](Client::SingleplayerSessionInfo info) {
OpenWorld(info); OpenWorld(info);
}; };
menu_ctx->RequestQuit += [this]() { menu_ctx->RequestQuit += [this] { Die(); };
Die(); menu_ctx->RequestToggleCredits += [this]{ credits_window->Toggle(); };
}; menu_ctx->RequestToggleSettings += [this] { settings_window->Toggle(); };
menu_ctx->RequestShowCredits += [this]()
{ game_ctx = new CaveGame::Client::GameSession();
credits_window->Visible(true);
};
} }
void CaveGameWindow::CreateMenuWindows() void CaveGameWindow::CreateMenuWindows()
@@ -154,10 +160,7 @@ namespace CaveGame::ClientApp {
void CaveGameWindow::create_settings_window() void CaveGameWindow::create_settings_window()
{ {
settings_window = new JUI::Window(wm); settings_window = new Client::SettingsMenu(wm);
settings_window->SetTitleFont(JGL::Fonts::Jupiteroid);
settings_window->SetTitle("Settings");
settings_window->Visible(false);
} }
@@ -236,9 +239,10 @@ namespace CaveGame::ClientApp {
void CaveGameWindow::Update(float elapsed) void CaveGameWindow::Update(float elapsed)
{ {
jstick::ReadEventLoop(); jstick::ReadEventLoop();
SceneManager::UpdateSceneState(elapsed);
// Update floating windows. // Update floating windows.
wm->Update(elapsed); wm->Update(elapsed);