mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Colored chat working as expected for both freetype and non-freetype builds. @nerzhul improvements * Add unit tests * Fix coding style * move guiChatConsole.hpp to client/
This commit is contained in:
parent
0e44af9f70
commit
1d40385d4a
13 changed files with 998 additions and 28 deletions
29
src/chat.cpp
29
src/chat.cpp
|
@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include "chat.h"
|
||||
#include "debug.h"
|
||||
#include "config.h"
|
||||
#include "util/strfnd.h"
|
||||
#include <cctype>
|
||||
#include <sstream>
|
||||
|
@ -251,8 +252,7 @@ u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
|
|||
u32 hanging_indentation = 0;
|
||||
|
||||
// Format the sender name and produce fragments
|
||||
if (!line.name.empty())
|
||||
{
|
||||
if (!line.name.empty()) {
|
||||
temp_frag.text = L"<";
|
||||
temp_frag.column = 0;
|
||||
//temp_frag.bold = 0;
|
||||
|
@ -267,28 +267,28 @@ u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
|
|||
next_frags.push_back(temp_frag);
|
||||
}
|
||||
|
||||
std::wstring name_sanitized = removeEscapes(line.name);
|
||||
|
||||
// Choose an indentation level
|
||||
if (line.name.empty())
|
||||
{
|
||||
if (line.name.empty()) {
|
||||
// Server messages
|
||||
hanging_indentation = 0;
|
||||
}
|
||||
else if (line.name.size() + 3 <= cols/2)
|
||||
{
|
||||
else if (name_sanitized.size() + 3 <= cols/2) {
|
||||
// Names shorter than about half the console width
|
||||
hanging_indentation = line.name.size() + 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
// Very long names
|
||||
hanging_indentation = 2;
|
||||
}
|
||||
ColoredString line_text(line.text);
|
||||
|
||||
next_line.first = true;
|
||||
bool text_processing = false;
|
||||
|
||||
// Produce fragments and layout them into lines
|
||||
while (!next_frags.empty() || in_pos < line.text.size())
|
||||
while (!next_frags.empty() || in_pos < line_text.size())
|
||||
{
|
||||
// Layout fragments into lines
|
||||
while (!next_frags.empty())
|
||||
|
@ -326,9 +326,9 @@ u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
|
|||
}
|
||||
|
||||
// Produce fragment
|
||||
if (in_pos < line.text.size())
|
||||
if (in_pos < line_text.size())
|
||||
{
|
||||
u32 remaining_in_input = line.text.size() - in_pos;
|
||||
u32 remaining_in_input = line_text.size() - in_pos;
|
||||
u32 remaining_in_output = cols - out_column;
|
||||
|
||||
// Determine a fragment length <= the minimum of
|
||||
|
@ -338,14 +338,14 @@ u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
|
|||
while (frag_length < remaining_in_input &&
|
||||
frag_length < remaining_in_output)
|
||||
{
|
||||
if (isspace(line.text[in_pos + frag_length]))
|
||||
if (isspace(line_text[in_pos + frag_length]))
|
||||
space_pos = frag_length;
|
||||
++frag_length;
|
||||
}
|
||||
if (space_pos != 0 && frag_length < remaining_in_input)
|
||||
frag_length = space_pos + 1;
|
||||
|
||||
temp_frag.text = line.text.substr(in_pos, frag_length);
|
||||
temp_frag.text = line_text.substr(in_pos, frag_length);
|
||||
temp_frag.column = 0;
|
||||
//temp_frag.bold = 0;
|
||||
next_frags.push_back(temp_frag);
|
||||
|
@ -686,9 +686,6 @@ ChatBackend::~ChatBackend()
|
|||
|
||||
void ChatBackend::addMessage(std::wstring name, std::wstring text)
|
||||
{
|
||||
name = unescape_enriched(name);
|
||||
text = unescape_enriched(text);
|
||||
|
||||
// Note: A message may consist of multiple lines, for example the MOTD.
|
||||
WStrfnd fnd(text);
|
||||
while (!fnd.at_end())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue