Skip to content

Commit

Permalink
Implement #6096
Browse files Browse the repository at this point in the history
  • Loading branch information
EXio4 authored and nerzhul committed Oct 17, 2017
1 parent 46f7fe9 commit 0e8ee84
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions builtin/settingtypes.txt
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions src/chat.cpp
Expand Up @@ -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):
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/chat.h
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/defaultsettings.cpp
Expand Up @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions src/game.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit 0e8ee84

Please sign in to comment.