32 #include <SDL2/SDL_timer.h> 35 #define ERR_NG LOG_STREAM(err, log_engine) 38 const int chat_message_border = 5;
39 const int chat_message_x = 10;
40 const color_t chat_message_color {255,255,255,SDL_ALPHA_OPAQUE};
41 const color_t chat_message_bg {0,0,0,140};
45 : speaker_handle(speaker),
handle(h), created_at(SDL_GetTicks())
53 const bool whisper = speaker.find(
"whisper: ") == 0;
54 std::string sender = speaker;
56 sender.assign(speaker, 9, speaker.size());
60 std::string::size_type pos = message.find(
" has disconnected");
61 if (pos != std::string::npos){
72 bool is_observer =
false;
88 }
else if (sender ==
"server") {
99 if (message.compare(0,4,
"/me ") == 0) {
100 msg.assign(message, 4, message.size());
111 ERR_NG <<
"Invalid utf-8 found, chat message is ignored.";
115 int ypos = chat_message_x;
120 color_t speaker_color {255,255,255,SDL_ALPHA_OPAQUE};
125 color_t message_color = chat_message_color;
126 std::stringstream str;
127 std::stringstream message_str;
131 str <<
"<" << speaker <<
" " << msg <<
">";
132 message_color = speaker_color;
135 if (!speaker.empty())
136 str <<
"<" << speaker <<
">";
141 str <<
"*" << speaker <<
" " << msg <<
"*";
142 message_color = speaker_color;
145 if (!speaker.empty())
146 str <<
"*" << speaker <<
"*";
152 std::stringstream message_complete;
159 spk_flabel.set_color(speaker_color);
160 spk_flabel.set_position(rect.x + chat_message_x, rect.y + ypos);
161 spk_flabel.set_clip_rect(rect);
163 spk_flabel.set_bg_color(chat_message_bg);
164 spk_flabel.set_border_size(chat_message_border);
165 spk_flabel.use_markup(
false);
171 msg_flabel.set_color(message_color);
174 msg_flabel.set_clip_rect(rect);
176 msg_flabel.set_bg_color(chat_message_bg);
177 msg_flabel.set_border_size(chat_message_border);
178 msg_flabel.use_markup(
false);
189 return (a > b) ? a -
b : 0;
198 const bool enable_aging = message_aging != 0;
200 const unsigned remove_before = enable_aging ?
safe_subtract(SDL_GetTicks(), message_aging * 60 * 1000) : 0;
203 if(enable_aging || remove_all ||
chat_messages_.size() > max_chat_messages) {
void public_message(bool is_lobby, const std::string &sender, const std::string &message)
static unsigned int safe_subtract(unsigned int a, unsigned int b)
void remove_floating_label(int handle, int fadeout)
removes the floating label given by 'handle' from the screen
const std::set< std::string > & whisperers() const
static const color_range get_side_color_range(int side)
void private_message(bool is_lobby, const std::string &sender, const std::string &message)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
void set_font_size(int font_size)
std::vector< chat_message > chat_messages_
void friend_message(bool is_lobby, const std::string &sender, const std::string &message)
chat_message(int speaker, int h)
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)
void move_floating_label(int handle, double xmove, double ymove)
moves the floating label given by 'handle' by (xmove,ymove)
bool is_friend(const std::string &nick)
void add_whisperer(const std::string &nick)
The basic class for representing 8-bit RGB or RGBA colour values.
bool headless()
The game is running headless.
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.
map_display and display: classes which take care of displaying the map and game-data on the screen...
void prune_chat_messages(bool remove_all=false)
void remove_whisperer(const std::string &nick)
bool is_ignored(const std::string &nick)
static lg::log_domain log_engine("engine")
Thrown by operations encountering invalid UTF-8 data.
bool is_observer() const
Check if we are an observer in this game.
An abstract description of a rectangle with integer coordinates.
const display_context & get_disp_context() const
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)
std::string get_chat_timestamp(const std::time_t &t)
Standard logging facilities (interface).
void server_message(bool is_lobby, const std::string &sender, const std::string &message)
rect map_outside_area() const
Returns the available area for a map, this may differ from the above.
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
std::shared_ptr< halo_record > handle
Transitional API for porting SDL_ttf-based code to Pango.
color_t mid() const
Average color shade.
bool word_match(const std::string &message, const std::string &word)
Check if a message contains a word.