|
|
|
@@ -1,3 +1,14 @@
|
|
|
|
|
/// CaveGame - A procedural 2D platformer sandbox.
|
|
|
|
|
/// Created by Josh O'Leary @ Redacted Software, 2020-2024
|
|
|
|
|
/// Contact: josh@redacted.cc
|
|
|
|
|
/// Contributors: william@redacted.cc maxi@redacted.cc
|
|
|
|
|
/// This work is dedicated to the public domain.
|
|
|
|
|
|
|
|
|
|
/// @file CaveGameWindow.hpp
|
|
|
|
|
/// @desc The Client App Window. See ReWindow's Documentation.
|
|
|
|
|
/// @edit 11/1/2024
|
|
|
|
|
/// @auth Josh O'Leary
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <Client/AssetService.hpp>
|
|
|
|
@@ -32,6 +43,12 @@ namespace CaveGame::ClientApp {
|
|
|
|
|
/// This class is derived from RWindow class.
|
|
|
|
|
class CaveGameWindow : public ReWindow::OpenGLWindow, public SceneManager {
|
|
|
|
|
public:
|
|
|
|
|
/// Constructs and returns an instance of the game program.
|
|
|
|
|
/// @param title
|
|
|
|
|
CaveGameWindow(const std::string& title, int width, int height);
|
|
|
|
|
/// Destructor called when deleting the CaveGameWindow.
|
|
|
|
|
~CaveGameWindow() override;
|
|
|
|
|
|
|
|
|
|
/// Returns the game's console GUI, which accepts commands and displays log messages.
|
|
|
|
|
Client::Console* Console();
|
|
|
|
|
/// Returns the Scene that holds global menu windows, which can appear in any game-context.
|
|
|
|
@@ -39,15 +56,13 @@ namespace CaveGame::ClientApp {
|
|
|
|
|
/// Returns the active game-world session, if it exists.
|
|
|
|
|
Client::GameSession* GameSession();
|
|
|
|
|
|
|
|
|
|
/// Constructs and returns an instance of the game program.
|
|
|
|
|
/// @param title
|
|
|
|
|
CaveGameWindow(const std::string& title, int width, int height);
|
|
|
|
|
~CaveGameWindow() override;
|
|
|
|
|
Vector2 GetMouseV2() const;
|
|
|
|
|
Vector2 GetSizeV2() const;
|
|
|
|
|
bool InGame() const;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] bool InGameSession() const;
|
|
|
|
|
/// @return the user's mouse coordinates from the RWindow layer.
|
|
|
|
|
[[nodiscard]] Vector2 GetMouseV2() const;
|
|
|
|
|
/// @return the window's size from the RWindow layer.
|
|
|
|
|
[[nodiscard]] Vector2 GetSizeV2() const;
|
|
|
|
|
/// @return true if the game is currently in-session.
|
|
|
|
|
[[nodiscard]] bool InGame() const;
|
|
|
|
|
/// @returns true if the game is currently in the main menu.
|
|
|
|
|
[[nodiscard]] bool InMainMenu() const;
|
|
|
|
|
|
|
|
|
|
/// This function runs the totality of the game loop, start to finish.
|
|
|
|
@@ -58,13 +73,15 @@ namespace CaveGame::ClientApp {
|
|
|
|
|
void Die();
|
|
|
|
|
/// This function sets up the initial program state, particularly that which must be performed **after** the window is opened.
|
|
|
|
|
void Init();
|
|
|
|
|
void tile_draw(int x, int y, int radius, Core::TileID tile);
|
|
|
|
|
/// This function cleans up any data or assets before closing the game.
|
|
|
|
|
void Cleanup();
|
|
|
|
|
/// This function performs logic calculation routines, once per refresh.
|
|
|
|
|
void Update(float elapsed);
|
|
|
|
|
/// This function performs rendering routines, once per refresh.
|
|
|
|
|
void Draw();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
void OnRefresh(float elapsed) override;
|
|
|
|
|
void OnMouseButtonDown(const ReWindow::MouseButtonDownEvent &ev) override;
|
|
|
|
@@ -75,6 +92,14 @@ namespace CaveGame::ClientApp {
|
|
|
|
|
void OnMouseMove(const ReWindow::MouseMoveEvent &ev) override;
|
|
|
|
|
bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent &ev) override;
|
|
|
|
|
void OnClosing() override;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/// Forwards a message to the console log.
|
|
|
|
|
void Log(const std::string& msg, const Color4& color = Colors::White);
|
|
|
|
|
bool HasCommand(const std::string &command);
|
|
|
|
|
Command GetCommand(const std::string &command);
|
|
|
|
|
void tile_draw(int x, int y, int radius, Core::TileID tile);
|
|
|
|
|
protected:
|
|
|
|
|
void create_tool_window();
|
|
|
|
|
void create_console_window();
|
|
|
|
@@ -91,36 +116,34 @@ namespace CaveGame::ClientApp {
|
|
|
|
|
void InGameControls(float elapsed);
|
|
|
|
|
void OnConsoleCommandInput(const std::string &command);
|
|
|
|
|
void DrawTileToolOverlayCursor();
|
|
|
|
|
/// Forwards a message to the console log.
|
|
|
|
|
void Log(const std::string& msg, const Color4& color = Colors::White);
|
|
|
|
|
|
|
|
|
|
/// Logs help information to the console. Called when the user runs the 'help' command.
|
|
|
|
|
bool HelpCommand(const CommandArgs& args);
|
|
|
|
|
bool ListCommand(const CommandArgs& args);
|
|
|
|
|
/// Toggles tile simulation if we are
|
|
|
|
|
bool ToggleTileSim(const CommandArgs& args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// What is this dog shit?
|
|
|
|
|
std::vector<Command> commands {
|
|
|
|
|
{"help", {}, [this](const auto& args) {return HelpCommand(args); }},
|
|
|
|
|
{"list", {}, [this](const auto& args) { return ListCommand(args); }},
|
|
|
|
|
{"quit", {"q"}, [this](const auto& args) {
|
|
|
|
|
Close();
|
|
|
|
|
return true;
|
|
|
|
|
}},
|
|
|
|
|
{"worldedit", {"we"}, [this](const auto& args) {
|
|
|
|
|
/// This table defines the supported console commands, their aliases, and the callback lambda.
|
|
|
|
|
#pragma region Commands
|
|
|
|
|
const std::vector<Command> commands {
|
|
|
|
|
{"help", {}, [this](const CommandArgs& args) { HelpCommand(args); }},
|
|
|
|
|
{"list", {}, [this](const CommandArgs& args) { ListCommand(args); }},
|
|
|
|
|
{"quit", {"q"}, [this](const CommandArgs& args) { Close(); }},
|
|
|
|
|
{"worldedit", {"we"}, [this](const CommandArgs& args) {
|
|
|
|
|
tile_tool->Enable(!tile_tool->IsEnabled());
|
|
|
|
|
return true;
|
|
|
|
|
}},
|
|
|
|
|
{"tilesim", {"q"}, [this](const auto& args) { return ToggleTileSim(args);}},
|
|
|
|
|
{"grid", {"q"}, [this](const auto& args) {}},
|
|
|
|
|
{"credits", {"q"}, [this](const auto& args) {credits_window->Visible(!credits_window->IsVisible()); }},
|
|
|
|
|
{"settings", {"q"}, [this](const auto& args) {}},
|
|
|
|
|
{"spawn", {"q"}, [this](const auto& args) {}},
|
|
|
|
|
{"settings", {"q"}, [this](const auto& args) {}},
|
|
|
|
|
{"give", {"q"}, [this](const auto& args) {}},
|
|
|
|
|
{"tp", {"q"}, [this](const auto& args) {}},
|
|
|
|
|
{"freecam", {"q"}, [this](const auto& args) {}},
|
|
|
|
|
{"noclip", {"q"}, [this](const auto& args) {}},
|
|
|
|
|
{"god", {"q"}, [this](const auto& args) {}},
|
|
|
|
|
{"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()); }},
|
|
|
|
|
{"settings", {"q"}, [this](const CommandArgs& args) {}},
|
|
|
|
|
{"spawn", {"q"}, [this](const CommandArgs& args) {}},
|
|
|
|
|
{"settings", {"q"}, [this](const CommandArgs& args) {}},
|
|
|
|
|
{"give", {"q"}, [this](const CommandArgs& args) {}},
|
|
|
|
|
{"tp", {"q"}, [this](const CommandArgs& args) {}},
|
|
|
|
|
{"freecam", {"q"}, [this](const CommandArgs& args) {}},
|
|
|
|
|
{"noclip", {"q"}, [this](const CommandArgs& args) {}},
|
|
|
|
|
{"god", {"q"}, [this](const CommandArgs& args) {}},
|
|
|
|
|
{"fullbright", {"q"}, [this](const auto& args) {}},
|
|
|
|
|
{"connect", {"q"}, [this](const auto& args) {}},
|
|
|
|
|
{"disconnect", {"q"}, [this](const auto& args) {}},
|
|
|
|
@@ -158,25 +181,24 @@ namespace CaveGame::ClientApp {
|
|
|
|
|
Log("Nope");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
|
|
bool HasCommand(const std::string &command);
|
|
|
|
|
Command GetCommand(const std::string &command);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
protected: // Complex class members.
|
|
|
|
|
Client::AssetService assets;
|
|
|
|
|
CaveGame::Client::Splash* splash_ctx;
|
|
|
|
|
CaveGame::Client::MainMenu* menu_ctx;
|
|
|
|
|
CaveGame::Client::GameSession* game_ctx;
|
|
|
|
|
JUI::Scene* wm;
|
|
|
|
|
JUI::Window* settings_window;
|
|
|
|
|
JUI::Window* credits_window;
|
|
|
|
|
Client::TileTool* tile_tool;
|
|
|
|
|
Client::Console* console_window;
|
|
|
|
|
CaveGame::Client::Splash* splash_ctx = nullptr;
|
|
|
|
|
CaveGame::Client::MainMenu* menu_ctx = nullptr;
|
|
|
|
|
CaveGame::Client::GameSession* game_ctx = nullptr;
|
|
|
|
|
JUI::Scene* wm = nullptr;
|
|
|
|
|
JUI::Window* settings_window = nullptr;
|
|
|
|
|
JUI::Window* credits_window = nullptr;
|
|
|
|
|
Client::TileTool* tile_tool = nullptr;
|
|
|
|
|
Client::Console* console_window = nullptr;
|
|
|
|
|
JUI::Window* stats_window = nullptr;
|
|
|
|
|
protected: // Primitive class members.
|
|
|
|
|
float tool_radius = 8.f;
|
|
|
|
|
float tool_percent = 100.f;
|
|
|
|
|
bool wanna_die = false; // This field indicates the program is ready to close.
|
|
|
|
|
JUI::Window* stats_window;
|
|
|
|
|
|
|
|
|
|
bool render_grid = true;
|
|
|
|
|
bool generate_grid = true;
|
|
|
|
|
bool mbd = false;
|
|
|
|
|