28 #include <boost/cstdint.hpp>
29 #include <SDL_timer.h>
30 #include <SDL_video.h>
33 #define ERR_NG LOG_STREAM(err, log_engine)
38 const int chat_message_border = 5;
39 const int chat_message_x = 10;
40 const SDL_Color chat_message_color = {255,255,255,SDL_ALPHA_OPAQUE};
41 const SDL_Color 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;
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.find(
"/me ") == 0) {
100 msg.assign(message, 4, message.size());
111 ERR_NG <<
"Invalid utf-8 found, chat message is ignored." << std::endl;
115 int ypos = chat_message_x;
120 SDL_Color speaker_color = {255,255,255,SDL_ALPHA_OPAQUE};
125 SDL_Color 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);
190 const unsigned message_ttl = remove_all ? 0 : message_aging * 60 * 1000;
194 if(message_aging != 0 || remove_all ||
chat_messages_.size() > max_chat_messages) {
196 (
chat_messages_.front().created_at + message_ttl < SDL_GetTicks() ||
GLuint GLuint GLsizei GLenum type
SDL_Color int_to_color(const Uint32 rgb)
static const color_range get_side_color_range(int side)
void remove_floating_label(int handle)
removes the floating label given by 'handle' from the screen
void parse_admin_authentication(const std::string &sender, const std::string &message)
std::string word_wrap_text(const std::string &unwrapped_text, int font_size, int max_width, int max_height, int max_lines, bool partial_line)
Wrap text.
void set_font_size(int font_size)
std::vector< chat_message > chat_messages_
chat_message(int speaker, int h)
void move_floating_label(int handle, double xmove, double ymove)
moves the floating label given by 'handle' by (xmove,ymove)
void friend_message(bool is_lobby, const std::string &sender, const std::string &message)
bool is_friend(const std::string &nick)
void add_whisperer(const std::string &nick)
void private_message(bool is_lobby, const std::string &sender, const std::string &message)
GLubyte GLubyte GLubyte GLubyte w
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.
void public_message(bool is_lobby, const std::string &sender, const std::string &message)
GLfloat GLfloat GLfloat GLfloat h
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
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 server_message(bool is_lobby, const std::string &sender, const std::string &message)
std::string get_chat_timestamp(const time_t &t)
Standard logging facilities (interface).
const SDL_Rect & map_outside_area() const
Returns the available area for a map, this may differ from the above.
CVideo & video()
Gets the underlying screen object.
bool is_observer() const
Check if we are an observer in this game.
GLsizei GLenum GLuint GLuint GLsizei char * message
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
const display_context & get_disp_context() const
void chat_message(std::string const &caption, std::string const &msg)
Displays a message in the chat window.
void add_chat_message(const time_t &time, const std::string &speaker, int side, const std::string &msg, events::chat_handler::MESSAGE_TYPE type, bool bell)
const std::set< std::string > & whisperers() const
GLsizei const GLcharARB ** string
boost::shared_ptr< halo_record > handle
bool word_match(const std::string &message, const std::string &word)
Check if a message contains a word.