summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/network/core/config.h2
-rw-r--r--src/network/network_chat_gui.cpp36
-rw-r--r--src/settings.cpp3
-rw-r--r--src/settings_type.h4
4 files changed, 32 insertions, 13 deletions
diff --git a/src/network/core/config.h b/src/network/core/config.h
index 4911d2a4c..72e4ca78a 100644
--- a/src/network/core/config.h
+++ b/src/network/core/config.h
@@ -32,7 +32,7 @@ enum {
NETWORK_PLAYERS_LENGTH = 200, ///< The maximum length for the list of players that controls a company, in bytes including '\0'
NETWORK_CLIENT_NAME_LENGTH = 25, ///< The maximum length of a player, in bytes including '\0'
NETWORK_RCONCOMMAND_LENGTH = 500, ///< The maximum length of a rconsole command, in bytes including '\0'
- NETWORK_CHAT_LENGTH = 1000, ///< The maximum length of a chat message, in bytes including '\0'
+ NETWORK_CHAT_LENGTH = 900, ///< The maximum length of a chat message, in bytes including '\0'
NETWORK_GRF_NAME_LENGTH = 80, ///< Maximum length of the name of a GRF
/**
diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp
index 40e328e6b..e2ee3e230 100644
--- a/src/network/network_chat_gui.cpp
+++ b/src/network/network_chat_gui.cpp
@@ -21,33 +21,37 @@
#include "../querystring_gui.h"
#include "../town.h"
#include "../window_func.h"
+#include "../settings_type.h"
#include "network_internal.h"
#include "network_client.h"
#include "table/strings.h"
-assert_compile((int)DRAW_STRING_BUFFER >= (int)NETWORK_CHAT_LENGTH);
+/* The draw buffer must be able to contain the chat message, player name and the "[All]" message,
+ * some spaces and possible translations of [All] to other languages. */
+assert_compile((int)DRAW_STRING_BUFFER >= (int)NETWORK_CHAT_LENGTH + NETWORK_NAME_LENGTH + 40);
enum {
- MAX_CHAT_MESSAGES = 10,
+ NETWORK_CHAT_LINE_HEIGHT = 13,
};
struct ChatMessage {
- char message[NETWORK_CHAT_LENGTH];
+ char message[DRAW_STRING_BUFFER];
uint16 color;
Date end_date;
};
/* used for chat window */
-static ChatMessage _chatmsg_list[MAX_CHAT_MESSAGES];
+static ChatMessage *_chatmsg_list = NULL;
static bool _chatmessage_dirty = false;
static bool _chatmessage_visible = false;
static bool _chat_tab_completion_active;
+static uint MAX_CHAT_MESSAGES = 0;
/* 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 PointDimension _chatmsg_box = {10, 30, 500, 150};
-static uint8 _chatmessage_backup[150 * 500 * 6]; // (height * width)
+static PointDimension _chatmsg_box;
+static uint8 *_chatmessage_backup = NULL;
static inline uint GetChatMessageCount()
{
@@ -67,7 +71,7 @@ static inline uint GetChatMessageCount()
*/
void CDECL NetworkAddChatMessage(uint16 color, uint8 duration, const char *message, ...)
{
- char buf[NETWORK_CHAT_LENGTH];
+ char buf[DRAW_STRING_BUFFER];
const char *bufp;
va_list va;
uint msg_count;
@@ -77,8 +81,7 @@ void CDECL NetworkAddChatMessage(uint16 color, uint8 duration, const char *messa
vsnprintf(buf, lengthof(buf), message, va);
va_end(va);
-
- Utf8TrimString(buf, NETWORK_CHAT_LENGTH);
+ Utf8TrimString(buf, DRAW_STRING_BUFFER);
/* Force linebreaks for strings that are too long */
lines = GB(FormatStringLinebreaks(buf, _chatmsg_box.width - 8), 0, 16) + 1;
@@ -109,6 +112,15 @@ void CDECL NetworkAddChatMessage(uint16 color, uint8 duration, const char *messa
void NetworkInitChatMessage()
{
+ MAX_CHAT_MESSAGES = _settings_client.gui.network_chat_box_height;
+
+ _chatmsg_list = ReallocT(_chatmsg_list, _settings_client.gui.network_chat_box_height);
+ _chatmsg_box.x = 10;
+ _chatmsg_box.y = 30;
+ _chatmsg_box.width = _settings_client.gui.network_chat_box_width;
+ _chatmsg_box.height = _settings_client.gui.network_chat_box_height * NETWORK_CHAT_LINE_HEIGHT;
+ _chatmessage_backup = ReallocT(_chatmessage_backup, _chatmsg_box.width * _chatmsg_box.height * sizeof(uint32));
+
for (uint i = 0; i < MAX_CHAT_MESSAGES; i++) {
_chatmsg_list[i].message[0] = '\0';
}
@@ -212,7 +224,7 @@ void NetworkDrawChatMessage()
}
if (width <= 0 || height <= 0) return;
- assert(blitter->BufferSize(width, height) < (int)sizeof(_chatmessage_backup));
+ assert(blitter->BufferSize(width, height) < (int)(_chatmsg_box.width * _chatmsg_box.height * sizeof(uint32)));
/* Make a copy of the screen as it is before painting (for undraw) */
blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
@@ -222,14 +234,14 @@ void NetworkDrawChatMessage()
/* Paint a half-transparent box behind the chat messages */
GfxFillRect(
_chatmsg_box.x,
- _screen.height - _chatmsg_box.y - count * 13 - 2,
+ _screen.height - _chatmsg_box.y - count * NETWORK_CHAT_LINE_HEIGHT - 2,
_chatmsg_box.x + _chatmsg_box.width - 1,
_screen.height - _chatmsg_box.y - 2,
PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOR // black, but with some alpha for background
);
/* Paint the chat messages starting with the lowest at the bottom */
- for (uint y = 13; count-- != 0; y += 13) {
+ for (uint y = NETWORK_CHAT_LINE_HEIGHT; count-- != 0; y += NETWORK_CHAT_LINE_HEIGHT) {
DoDrawString(_chatmsg_list[count].message, _chatmsg_box.x + 3, _screen.height - _chatmsg_box.y - y + 1, _chatmsg_list[count].color);
}
diff --git a/src/settings.cpp b/src/settings.cpp
index 8f82d7eae..1bc60f85f 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1804,6 +1804,9 @@ const SettingDesc _patch_settings[] = {
SDTC_VAR(gui.cycle_signal_types, SLE_UINT8, S, MS, 0, 0, 2, 1, STR_CONFIG_PATCHES_CYCLE_SIGNAL_TYPES, NULL),
#ifdef ENABLE_NETWORK
+ SDTC_VAR(gui.network_chat_box_width, SLE_UINT16, S, 0, 700, 200, 65535, 0, STR_NULL, NULL),
+ SDTC_VAR(gui.network_chat_box_height, SLE_UINT8, S, 0, 25, 5, 255, 0, STR_NULL, NULL),
+
SDTC_VAR(network.sync_freq, SLE_UINT16,C|S,NO, 100, 0, 100, 0, STR_NULL, NULL),
SDTC_VAR(network.frame_freq, SLE_UINT8,C|S,NO, 0, 0, 100, 0, STR_NULL, NULL),
SDTC_VAR(network.max_join_time, SLE_UINT16, S, NO, 500, 0, 32000, 0, STR_NULL, NULL),
diff --git a/src/settings_type.h b/src/settings_type.h
index c7341cd5a..833d37520 100644
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -82,6 +82,10 @@ struct GUISettings {
bool show_track_reservation; ///< highlight reserved tracks.
uint8 default_signal_type; ///< the signal type to build by default.
uint8 cycle_signal_types; ///< what signal types to cycle with the build signal tool.
+#ifdef ENABLE_NETWORK
+ uint16 network_chat_box_width; ///< width of the chat box in pixels
+ uint8 network_chat_box_height; ///< height of the chat box in lines
+#endif
};
/** Settings related to currency/unit systems. */