]> git.lizzy.rs Git - minetest.git/commitdiff
Implement #6096
authorEsteban I. RM <me@exio4.xyz>
Sun, 15 Oct 2017 23:28:42 +0000 (20:28 -0300)
committerLoic Blot <loic.blot@unix-experience.fr>
Tue, 17 Oct 2017 17:21:32 +0000 (19:21 +0200)
builtin/settingtypes.txt
src/chat.cpp
src/chat.h
src/defaultsettings.cpp
src/game.cpp

index 4f7a5c769bc4bed3f5927d44a73f723211914e85..982fe55ef72ce14ff00f326294594b0f492d72dc 100644 (file)
@@ -634,6 +634,9 @@ crosshair_color (Crosshair color) string (255,255,255)
 #    Crosshair alpha (opaqueness, between 0 and 255).
 crosshair_alpha (Crosshair alpha) int 255 0 255
 
+#    Maximum number of recent chat items to show
+recent_chat_size (Recent Chat Messages) int 6 3 99
+
 #    Whether node texture animations should be desynchronized per mapblock.
 desynchronize_mapblock_texture_animation (Desynchronize block animation) bool true
 
index fd0718707ef54d8c37026b18ff4b5ad27a68371c..967e159f8a7ac1e6257c0a1d224def386a589197 100644 (file)
@@ -369,6 +369,13 @@ s32 ChatBuffer::getBottomScrollPos() const
        return formatted_count - rows;
 }
 
+void ChatBuffer::resize(u32 scrollback) {
+       m_scrollback = scrollback;
+       if (m_unformatted.size() > m_scrollback)
+       {
+               deleteOldest(m_unformatted.size() - m_scrollback);
+       }       
+}
 
 
 ChatPrompt::ChatPrompt(const std::wstring &prompt, u32 history_limit):
@@ -731,6 +738,11 @@ void ChatBackend::clearRecentChat()
        m_recent_buffer.clear();
 }
 
+
+void ChatBackend::applySettings(Settings* settings) {
+       m_recent_buffer.resize(settings->getU32("recent_chat_size"));
+}
+
 void ChatBackend::step(float dtime)
 {
        m_recent_buffer.step(dtime);
index 38727c6680a4bcd7f71b456079f90838471fb8f9..b1b3edcb093007d7e5d10068ba2d7ce093a10f03 100644 (file)
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "irrlichttypes.h"
 #include "util/enriched_string.h"
+#include "settings.h"
 
 // Chat console related classes
 
@@ -118,6 +119,7 @@ class ChatBuffer
        u32 formatChatLine(const ChatLine& line, u32 cols,
                        std::vector<ChatFormattedLine>& destination) const;
 
+    void resize(u32 scrollback);
 protected:
        s32 getTopScrollPos() const;
        s32 getBottomScrollPos() const;
@@ -281,6 +283,9 @@ class ChatBackend
        void scrollPageDown();
        void scrollPageUp();
 
+    // Resize recent buffer based on settings
+    void applySettings(Settings* settings);
+    
 private:
        ChatBuffer m_console_buffer;
        ChatBuffer m_recent_buffer;
index 7612ceb44c0629bd39b7eb4c006f21a75afb9228..e2a7ea562c37cadf4a3dfb1316230ed7d5b0ef29 100644 (file)
@@ -190,6 +190,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("node_highlighting", "box");
        settings->setDefault("crosshair_color", "(255,255,255)");
        settings->setDefault("crosshair_alpha", "255");
+       settings->setDefault("recent_chat_size", "6");
        settings->setDefault("hud_scaling", "1.0");
        settings->setDefault("gui_scaling", "1.0");
        settings->setDefault("gui_scaling_filter", "false");
index 8da789a9eb4bf743697a245c1c2e251de4f6af6e..7f717cb5f04e974419401a9b1dce6c1f7504867f 100644 (file)
@@ -2051,6 +2051,9 @@ bool Game::initGui()
        // Remove stale "recent" chat messages from previous connections
        chat_backend->clearRecentChat();
 
+    // Make sure the size of the recent messages buffer is right
+    chat_backend->applySettings(g_settings);
+    
        // Chat backend and console
        gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(),
                        -1, chat_backend, client, &g_menumgr);