31 #define ERR_NG LOG_STREAM(err, log_engine)
34 const int chat_message_border = 5;
35 const int chat_message_x = 10;
36 const color_t chat_message_color {255,255,255,SDL_ALPHA_OPAQUE};
37 const color_t chat_message_bg {0,0,0,140};
41 : speaker_handle(speaker),
handle(
h), created_at(std::
chrono::steady_clock::now())
49 const bool whisper = speaker.find(
"whisper: ") == 0;
50 std::string sender = speaker;
52 sender.assign(speaker, 9, speaker.size());
56 std::string::size_type pos = message.find(
" has disconnected");
57 if (pos != std::string::npos){
68 bool is_observer =
false;
84 }
else if (sender ==
"server") {
95 if (message.compare(0,4,
"/me ") == 0) {
96 msg.assign(message, 4, message.size());
107 ERR_NG <<
"Invalid utf-8 found, chat message is ignored.";
111 int ypos = chat_message_x;
116 color_t speaker_color {255,255,255,SDL_ALPHA_OPAQUE};
121 color_t message_color = chat_message_color;
122 std::stringstream str;
123 std::stringstream message_str;
127 str <<
"<" << speaker <<
" " <<
msg <<
">";
128 message_color = speaker_color;
131 if (!speaker.empty())
132 str <<
"<" << speaker <<
">";
137 str <<
"*" << speaker <<
" " <<
msg <<
"*";
138 message_color = speaker_color;
141 if (!speaker.empty())
142 str <<
"*" << speaker <<
"*";
148 std::stringstream message_complete;
188 const unsigned max_chat_messages =
prefs::get().chat_lines();
189 const bool enable_aging = message_aging != std::chrono::minutes{0};
191 const auto remove_before = enable_aging
192 ? std::chrono::steady_clock::now() - message_aging
193 : std::chrono::steady_clock::time_point::min();
197 if(enable_aging || remove_all ||
chat_messages_.size() > max_chat_messages) {
color_t mid() const
Average color shade.
void remove_whisperer(const std::string &nick)
void add_whisperer(const std::string &nick)
const std::set< std::string > & whisperers() const
void prune_chat_messages(bool remove_all=false)
void add_chat_message(const std::time_t &time, const std::string &speaker, int side, const std::string &msg, events::chat_handler::MESSAGE_TYPE type, bool bell)
std::vector< chat_message > chat_messages_
bool is_observer() const
Check if we are an observer in this game.
rect map_outside_area() const
Returns the available area for a map, this may differ from the above.
const display_context & context() const
void set_position(double xpos, double ypos)
void set_alignment(ALIGN align)
void set_color(const color_t &color)
void set_border_size(int border)
void set_clip_rect(const SDL_Rect &r)
void set_bg_color(const color_t &bg_color)
void set_font_size(int font_size)
std::chrono::minutes chat_message_aging()
std::string get_chat_timestamp(const std::chrono::system_clock::time_point &t)
bool is_ignored(const std::string &nick)
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
static const color_range get_side_color_range(int side)
Thrown by operations encountering invalid UTF-8 data.
map_display and display: classes which take care of displaying the map and game-data on the screen.
static lg::log_domain log_engine("engine")
Standard logging facilities (interface).
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
SDL_Rect get_floating_label_rect(int handle)
void remove_floating_label(int handle, const std::chrono::milliseconds &fadeout)
removes the floating label given by 'handle' from the screen
void move_floating_label(int handle, double xmove, double ymove)
moves the floating label given by 'handle' by (xmove,ymove)
std::string pango_word_wrap(const std::string &unwrapped_text, int font_size, int max_width, int max_height, int max_lines, bool)
Uses Pango to word wrap text.
std::shared_ptr< halo_record > handle
void public_message(bool is_lobby, const std::string &sender, const std::string &message)
void private_message(bool is_lobby, const std::string &sender, const std::string &message)
void friend_message(bool is_lobby, const std::string &sender, const std::string &message)
void server_message(bool is_lobby, const std::string &sender, const std::string &message)
bool word_match(const std::string &message, const std::string &word)
Check if a message contains a word.
bool headless()
The game is running headless.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Transitional API for porting SDL_ttf-based code to Pango.
The basic class for representing 8-bit RGB or RGBA colour values.
chat_message(int speaker, int h)
An abstract description of a rectangle with integer coordinates.