Skip to content

Commit 0e8ee84

Browse files
EXio4nerzhul
authored andcommittedOct 17, 2017
Implement #6096
1 parent 46f7fe9 commit 0e8ee84

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed
 

Diff for: ‎builtin/settingtypes.txt

+3
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,9 @@ crosshair_color (Crosshair color) string (255,255,255)
634634
# Crosshair alpha (opaqueness, between 0 and 255).
635635
crosshair_alpha (Crosshair alpha) int 255 0 255
636636

637+
# Maximum number of recent chat items to show
638+
recent_chat_size (Recent Chat Messages) int 6 3 99
639+
637640
# Whether node texture animations should be desynchronized per mapblock.
638641
desynchronize_mapblock_texture_animation (Desynchronize block animation) bool true
639642

Diff for: ‎src/chat.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,13 @@ s32 ChatBuffer::getBottomScrollPos() const
369369
return formatted_count - rows;
370370
}
371371

372+
void ChatBuffer::resize(u32 scrollback) {
373+
m_scrollback = scrollback;
374+
if (m_unformatted.size() > m_scrollback)
375+
{
376+
deleteOldest(m_unformatted.size() - m_scrollback);
377+
}
378+
}
372379

373380

374381
ChatPrompt::ChatPrompt(const std::wstring &prompt, u32 history_limit):
@@ -731,6 +738,11 @@ void ChatBackend::clearRecentChat()
731738
m_recent_buffer.clear();
732739
}
733740

741+
742+
void ChatBackend::applySettings(Settings* settings) {
743+
m_recent_buffer.resize(settings->getU32("recent_chat_size"));
744+
}
745+
734746
void ChatBackend::step(float dtime)
735747
{
736748
m_recent_buffer.step(dtime);

Diff for: ‎src/chat.h

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2525

2626
#include "irrlichttypes.h"
2727
#include "util/enriched_string.h"
28+
#include "settings.h"
2829

2930
// Chat console related classes
3031

@@ -118,6 +119,7 @@ class ChatBuffer
118119
u32 formatChatLine(const ChatLine& line, u32 cols,
119120
std::vector<ChatFormattedLine>& destination) const;
120121

122+
void resize(u32 scrollback);
121123
protected:
122124
s32 getTopScrollPos() const;
123125
s32 getBottomScrollPos() const;
@@ -281,6 +283,9 @@ class ChatBackend
281283
void scrollPageDown();
282284
void scrollPageUp();
283285

286+
// Resize recent buffer based on settings
287+
void applySettings(Settings* settings);
288+
284289
private:
285290
ChatBuffer m_console_buffer;
286291
ChatBuffer m_recent_buffer;

Diff for: ‎src/defaultsettings.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ void set_default_settings(Settings *settings)
190190
settings->setDefault("node_highlighting", "box");
191191
settings->setDefault("crosshair_color", "(255,255,255)");
192192
settings->setDefault("crosshair_alpha", "255");
193+
settings->setDefault("recent_chat_size", "6");
193194
settings->setDefault("hud_scaling", "1.0");
194195
settings->setDefault("gui_scaling", "1.0");
195196
settings->setDefault("gui_scaling_filter", "false");

Diff for: ‎src/game.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2051,6 +2051,9 @@ bool Game::initGui()
20512051
// Remove stale "recent" chat messages from previous connections
20522052
chat_backend->clearRecentChat();
20532053

2054+
// Make sure the size of the recent messages buffer is right
2055+
chat_backend->applySettings(g_settings);
2056+
20542057
// Chat backend and console
20552058
gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(),
20562059
-1, chat_backend, client, &g_menumgr);

0 commit comments

Comments
 (0)