--- display.cpp 2005-04-17 22:59:32.000000000 +0200 +++ display.cpp.maj 2005-04-22 00:35:09.619606096 +0200 @@ -2149,6 +2149,30 @@ grid_ = grid; } +// timestring() returns the current date as a string. +// Example: 20:42:18 +char *timestring ( void ) +{ +# define TIME_SIZE 40 + + const struct tm *tm; + size_t len; + time_t now; + char *s; + + now = time ( NULL ); + tm = localtime ( &now ); + + s = new char[TIME_SIZE]; + + // alternative mode, including the day ... + // len = strftime ( s, TIME_SIZE, "%Y-%m-%d %H:%M:%S", tm ); + len = strftime ( s, TIME_SIZE, "%H:%M:%S", tm ); + + return s; +# undef TIME_SIZE +} + void display::debug_highlight(const gamemap::location& loc, fixed_t amount) { wassert(game_config::debug); @@ -2261,7 +2285,6 @@ } namespace { - const unsigned int max_chat_messages = 6; const int chat_message_border = 5; const int chat_message_x = 10; const int chat_message_y = 10; @@ -2280,6 +2303,7 @@ msg = message; action = false; } + msg = font::word_wrap_text(msg,font::SIZE_SMALL,mapx()*3/4); int ypos = chat_message_x; @@ -2314,9 +2338,15 @@ } } + // prepend message with timestamp + std::stringstream message_meta; + if (preferences::chat_timestamp()) { + message_meta << timestring() << " "; + } + message_meta << str.str(); const SDL_Rect rect = map_area(); - const int speaker_handle = font::add_floating_label(str.str(),font::SIZE_SMALL,speaker_colour, + const int speaker_handle = font::add_floating_label(message_meta.str(),font::SIZE_SMALL,speaker_colour, rect.x+chat_message_x,rect.y+ypos, 0,0,-1,rect,font::LEFT_ALIGN,&chat_message_bg,chat_message_border); @@ -2337,6 +2367,8 @@ void display::prune_chat_messages(bool remove_all) { const unsigned int message_ttl = remove_all ? 0 : 1200000; + const unsigned int max_chat_messages = preferences::chat_lines(); + if(chat_messages_.empty() == false && (chat_messages_.front().created_at+message_ttl < SDL_GetTicks() || chat_messages_.size() > max_chat_messages)) { const int movement = font::get_floating_label_rect(chat_messages_.front().handle).h;