2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file texteff.cpp Handling of text effects. */
|
2007-04-04 03:21:14 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2007-04-12 13:07:15 +00:00
|
|
|
#include "landscape.h"
|
2008-01-09 09:57:48 +00:00
|
|
|
#include "gfx_func.h"
|
2008-05-24 10:15:06 +00:00
|
|
|
#include "console_func.h"
|
2005-07-21 18:44:27 +00:00
|
|
|
#include "variables.h"
|
2007-06-17 20:30:28 +00:00
|
|
|
#include "blitter/factory.hpp"
|
2007-06-21 16:17:47 +00:00
|
|
|
#include "texteff.hpp"
|
2007-07-05 12:23:54 +00:00
|
|
|
#include "video/video_driver.hpp"
|
2007-11-10 01:17:15 +00:00
|
|
|
#include "transparency.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-25 09:48:53 +00:00
|
|
|
#include "core/alloc_func.hpp"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_func.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "functions.h"
|
2008-01-09 09:57:48 +00:00
|
|
|
#include "viewport_func.h"
|
2008-01-13 14:37:30 +00:00
|
|
|
#include "settings_type.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/sprites.h"
|
|
|
|
|
|
|
|
#include <stdarg.h> /* va_list */
|
|
|
|
|
2006-12-30 00:46:48 +00:00
|
|
|
enum {
|
2007-03-05 00:45:56 +00:00
|
|
|
MAX_TEXTMESSAGE_LENGTH = 200,
|
2007-06-21 16:17:47 +00:00
|
|
|
INIT_NUM_TEXT_MESSAGES = 20,
|
2006-12-30 00:46:48 +00:00
|
|
|
MAX_CHAT_MESSAGES = 10,
|
|
|
|
};
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct TextEffect {
|
2004-08-09 17:04:08 +00:00
|
|
|
StringID string_id;
|
2005-01-03 08:50:44 +00:00
|
|
|
int32 x;
|
|
|
|
int32 y;
|
|
|
|
int32 right;
|
|
|
|
int32 bottom;
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 duration;
|
2007-06-21 19:08:47 +00:00
|
|
|
uint64 params_1;
|
|
|
|
uint64 params_2;
|
2007-06-21 16:17:47 +00:00
|
|
|
TextEffectMode mode;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
struct ChatMessage {
|
2004-12-04 17:54:56 +00:00
|
|
|
char message[MAX_TEXTMESSAGE_LENGTH];
|
|
|
|
uint16 color;
|
2006-08-23 20:46:54 +00:00
|
|
|
Date end_date;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
/* used for text effects */
|
2007-06-21 16:17:47 +00:00
|
|
|
static TextEffect *_text_effect_list = NULL;
|
2007-08-19 09:38:30 +00:00
|
|
|
static uint16 _num_text_effects = INIT_NUM_TEXT_MESSAGES;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
/* used for chat window */
|
|
|
|
static ChatMessage _chatmsg_list[MAX_CHAT_MESSAGES];
|
|
|
|
static bool _chatmessage_dirty = false;
|
|
|
|
static bool _chatmessage_visible = false;
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2006-10-27 10:27:38 +00:00
|
|
|
/* 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 */
|
2007-12-22 23:30:28 +00:00
|
|
|
static const PointDimension _chatmsg_box = {10, 30, 500, 150};
|
2007-08-19 09:38:30 +00:00
|
|
|
static uint8 _chatmessage_backup[150 * 500 * 6]; // (height * width)
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
static inline uint GetChatMessageCount()
|
2006-10-27 11:08:17 +00:00
|
|
|
{
|
2006-10-27 11:17:38 +00:00
|
|
|
uint i;
|
2006-10-27 11:08:17 +00:00
|
|
|
|
2006-10-27 11:17:38 +00:00
|
|
|
for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
|
2007-08-19 09:38:30 +00:00
|
|
|
if (_chatmsg_list[i].message[0] == '\0') break;
|
2006-10-27 11:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
2007-08-19 09:38:30 +00:00
|
|
|
void CDECL AddChatMessage(uint16 color, uint8 duration, const char *message, ...)
|
2004-12-04 17:54:56 +00:00
|
|
|
{
|
2005-09-24 06:43:26 +00:00
|
|
|
char buf[MAX_TEXTMESSAGE_LENGTH];
|
2006-10-27 11:08:17 +00:00
|
|
|
const char *bufp;
|
2004-12-04 17:54:56 +00:00
|
|
|
va_list va;
|
2006-10-27 11:08:17 +00:00
|
|
|
uint msg_count;
|
|
|
|
uint16 lines;
|
2004-12-04 17:54:56 +00:00
|
|
|
|
|
|
|
va_start(va, message);
|
2005-08-28 12:24:57 +00:00
|
|
|
vsnprintf(buf, lengthof(buf), message, va);
|
2004-12-04 17:54:56 +00:00
|
|
|
va_end(va);
|
|
|
|
|
2007-03-05 00:45:56 +00:00
|
|
|
|
|
|
|
Utf8TrimString(buf, MAX_TEXTMESSAGE_LENGTH);
|
|
|
|
|
2006-10-27 11:08:17 +00:00
|
|
|
/* Force linebreaks for strings that are too long */
|
2007-08-19 09:38:30 +00:00
|
|
|
lines = GB(FormatStringLinebreaks(buf, _chatmsg_box.width - 8), 0, 16) + 1;
|
2006-10-27 11:08:17 +00:00
|
|
|
if (lines >= MAX_CHAT_MESSAGES) return;
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
msg_count = GetChatMessageCount();
|
2006-10-27 11:08:17 +00:00
|
|
|
/* 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);
|
2007-08-19 09:38:30 +00:00
|
|
|
memmove(&_chatmsg_list[0], &_chatmsg_list[i], sizeof(_chatmsg_list[0]) * (msg_count - i));
|
2006-10-27 11:08:17 +00:00
|
|
|
msg_count = MAX_CHAT_MESSAGES - lines;
|
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2006-10-27 11:08:17 +00:00
|
|
|
for (bufp = buf; lines != 0; lines--) {
|
2007-08-19 09:38:30 +00:00
|
|
|
ChatMessage *cmsg = &_chatmsg_list[msg_count++];
|
|
|
|
ttd_strlcpy(cmsg->message, bufp, sizeof(cmsg->message));
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2006-10-27 11:08:17 +00:00
|
|
|
/* The default colour for a message is player colour. Replace this with
|
|
|
|
* white for any additional lines */
|
2007-08-19 09:38:30 +00:00
|
|
|
cmsg->color = (bufp == buf && color & IS_PALETTE_COLOR) ? color : (0x1D - 15) | IS_PALETTE_COLOR;
|
|
|
|
cmsg->end_date = _date + duration;
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2006-10-27 11:08:17 +00:00
|
|
|
bufp += strlen(bufp) + 1; // jump to 'next line' in the formatted string
|
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
_chatmessage_dirty = true;
|
2004-12-04 17:54:56 +00:00
|
|
|
}
|
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
void InitChatMessage()
|
2004-12-04 17:54:56 +00:00
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
uint i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
|
2007-08-19 09:38:30 +00:00
|
|
|
_chatmsg_list[i].message[0] = '\0';
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
}
|
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
/** Hide the chatbox */
|
|
|
|
void UndrawChatMessage()
|
2004-12-04 17:54:56 +00:00
|
|
|
{
|
2007-08-19 09:38:30 +00:00
|
|
|
if (_chatmessage_visible) {
|
2007-06-17 20:30:28 +00:00
|
|
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
2006-12-30 00:46:48 +00:00
|
|
|
/* 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 ;))
|
|
|
|
*/
|
2004-12-04 17:54:56 +00:00
|
|
|
|
|
|
|
if (_cursor.visible) {
|
2007-08-19 09:38:30 +00:00
|
|
|
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) {
|
2004-12-04 17:54:56 +00:00
|
|
|
UndrawMouseCursor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
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;
|
2007-03-23 22:20:39 +00:00
|
|
|
if (y < 0) {
|
2007-08-19 09:38:30 +00:00
|
|
|
height = max(height + y, min(_chatmsg_box.height, _screen.height));
|
2007-03-23 22:20:39 +00:00
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
if (x + width >= _screen.width) {
|
|
|
|
width = _screen.width - x;
|
|
|
|
}
|
2007-03-25 00:13:22 +00:00
|
|
|
if (width <= 0 || height <= 0) return;
|
2007-03-23 22:20:39 +00:00
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
_chatmessage_visible = false;
|
2006-12-30 00:46:48 +00:00
|
|
|
/* Put our 'shot' back to the screen */
|
2007-08-19 09:38:30 +00:00
|
|
|
blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
|
2006-12-30 00:46:48 +00:00
|
|
|
/* And make sure it is updated next time */
|
2007-07-05 12:23:54 +00:00
|
|
|
_video_driver->MakeDirty(x, y, width, height);
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
_chatmessage_dirty = true;
|
2004-12-04 17:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/** Check if a message is expired every day */
|
2007-08-19 09:38:30 +00:00
|
|
|
void ChatMessageDailyLoop()
|
2004-12-04 17:54:56 +00:00
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
uint i;
|
|
|
|
|
2005-03-28 12:38:02 +00:00
|
|
|
for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
|
2007-08-19 09:38:30 +00:00
|
|
|
ChatMessage *cmsg = &_chatmsg_list[i];
|
|
|
|
if (cmsg->message[0] == '\0') continue;
|
2005-03-28 12:38:02 +00:00
|
|
|
|
2006-10-27 11:08:17 +00:00
|
|
|
/* Message has expired, remove from the list */
|
2007-08-19 09:38:30 +00:00
|
|
|
if (cmsg->end_date < _date) {
|
2005-03-28 12:38:02 +00:00
|
|
|
/* Move the remaining messages over the current message */
|
2007-08-19 09:38:30 +00:00
|
|
|
if (i != MAX_CHAT_MESSAGES - 1) memmove(cmsg, cmsg + 1, sizeof(*cmsg) * (MAX_CHAT_MESSAGES - i - 1));
|
2005-03-28 12:38:02 +00:00
|
|
|
|
|
|
|
/* Mark the last item as empty */
|
2007-08-19 09:38:30 +00:00
|
|
|
_chatmsg_list[MAX_CHAT_MESSAGES - 1].message[0] = '\0';
|
|
|
|
_chatmessage_dirty = true;
|
2005-03-28 12:38:02 +00:00
|
|
|
|
|
|
|
/* Go one item back, because we moved the array 1 to the left */
|
|
|
|
i--;
|
2004-12-04 17:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
/** Draw the chat message-box */
|
|
|
|
void DrawChatMessage()
|
2004-12-04 17:54:56 +00:00
|
|
|
{
|
2007-06-17 20:30:28 +00:00
|
|
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
2007-08-19 09:38:30 +00:00
|
|
|
if (!_chatmessage_dirty) return;
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2006-12-30 00:46:48 +00:00
|
|
|
/* First undraw if needed */
|
2007-08-19 09:38:30 +00:00
|
|
|
UndrawChatMessage();
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2006-10-27 11:17:38 +00:00
|
|
|
if (_iconsole_mode == ICONSOLE_FULL) return;
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2005-03-28 12:38:02 +00:00
|
|
|
/* Check if we have anything to draw at all */
|
2007-08-19 09:38:30 +00:00
|
|
|
uint count = GetChatMessageCount();
|
2006-10-27 11:49:51 +00:00
|
|
|
if (count == 0) return;
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
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;
|
2007-03-23 22:20:39 +00:00
|
|
|
if (y < 0) {
|
2007-08-19 09:38:30 +00:00
|
|
|
height = max(height + y, min(_chatmsg_box.height, _screen.height));
|
2007-03-23 22:20:39 +00:00
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
if (x + width >= _screen.width) {
|
|
|
|
width = _screen.width - x;
|
|
|
|
}
|
2007-03-25 00:13:22 +00:00
|
|
|
if (width <= 0 || height <= 0) return;
|
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
assert(blitter->BufferSize(width, height) < (int)sizeof(_chatmessage_backup));
|
2007-06-21 12:36:46 +00:00
|
|
|
|
2006-12-30 00:46:48 +00:00
|
|
|
/* Make a copy of the screen as it is before painting (for undraw) */
|
2007-08-19 09:38:30 +00:00
|
|
|
blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2006-10-27 11:49:51 +00:00
|
|
|
_cur_dpi = &_screen; // switch to _screen painting
|
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
/* Paint a half-transparent box behind the chat messages */
|
2006-10-27 11:49:51 +00:00
|
|
|
GfxFillRect(
|
2007-08-19 09:38:30 +00:00
|
|
|
_chatmsg_box.x,
|
|
|
|
_screen.height - _chatmsg_box.y - count * 13 - 2,
|
|
|
|
_chatmsg_box.x + _chatmsg_box.width - 1,
|
|
|
|
_screen.height - _chatmsg_box.y - 2,
|
2008-06-28 15:44:24 +00:00
|
|
|
PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOR // black, but with some alpha for background
|
2006-10-27 11:49:51 +00:00
|
|
|
);
|
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
/* Paint the chat messages starting with the lowest at the bottom */
|
2007-03-23 22:20:39 +00:00
|
|
|
for (uint y = 13; count-- != 0; y += 13) {
|
2007-08-19 09:38:30 +00:00
|
|
|
DoDrawString(_chatmsg_list[count].message, _chatmsg_box.x + 3, _screen.height - _chatmsg_box.y - y + 1, _chatmsg_list[count].color);
|
2007-04-18 22:41:53 +00:00
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2006-12-30 00:46:48 +00:00
|
|
|
/* Make sure the data is updated next flush */
|
2007-07-05 12:23:54 +00:00
|
|
|
_video_driver->MakeDirty(x, y, width, height);
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2007-08-19 09:38:30 +00:00
|
|
|
_chatmessage_visible = true;
|
|
|
|
_chatmessage_dirty = false;
|
2004-12-04 17:54:56 +00:00
|
|
|
}
|
|
|
|
|
2007-09-09 10:13:17 +00:00
|
|
|
/* Text Effects */
|
|
|
|
/**
|
|
|
|
* Mark the area of the text effect as dirty.
|
|
|
|
*
|
|
|
|
* This function marks the area of a text effect as dirty for repaint.
|
|
|
|
*
|
|
|
|
* @param te The TextEffect to mark the area dirty
|
|
|
|
* @ingroup dirty
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
static void MarkTextEffectAreaDirty(TextEffect *te)
|
|
|
|
{
|
2007-09-07 21:15:32 +00:00
|
|
|
/* Width and height of the text effect are doubled, so they are correct in both zoom out levels 1x and 2x. */
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkAllViewportsDirty(
|
|
|
|
te->x,
|
|
|
|
te->y - 1,
|
|
|
|
(te->right - te->x)*2 + te->x + 1,
|
|
|
|
(te->bottom - (te->y - 1)) * 2 + (te->y - 1) + 1
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-06-21 16:17:47 +00:00
|
|
|
TextEffectID AddTextEffect(StringID msg, int x, int y, uint16 duration, TextEffectMode mode)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
TextEffect *te;
|
|
|
|
int w;
|
|
|
|
char buffer[100];
|
2007-06-21 16:17:47 +00:00
|
|
|
TextEffectID i;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-21 16:17:47 +00:00
|
|
|
if (_game_mode == GM_MENU) return INVALID_TE_ID;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-06-21 16:17:47 +00:00
|
|
|
/* Look for a free spot in the text effect array */
|
|
|
|
for (i = 0; i < _num_text_effects; i++) {
|
|
|
|
if (_text_effect_list[i].string_id == INVALID_STRING_ID) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-21 16:17:47 +00:00
|
|
|
/* If there is none found, we grow the array */
|
|
|
|
if (i == _num_text_effects) {
|
|
|
|
_num_text_effects += 25;
|
2007-12-08 14:50:41 +00:00
|
|
|
_text_effect_list = ReallocT<TextEffect>(_text_effect_list, _num_text_effects);
|
2007-06-21 16:17:47 +00:00
|
|
|
for (; i < _num_text_effects; i++) _text_effect_list[i].string_id = INVALID_STRING_ID;
|
|
|
|
i = _num_text_effects - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
te = &_text_effect_list[i];
|
|
|
|
|
|
|
|
/* Start defining this object */
|
2004-08-09 17:04:08 +00:00
|
|
|
te->string_id = msg;
|
|
|
|
te->duration = duration;
|
|
|
|
te->y = y - 5;
|
|
|
|
te->bottom = y + 5;
|
2004-12-02 22:53:07 +00:00
|
|
|
te->params_1 = GetDParam(0);
|
|
|
|
te->params_2 = GetDParam(4);
|
2007-06-21 16:17:47 +00:00
|
|
|
te->mode = mode;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(buffer, msg, lastof(buffer));
|
2006-09-16 13:20:14 +00:00
|
|
|
w = GetStringBoundingBox(buffer).width;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
te->x = x - (w >> 1);
|
|
|
|
te->right = x + (w >> 1) - 1;
|
|
|
|
MarkTextEffectAreaDirty(te);
|
2007-06-21 16:17:47 +00:00
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateTextEffect(TextEffectID te_id, StringID msg)
|
|
|
|
{
|
|
|
|
assert(te_id < _num_text_effects);
|
|
|
|
TextEffect *te;
|
|
|
|
|
|
|
|
/* Update details */
|
|
|
|
te = &_text_effect_list[te_id];
|
|
|
|
te->string_id = msg;
|
|
|
|
te->params_1 = GetDParam(0);
|
|
|
|
te->params_2 = GetDParam(4);
|
|
|
|
|
2007-09-07 21:15:32 +00:00
|
|
|
/* Update width of text effect */
|
|
|
|
char buffer[100];
|
|
|
|
GetString(buffer, msg, lastof(buffer));
|
|
|
|
int w = GetStringBoundingBox(buffer).width;
|
|
|
|
|
|
|
|
/* Only allow to make it broader, so it completely covers the old text. That avoids remnants of the old text. */
|
|
|
|
int right_new = te->x + w;
|
|
|
|
if (te->right < right_new) te->right = right_new;
|
|
|
|
|
2007-06-21 16:17:47 +00:00
|
|
|
MarkTextEffectAreaDirty(te);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveTextEffect(TextEffectID te_id)
|
|
|
|
{
|
|
|
|
assert(te_id < _num_text_effects);
|
|
|
|
TextEffect *te;
|
|
|
|
|
|
|
|
te = &_text_effect_list[te_id];
|
|
|
|
MarkTextEffectAreaDirty(te);
|
|
|
|
te->string_id = INVALID_STRING_ID;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void MoveTextEffect(TextEffect *te)
|
|
|
|
{
|
2007-06-21 16:17:47 +00:00
|
|
|
/* Never expire for duration of 0xFFFF */
|
|
|
|
if (te->duration == 0xFFFF) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (te->duration < 8) {
|
2005-09-28 21:49:55 +00:00
|
|
|
te->string_id = INVALID_STRING_ID;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-10-23 13:04:44 +00:00
|
|
|
te->duration -= 8;
|
2004-08-09 17:04:08 +00:00
|
|
|
te->y--;
|
|
|
|
te->bottom--;
|
|
|
|
}
|
|
|
|
MarkTextEffectAreaDirty(te);
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void MoveAllTextEffects()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-06-21 16:17:47 +00:00
|
|
|
for (TextEffectID i = 0; i < _num_text_effects; i++) {
|
|
|
|
TextEffect *te = &_text_effect_list[i];
|
|
|
|
if (te->string_id != INVALID_STRING_ID && te->mode == TE_RISING) MoveTextEffect(te);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitTextEffects()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-06-21 16:17:47 +00:00
|
|
|
if (_text_effect_list == NULL) _text_effect_list = MallocT<TextEffect>(_num_text_effects);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-21 16:17:47 +00:00
|
|
|
for (TextEffectID i = 0; i < _num_text_effects; i++) _text_effect_list[i].string_id = INVALID_STRING_ID;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrawTextEffects(DrawPixelInfo *dpi)
|
|
|
|
{
|
2006-08-31 07:13:36 +00:00
|
|
|
switch (dpi->zoom) {
|
2007-05-15 14:08:39 +00:00
|
|
|
case ZOOM_LVL_NORMAL:
|
2007-06-21 16:17:47 +00:00
|
|
|
for (TextEffectID i = 0; i < _num_text_effects; i++) {
|
|
|
|
TextEffect *te = &_text_effect_list[i];
|
2006-08-31 07:13:36 +00:00
|
|
|
if (te->string_id != INVALID_STRING_ID &&
|
|
|
|
dpi->left <= te->right &&
|
|
|
|
dpi->top <= te->bottom &&
|
|
|
|
dpi->left + dpi->width > te->x &&
|
|
|
|
dpi->top + dpi->height > te->y) {
|
2008-05-29 15:13:28 +00:00
|
|
|
if (te->mode == TE_RISING || (_settings_client.gui.loading_indicators && !IsTransparencySet(TO_LOADING))) {
|
2007-06-21 16:17:47 +00:00
|
|
|
AddStringToDraw(te->x, te->y, te->string_id, te->params_1, te->params_2);
|
|
|
|
}
|
2006-08-31 07:13:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-05-15 14:08:39 +00:00
|
|
|
case ZOOM_LVL_OUT_2X:
|
2007-06-21 16:17:47 +00:00
|
|
|
for (TextEffectID i = 0; i < _num_text_effects; i++) {
|
|
|
|
TextEffect *te = &_text_effect_list[i];
|
2006-08-31 07:13:36 +00:00
|
|
|
if (te->string_id != INVALID_STRING_ID &&
|
|
|
|
dpi->left <= te->right * 2 - te->x &&
|
|
|
|
dpi->top <= te->bottom * 2 - te->y &&
|
|
|
|
dpi->left + dpi->width > te->x &&
|
|
|
|
dpi->top + dpi->height > te->y) {
|
2008-05-29 15:13:28 +00:00
|
|
|
if (te->mode == TE_RISING || (_settings_client.gui.loading_indicators && !IsTransparencySet(TO_LOADING))) {
|
2007-06-21 16:17:47 +00:00
|
|
|
AddStringToDraw(te->x, te->y, (StringID)(te->string_id - 1), te->params_1, te->params_2);
|
|
|
|
}
|
2006-08-31 07:13:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2007-05-15 14:08:39 +00:00
|
|
|
|
2007-05-15 16:08:46 +00:00
|
|
|
case ZOOM_LVL_OUT_4X:
|
2007-05-19 22:48:04 +00:00
|
|
|
case ZOOM_LVL_OUT_8X:
|
2007-05-15 14:08:39 +00:00
|
|
|
break;
|
2007-05-15 16:08:46 +00:00
|
|
|
|
|
|
|
default: NOT_REACHED();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|