Index: src/functions.h =================================================================== --- src/functions.h (revision 9153) +++ src/functions.h (working copy) @@ -114,7 +114,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(); bool AddAnimatedTile(TileIndex tile); Index: src/lang/english.txt =================================================================== --- src/lang/english.txt (revision 9153) +++ src/lang/english.txt (working copy) @@ -1090,6 +1090,8 @@ 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_TEXT_STAYS_VISIBLE :{LTBLUE}Keep chat text visible at least {ORANGE}{STRING1} {LTBLUE}seconds + 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 9153) +++ src/network/network.cpp (working copy) @@ -37,7 +37,9 @@ #include "../console.h" /* IConsoleCmdExec */ #include /* va_list */ #include "../md5.h" +#include + /* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */ assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE); @@ -136,7 +138,7 @@ { char buf[1024]; va_list va; - const int duration = 10; // Game days the messages stay visible + char message[1024]; char temp[1024]; @@ -196,7 +198,7 @@ } IConsolePrintF(color, "%s", message); - AddTextMessage(color, duration, "%s", message); + AddTextMessage(color, "%s", message); } // Calculate the frame-lag of a client Index: src/settings.cpp =================================================================== --- src/settings.cpp (revision 9153) +++ src/settings.cpp (working copy) @@ -1283,6 +1283,7 @@ 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, text_stays_visible, SLE_UINT16,S,NC, 60,10,900,10, STR_CONFIG_PATCHES_TEXT_STAYS_VISIBLE, 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), Index: src/settings_gui.cpp =================================================================== --- src/settings_gui.cpp (revision 9153) +++ src/settings_gui.cpp (working copy) @@ -576,6 +576,7 @@ "link_terraform_toolbar", "liveries", "prefer_teamchat", + "text_stays_visible", /* 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 9153) +++ src/texteff.cpp (working copy) @@ -15,11 +15,13 @@ #include "table/sprites.h" #include /* va_list */ #include "date.h" +#include + enum { - MAX_TEXTMESSAGE_LENGTH = 200, - MAX_TEXT_MESSAGES = 30, - MAX_CHAT_MESSAGES = 10, + MAX_TEXTMESSAGE_LENGTH = 256, + 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_ANIMATED_TILES = 256, }; @@ -35,10 +37,15 @@ }; +/* Storage for the on-screen text display + * @param message Text to be displayed + * @param color Text color + * @param time_stamp timestamp when message was created, in real-seconds since 1/1/1970 + */ struct TextMessage { char message[MAX_TEXTMESSAGE_LENGTH]; uint16 color; - Date end_date; + time_t time_stamp; }; static TextEffect _text_effect_list[MAX_TEXT_MESSAGES]; @@ -49,9 +56,11 @@ static bool _textmessage_visible = false; /* 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 Pixel _textmessage_backup[150 * 500]; // (height * width) + * the left and pixels from the bottom. The height is the maximum height + * @todo dynamically resize text box according to current screen dimensions + */ +static const Oblong _textmsg_box = {10, 30, 512, 330}; // height adjusted to allow for 24 lines of allowed text in MAX_TEXT_MESSAGES +static Pixel _textmessage_backup[330 * 512]; // (height * width) extern void memcpy_pitch(void *dst, void *src, int w, int h, int srcpitch, int dstpitch); @@ -68,9 +77,8 @@ /* 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, ...) +void CDECL AddTextMessage(uint16 color, const char *message, ...) { char buf[MAX_TEXTMESSAGE_LENGTH]; const char *bufp; @@ -82,7 +90,6 @@ vsnprintf(buf, lengthof(buf), message, va); va_end(va); - Utf8TrimString(buf, MAX_TEXTMESSAGE_LENGTH); /* Force linebreaks for strings that are too long */ @@ -104,7 +111,7 @@ /* The default colour for a message is player colour. Replace this with * white for any additional lines */ tmsg->color = (bufp == buf && color & IS_PALETTE_COLOR) ? color : (0x1D - 15) | IS_PALETTE_COLOR; - tmsg->end_date = _date + duration; + 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 } @@ -162,23 +169,20 @@ /* Check if a message is expired every day */ void TextMessageDailyLoop() { - uint i; + time_t tstamp; + time( &tstamp ); + tstamp = tstamp - _patches.text_stays_visible; // 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]; + if (tmsg->message != '\0') { /* Message has expired, remove from the list */ - if (tmsg->end_date < _date) { + if (tmsg->time_stamp < tstamp ) { // time_stamp must be older than tstamp to be expired /* 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)); - + 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--; } } } Index: src/variables.h =================================================================== --- src/variables.h (revision 9153) +++ src/variables.h (working copy) @@ -129,6 +129,7 @@ bool measure_tooltip; // Show a permanent tooltip when dragging tools byte liveries; // Options for displaying company liveries, 0=none, 1=self, 2=all bool prefer_teamchat; // Choose the chat message target with , true=all players, false=your team + uint16 text_stays_visible; // Min time, in real-time seconds, chat text stays visible 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