]> git.lizzy.rs Git - minetest.git/commitdiff
Add chat HUD flag (#13189)
authorAlex <24834740+GreenXenith@users.noreply.github.com>
Mon, 20 Feb 2023 20:00:37 +0000 (12:00 -0800)
committerGitHub <noreply@github.com>
Mon, 20 Feb 2023 20:00:37 +0000 (21:00 +0100)
doc/lua_api.txt
src/client/game.cpp
src/client/gameui.cpp
src/client/gameui.h
src/hud.cpp
src/hud.h
src/player.cpp

index c1e26c72eacc6ec0fbc99264f63c954354ec4c44..85f88db335448aa449ec8da4662fd7646b92f6ed 100644 (file)
@@ -7274,6 +7274,8 @@ child will follow movement and rotation of that bone.
         * `basic_debug`: Allow showing basic debug info that might give a gameplay advantage.
           This includes map seed, player position, look direction, the pointed node and block bounds.
           Does not affect players with the `debug` privilege.
+        * `chat`: Modifies the client's permission to view chat on the HUD.
+          The client may locally elect to not view chat. Does not affect the console.
     * If a flag equals `nil`, the flag is not modified
 * `hud_get_flags()`: returns a table of player HUD flags with boolean values.
     * See `hud_set_flags` for a list of flags that can be toggled.
index 94a09537adf3205373a2a09e3793e018300082be..833093673514f032cd48ebcd8fbd1480b0530459 100644 (file)
@@ -2085,7 +2085,7 @@ void Game::processKeyInput()
        } else if (wasKeyDown(KeyType::MINIMAP)) {
                toggleMinimap(isKeyDown(KeyType::SNEAK));
        } else if (wasKeyDown(KeyType::TOGGLE_CHAT)) {
-               m_game_ui->toggleChat();
+               m_game_ui->toggleChat(client);
        } else if (wasKeyDown(KeyType::TOGGLE_FOG)) {
                toggleFog();
        } else if (wasKeyDown(KeyType::TOGGLE_UPDATE_CAMERA)) {
index 9daecc355b223afba79e5590a0b1c52ef92d9bbe..8d346980c54d311256365929c5e8d033d96a740f 100644 (file)
@@ -102,6 +102,8 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_
 {
        v2u32 screensize = RenderingEngine::getWindowSize();
 
+       LocalPlayer *player = client->getEnv().getLocalPlayer();
+
        s32 minimal_debug_height = 0;
 
        // Minimal debug text must only contain info that can't give a gameplay advantage
@@ -137,7 +139,6 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_
 
        // Basic debug text also shows info that might give a gameplay advantage
        if (m_flags.show_basic_debug) {
-               LocalPlayer *player = client->getEnv().getLocalPlayer();
                v3f player_position = player->getPosition();
 
                std::ostringstream os(std::ios_base::binary);
@@ -208,8 +209,8 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_
                m_guitext_status->enableOverrideColor(true);
        }
 
-       // Hide chat when console is visible
-       m_guitext_chat->setVisible(isChatVisible() && !chat_console->isVisible());
+       // Hide chat when disabled by server or when console is visible
+       m_guitext_chat->setVisible(isChatVisible() && !chat_console->isVisible() && (player->hud_flags & HUD_FLAG_CHAT_VISIBLE));
 }
 
 void GameUI::initFlags()
@@ -287,13 +288,18 @@ void GameUI::updateProfiler()
        m_guitext_profiler->setVisible(m_profiler_current_page != 0);
 }
 
-void GameUI::toggleChat()
+void GameUI::toggleChat(Client *client)
 {
-       m_flags.show_chat = !m_flags.show_chat;
-       if (m_flags.show_chat)
-               showTranslatedStatusText("Chat shown");
-       else
-               showTranslatedStatusText("Chat hidden");
+       if (client->getEnv().getLocalPlayer()->hud_flags & HUD_FLAG_CHAT_VISIBLE) {
+               m_flags.show_chat = !m_flags.show_chat;
+               if (m_flags.show_chat)
+                       showTranslatedStatusText("Chat shown");
+               else
+                       showTranslatedStatusText("Chat hidden");
+       } else {
+               showTranslatedStatusText("Chat currently disabled by game or mod");
+       }
+
 }
 
 void GameUI::toggleHud()
index cc9377bdca4622ddc695edf0640eb59402b07a53..589328a286e0f933aa2210e7ca97e899e48c6815 100644 (file)
@@ -93,7 +93,7 @@ class GameUI
 
        void updateProfiler();
 
-       void toggleChat();
+       void toggleChat(Client *client);
        void toggleHud();
        void toggleProfiler();
 
index 841c907587eb456f199791d94c0ba6185d256549..9b336cdef4080c756eec74bc9fa496071fb0709f 100644 (file)
@@ -64,5 +64,6 @@ const struct EnumString es_HudBuiltinElement[] =
        {HUD_FLAG_MINIMAP_VISIBLE,       "minimap"},
        {HUD_FLAG_MINIMAP_RADAR_VISIBLE, "minimap_radar"},
        {HUD_FLAG_BASIC_DEBUG,           "basic_debug"},
+       {HUD_FLAG_CHAT_VISIBLE,          "chat"},
        {0, NULL},
 };
index 173633fcc824283bd34f0ad1de45da5881dc9249..922fdca19155d1028adcdefda0f72515bff235cb 100644 (file)
--- a/src/hud.h
+++ b/src/hud.h
@@ -48,6 +48,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #define HUD_FLAG_MINIMAP_VISIBLE       (1 << 5)
 #define HUD_FLAG_MINIMAP_RADAR_VISIBLE (1 << 6)
 #define HUD_FLAG_BASIC_DEBUG           (1 << 7)
+#define HUD_FLAG_CHAT_VISIBLE          (1 << 8)
 
 #define HUD_PARAM_HOTBAR_ITEMCOUNT 1
 #define HUD_PARAM_HOTBAR_IMAGE 2
index 1e064c1dac557d43c92ab9663c9d552f4c3f8e7b..8742454d2962dd751a952e8e3f2d6dbed2a03430 100644 (file)
@@ -71,7 +71,8 @@ Player::Player(const char *name, IItemDefManager *idef):
                HUD_FLAG_HOTBAR_VISIBLE    | HUD_FLAG_HEALTHBAR_VISIBLE |
                HUD_FLAG_CROSSHAIR_VISIBLE | HUD_FLAG_WIELDITEM_VISIBLE |
                HUD_FLAG_BREATHBAR_VISIBLE | HUD_FLAG_MINIMAP_VISIBLE   |
-               HUD_FLAG_MINIMAP_RADAR_VISIBLE | HUD_FLAG_BASIC_DEBUG;
+               HUD_FLAG_MINIMAP_RADAR_VISIBLE | HUD_FLAG_BASIC_DEBUG   |
+               HUD_FLAG_CHAT_VISIBLE;
 
        hud_hotbar_itemcount = HUD_HOTBAR_ITEMCOUNT_DEFAULT;