30 #include <SDL2/SDL_timer.h>
33 #define ERR_NG LOG_STREAM(err, log_engine)
36 const int chat_message_border = 5;
37 const int chat_message_x = 10;
38 const color_t chat_message_color {255,255,255,SDL_ALPHA_OPAQUE};
39 const color_t chat_message_bg {0,0,0,140};
43 : speaker_handle(speaker),
handle(
h), created_at(SDL_GetTicks())
51 const bool whisper = speaker.find(
"whisper: ") == 0;
52 std::string sender = speaker;
54 sender.assign(speaker, 9, speaker.size());
58 std::string::size_type pos = message.find(
" has disconnected");
59 if (pos != std::string::npos){
70 bool is_observer =
false;
86 }
else if (sender ==
"server") {
97 if (message.compare(0,4,
"/me ") == 0) {
98 msg.assign(message, 4, message.size());
109 ERR_NG <<
"Invalid utf-8 found, chat message is ignored.";
113 int ypos = chat_message_x;
118 color_t speaker_color {255,255,255,SDL_ALPHA_OPAQUE};
123 color_t message_color = chat_message_color;
124 std::stringstream str;
125 std::stringstream message_str;
129 str <<
"<" << speaker <<
" " <<
msg <<
">";
130 message_color = speaker_color;
133 if (!speaker.empty())
134 str <<
"<" << speaker <<
">";
139 str <<
"*" << speaker <<
" " <<
msg <<
"*";
140 message_color = speaker_color;
143 if (!speaker.empty())
144 str <<
"*" << speaker <<
"*";
150 std::stringstream message_complete;
187 return (a >
b) ? a -
b : 0;
194 const unsigned message_aging =
prefs::get().chat_message_aging();
195 const unsigned max_chat_messages =
prefs::get().chat_lines();
196 const bool enable_aging = message_aging != 0;
198 const unsigned remove_before = enable_aging ?
safe_subtract(SDL_GetTicks(), message_aging * 60 * 1000) : 0;
201 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)
bool is_ignored(const std::string &nick)
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
std::string get_chat_timestamp(const std::time_t &t)
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")
static unsigned int safe_subtract(unsigned int a, unsigned int b)
Standard logging facilities (interface).
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
void remove_floating_label(int handle, int fadeout)
removes the floating label given by 'handle' from the screen
SDL_Rect get_floating_label_rect(int handle)
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.