summaryrefslogtreecommitdiffstats
path: root/game/client
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-03-15 16:59:59 +0500
committeruntodesu <kirill@untode.su>2025-03-15 16:59:59 +0500
commite53cca0ec8b4186cf79b6f927d74483f1301d5f6 (patch)
treea58bc914d7e21eea381470c8089d5b6d1b5c8bd3 /game/client
parent7ca5d9cdea5a26183808e06d7fb055674823ed5d (diff)
downloadvoxelius-e53cca0ec8b4186cf79b6f927d74483f1301d5f6.tar.bz2
voxelius-e53cca0ec8b4186cf79b6f927d74483f1301d5f6.zip
Add a key binding to show/hide HUD elements
- Just like in Minecraft, by default one would press the F1 key to toggle HUD elements (including player_target) visibility - Consequently moved player_target::render back into itself - Fixed-upped some language key-value pairs
Diffstat (limited to 'game/client')
-rw-r--r--game/client/chat.cc15
-rw-r--r--game/client/game.cc30
-rw-r--r--game/client/game.hh5
-rw-r--r--game/client/player_target.cc14
-rw-r--r--game/client/player_target.hh1
5 files changed, 52 insertions, 13 deletions
diff --git a/game/client/chat.cc b/game/client/chat.cc
index 64fba2a..177db08 100644
--- a/game/client/chat.cc
+++ b/game/client/chat.cc
@@ -205,8 +205,19 @@ void client_chat::layout(void)
auto fadeout_seconds = 10.0f;
auto fadeout = std::exp(-1.0f * std::pow(1.0e-6 * static_cast<float>(globals::curtime - it->spawn) / fadeout_seconds, 10.0f));
- auto rect_alpha = ((globals::gui_screen == GUI_CHAT) ? (0.75f) : (0.50f * fadeout));
- auto text_alpha = ((globals::gui_screen == GUI_CHAT) ? (1.00f) : (1.00f * fadeout));
+
+ float rect_alpha;
+ float text_alpha;
+
+ if(globals::gui_screen == GUI_CHAT) {
+ rect_alpha = 0.75f;
+ text_alpha = 1.00f;
+ }
+ else if(!client_game::hide_hud) {
+ rect_alpha = 0.50f * fadeout;
+ text_alpha = 1.00f * fadeout;
+ }
+ else break;
auto rect_col = ImGui::GetColorU32(ImGuiCol_FrameBg, rect_alpha);
auto text_col = ImGui::GetColorU32(ImVec4(it->color.x, it->color.y, it->color.z, it->color.w * text_alpha));
diff --git a/game/client/game.cc b/game/client/game.cc
index e6777c2..dcd463c 100644
--- a/game/client/game.cc
+++ b/game/client/game.cc
@@ -41,6 +41,7 @@
#include "client/gui_screen.hh"
#include "client/hotbar.hh"
#include "client/interpolation.hh"
+#include "client/keybind.hh"
#include "client/language.hh"
#include "client/listener.hh"
#include "client/main_menu.hh"
@@ -76,6 +77,10 @@ ConfigUnsigned client_game::pixel_size(2U, 1U, 4U);
ConfigUnsigned client_game::fog_mode(1U, 0U, 2U);
ConfigString client_game::username("player");
+bool client_game::hide_hud = false;
+
+static ConfigKeyBind hide_hud_toggle(GLFW_KEY_F1);
+
static resource_ptr<BinFile> bin_unscii16;
static resource_ptr<BinFile> bin_unscii8;
@@ -160,6 +165,13 @@ static void on_glfw_framebuffer_size(const GlfwFramebufferSizeEvent &event)
}
}
+static void on_glfw_key(const GlfwKeyEvent &event)
+{
+ if(!globals::gui_keybind_ptr && hide_hud_toggle.equals(event.key) && (event.action == GLFW_PRESS)) {
+ client_game::hide_hud = !client_game::hide_hud;
+ }
+}
+
void client_game::init(void)
{
bin_unscii16 = resource::load<BinFile>("fonts/unscii-16.ttf");
@@ -179,7 +191,8 @@ void client_game::init(void)
globals::client_config.add_value("game.pixel_size", client_game::pixel_size);
globals::client_config.add_value("game.fog_mode", client_game::fog_mode);
globals::client_config.add_value("game.username", client_game::username);
-
+ globals::client_config.add_value("game.key.toggle_hide_hud", hide_hud_toggle);
+
settings::init();
settings::add_checkbox(0, client_game::streamer_mode, settings_location::VIDEO_GUI, "game.streamer_mode", true);
@@ -188,6 +201,7 @@ void client_game::init(void)
settings::add_slider(1, client_game::pixel_size, settings_location::VIDEO, "game.pixel_size", true);
settings::add_stepper(3, client_game::fog_mode, settings_location::VIDEO, "game.fog_mode", false);
settings::add_input(1, client_game::username, settings_location::GENERAL, "game.username", true, false);
+ settings::add_keybind(4, hide_hud_toggle, settings_location::KEYBOARD_MISC, "game.key.toggle_hide_hud");
globals::client_host = enet_host_create(nullptr, 1, 1, 0, 0);
globals::client_host->checksum = &enet_crc32;
@@ -334,6 +348,7 @@ void client_game::init(void)
experiments::init();
globals::dispatcher.sink<GlfwFramebufferSizeEvent>().connect<&on_glfw_framebuffer_size>();
+ globals::dispatcher.sink<GlfwKeyEvent>().connect<&on_glfw_key>();
}
void client_game::init_late(void)
@@ -555,20 +570,13 @@ void client_game::render(void)
glEnable(GL_DEPTH_TEST);
- if(player_target::voxel != NULL_VOXEL_ID) {
- auto cpos = coord::to_chunk(player_target::coord);
- auto fpos = coord::to_local(player_target::coord);
-
- outline::prepare();
- outline::cube(cpos, glm::fvec3(fpos), glm::fvec3(1.0f), 2.0f, glm::fvec4(0.0f, 0.0f, 0.0f, 1.0f));
- }
+ player_target::render();
if(globals::dimension) {
auto group = globals::dimension->entities.group(entt::get<PlayerComponent, CollisionComponent, HeadComponentIntr, TransformComponentIntr>);
outline::prepare();
-
for(const auto [entity, collision, head, transform] : group.each()) {
if(entity == globals::player) {
// Don't render ourselves
@@ -607,7 +615,7 @@ void client_game::layout(void)
}
if(!globals::gui_screen || (globals::gui_screen == GUI_CHAT) || (globals::gui_screen == GUI_DEBUG_WINDOW)) {
- if(toggles::draw_metrics) {
+ if(toggles::draw_metrics && !client_game::hide_hud) {
// This contains Minecraft-esque debug information
// about the hardware, world state and other
// things that might be uesful
@@ -619,7 +627,7 @@ void client_game::layout(void)
client_chat::layout();
scoreboard::layout();
- if(!globals::gui_screen) {
+ if(!globals::gui_screen && !client_game::hide_hud) {
hotbar::layout();
status_lines::layout();
crosshair::layout();
diff --git a/game/client/game.hh b/game/client/game.hh
index 7deec6a..0887703 100644
--- a/game/client/game.hh
+++ b/game/client/game.hh
@@ -18,6 +18,11 @@ extern ConfigString username;
namespace client_game
{
+extern bool hide_hud;
+} // namespace client_game
+
+namespace client_game
+{
void init(void);
void init_late(void);
void deinit(void);
diff --git a/game/client/player_target.cc b/game/client/player_target.cc
index f2dd980..0c91876 100644
--- a/game/client/player_target.cc
+++ b/game/client/player_target.cc
@@ -1,11 +1,14 @@
#include "client/pch.hh"
#include "client/player_target.hh"
+#include "shared/coord.hh"
#include "shared/dimension.hh"
#include "shared/ray_dda.hh"
#include "client/camera.hh"
+#include "client/game.hh"
#include "client/globals.hh"
+#include "client/outline.hh"
#include "client/session.hh"
constexpr static float MAX_REACH = 16.0f;
@@ -50,3 +53,14 @@ void player_target::update(void)
player_target::info = nullptr;
}
}
+
+void player_target::render(void)
+{
+ if((player_target::voxel != NULL_VOXEL_ID) && !client_game::hide_hud) {
+ auto cpos = coord::to_chunk(player_target::coord);
+ auto fpos = coord::to_local(player_target::coord);
+
+ outline::prepare();
+ outline::cube(cpos, glm::fvec3(fpos), glm::fvec3(1.0f), 2.0f, glm::fvec4(0.0f, 0.0f, 0.0f, 1.0f));
+ }
+}
diff --git a/game/client/player_target.hh b/game/client/player_target.hh
index c584209..c48bcf6 100644
--- a/game/client/player_target.hh
+++ b/game/client/player_target.hh
@@ -16,6 +16,7 @@ namespace player_target
{
void init(void);
void update(void);
+void render(void);
} // namespace player_target
#endif /* CLIENT_PLAYER_TARGET_HH */