Finalize Pause menu and setup of settings menu.
This commit is contained in:
@@ -38,6 +38,9 @@ namespace CaveGame::Client {
|
||||
class GameSession : public Scene {
|
||||
public:
|
||||
|
||||
Event<> OnSessionExit;
|
||||
Event<> RequestToggleSettings;
|
||||
|
||||
GameSession() = default;
|
||||
explicit GameSession(bool createNewWorld);
|
||||
void Update(float elapsed) override;
|
||||
|
@@ -30,7 +30,9 @@ namespace CaveGame::Client
|
||||
public:
|
||||
Event<SingleplayerSessionInfo> RequestWorld;
|
||||
Event<> RequestQuit;
|
||||
Event<> RequestShowCredits;
|
||||
Event<> RequestToggleCredits;
|
||||
Event<> RequestToggleSettings;
|
||||
|
||||
MainMenu();
|
||||
void Update(float elapsed) override;
|
||||
void Draw() override;
|
||||
|
@@ -21,7 +21,10 @@ namespace CaveGame::Client
|
||||
void ChangeScene(Scene* new_scene);
|
||||
Scene* CurrentScene();
|
||||
protected:
|
||||
void UpdateSceneState(float elapsed);
|
||||
protected:
|
||||
Scene* next_scene = nullptr;
|
||||
Scene* current_scene = nullptr;
|
||||
private:
|
||||
Scene* prev_scene = nullptr;
|
||||
};
|
||||
}
|
@@ -20,35 +20,53 @@
|
||||
namespace CaveGame::Client {
|
||||
|
||||
// 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:
|
||||
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->Size({100_percent, 100_px});
|
||||
general_section->Title("General");
|
||||
|
||||
auto* gen_layout = new JUI::VerticalListLayout(general_section);
|
||||
|
||||
|
||||
sound_section = new JUI::Collapsible(root_layout);
|
||||
sound_section->Size({100_percent, 100_px});
|
||||
sound_section->Title("Sound");
|
||||
|
||||
auto* snd_layout = new JUI::VerticalListLayout(sound_section);
|
||||
|
||||
graphics_section = new JUI::Collapsible(root_layout);
|
||||
graphics_section->Size({100_percent, 100_px});
|
||||
graphics_section->Title("Graphics");
|
||||
|
||||
auto* gfx_layout = new JUI::VerticalListLayout(graphics_section);
|
||||
|
||||
input_section = new JUI::Collapsible(root_layout);
|
||||
input_section->Size({100_percent, 100_px});
|
||||
input_section->Title("Input");
|
||||
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
explicit SettingsMenu(Widget* parent) : SettingsMenu()
|
||||
{
|
||||
Parent(parent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
JUI::Collapsible* general_section;
|
||||
JUI::Collapsible* sound_section;
|
||||
|
@@ -29,7 +29,7 @@ void CaveGame::Client::GameSession::Load() {
|
||||
pause_menu = new PauseMenuWidget(hud);
|
||||
pause_menu->OnQuitButtonPressed += [this] (){ SaveAndExit();};
|
||||
pause_menu->OnResumeButtonPressed += [this] () { pause_menu->Close(); };
|
||||
pause_menu->OnSettingsButtonPressed += [this] () { Client::SettingsMenu::Instance().Toggle(); };
|
||||
pause_menu->OnSettingsButtonPressed += [this] () { RequestToggleSettings.Invoke(); };
|
||||
|
||||
hotbar = TileHotbar();
|
||||
// TODO: Redundant, use the constructor.
|
||||
@@ -69,6 +69,7 @@ void CaveGame::Client::GameSession::Draw() {
|
||||
|
||||
void CaveGame::Client::GameSession::SaveAndExit() {
|
||||
world->SaveAndExit();
|
||||
OnSessionExit.Invoke();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include "JUI/Widgets/Button.hpp"
|
||||
#include "JUI/Widgets/Image.hpp"
|
||||
#include "Client/AssetService.hpp"
|
||||
#include <Client/SettingsMenu.hpp>
|
||||
|
||||
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) {
|
||||
// if (b)
|
||||
// RequestWorld.Invoke({});
|
||||
//};
|
||||
settings_btn->OnReleaseEvent += [this] (Vector2 pos, JUI::MouseButton btn, bool b) mutable {
|
||||
if (b)
|
||||
RequestToggleSettings.Invoke();
|
||||
};
|
||||
|
||||
auto *mp_btn = create_mainmenu_btn("Multiplayer", button_list);
|
||||
auto *credits_btn = create_mainmenu_btn("Credits", button_list);
|
||||
|
||||
credits_btn->OnReleaseEvent += [this](Vector2 pos, JUI::MouseButton btn, bool b) {
|
||||
if (b)
|
||||
RequestShowCredits.Invoke();
|
||||
RequestToggleCredits.Invoke();
|
||||
};
|
||||
|
||||
// TODO: Replace with IconButton with steam logo
|
||||
|
@@ -6,11 +6,31 @@ namespace CaveGame::Client
|
||||
{
|
||||
void SceneManager::ChangeScene(Scene* new_scene)
|
||||
{
|
||||
if (current_scene != nullptr)
|
||||
current_scene->Unload();
|
||||
next_scene = new_scene;
|
||||
|
||||
current_scene = new_scene;
|
||||
current_scene->Load();
|
||||
//if (current_scene != nullptr)
|
||||
// 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; }
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <Client/CreditsWindow.hpp>
|
||||
#include "ClientApp/CaveGameWindow.hpp"
|
||||
|
||||
#include <Client/SettingsMenu.hpp>
|
||||
#include <bits/random.h>
|
||||
#include <Core/Explosion.hpp>
|
||||
#include <Core/Loggers.hpp>
|
||||
@@ -46,8 +46,17 @@ namespace CaveGame::ClientApp {
|
||||
{
|
||||
Logs::Info(std::format("Game session requested.", info.NewWorld));
|
||||
game_ctx = new CaveGame::Client::GameSession(info.NewWorld);
|
||||
|
||||
// TODO: Parse Info to construct gameworld files.
|
||||
ChangeScene(game_ctx);
|
||||
|
||||
game_ctx->RequestToggleSettings += [&, this] mutable {
|
||||
settings_window->Toggle();
|
||||
};
|
||||
|
||||
game_ctx->OnSessionExit += [&, this] mutable {
|
||||
ChangeScene(menu_ctx);
|
||||
};
|
||||
}
|
||||
|
||||
void CaveGameWindow::CreateContexts()
|
||||
@@ -56,18 +65,15 @@ namespace CaveGame::ClientApp {
|
||||
splash_ctx = new CaveGame::Client::Splash();
|
||||
Logs::Info("Building main menu.");
|
||||
menu_ctx = new CaveGame::Client::MainMenu();
|
||||
game_ctx = new CaveGame::Client::GameSession();
|
||||
|
||||
menu_ctx->RequestWorld += [this](Client::SingleplayerSessionInfo info) {
|
||||
OpenWorld(info);
|
||||
};
|
||||
menu_ctx->RequestQuit += [this]() {
|
||||
Die();
|
||||
};
|
||||
menu_ctx->RequestShowCredits += [this]()
|
||||
{
|
||||
credits_window->Visible(true);
|
||||
};
|
||||
menu_ctx->RequestQuit += [this] { Die(); };
|
||||
menu_ctx->RequestToggleCredits += [this]{ credits_window->Toggle(); };
|
||||
menu_ctx->RequestToggleSettings += [this] { settings_window->Toggle(); };
|
||||
|
||||
game_ctx = new CaveGame::Client::GameSession();
|
||||
}
|
||||
|
||||
void CaveGameWindow::CreateMenuWindows()
|
||||
@@ -154,10 +160,7 @@ namespace CaveGame::ClientApp {
|
||||
|
||||
void CaveGameWindow::create_settings_window()
|
||||
{
|
||||
settings_window = new JUI::Window(wm);
|
||||
settings_window->SetTitleFont(JGL::Fonts::Jupiteroid);
|
||||
settings_window->SetTitle("Settings");
|
||||
settings_window->Visible(false);
|
||||
settings_window = new Client::SettingsMenu(wm);
|
||||
}
|
||||
|
||||
|
||||
@@ -236,9 +239,10 @@ namespace CaveGame::ClientApp {
|
||||
|
||||
void CaveGameWindow::Update(float elapsed)
|
||||
{
|
||||
|
||||
jstick::ReadEventLoop();
|
||||
|
||||
SceneManager::UpdateSceneState(elapsed);
|
||||
|
||||
// Update floating windows.
|
||||
wm->Update(elapsed);
|
||||
|
||||
|
Reference in New Issue
Block a user