Implement basis for Pause Menu.
This commit is contained in:
@@ -25,24 +25,14 @@
|
||||
#include <Core/Item.hpp>
|
||||
#include "TileTool.hpp"
|
||||
#include "ContainerWindow.hpp"
|
||||
#include <Client/PauseMenu.hpp>
|
||||
|
||||
namespace CaveGame::Client {
|
||||
using namespace Core;
|
||||
|
||||
class LootTable {
|
||||
|
||||
};
|
||||
|
||||
class LootTable {};
|
||||
class CraftingStation {};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ContainerGUI {
|
||||
|
||||
};
|
||||
class ContainerGUI {};
|
||||
|
||||
using namespace JUI::UDimLiterals;
|
||||
using CaveGame::Core::Entity;
|
||||
@@ -50,7 +40,7 @@ namespace CaveGame::Client {
|
||||
public:
|
||||
|
||||
GameSession() = default;
|
||||
GameSession(bool createNewWorld);
|
||||
explicit GameSession(bool createNewWorld);
|
||||
void Update(float elapsed) override;
|
||||
void Draw() override;
|
||||
void Load() override;
|
||||
@@ -99,6 +89,7 @@ namespace CaveGame::Client {
|
||||
LocalWorld* world = nullptr;
|
||||
TileHotbar hotbar;
|
||||
JUI::Scene* hud = nullptr;
|
||||
PauseMenuWidget* pause_menu = nullptr;
|
||||
Vector2 mouse_pos = {0,0};
|
||||
RNG tool_rng;
|
||||
|
||||
|
@@ -1,11 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include <JUI/Widgets/Rect.hpp>
|
||||
#include <JUI/Widgets/ListLayout.hpp>
|
||||
#include <JUI/Widgets/TextButton.hpp>
|
||||
|
||||
namespace CaveGame::Client
|
||||
{
|
||||
class PauseMenuWidget : public JUI::Rect {
|
||||
using namespace JUI::UDimLiterals;
|
||||
|
||||
class PauseMenuWidget : public JUI::Rect {
|
||||
public:
|
||||
Event<> OnSettingsButtonPressed;
|
||||
Event<> OnQuitButtonPressed;
|
||||
|
||||
PauseMenuWidget() {
|
||||
this->Size({100_percent, 100_percent}); // Full Screen.
|
||||
this->BGColor({128, 128, 128, 128}); // Transparent Gray.
|
||||
|
||||
button_box = new JUI::Rect(this);
|
||||
button_box->Size({150_px, 150_px});
|
||||
|
||||
button_list = new JUI::VerticalListLayout(button_box);
|
||||
|
||||
resume_btn = new JUI::TextButton(button_list);
|
||||
resume_btn->SetContent("Resume");
|
||||
|
||||
|
||||
settings_btn = new JUI::TextButton(button_list);
|
||||
settings_btn->SetContent("Settings");
|
||||
|
||||
quit_btn = new JUI::TextButton(button_list);
|
||||
quit_btn->SetContent("Save & Exit World");
|
||||
}
|
||||
|
||||
explicit PauseMenuWidget(Widget* parent) : PauseMenuWidget() {
|
||||
this->Parent(parent);
|
||||
}
|
||||
|
||||
void Toggle() {
|
||||
is_open = !is_open;
|
||||
this->Visible(is_open);
|
||||
}
|
||||
protected:
|
||||
JUI::Rect* button_box;
|
||||
JUI::VerticalListLayout* button_list;
|
||||
JUI::TextButton* resume_btn;
|
||||
JUI::TextButton* settings_btn;
|
||||
JUI::TextButton* quit_btn;
|
||||
|
||||
bool is_open;
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
|
@@ -24,6 +24,9 @@ void CaveGame::Client::GameSession::Load() {
|
||||
world->PostInit();
|
||||
Logs::Info("Building player HUD.");
|
||||
hud = new JUI::Scene();
|
||||
|
||||
pause_menu = new PauseMenuWidget(hud);
|
||||
|
||||
hotbar = TileHotbar();
|
||||
// TODO: Redundant, use the constructor.
|
||||
hotbar.Load(world);
|
||||
@@ -98,8 +101,6 @@ void CaveGame::Client::GameSession::WorldEditToolDrawTiles(TileID tile) {
|
||||
//Vector2i rounded_coords = {Math::FloorInt(world_coords.x), Math::FloorInt(world_coords.y)};
|
||||
|
||||
|
||||
|
||||
|
||||
int radius = Math::FloorInt(tile_tool->BrushRadius());
|
||||
int density = Math::FloorInt(tile_tool->BrushDensity());
|
||||
int x = Math::FloorInt(world_coords.x);
|
||||
@@ -183,7 +184,7 @@ void CaveGame::Client::GameSession::Update(float elapsed) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Move the tile cursor when controller thumbstick is moved.
|
||||
auto rstick = jstick::GetRightThumbstickAxisNormalized();
|
||||
|
||||
if (rstick.Magnitude() > 0.1f)
|
||||
@@ -191,40 +192,6 @@ void CaveGame::Client::GameSession::Update(float elapsed) {
|
||||
float joystick_cursor_speed = 250.f;
|
||||
mouse_pos += rstick*elapsed*joystick_cursor_speed;
|
||||
}
|
||||
|
||||
|
||||
// FIXME: Temporary hack, we poll the bumper button state each frame, cause the jstick event doesn't propagate for some reason.
|
||||
/* bool lprn = jstick::IsButtonDown(jstick::XBoxButton::BumperL);
|
||||
bool rprn = jstick::IsButtonDown(jstick::XBoxButton::BumperR);
|
||||
|
||||
if (lprn && !lp)
|
||||
hotbar.PrevSlot();
|
||||
|
||||
if (rprn && !rp)
|
||||
hotbar.NextSlot();
|
||||
|
||||
lp = lprn;
|
||||
rp = rprn;*/
|
||||
|
||||
|
||||
/*
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
float angle = tool_rng.Float01Incl() * Math::TwoPi;
|
||||
Vector2 unit = {Math::Cos(angle), Math::Sin(angle)};
|
||||
Vector2 velocity = unit * tool_rng.Float(1, 50);
|
||||
world->Emit({.position = transformed, .velocity = velocity, .color = Colors::Red, .size = 2, .life = 3});
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: Do this once JUI can consume input.
|
||||
//
|
||||
// WorldEditToolControlsUpdate(elapsed);
|
||||
|
||||
//for (auto& entity: entity_list)
|
||||
//{
|
||||
// entity->Update(elapsed);
|
||||
//}
|
||||
}
|
||||
|
||||
void CaveGame::Client::GameSession::WorldEditToolDrawOverlay()
|
||||
@@ -275,6 +242,9 @@ void CaveGame::Client::GameSession::PassWindowSize(const Vector2 &size) {
|
||||
void CaveGame::Client::GameSession::PassKeyInput(Key key, bool pressed) {
|
||||
// DO NOT chain input conditions with else; you will introduce biasing
|
||||
|
||||
if (key == Keys::Escape)
|
||||
pause_menu->Toggle();
|
||||
|
||||
hud->ObserveKeyInput(key, pressed);
|
||||
hotbar.OnKeyInput(key, pressed);
|
||||
}
|
||||
|
Reference in New Issue
Block a user