src/texteff.cpp
author rubidium
Sat, 16 Jun 2007 10:10:22 +0000
changeset 6915 67a982c01f44
parent 6878 5cefd3ac59c7
child 6937 40c760fcf1f6
permissions -rw-r--r--
(svn r10168) -Fix [FS#879]: cannot build airport when an aircraft is flying over it.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6374
diff changeset
     3
/** @file texteff.cpp */
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6374
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     6
#include "openttd.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2153
diff changeset
     7
#include "functions.h"
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
     8
#include "macros.h"
1309
4403a69da4f8 (svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents: 1174
diff changeset
     9
#include "strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "gfx.h"
6453
226bcddeba32 (svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents: 6422
diff changeset
    11
#include "landscape.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "saveload.h"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    14
#include "hal.h"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    15
#include "console.h"
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
    16
#include "string.h"
2153
ecfc674410b4 (svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents: 2062
diff changeset
    17
#include "variables.h"
2218
2132596a35c0 (svn r2736) -Codechange: De-mystified GfxDrawFillRect a bit, and used enums from table/sprites.h. You can now change the number of bits used for sprites and switches in the SpriteSetup enum and the rest should work automagically. Can be used to increase the number of active sprites to 2^19 in case there are no colortables (recolor sprites) in any newgrf. We should possibly move the the colortables to an own list, but how to detect them in a newgrf.
celestar
parents: 2186
diff changeset
    18
#include "table/sprites.h"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    19
#include <stdarg.h> /* va_list */
4261
28670f743746 (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 2685
diff changeset
    20
#include "date.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
    22
enum {
6215
bbd141b026b5 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 5668
diff changeset
    23
	MAX_TEXTMESSAGE_LENGTH = 200,
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
    24
	MAX_TEXT_MESSAGES      =  30,
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
    25
	MAX_CHAT_MESSAGES      =  10,
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
    26
	MAX_ANIMATED_TILES     = 256,
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
    27
};
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
    28
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    29
struct TextEffect {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	StringID string_id;
849
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    31
	int32 x;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    32
	int32 y;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    33
	int32 right;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    34
	int32 bottom;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	uint16 duration;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	uint32 params_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
	uint32 params_2;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    38
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    40
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    41
struct TextMessage {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    42
	char message[MAX_TEXTMESSAGE_LENGTH];
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    43
	uint16 color;
4363
8a38cd70dab9 (svn r6078) -Fix: forgot one uint16 -> Date conversion. Tnx to #openttdcoop team for detecting and Rubidium for finding the cause.
truelight
parents: 4261
diff changeset
    44
	Date end_date;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    45
};
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    46
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
    47
static TextEffect _text_effect_list[MAX_TEXT_MESSAGES];
4956
49ecd2a36222 (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
    48
static TextMessage _textmsg_list[MAX_CHAT_MESSAGES];
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
    49
TileIndex _animated_tile_list[MAX_ANIMATED_TILES];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
4956
49ecd2a36222 (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
    51
static bool _textmessage_dirty = false;
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2470
diff changeset
    52
static bool _textmessage_visible = false;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    53
4956
49ecd2a36222 (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
    54
/* The chatbox grows from the bottom so the coordinates are pixels from
49ecd2a36222 (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
    55
 * the left and pixels from the bottom. The height is the maximum height */
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    56
static const Oblong _textmsg_box = {10, 30, 500, 150};
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6853
diff changeset
    57
static uint8 _textmessage_backup[150 * 500 * 4]; // (height * width)
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    58
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6215
diff changeset
    59
static inline uint GetTextMessageCount()
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    60
{
4959
9a25901ce3e6 (svn r6958) -Fix (r6956): GCC warning (thx Tron) and a coding style forgotten in r6957
Darkvater
parents: 4958
diff changeset
    61
	uint i;
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    62
4959
9a25901ce3e6 (svn r6958) -Fix (r6956): GCC warning (thx Tron) and a coding style forgotten in r6957
Darkvater
parents: 4958
diff changeset
    63
	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    64
		if (_textmsg_list[i].message[0] == '\0') break;
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    65
	}
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    66
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    67
	return i;
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    68
}
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    69
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    70
/* Add a text message to the 'chat window' to be shown
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    71
 * @param color The colour this message is to be shown in
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    72
 * @param duration The duration of the chat message in game-days
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    73
 * @param message message itself in printf() style */
1022
d5ec3467d2a4 (svn r1523) -Fix: somehow mousewheel was disabled on windows using SDL; reenabled again
darkvater
parents: 849
diff changeset
    74
void CDECL AddTextMessage(uint16 color, uint8 duration, const char *message, ...)
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    75
{
2455
43283b066cc4 (svn r2981) Remove a no-op
tron
parents: 2424
diff changeset
    76
	char buf[MAX_TEXTMESSAGE_LENGTH];
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    77
	const char *bufp;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    78
	va_list va;
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    79
	uint msg_count;
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    80
	uint16 lines;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    81
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    82
	va_start(va, message);
2373
e073ec69bf56 (svn r2899) -Fix: Several format string vulnerabilities and buffer overflows in the network code
tron
parents: 2295
diff changeset
    83
	vsnprintf(buf, lengthof(buf), message, va);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    84
	va_end(va);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    85
6215
bbd141b026b5 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 5668
diff changeset
    86
bbd141b026b5 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 5668
diff changeset
    87
	Utf8TrimString(buf, MAX_TEXTMESSAGE_LENGTH);
bbd141b026b5 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 5668
diff changeset
    88
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    89
	/* Force linebreaks for strings that are too long */
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    90
	lines = GB(FormatStringLinebreaks(buf, _textmsg_box.width - 8), 0, 16) + 1;
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    91
	if (lines >= MAX_CHAT_MESSAGES) return;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    92
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    93
	msg_count = GetTextMessageCount();
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    94
	/* We want to add more chat messages than there is free space for, remove 'old' */
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    95
	if (lines > MAX_CHAT_MESSAGES - msg_count) {
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    96
		int i = lines - (MAX_CHAT_MESSAGES - msg_count);
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    97
		memmove(&_textmsg_list[0], &_textmsg_list[i], sizeof(_textmsg_list[0]) * (msg_count - i));
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    98
		msg_count = MAX_CHAT_MESSAGES - lines;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    99
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   100
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   101
	for (bufp = buf; lines != 0; lines--) {
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   102
		TextMessage *tmsg = &_textmsg_list[msg_count++];
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   103
		ttd_strlcpy(tmsg->message, bufp, sizeof(tmsg->message));
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   104
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   105
		/* The default colour for a message is player colour. Replace this with
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   106
		 * white for any additional lines */
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   107
		tmsg->color = (bufp == buf && color & IS_PALETTE_COLOR) ? color : (0x1D - 15) | IS_PALETTE_COLOR;
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   108
		tmsg->end_date = _date + duration;
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   109
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   110
		bufp += strlen(bufp) + 1; // jump to 'next line' in the formatted string
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   111
	}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   112
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   113
	_textmessage_dirty = true;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   114
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   115
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6215
diff changeset
   116
void InitTextMessage()
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   117
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   118
	uint i;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   119
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   120
	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
4956
49ecd2a36222 (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
   121
		_textmsg_list[i].message[0] = '\0';
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   122
	}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   123
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   124
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6374
diff changeset
   125
/** Hide the textbox */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6215
diff changeset
   126
void UndrawTextMessage()
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   127
{
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   128
	if (_textmessage_visible) {
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   129
		/* Sometimes we also need to hide the cursor
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   130
		 *   This is because both textmessage and the cursor take a shot of the
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   131
		 *   screen before drawing.
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   132
		 *   Now the textmessage takes his shot and paints his data before the cursor
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   133
		 *   does, so in the shot of the cursor is the screen-data of the textmessage
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   134
		 *   included when the cursor hangs somewhere over the textmessage. To
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   135
		 *   avoid wrong repaints, we undraw the cursor in that case, and everything
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   136
		 *   looks nicely ;)
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   137
		 * (and now hope this story above makes sense to you ;))
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   138
		 */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   139
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   140
		if (_cursor.visible) {
4956
49ecd2a36222 (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
   141
			if (_cursor.draw_pos.x + _cursor.draw_size.x >= _textmsg_box.x &&
49ecd2a36222 (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
   142
				_cursor.draw_pos.x <= _textmsg_box.x + _textmsg_box.width &&
49ecd2a36222 (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
   143
				_cursor.draw_pos.y + _cursor.draw_size.y >= _screen.height - _textmsg_box.y - _textmsg_box.height &&
49ecd2a36222 (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
   144
				_cursor.draw_pos.y <= _screen.height - _textmsg_box.y) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   145
				UndrawMouseCursor();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   146
			}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   147
		}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   148
6366
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   149
		int x      = _textmsg_box.x;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   150
		int y      = _screen.height - _textmsg_box.y - _textmsg_box.height;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   151
		int width  = _textmsg_box.width;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   152
		int height = _textmsg_box.height;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   153
		if (y < 0) {
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   154
			height = max(height + y, min(_textmsg_box.height, _screen.height));
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   155
			y = 0;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   156
		}
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   157
		if (x + width >= _screen.width) {
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   158
			width = _screen.width - x;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   159
		}
6374
0de6e30b49db (svn r9437) -Fix (r9420): dedicated server crashed when the y part of the resolution was less than 10.
rubidium
parents: 6366
diff changeset
   160
		if (width <= 0 || height <= 0) return;
6366
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   161
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   162
		_textmessage_visible = false;
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   163
		/* Put our 'shot' back to the screen */
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6853
diff changeset
   164
		_screen.renderer->CopyFromBuffer(_screen.renderer->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height, _textmsg_box.width);
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   165
		/* And make sure it is updated next time */
6366
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   166
		_video_driver->make_dirty(x, y, width, height);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   167
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   168
		_textmessage_dirty = true;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   169
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   170
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   171
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6374
diff changeset
   172
/** Check if a message is expired every day */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6215
diff changeset
   173
void TextMessageDailyLoop()
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   174
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   175
	uint i;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   176
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   177
	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   178
		TextMessage *tmsg = &_textmsg_list[i];
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   179
		if (tmsg->message[0] == '\0') continue;
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   180
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   181
		/* Message has expired, remove from the list */
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   182
		if (tmsg->end_date < _date) {
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   183
			/* Move the remaining messages over the current message */
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   184
			if (i != MAX_CHAT_MESSAGES - 1) memmove(tmsg, tmsg + 1, sizeof(*tmsg) * (MAX_CHAT_MESSAGES - i - 1));
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   185
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   186
			/* Mark the last item as empty */
4956
49ecd2a36222 (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
   187
			_textmsg_list[MAX_CHAT_MESSAGES - 1].message[0] = '\0';
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   188
			_textmessage_dirty = true;
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   189
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   190
			/* Go one item back, because we moved the array 1 to the left */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   191
			i--;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   192
		}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   193
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   194
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   195
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6374
diff changeset
   196
/** Draw the textmessage-box */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6215
diff changeset
   197
void DrawTextMessage()
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   198
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   199
	if (!_textmessage_dirty) return;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   200
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   201
	/* First undraw if needed */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   202
	UndrawTextMessage();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   203
4959
9a25901ce3e6 (svn r6958) -Fix (r6956): GCC warning (thx Tron) and a coding style forgotten in r6957
Darkvater
parents: 4958
diff changeset
   204
	if (_iconsole_mode == ICONSOLE_FULL) return;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   205
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   206
	/* Check if we have anything to draw at all */
6366
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   207
	uint count = GetTextMessageCount();
4960
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   208
	if (count == 0) return;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   209
6366
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   210
	int x      = _textmsg_box.x;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   211
	int y      = _screen.height - _textmsg_box.y - _textmsg_box.height;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   212
	int width  = _textmsg_box.width;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   213
	int height = _textmsg_box.height;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   214
	if (y < 0) {
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   215
		height = max(height + y, min(_textmsg_box.height, _screen.height));
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   216
		y = 0;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   217
	}
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   218
	if (x + width >= _screen.width) {
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   219
		width = _screen.width - x;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   220
	}
6374
0de6e30b49db (svn r9437) -Fix (r9420): dedicated server crashed when the y part of the resolution was less than 10.
rubidium
parents: 6366
diff changeset
   221
	if (width <= 0 || height <= 0) return;
0de6e30b49db (svn r9437) -Fix (r9420): dedicated server crashed when the y part of the resolution was less than 10.
rubidium
parents: 6366
diff changeset
   222
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   223
	/* Make a copy of the screen as it is before painting (for undraw) */
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6853
diff changeset
   224
	_screen.renderer->CopyToBuffer(_screen.renderer->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height, _textmsg_box.width);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   225
4960
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   226
	_cur_dpi = &_screen; // switch to _screen painting
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   227
4960
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   228
	/* Paint a half-transparent box behind the text messages */
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   229
	GfxFillRect(
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   230
			_textmsg_box.x,
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   231
			_screen.height - _textmsg_box.y - count * 13 - 2,
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   232
			_textmsg_box.x + _textmsg_box.width - 1,
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   233
			_screen.height - _textmsg_box.y - 2,
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   234
			PALETTE_TO_TRANSPARENT | (1 << USE_COLORTABLE) // black, but with some alpha for background
4960
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   235
		);
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   236
4960
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   237
	/* Paint the messages starting with the lowest at the bottom */
6366
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   238
	for (uint y = 13; count-- != 0; y += 13) {
4960
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   239
		DoDrawString(_textmsg_list[count].message, _textmsg_box.x + 3, _screen.height - _textmsg_box.y - y + 1, _textmsg_list[count].color);
6492
286a52449b54 (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6453
diff changeset
   240
	}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   241
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   242
	/* Make sure the data is updated next flush */
6366
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   243
	_video_driver->make_dirty(x, y, width, height);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   244
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   245
	_textmessage_visible = true;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   246
	_textmessage_dirty = false;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   247
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   248
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
static void MarkTextEffectAreaDirty(TextEffect *te)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
		te->x,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
		te->y - 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
		(te->right - te->x)*2 + te->x + 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
		(te->bottom - (te->y - 1)) * 2 + (te->y - 1) + 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
void AddTextEffect(StringID msg, int x, int y, uint16 duration)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
	TextEffect *te;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
	int w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
	char buffer[100];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
4958
5bf9f412940a (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4957
diff changeset
   265
	if (_game_mode == GM_MENU) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   266
2470
bdbac11a61ab (svn r2996) 0xFFFF -> INVALID_STRING_ID
tron
parents: 2458
diff changeset
   267
	for (te = _text_effect_list; te->string_id != INVALID_STRING_ID; ) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   268
		if (++te == endof(_text_effect_list)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
	te->string_id = msg;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
	te->duration = duration;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
	te->y = y - 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
	te->bottom = y + 5;
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 425
diff changeset
   275
	te->params_1 = GetDParam(0);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 425
diff changeset
   276
	te->params_2 = GetDParam(4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4609
diff changeset
   278
	GetString(buffer, msg, lastof(buffer));
4609
954fe701062f (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4469
diff changeset
   279
	w = GetStringBoundingBox(buffer).width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
	te->x = x - (w >> 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
	te->right = x + (w >> 1) - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
	MarkTextEffectAreaDirty(te);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
static void MoveTextEffect(TextEffect *te)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
	if (te->duration < 8) {
2470
bdbac11a61ab (svn r2996) 0xFFFF -> INVALID_STRING_ID
tron
parents: 2458
diff changeset
   289
		te->string_id = INVALID_STRING_ID;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
	} else {
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   291
		te->duration -= 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
		te->y--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
		te->bottom--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
	MarkTextEffectAreaDirty(te);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6215
diff changeset
   298
void MoveAllTextEffects()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
	TextEffect *te;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   302
	for (te = _text_effect_list; te != endof(_text_effect_list); te++) {
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   303
		if (te->string_id != INVALID_STRING_ID) MoveTextEffect(te);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6215
diff changeset
   307
void InitTextEffects()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
	TextEffect *te;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   311
	for (te = _text_effect_list; te != endof(_text_effect_list); te++) {
2470
bdbac11a61ab (svn r2996) 0xFFFF -> INVALID_STRING_ID
tron
parents: 2458
diff changeset
   312
		te->string_id = INVALID_STRING_ID;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
void DrawTextEffects(DrawPixelInfo *dpi)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
{
4469
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   318
	const TextEffect* te;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
4469
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   320
	switch (dpi->zoom) {
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6492
diff changeset
   321
		case ZOOM_LVL_NORMAL:
4469
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   322
			for (te = _text_effect_list; te != endof(_text_effect_list); te++) {
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   323
				if (te->string_id != INVALID_STRING_ID &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   324
						dpi->left <= te->right &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   325
						dpi->top  <= te->bottom &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   326
						dpi->left + dpi->width  > te->x &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   327
						dpi->top  + dpi->height > te->y) {
5026
d589561bc43d (svn r7067) Remove the unused parameter params_3 from AddStringToDraw()
tron
parents: 4960
diff changeset
   328
					AddStringToDraw(te->x, te->y, te->string_id, te->params_1, te->params_2);
4469
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   329
				}
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   330
			}
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   331
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6492
diff changeset
   333
		case ZOOM_LVL_OUT_2X:
4469
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   334
			for (te = _text_effect_list; te != endof(_text_effect_list); te++) {
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   335
				if (te->string_id != INVALID_STRING_ID &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   336
						dpi->left <= te->right  * 2 - te->x &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   337
						dpi->top  <= te->bottom * 2 - te->y &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   338
						dpi->left + dpi->width  > te->x &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   339
						dpi->top  + dpi->height > te->y) {
5026
d589561bc43d (svn r7067) Remove the unused parameter params_3 from AddStringToDraw()
tron
parents: 4960
diff changeset
   340
					AddStringToDraw(te->x, te->y, (StringID)(te->string_id-1), te->params_1, te->params_2);
4469
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   341
				}
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   342
			}
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   343
			break;
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6492
diff changeset
   344
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   345
		case ZOOM_LVL_OUT_4X:
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   346
		case ZOOM_LVL_OUT_8X:
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6492
diff changeset
   347
			break;
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   348
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   349
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   353
void DeleteAnimatedTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
{
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   355
	TileIndex *ti;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   357
	for (ti = _animated_tile_list; ti != endof(_animated_tile_list); ti++) {
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   358
		if (tile == *ti) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
			/* remove the hole */
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   360
			memmove(ti, ti + 1, (lastof(_animated_tile_list) - ti) * sizeof(*ti));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
			/* and clear last item */
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   362
			*lastof(_animated_tile_list) = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
			return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   365
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   369
bool AddAnimatedTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
{
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   371
	TileIndex *ti;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   373
	for (ti = _animated_tile_list; ti != endof(_animated_tile_list); ti++) {
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   374
		if (tile == *ti || *ti == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
			*ti = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   379
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6215
diff changeset
   384
void AnimateAnimatedTiles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
{
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   386
	const TileIndex* ti;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   388
	for (ti = _animated_tile_list; ti != endof(_animated_tile_list) && *ti != 0; ti++) {
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   389
		AnimateTile(*ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6215
diff changeset
   393
void InitializeAnimatedTiles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
	memset(_animated_tile_list, 0, sizeof(_animated_tile_list));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6215
diff changeset
   398
static void SaveLoad_ANIT()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
{
5428
00fab4aeff78 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5427
diff changeset
   400
	/* In pre version 6, we has 16bit per tile, now we have 32bit per tile, convert it ;) */
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2639
diff changeset
   401
	if (CheckSavegameVersion(6)) {
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1595
diff changeset
   402
		SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_FILE_U16 | SLE_VAR_U32);
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   403
	} else {
1174
6a5e747f3ba6 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1093
diff changeset
   404
		SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_UINT32);
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   405
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   409
extern const ChunkHandler _animated_tile_chunk_handlers[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
	{ 'ANIT', SaveLoad_ANIT, SaveLoad_ANIT, CH_RIFF | CH_LAST},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
};