Index: src/lang/english.txt =================================================================== --- src/lang/english.txt (revision 10369) +++ src/lang/english.txt (working copy) @@ -1096,6 +1096,12 @@ STR_CONFIG_PATCHES_LIVERIES_OWN :Own company STR_CONFIG_PATCHES_LIVERIES_ALL :All companies STR_CONFIG_PATCHES_PREFER_TEAMCHAT :{LTBLUE}Prefer team chat with : {ORANGE}{STRING1} +STR_CONFIG_PATCHES_CHAT_TEXT_LIFESPAN :{LTBLUE}Chat text stays on screen at least {ORANGE}{STRING1}{LTBLUE} seconds +STR_CONFIG_PATCHES_CHAT_TEXT_SHADOW :{LTBLUE}Chat text shadowing: {ORANGE}{STRING1}{LTBLUE} +STR_CONFIG_PATCHES_CHAT_TEXT_SHADOW_NONE :none +STR_CONFIG_PATCHES_CHAT_TEXT_SHADOW_LINE :line +STR_CONFIG_PATCHES_CHAT_TEXT_SHADOW_BOX :box (default) + STR_CONFIG_PATCHES_SCROLLWHEEL_SCROLLING :{LTBLUE}Function of scrollwheel: {ORANGE}{STRING1} STR_CONFIG_PATCHES_SCROLLWHEEL_ZOOM :Zoom map STR_CONFIG_PATCHES_SCROLLWHEEL_SCROLL :Scroll map Index: src/network/network.cpp =================================================================== --- src/network/network.cpp (revision 10369) +++ src/network/network.cpp (working copy) @@ -136,7 +136,6 @@ { char buf[1024]; va_list va; - const int duration = 10; // Game days the messages stay visible char message[1024]; char temp[1024]; @@ -196,7 +195,7 @@ } IConsolePrintF(color, "%s", message); - AddTextMessage(color, duration, "%s", message); + AddTextMessage(color, "%s", message); } // Calculate the frame-lag of a client @@ -212,7 +211,6 @@ return lag; } - // There was a non-recoverable error, drop back to the main menu with a nice // error static void NetworkError(StringID error_string) Index: src/settings.cpp =================================================================== --- src/settings.cpp (revision 10369) +++ src/settings.cpp (working copy) @@ -1345,6 +1345,8 @@ SDT_BOOL(Patches, link_terraform_toolbar, S, 0, false, STR_CONFIG_PATCHES_LINK_TERRAFORM_TOOLBAR,NULL), SDT_VAR(Patches, liveries, SLE_UINT8, S,MS, 2, 0, 2, 0, STR_CONFIG_PATCHES_LIVERIES, RedrawScreen), SDT_BOOL(Patches, prefer_teamchat, S, 0, false, STR_CONFIG_PATCHES_PREFER_TEAMCHAT, NULL), + SDT_VAR(Patches, chat_text_lifespan, SLE_UINT16,S,NC, 60,10,900,10, STR_CONFIG_PATCHES_CHAT_TEXT_LIFESPAN, NULL), + SDT_VAR(Patches, chat_text_shadow, SLE_UINT8, S,MS, 2, 0, 2, 1, STR_CONFIG_PATCHES_CHAT_TEXT_SHADOW, NULL), SDT_VAR(Patches, scrollwheel_scrolling,SLE_UINT8,S,MS, 0, 0, 2, 0, STR_CONFIG_PATCHES_SCROLLWHEEL_SCROLLING, NULL), SDT_VAR(Patches,scrollwheel_multiplier,SLE_UINT8,S, 0, 5, 1, 15, 1, STR_CONFIG_PATCHES_SCROLLWHEEL_MULTIPLIER,NULL), SDT_BOOL(Patches, pause_on_newgame, S, 0, false, STR_CONFIG_PATCHES_PAUSE_ON_NEW_GAME, NULL), Index: src/settings_gui.cpp =================================================================== --- src/settings_gui.cpp (revision 10369) +++ src/settings_gui.cpp (working copy) @@ -645,6 +645,9 @@ "link_terraform_toolbar", "liveries", "prefer_teamchat", + /* chat_text_* are used by the same routines and must stay together */ + "chat_text_lifespan", + "chat_text_shadow", /* While the horizontal scrollwheel scrolling is written as general code, only * the cocoa (OSX) driver generates input for it. * Since it's also able to completely disable the scrollwheel will we display it on all platforms anyway */ Index: src/texteff.cpp =================================================================== --- src/texteff.cpp (revision 10369) +++ src/texteff.cpp (working copy) @@ -19,12 +19,15 @@ #include "blitter/factory.hpp" #include /* va_list */ #include "date.h" +#include #include "texteff.hpp" enum { - MAX_TEXTMESSAGE_LENGTH = 200, - INIT_NUM_TEXT_MESSAGES = 20, - MAX_CHAT_MESSAGES = 10, + MAX_TEXTMESSAGE_LENGTH = 255, ///< maximum text message length in bytes + MAX_TEXT_MESSAGES = 24, ///< adjusted _text and _chat values to keep more messages on the screen, and to keep + MAX_CHAT_MESSAGES = 24, ///< text within the limits of _textmsg_box below. _chat doesn't need to be less than _text + MAX_CHATMESSAGE_HEIGHT = 13, ///< height between lines of text for the chat message display, including padding + INIT_NUM_TEXT_EFFECTS = 20, MAX_ANIMATED_TILES = 256, }; @@ -40,11 +43,11 @@ TextEffectMode mode; }; - +/* Storage for the on-screen text display */ struct TextMessage { - char message[MAX_TEXTMESSAGE_LENGTH]; - uint16 color; - Date end_date; + char message[MAX_TEXTMESSAGE_LENGTH]; ///< message to be displayed + uint16 color; ///< text color + time_t time_stamp; ///< timestamp of when message was created, in real-seconds since 1/1/1970 }; static TextEffect *_text_effect_list = NULL; @@ -53,12 +56,14 @@ static bool _textmessage_dirty = false; static bool _textmessage_visible = false; -static uint16 _num_text_effects = INIT_NUM_TEXT_MESSAGES; +static uint16 _num_text_effects = INIT_NUM_TEXT_EFFECTS; /* The chatbox grows from the bottom so the coordinates are pixels from - * the left and pixels from the bottom. The height is the maximum height */ -static const Oblong _textmsg_box = {10, 30, 500, 150}; -static uint8 _textmessage_backup[150 * 500 * 6]; // (height * width) + * the left and pixels from the bottom. The height is the maximum height + * @todo What was the "* 6" added for in the unpatched code? + */ +static const Oblong _textmsg_box = {10, 30, 512, (MAX_CHAT_MESSAGES * MAX_CHATMESSAGE_HEIGHT)}; ///< height now set near top of file +static uint8 _textmessage_backup[((MAX_CHAT_MESSAGES * MAX_CHATMESSAGE_HEIGHT) * 512) * 6]; ///< ((height) * width) * 6) static inline uint GetTextMessageCount() { @@ -73,9 +78,9 @@ /* Add a text message to the 'chat window' to be shown * @param color The colour this message is to be shown in - * @param duration The duration of the chat message in game-days - * @param message message itself in printf() style */ -void CDECL AddTextMessage(uint16 color, uint8 duration, const char *message, ...) + * @param message message itself in printf() style + */ +void CDECL AddTextMessage(uint16 color, const char *message, ...) { char buf[MAX_TEXTMESSAGE_LENGTH]; const char *bufp; @@ -87,7 +92,6 @@ vsnprintf(buf, lengthof(buf), message, va); va_end(va); - Utf8TrimString(buf, MAX_TEXTMESSAGE_LENGTH); /* Force linebreaks for strings that are too long */ @@ -107,11 +111,11 @@ ttd_strlcpy(tmsg->message, bufp, sizeof(tmsg->message)); /* The default colour for a message is player colour. Replace this with - * white for any additional lines */ + * white for any additional lines + */ tmsg->color = (bufp == buf && color & IS_PALETTE_COLOR) ? color : (0x1D - 15) | IS_PALETTE_COLOR; - tmsg->end_date = _date + duration; - - bufp += strlen(bufp) + 1; // jump to 'next line' in the formatted string + time(&tmsg->time_stamp); ///< Current real time in seconds. Daily loop compares this against current time minus _patch.text_stays_visible + bufp += strlen(bufp) + 1; ///< jump to 'next line' in the formatted string } _textmessage_dirty = true; @@ -141,7 +145,6 @@ * looks nicely ;) * (and now hope this story above makes sense to you ;)) */ - if (_cursor.visible) { if (_cursor.draw_pos.x + _cursor.draw_size.x >= _textmsg_box.x && _cursor.draw_pos.x <= _textmsg_box.x + _textmsg_box.width && @@ -174,31 +177,26 @@ } } -/** Check if a message is expired every day */ +/** Check if a chat message is expired every day */ void TextMessageDailyLoop() { - uint i; + time_t tstamp; + time(&tstamp); + tstamp = tstamp - _patches.chat_text_lifespan; // adjust tstamp for comparing against tmsg->time_stamp - for (i = 0; i < MAX_CHAT_MESSAGES; i++) { - TextMessage *tmsg = &_textmsg_list[i]; - if (tmsg->message[0] == '\0') continue; + TextMessage *tmsg = &_textmsg_list[0]; + while (tmsg->message[0] != '\0' && tmsg->time_stamp < tstamp) { ///< if message exists, and it is older than tstamp, expire it - /* Message has expired, remove from the list */ - if (tmsg->end_date < _date) { - /* Move the remaining messages over the current message */ - if (i != MAX_CHAT_MESSAGES - 1) memmove(tmsg, tmsg + 1, sizeof(*tmsg) * (MAX_CHAT_MESSAGES - i - 1)); + /* Move the remaining messages over the current message */ + memmove(tmsg, tmsg + 1, sizeof(*tmsg) * (MAX_CHAT_MESSAGES - 1)); - /* Mark the last item as empty */ - _textmsg_list[MAX_CHAT_MESSAGES - 1].message[0] = '\0'; - _textmessage_dirty = true; - - /* Go one item back, because we moved the array 1 to the left */ - i--; - } + /* Mark the last item as empty */ + _textmsg_list[MAX_CHAT_MESSAGES - 1].message[0] = '\0'; + _textmessage_dirty = true; } } -/** Draw the textmessage-box */ +/** Draw the chat message-box */ void DrawTextMessage() { Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); @@ -206,7 +204,6 @@ /* First undraw if needed */ UndrawTextMessage(); - if (_iconsole_mode == ICONSOLE_FULL) return; /* Check if we have anything to draw at all */ @@ -228,23 +225,46 @@ assert(blitter->BufferSize(width, height) < (int)sizeof(_textmessage_backup)); + enum { ///< text shadowing + CS_NONE, ///< 0 = none + CS_LINE, ///< 1 = individual lines + CS_BOX, ///< 2 = whole box (default) + }; + /* Make a copy of the screen as it is before painting (for undraw) */ blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height); _cur_dpi = &_screen; // switch to _screen painting - /* Paint a half-transparent box behind the text messages */ - GfxFillRect( - _textmsg_box.x, - _screen.height - _textmsg_box.y - count * 13 - 2, - _textmsg_box.x + _textmsg_box.width - 1, - _screen.height - _textmsg_box.y - 2, - PALETTE_TO_TRANSPARENT | (1 << USE_COLORTABLE) // black, but with some alpha for background + /* Paint the messages from bottom to top. + * Lowest numbered 'count' is the oldest, and prints at the top. + * Highest numbered 'count' is the most recent, and prints at the bottom. + * Since 'count' is not consistent enough between cycles to use for line position, we print the lines + * based on line position, reducing 'count' for each line until 'count' is 0 + * We could make it cleaner here, but that would mean making it messier for the other functions that + * manipulate the strings. + */ + for (uint y = 1; count-- != 0; y++) { + + int16 length = GetStringBoundingBox(_textmsg_list[count].message).width; ///< length is the pixel-length of the current line of text being dealt with + + /* Paint a half-transparent box behind the individual text messages */ + if (_patches.chat_text_shadow != CS_NONE) { ///< if shadow is set to none, no need to run this function + GfxFillRect( + _textmsg_box.x, + _screen.height - _textmsg_box.y - (y * MAX_CHATMESSAGE_HEIGHT), + _textmsg_box.x + (_patches.chat_text_shadow != CS_LINE ? _textmsg_box.width - 1 : length + 5), ///< if shadow is not set to line, then default behavior + _screen.height - _textmsg_box.y - (y * MAX_CHATMESSAGE_HEIGHT) + (MAX_CHATMESSAGE_HEIGHT - 1), + PALETTE_TO_TRANSPARENT | (1 << USE_COLORTABLE) ///< black, but with some alpha for background + ); + } + /* Output the line of text to the chat window area */ + DoDrawString( + _textmsg_list[count].message, + _textmsg_box.x + 3, ///< 3 is enough offset to center the text in the shaded box + _screen.height - _textmsg_box.y - (y * MAX_CHATMESSAGE_HEIGHT) + 2, ///< 2 is enough offset to center the text in the shaded box + _textmsg_list[count].color ); - - /* Paint the messages starting with the lowest at the bottom */ - for (uint y = 13; count-- != 0; y += 13) { - DoDrawString(_textmsg_list[count].message, _textmsg_box.x + 3, _screen.height - _textmsg_box.y - y + 1, _textmsg_list[count].color); } /* Make sure the data is updated next flush */ @@ -377,7 +397,6 @@ } } break; - case ZOOM_LVL_OUT_2X: for (TextEffectID i = 0; i < _num_text_effects; i++) { TextEffect *te = &_text_effect_list[i]; @@ -428,7 +447,6 @@ return true; } } - return false; } @@ -456,7 +474,6 @@ } } - extern const ChunkHandler _animated_tile_chunk_handlers[] = { { 'ANIT', SaveLoad_ANIT, SaveLoad_ANIT, CH_RIFF | CH_LAST}, }; Index: src/texteff.hpp =================================================================== --- src/texteff.hpp (revision 10369) +++ src/texteff.hpp (working copy) @@ -24,7 +24,7 @@ void InitTextMessage(); void DrawTextMessage(); -void CDECL AddTextMessage(uint16 color, uint8 duration, const char *message, ...); +void CDECL AddTextMessage(uint16 color, const char *message, ...); void UndrawTextMessage(); /* misc_gui.cpp */ Index: src/variables.h =================================================================== --- src/variables.h (revision 10369) +++ src/variables.h (working copy) @@ -136,6 +136,9 @@ bool loading_indicators; // Show loading indicators uint8 default_rail_type; ///< The default rail type for the rail GUI + uint16 chat_text_lifespan; ///< Chat text min lifespan (in real-time seconds) + uint8 chat_text_shadow; ///< Chat text shadowing style (0=none, 1=line, 2=box) + uint8 toolbar_pos; // position of toolbars, 0=left, 1=center, 2=right uint8 window_snap_radius; // Windows snap at each other if closer than this