Added functionality to PauseMenu, other various edits.

This commit is contained in:
2025-04-10 14:57:22 -05:00
parent 35298ec28d
commit 6f0d7d734f
12 changed files with 81 additions and 214 deletions

View File

@@ -69,7 +69,7 @@ CPMAddPackage(
CPMAddPackage(
NAME JUI
URL https://git.redacted.cc/josh/ReJUI/archive/Prerelease-5.15.zip
URL https://git.redacted.cc/josh/ReJUI/archive/Prerelease-5.16.zip
)
CPMAddPackage(

View File

@@ -74,16 +74,19 @@ namespace CaveGame::Client {
bool LoadFromQueue(float maxTimeExpenditure = 1e-3f);
bool LoadAsset(const AssetRequest& request);
bool IsLoadComplete() const { return queue.empty(); }
void EnqueueDefaultAssetsFolder();
std::string LastAsset() const { return last_asset_processed; }
unsigned int TotalQueued() const { return total_queued; }
unsigned int TotalLoaded() const { return total_loaded; }
/// Read the manifest.json file to know which assets to enqueue for the loading screen sequence.
void ParseManifest();
/// Load certain critical assets immediately.
void PreloadCertainAssets();
protected:

View File

@@ -1,46 +0,0 @@
/// CaveGame - A procedural 2D platformer sandbox.
/// Created by Josh O'Leary @ Redacted Software, 2020-2025
/// Contact: josh@redacted.cc
/// Contributors: william@redacted.cc maxi@redacted.cc
/// This work is dedicated to the public domain.
/// @file Console.hpp
/// @desc The client-side user interface for the command console.
/// @edit 1/28/2025
/// @auth Josh O'Leary
#pragma once
#include <JUI/Widgets/Window.hpp>
#include <JUI/Widgets/TextInputForm.hpp>
#include <JUI/Widgets/ScrollingRect.hpp>
#include <JUI/Widgets/ListLayout.hpp>
namespace CaveGame::Client {
using namespace JUI::UDimLiterals;
class Console : public JUI::Window {
public:
int index = 0;
Event<std::string> OnInput;
void OnInputEvent(const std::string& msg);
explicit Console(Widget* parent);
void Log(const std::string& message, const Color4& color = Colors::White);
void ObserveKeyInput(Key key, bool pressed) override;
bool IsOpen() const;
void SetOpen(bool open);
protected:
JUI::TextInputForm* input_box;
JUI::ScrollingRect* message_log_box;
JUI::VerticalListLayout* message_log_layout;
bool console_open = false;
std::vector<std::string> history;
private:
};
}

View File

@@ -45,27 +45,12 @@ namespace CaveGame::Client {
void Load() override;
void Unload() override;
void PassWindowSize(const J3ML::LinearAlgebra::Vector2 &size) override;
void PassMouseInput(unsigned int a, bool b) override {
hud->ObserveMouseInput((JUI::MouseButton)a, b);
}
void PassMouseMovement(const J3ML::LinearAlgebra::Vector2 &pos) override {
void PassMouseInput(unsigned int a, bool b) override;
mouse_pos = pos;
world->mouse_pos = pos;
hud->ObserveMouseMovement(pos);
}
void PassMouseWheel(int wheel) override {
if (InputService::IsKeyDown(Keys::LeftShift)) {
float radius = tile_tool->BrushRadius();
radius -= wheel / 2.f;
radius = Math::Max(radius, 0.45f); // TODO: perform clamping inside the setter maybe?
tile_tool->BrushRadius(radius);
} else {
// TODO: hud->ObserveMouseWheel(wheel);
hotbar.OnMouseWheel(wheel);
}
void PassMouseMovement(const J3ML::LinearAlgebra::Vector2 &pos) override;
void PassMouseWheel(int wheel) override;
}
void PassKeyInput(Key key, bool pressed) override;
void SaveAndExit();
@@ -93,14 +78,9 @@ namespace CaveGame::Client {
RNG tool_rng;
private:
void WorldEditToolDrawTiles(TileID tile);
void WorldEditToolDrawTiles(int x, int y, int radius, int density, TileID tile);
void WorldEditToolDrawOverlay();
Vector2 MouseWorldPos();
Vector2 MouseWorldPos() const;
};
}

View File

@@ -22,8 +22,7 @@ namespace CaveGame::Client
/// It is safe to assume the parent will **ALWAYS** be the Scene* instance GameSession::hud.
explicit PauseMenuWidget(Widget* parent);
// TODO: This function signature will return void in the next JUI release.
void ObserveMouseInput(JUI::MouseButton btn, bool pressed) override;
bool ObserveMouseInput(JUI::MouseButton btn, bool pressed) override;
/// Switches the PauseMenu to it's alternate state, which is either "Open" or "Closed".
void Toggle();
@@ -35,10 +34,11 @@ namespace CaveGame::Client
[[nodiscard]] bool GetOpen() const;
/// Sets the state of the PauseMenu to "Open".
void Open() { SetOpen(true); }
void Open();
/// Sets the state of the Paus
void Close() { SetOpen(false); }
void Close();
protected:
JUI::Rect* button_box;
JUI::VerticalListLayout* button_list;

View File

@@ -47,16 +47,8 @@ namespace CaveGame::Client {
input_section = new JUI::Collapsible(root_layout);
input_section->Title("Input");
}
bool GetOpen() const;
void SetOpen(bool value);
void Toggle();
void Open();
void Close();
protected:
JUI::Collapsible* general_section;
JUI::Collapsible* sound_section;

View File

@@ -15,18 +15,7 @@ CaveGame::Client::AssetService::AssetService() {
ParseManifest();
}
void CaveGame::Client::AssetService::TempLoadSimple() {
//player_sprite = new JGL::Texture("assets/textures/player.png", JGL::FilteringMode::NEAREST);
//explosion_sprite = new JGL::Texture("assets/textures/explosion.png", JGL::FilteringMode::NEAREST);
//title_img = new JGL::Texture("assets/textures/title_1.png");
}
void CaveGame::Client::AssetService::EnqueueDefaultAssetsFolder() {
//EnqueueContents("assets");
//textures.emplace("player", new JGL::Texture("assets/textures/player.png"));
}
std::string CaveGame::Client::AssetService::FilenameFromPath(const std::filesystem::path &path) {
return path.string().substr(path.string().find_last_of("/\\") + 1);

View File

@@ -1,87 +0,0 @@
#include <Client/Console.hpp>
#include <Core/Loggers.hpp>
void CaveGame::Client::Console::OnInputEvent(const std::string &msg) {
Log(std::format(">{}", msg));
OnInput.Invoke(msg);
// TODO: Handle within JUI
input_box->SetAutoCompleteText("");
input_box->SetContent("");
}
CaveGame::Client::Console::Console(JUI::Widget *parent) : JUI::Window(parent)
{
this->SetTitle("Console");
message_log_box = new JUI::ScrollingRect(this->ViewportInstance());
message_log_box->Size(JUI::UDim2(0, -20, 1, 1));
message_log_layout = new JUI::VerticalListLayout(message_log_box);
message_log_layout->LayoutOrder(JUI::LayoutOrder::V::BOTTOM);
//message_log_view->Position(JUI::UDim2());
input_box = new JUI::TextInputForm(this->ViewportInstance());
input_box->SetContent("Test");
input_box->Size(JUI::UDim2(0, 20, 1, 0));
input_box->Position(JUI::UDim2(0, -20, 0, 1));
input_box->BGColor(Colors::Grays::DarkSlateGray);
input_box->SetTextSize(16);
input_box->SetAutoCompleteText("");
input_box->SetTextColor(Colors::White);
input_box->SetAutocompleteTextColor(Colors::White);
// TODO: input_box->ClearTextOnReturn(true);
input_box->OnReturn += [this] (const std::string& msg) {
OnInputEvent(msg);
};
CaveGame::Logs::Info.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Debug.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Warning.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Error.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Fatal.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Client.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Server.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Generator.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Lighting.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
// TODO: Integrate loggers into game console.
}
void CaveGame::Client::Console::Log(const std::string &message, const Color4& color) {
Color4 col_a = {64, 64, 64};
Color4 col_b = {92, 92, 92};
auto* entry = new JUI::TextRect(message_log_layout);
entry->Size({100_percent, 16_px});
entry->SetContent(message);
entry->LayoutOrder(index++);
entry->SetTextColor(Colors::Black);
entry->BGColor(index%2==0 ? col_a : col_b);
entry->SetTextSize(14);
entry->SetTextColor(color);
}
void CaveGame::Client::Console::ObserveKeyInput(Key key, bool pressed) {
if (!IsVisible())
return;
Widget::ObserveKeyInput(key, pressed);
}
void CaveGame::Client::Console::SetOpen(bool open) {
console_open = open;
if (open)
input_box->GrabFocus();
else
input_box->DropFocus();
Visible(open);
}
bool CaveGame::Client::Console::IsOpen() const { return console_open;}

View File

@@ -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().Open(); };
pause_menu->OnSettingsButtonPressed += [this] () { Client::SettingsMenu::Instance().Toggle(); };
hotbar = TileHotbar();
// TODO: Redundant, use the constructor.
@@ -46,10 +46,8 @@ void CaveGame::Client::GameSession::Load() {
//conn.Invoke(jstick::XBoxButton::BumperR);
//jstick::ButtonPressed.Invoke(jstick::XBoxButton::BumperL);
tile_tool = new TileTool(hud);
tile_tool->TileSimulationDisabledChanged += [this] (bool value) {
@@ -60,8 +58,6 @@ void CaveGame::Client::GameSession::Load() {
for (int i = 0; i < steps; i++)
World()->DoTileTiccs(0.f);
};
}
void CaveGame::Client::GameSession::Draw() {
@@ -76,13 +72,10 @@ void CaveGame::Client::GameSession::SaveAndExit() {
}
void CaveGame::Client::GameSession::WorldEditToolDrawTiles(int x, int y, int radius, int density, TileID tile)
{
void CaveGame::Client::GameSession::WorldEditToolDrawTiles(int x, int y, int radius, int density, TileID tile) {
tool_rng = RNG(x + y);
World()->SetTile(x, y, tile);
for (int dx = -radius; dx <= radius; ++dx)
for (int dy = -radius; dy <= radius; ++dy)
if (density >= 100 || density > tool_rng.Float(0, 99))
@@ -94,8 +87,7 @@ bool following = false;
Vector2 last = {0,0};
Vector2 CaveGame::Client::GameSession::MouseWorldPos()
{
Vector2 CaveGame::Client::GameSession::MouseWorldPos() const {
return World()->camera.ScreenToWorld(mouse_pos);
}
@@ -130,9 +122,6 @@ void CaveGame::Client::GameSession::WorldEditToolDrawTiles(TileID tile) {
last = floor_wc;
//}
}
void CaveGame::Client::GameSession::WorldEditToolControlsUpdate(float elapsed){
@@ -144,7 +133,6 @@ void CaveGame::Client::GameSession::WorldEditToolControlsUpdate(float elapsed){
}
WorldEditToolDrawTiles(Tiles()["air"].numeric_id);
} else {
if (following)
@@ -233,9 +221,6 @@ CaveGame::Client::GameSession::GameSession(bool overwite_world) : Scene() {
// Spawn in the player when the world is first loaded up.
world->AddEntity(new Core::Player({0, 0}));
//hud = new JUI::Scene();
}
void CaveGame::Client::GameSession::PassWindowSize(const Vector2 &size) {
@@ -243,6 +228,30 @@ void CaveGame::Client::GameSession::PassWindowSize(const Vector2 &size) {
hud->SetViewportSize(size);
}
void CaveGame::Client::GameSession::PassMouseInput(unsigned int a, bool b) {
hud->ObserveMouseInput((JUI::MouseButton)a, b);
}
void CaveGame::Client::GameSession::PassMouseMovement(const J3ML::LinearAlgebra::Vector2 &pos) {
mouse_pos = pos;
world->mouse_pos = pos;
hud->ObserveMouseMovement(pos);
}
void CaveGame::Client::GameSession::PassMouseWheel(int wheel) {
if (InputService::IsKeyDown(Keys::LeftShift)) {
float radius = tile_tool->BrushRadius();
radius -= wheel / 2.f;
radius = Math::Max(radius, 0.45f); // TODO: perform clamping inside the setter maybe?
tile_tool->BrushRadius(radius);
} else {
// TODO: hud->ObserveMouseWheel(wheel);
hotbar.OnMouseWheel(wheel);
}
}
void CaveGame::Client::GameSession::PassKeyInput(Key key, bool pressed) {
// DO NOT chain input conditions with else; you will introduce biasing
@@ -253,7 +262,6 @@ void CaveGame::Client::GameSession::PassKeyInput(Key key, bool pressed) {
hotbar.OnKeyInput(key, pressed);
}
void CaveGame::Client::GameSession::UnloadHUD() {
Logs::Info("Unloading player HUD.");
delete hud;

View File

@@ -31,6 +31,10 @@ namespace CaveGame::Client
resume_btn->BGColor(resume_btn->BaseBGColor());
resume_btn->SetContent("Resume");
resume_btn->OnClickEvent += [this] (Vector2 pos, JUI::MouseButton state) {
OnResumeButtonPressed.Invoke();
};
settings_btn = new JUI::TextButton(button_list);
settings_btn->Size({100_percent, 50_px});
settings_btn->CornerRounding(7);
@@ -42,6 +46,10 @@ namespace CaveGame::Client
settings_btn->BGColor(settings_btn->BaseBGColor());
settings_btn->SetContent("Settings");
settings_btn->OnClickEvent += [this] (Vector2 pos, JUI::MouseButton state) {
OnSettingsButtonPressed.Invoke();
};
quit_btn = new JUI::TextButton(button_list);
quit_btn->Size({100_percent, 50_px});
quit_btn->CornerRounding(7);
@@ -53,6 +61,10 @@ namespace CaveGame::Client
quit_btn->BGColor(quit_btn->BaseBGColor());
quit_btn->SetContent("Save & Exit World");
quit_btn->OnClickEvent += [this] (Vector2 pos, JUI::MouseButton state) {
OnQuitButtonPressed.Invoke();
};
// Default-initialize as closed.
this->Close();
}
@@ -61,9 +73,11 @@ namespace CaveGame::Client
this->Parent(parent);
}
void PauseMenuWidget::ObserveMouseInput(JUI::MouseButton btn, bool pressed) {
bool PauseMenuWidget::ObserveMouseInput(JUI::MouseButton btn, bool pressed) {
if (is_open)
return Rect::ObserveMouseInput(btn, pressed);
return false;
}
void PauseMenuWidget::Toggle() {
@@ -76,5 +90,9 @@ namespace CaveGame::Client
}
bool PauseMenuWidget::GetOpen() const { return is_open; }
void PauseMenuWidget::Open() { SetOpen(true); }
void PauseMenuWidget::Close() { SetOpen(false); }
}

View File

@@ -23,7 +23,7 @@
#include <JUI/Widgets/Window.hpp>
#include <Client/Scene.hpp>
#include <Client/SceneManager.hpp>
#include <Client/Console.hpp>
#include <JUI/Widgets/CommandLine.hpp>
#include <Client/TileTool.hpp>
#include "Command.hpp"
#include <Core/Player.hpp>
@@ -69,7 +69,7 @@ namespace CaveGame::ClientApp {
bool ReadyToClose() const;
/// Returns the game's console GUI, which accepts commands and displays log messages.
Client::Console* Console();
JUI::CommandLine* Console();
/// Returns the Scene that holds global menu windows, which can appear in any game-context.
JUI::Scene* WindowManager();
/// Returns the active game-world session, if it exists.
@@ -165,7 +165,7 @@ namespace CaveGame::ClientApp {
}},
{"tilesim", {"q"}, [this](const CommandArgs& args) { return ToggleTileSim(args);}},
{"grid", {"q"}, [this](const CommandArgs& args) {}},
{"credits", {"q"}, [this](const CommandArgs& args) { credits_window->Visible(!credits_window->IsVisible()); }},
{"credits", {"q"}, [this](const CommandArgs& args) { credits_window->Toggle(); }},
{"settings", {"q"}, [this](const CommandArgs& args) {}},
{"spawn", {}, [this](const CommandArgs& args) {
if (!InGame())
@@ -261,7 +261,7 @@ namespace CaveGame::ClientApp {
JUI::Window* settings_window = nullptr;
JUI::Window* credits_window = nullptr;
Client::Console* console_window = nullptr;
JUI::CommandLine* console_window = nullptr;
JUI::Window* stats_window = nullptr;
protected: // Primitive class members.
/// This field indicates the program is ready to close.

View File

@@ -121,10 +121,6 @@ namespace CaveGame::ClientApp {
this->assets.PreloadCertainAssets();
this->assets.ParseManifest();
// TODO: Replace w/ constructor?
this->assets.TempLoadSimple();
this->assets.EnqueueDefaultAssetsFolder();
//for (int i = 0; i < 10; i++)
//{
//assets.EnqueueTexture("assets/textures/redacted.png");
@@ -529,8 +525,22 @@ namespace CaveGame::ClientApp {
}
void CaveGameWindow::create_console_window() {
console_window = new Client::Console(this->wm);
console_window = new JUI::CommandLine(this->wm);
console_window->Visible(false);
CaveGame::Logs::Info.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Debug.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Warning.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Error.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Fatal.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Client.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Server.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Generator.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
CaveGame::Logs::Lighting.OnLog += [this](std::string m, Color4 c) {Log(m, c); };
//console_window->
console_window->OnInput += [this] (const std::string& msg)
{
@@ -573,7 +583,7 @@ namespace CaveGame::ClientApp {
JUI::Scene *CaveGameWindow::WindowManager() { return wm;}
Client::Console *CaveGameWindow::Console() { return console_window; }
JUI::CommandLine *CaveGameWindow::Console() { return console_window; }
bool CaveGameWindow::ToggleTileSim(const CommandArgs &args) {
if (InGame())