summaryrefslogtreecommitdiff
path: root/src/texteff.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-08-11 22:45:11 +0000
committerrubidium <rubidium@openttd.org>2008-08-11 22:45:11 +0000
commitd0c1a989a4226cc06a50b1a8c95b9ca8f0b9599e (patch)
tree96b3b7c215db821df9b9268eb9af5a55ee1200ce /src/texteff.cpp
parent6995365535370da08116d49a30ebd84d56e7d8ff (diff)
downloadopenttd-d0c1a989a4226cc06a50b1a8c95b9ca8f0b9599e.tar.xz
(svn r14047) -Codechange: move chatmessage handling to the network directory as that's the only case chat messages are used. Furthermore remove any trace of chatmessages when compiling without network support.
Diffstat (limited to 'src/texteff.cpp')
-rw-r--r--src/texteff.cpp226
1 files changed, 3 insertions, 223 deletions
diff --git a/src/texteff.cpp b/src/texteff.cpp
index c6b8daa47..cf71d9c5d 100644
--- a/src/texteff.cpp
+++ b/src/texteff.cpp
@@ -6,27 +6,18 @@
#include "openttd.h"
#include "landscape.h"
#include "gfx_func.h"
-#include "console_func.h"
#include "variables.h"
-#include "blitter/factory.hpp"
#include "texteff.hpp"
-#include "video/video_driver.hpp"
+#include "core/bitmath_func.hpp"
#include "transparency.h"
#include "strings_func.h"
#include "core/alloc_func.hpp"
-#include "date_func.h"
#include "functions.h"
#include "viewport_func.h"
#include "settings_type.h"
-#include "table/sprites.h"
-
-#include <stdarg.h> /* va_list */
-
enum {
- MAX_TEXTMESSAGE_LENGTH = 200,
- INIT_NUM_TEXT_MESSAGES = 20,
- MAX_CHAT_MESSAGES = 10,
+ INIT_NUM_TEXT_EFFECTS = 20,
};
struct TextEffect {
@@ -41,220 +32,9 @@ struct TextEffect {
TextEffectMode mode;
};
-
-struct ChatMessage {
- char message[MAX_TEXTMESSAGE_LENGTH];
- uint16 color;
- Date end_date;
-};
-
/* used for text effects */
static TextEffect *_text_effect_list = NULL;
-static uint16 _num_text_effects = INIT_NUM_TEXT_MESSAGES;
-
-/* used for chat window */
-static ChatMessage _chatmsg_list[MAX_CHAT_MESSAGES];
-static bool _chatmessage_dirty = false;
-static bool _chatmessage_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 PointDimension _chatmsg_box = {10, 30, 500, 150};
-static uint8 _chatmessage_backup[150 * 500 * 6]; // (height * width)
-
-static inline uint GetChatMessageCount()
-{
- uint i;
-
- for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
- if (_chatmsg_list[i].message[0] == '\0') break;
- }
-
- return i;
-}
-
-/* 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 AddChatMessage(uint16 color, uint8 duration, const char *message, ...)
-{
- char buf[MAX_TEXTMESSAGE_LENGTH];
- const char *bufp;
- va_list va;
- uint msg_count;
- uint16 lines;
-
- va_start(va, message);
- vsnprintf(buf, lengthof(buf), message, va);
- va_end(va);
-
-
- Utf8TrimString(buf, MAX_TEXTMESSAGE_LENGTH);
-
- /* Force linebreaks for strings that are too long */
- lines = GB(FormatStringLinebreaks(buf, _chatmsg_box.width - 8), 0, 16) + 1;
- if (lines >= MAX_CHAT_MESSAGES) return;
-
- msg_count = GetChatMessageCount();
- /* We want to add more chat messages than there is free space for, remove 'old' */
- if (lines > MAX_CHAT_MESSAGES - msg_count) {
- int i = lines - (MAX_CHAT_MESSAGES - msg_count);
- memmove(&_chatmsg_list[0], &_chatmsg_list[i], sizeof(_chatmsg_list[0]) * (msg_count - i));
- msg_count = MAX_CHAT_MESSAGES - lines;
- }
-
- for (bufp = buf; lines != 0; lines--) {
- ChatMessage *cmsg = &_chatmsg_list[msg_count++];
- ttd_strlcpy(cmsg->message, bufp, sizeof(cmsg->message));
-
- /* The default colour for a message is player colour. Replace this with
- * white for any additional lines */
- cmsg->color = (bufp == buf && color & IS_PALETTE_COLOR) ? color : (0x1D - 15) | IS_PALETTE_COLOR;
- cmsg->end_date = _date + duration;
-
- bufp += strlen(bufp) + 1; // jump to 'next line' in the formatted string
- }
-
- _chatmessage_dirty = true;
-}
-
-void InitChatMessage()
-{
- uint i;
-
- for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
- _chatmsg_list[i].message[0] = '\0';
- }
-}
-
-/** Hide the chatbox */
-void UndrawChatMessage()
-{
- if (_chatmessage_visible) {
- Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
- /* Sometimes we also need to hide the cursor
- * This is because both textmessage and the cursor take a shot of the
- * screen before drawing.
- * Now the textmessage takes his shot and paints his data before the cursor
- * does, so in the shot of the cursor is the screen-data of the textmessage
- * included when the cursor hangs somewhere over the textmessage. To
- * avoid wrong repaints, we undraw the cursor in that case, and everything
- * looks nicely ;)
- * (and now hope this story above makes sense to you ;))
- */
-
- if (_cursor.visible) {
- if (_cursor.draw_pos.x + _cursor.draw_size.x >= _chatmsg_box.x &&
- _cursor.draw_pos.x <= _chatmsg_box.x + _chatmsg_box.width &&
- _cursor.draw_pos.y + _cursor.draw_size.y >= _screen.height - _chatmsg_box.y - _chatmsg_box.height &&
- _cursor.draw_pos.y <= _screen.height - _chatmsg_box.y) {
- UndrawMouseCursor();
- }
- }
-
- int x = _chatmsg_box.x;
- int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
- int width = _chatmsg_box.width;
- int height = _chatmsg_box.height;
- if (y < 0) {
- height = max(height + y, min(_chatmsg_box.height, _screen.height));
- y = 0;
- }
- if (x + width >= _screen.width) {
- width = _screen.width - x;
- }
- if (width <= 0 || height <= 0) return;
-
- _chatmessage_visible = false;
- /* Put our 'shot' back to the screen */
- blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
- /* And make sure it is updated next time */
- _video_driver->MakeDirty(x, y, width, height);
-
- _chatmessage_dirty = true;
- }
-}
-
-/** Check if a message is expired every day */
-void ChatMessageDailyLoop()
-{
- uint i;
-
- for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
- ChatMessage *cmsg = &_chatmsg_list[i];
- if (cmsg->message[0] == '\0') continue;
-
- /* Message has expired, remove from the list */
- if (cmsg->end_date < _date) {
- /* Move the remaining messages over the current message */
- if (i != MAX_CHAT_MESSAGES - 1) memmove(cmsg, cmsg + 1, sizeof(*cmsg) * (MAX_CHAT_MESSAGES - i - 1));
-
- /* Mark the last item as empty */
- _chatmsg_list[MAX_CHAT_MESSAGES - 1].message[0] = '\0';
- _chatmessage_dirty = true;
-
- /* Go one item back, because we moved the array 1 to the left */
- i--;
- }
- }
-}
-
-/** Draw the chat message-box */
-void DrawChatMessage()
-{
- Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
- if (!_chatmessage_dirty) return;
-
- /* First undraw if needed */
- UndrawChatMessage();
-
- if (_iconsole_mode == ICONSOLE_FULL) return;
-
- /* Check if we have anything to draw at all */
- uint count = GetChatMessageCount();
- if (count == 0) return;
-
- int x = _chatmsg_box.x;
- int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
- int width = _chatmsg_box.width;
- int height = _chatmsg_box.height;
- if (y < 0) {
- height = max(height + y, min(_chatmsg_box.height, _screen.height));
- y = 0;
- }
- if (x + width >= _screen.width) {
- width = _screen.width - x;
- }
- if (width <= 0 || height <= 0) return;
-
- assert(blitter->BufferSize(width, height) < (int)sizeof(_chatmessage_backup));
-
- /* 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);
-
- _cur_dpi = &_screen; // switch to _screen painting
-
- /* Paint a half-transparent box behind the chat messages */
- GfxFillRect(
- _chatmsg_box.x,
- _screen.height - _chatmsg_box.y - count * 13 - 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) {
- DoDrawString(_chatmsg_list[count].message, _chatmsg_box.x + 3, _screen.height - _chatmsg_box.y - y + 1, _chatmsg_list[count].color);
- }
-
- /* Make sure the data is updated next flush */
- _video_driver->MakeDirty(x, y, width, height);
-
- _chatmessage_visible = true;
- _chatmessage_dirty = false;
-}
+static uint16 _num_text_effects = INIT_NUM_TEXT_EFFECTS;
/* Text Effects */
/**