author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1309 | 4403a69da4f8 |
child 1569 | 32abdc483dc5 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.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
|
3 |
#include "strings.h" |
0 | 4 |
#include "gfx.h" |
5 |
#include "viewport.h" |
|
6 |
#include "saveload.h" |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
7 |
#include "hal.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
8 |
#include "console.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
9 |
#include <stdarg.h> /* va_list */ |
0 | 10 |
|
11 |
typedef struct TextEffect { |
|
12 |
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
|
13 |
int32 x; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
14 |
int32 y; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
15 |
int32 right; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
16 |
int32 bottom; |
0 | 17 |
uint16 duration; |
18 |
uint32 params_1; |
|
19 |
uint32 params_2; |
|
20 |
} TextEffect; |
|
21 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
22 |
#define MAX_TEXTMESSAGE_LENGTH 250 |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
23 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
24 |
typedef struct TextMessage { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
25 |
char message[MAX_TEXTMESSAGE_LENGTH]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
26 |
uint16 color; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
27 |
uint16 end_date; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
28 |
} TextMessage; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
29 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
30 |
#define MAX_CHAT_MESSAGES 10 |
0 | 31 |
static TextEffect _text_effect_list[30]; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
32 |
static TextMessage _text_message_list[MAX_CHAT_MESSAGES]; |
0 | 33 |
TileIndex _animated_tile_list[256]; |
34 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
35 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
36 |
int _textmessage_width = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
37 |
bool _textmessage_dirty = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
38 |
bool _textmessage_visible = false; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
39 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
40 |
const int _textmessage_box_left = 10; // Pixels from left |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
41 |
const int _textmessage_box_y = 150; // Height of box |
649 | 42 |
const int _textmessage_box_bottom = 30; // Pixels from bottom |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
43 |
const int _textmessage_box_max_width = 400; // Max width of box |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
44 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
45 |
static byte _textmessage_backup[150*400]; // (y * max_width) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
46 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
47 |
extern void memcpy_pitch(void *d, void *s, int w, int h, int spitch, int dpitch); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
48 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
49 |
// Duration is in game-days |
1022
d5ec3467d2a4
(svn r1523) -Fix: somehow mousewheel was disabled on windows using SDL; reenabled again
darkvater
parents:
849
diff
changeset
|
50 |
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
|
51 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
52 |
int i; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
53 |
char buf[1024]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
54 |
char buf2[MAX_TEXTMESSAGE_LENGTH]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
55 |
va_list va; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
56 |
int length; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
57 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
58 |
va_start(va, message); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
59 |
vsprintf(buf, message, va); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
60 |
va_end(va); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
61 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
62 |
if ((color & 0xFF) == 0xC9) color = 0x1CA; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
63 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
64 |
length = MAX_TEXTMESSAGE_LENGTH; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
65 |
snprintf(buf2, length, "%s", buf); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
66 |
while (GetStringWidth(buf2) > _textmessage_width - 9) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
67 |
snprintf(buf2, --length, "%s", buf); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
68 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
69 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
70 |
for (i = 0; i < MAX_CHAT_MESSAGES; i++) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
71 |
if (_text_message_list[i].message[0] == '\0') { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
72 |
// Empty spot |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
73 |
snprintf(_text_message_list[i].message, MAX_TEXTMESSAGE_LENGTH, "%s", buf2); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
74 |
_text_message_list[i].color = color; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
75 |
_text_message_list[i].end_date = _date + duration; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
76 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
77 |
_textmessage_dirty = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
78 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
79 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
80 |
} |
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 |
// We did not found a free spot, trash the first one, and add to the end |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
83 |
memmove(&_text_message_list[0], &_text_message_list[1], sizeof(TextMessage) * (MAX_CHAT_MESSAGES - 1)); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
84 |
snprintf(_text_message_list[MAX_CHAT_MESSAGES - 1].message, MAX_TEXTMESSAGE_LENGTH, "%s", buf2); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
85 |
_text_message_list[MAX_CHAT_MESSAGES - 1].color = color; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
86 |
_text_message_list[i].end_date = _date + duration; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
87 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
88 |
_textmessage_dirty = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
89 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
90 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1022
diff
changeset
|
91 |
void InitTextMessage(void) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
92 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
93 |
int i; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
94 |
for (i = 0; i < MAX_CHAT_MESSAGES; i++) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
95 |
_text_message_list[i].message[0] = '\0'; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
96 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
97 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
98 |
_textmessage_width = _textmessage_box_max_width; |
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 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
101 |
// Hide the textbox |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1022
diff
changeset
|
102 |
void UndrawTextMessage(void) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
103 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
104 |
if (_textmessage_visible) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
105 |
// Sometimes we also need to hide the cursor |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
106 |
// This is because both textmessage and the cursor take a shot of the |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
107 |
// screen before drawing. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
108 |
// Now the textmessage takes his shot and paints his data before the cursor |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
109 |
// does, so in the shot of the cursor is the screen-data of the textmessage |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
110 |
// included when the cursor hangs somewhere over the textmessage. To |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
111 |
// avoid wrong repaints, we undraw the cursor in that case, and everything |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
112 |
// looks nicely ;) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
113 |
// (and now hope this story above makes sense to you ;)) |
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 |
if (_cursor.visible) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
116 |
if (_cursor.draw_pos.x + _cursor.draw_size.x >= _textmessage_box_left && |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
117 |
_cursor.draw_pos.x <= _textmessage_box_left + _textmessage_width && |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
118 |
_cursor.draw_pos.y + _cursor.draw_size.y >= _screen.height - _textmessage_box_bottom - _textmessage_box_y && |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
119 |
_cursor.draw_pos.y <= _screen.height - _textmessage_box_bottom) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
120 |
UndrawMouseCursor(); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
121 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
122 |
} |
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 |
_textmessage_visible = false; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
125 |
// Put our 'shot' back to the screen |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
126 |
memcpy_pitch( |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
127 |
_screen.dst_ptr + _textmessage_box_left + (_screen.height-_textmessage_box_bottom-_textmessage_box_y) * _screen.pitch, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
128 |
_textmessage_backup, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
129 |
_textmessage_width, _textmessage_box_y, _textmessage_width, _screen.pitch); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
130 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
131 |
// And make sure it is updated next time |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
132 |
_video_driver->make_dirty(_textmessage_box_left, _screen.height-_textmessage_box_bottom-_textmessage_box_y, _textmessage_width, _textmessage_box_y); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
133 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
134 |
_textmessage_dirty = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
135 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
136 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
137 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
138 |
// Check if a message is expired every day |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1022
diff
changeset
|
139 |
void TextMessageDailyLoop(void) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
140 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
141 |
int i = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
142 |
while (i < MAX_CHAT_MESSAGES) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
143 |
if (_text_message_list[i].message[0] == '\0') break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
144 |
if (_date > _text_message_list[i].end_date) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
145 |
memmove(&_text_message_list[i], &_text_message_list[i+1], sizeof(TextMessage) * ((MAX_CHAT_MESSAGES - 1) - i)); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
146 |
_text_message_list[MAX_CHAT_MESSAGES - 1].message[0] = '\0'; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
147 |
i--; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
148 |
_textmessage_dirty = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
149 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
150 |
i++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
151 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
152 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
153 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
154 |
// Draw the textmessage-box |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1022
diff
changeset
|
155 |
void DrawTextMessage(void) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
156 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
157 |
int i, j; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
158 |
bool has_message; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
159 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
160 |
if (!_textmessage_dirty) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
161 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
162 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
163 |
// First undraw if needed |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
164 |
UndrawTextMessage(); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
165 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
166 |
if (_iconsole_mode == ICONSOLE_FULL) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
167 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
168 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
169 |
has_message = false; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
170 |
for ( i = 0; i < MAX_CHAT_MESSAGES; i++) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
171 |
if (_text_message_list[i].message[0] == '\0') break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
172 |
has_message = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
173 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
174 |
if (!has_message) return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
175 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
176 |
// Make a copy of the screen as it is before painting (for undraw) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
177 |
memcpy_pitch( |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
178 |
_textmessage_backup, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
179 |
_screen.dst_ptr + _textmessage_box_left + (_screen.height-_textmessage_box_bottom-_textmessage_box_y) * _screen.pitch, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
180 |
_textmessage_width, _textmessage_box_y, _screen.pitch, _textmessage_width); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
181 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
182 |
// Switch to _screen painting |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
183 |
_cur_dpi = &_screen; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
184 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
185 |
j = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
186 |
// Paint the messages |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
187 |
for (i = MAX_CHAT_MESSAGES - 1; i >= 0; i--) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
188 |
if (_text_message_list[i].message[0] == '\0') continue; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
189 |
j++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
190 |
GfxFillRect(_textmessage_box_left, _screen.height-_textmessage_box_bottom-j*13-2, _textmessage_box_left+_textmessage_width - 1, _screen.height-_textmessage_box_bottom-j*13+10, /* black, but with some alpha */ 0x4322); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
191 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
192 |
DoDrawString(_text_message_list[i].message, _textmessage_box_left + 2, _screen.height - _textmessage_box_bottom - j * 13 - 1, 0x10); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
193 |
DoDrawString(_text_message_list[i].message, _textmessage_box_left + 3, _screen.height - _textmessage_box_bottom - j * 13, _text_message_list[i].color); |
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 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
196 |
// Make sure the data is updated next flush |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
197 |
_video_driver->make_dirty(_textmessage_box_left, _screen.height-_textmessage_box_bottom-_textmessage_box_y, _textmessage_width, _textmessage_box_y); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
198 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
199 |
_textmessage_visible = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
200 |
_textmessage_dirty = false; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
201 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
202 |
|
0 | 203 |
static void MarkTextEffectAreaDirty(TextEffect *te) |
204 |
{ |
|
205 |
MarkAllViewportsDirty( |
|
206 |
te->x, |
|
207 |
te->y - 1, |
|
208 |
(te->right - te->x)*2 + te->x + 1, |
|
209 |
(te->bottom - (te->y - 1)) * 2 + (te->y - 1) + 1 |
|
210 |
); |
|
211 |
} |
|
212 |
||
213 |
void AddTextEffect(StringID msg, int x, int y, uint16 duration) |
|
214 |
{ |
|
215 |
TextEffect *te; |
|
216 |
int w; |
|
217 |
char buffer[100]; |
|
218 |
||
219 |
if (_game_mode == GM_MENU) |
|
220 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
0
diff
changeset
|
221 |
|
0 | 222 |
for (te = _text_effect_list; te->string_id != 0xFFFF; ) { |
223 |
if (++te == endof(_text_effect_list)) |
|
224 |
return; |
|
225 |
} |
|
226 |
||
227 |
te->string_id = msg; |
|
228 |
te->duration = duration; |
|
229 |
te->y = y - 5; |
|
230 |
te->bottom = y + 5; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
425
diff
changeset
|
231 |
te->params_1 = GetDParam(0); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
425
diff
changeset
|
232 |
te->params_2 = GetDParam(4); |
0 | 233 |
|
234 |
GetString(buffer, msg); |
|
235 |
w = GetStringWidth(buffer); |
|
236 |
||
237 |
te->x = x - (w >> 1); |
|
238 |
te->right = x + (w >> 1) - 1; |
|
239 |
MarkTextEffectAreaDirty(te); |
|
240 |
} |
|
241 |
||
242 |
static void MoveTextEffect(TextEffect *te) |
|
243 |
{ |
|
244 |
if (te->duration < 8) { |
|
245 |
te->string_id = 0xFFFF; |
|
246 |
} else { |
|
247 |
te->duration-=8; |
|
248 |
te->y--; |
|
249 |
te->bottom--; |
|
250 |
} |
|
251 |
MarkTextEffectAreaDirty(te); |
|
252 |
} |
|
253 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1022
diff
changeset
|
254 |
void MoveAllTextEffects(void) |
0 | 255 |
{ |
256 |
TextEffect *te; |
|
257 |
||
258 |
for (te = _text_effect_list; te != endof(_text_effect_list); te++ ) { |
|
259 |
if (te->string_id != 0xFFFF) |
|
260 |
MoveTextEffect(te); |
|
261 |
} |
|
262 |
} |
|
263 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1022
diff
changeset
|
264 |
void InitTextEffects(void) |
0 | 265 |
{ |
266 |
TextEffect *te; |
|
267 |
||
268 |
for (te = _text_effect_list; te != endof(_text_effect_list); te++ ) { |
|
269 |
te->string_id = 0xFFFF; |
|
270 |
} |
|
271 |
} |
|
272 |
||
273 |
void DrawTextEffects(DrawPixelInfo *dpi) |
|
274 |
{ |
|
275 |
TextEffect *te; |
|
276 |
||
277 |
if (dpi->zoom < 1) { |
|
278 |
for (te = _text_effect_list; te != endof(_text_effect_list); te++ ) { |
|
279 |
if (te->string_id == 0xFFFF) |
|
280 |
continue; |
|
281 |
||
282 |
/* intersection? */ |
|
849
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
283 |
if (dpi->left > te->right || |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
284 |
dpi->top > te->bottom || |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
285 |
dpi->left + dpi->width <= te->x || |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
286 |
dpi->top + dpi->height <= te->y) |
0 | 287 |
continue; |
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
649
diff
changeset
|
288 |
AddStringToDraw(te->x, te->y, te->string_id, te->params_1, te->params_2, 0); |
0 | 289 |
} |
290 |
} else if (dpi->zoom == 1) { |
|
291 |
for (te = _text_effect_list; te != endof(_text_effect_list); te++ ) { |
|
292 |
if (te->string_id == 0xFFFF) |
|
293 |
continue; |
|
294 |
||
295 |
/* intersection? */ |
|
296 |
if (dpi->left > te->right*2 - te->x || |
|
297 |
dpi->top > te->bottom*2 - te->y || |
|
298 |
(dpi->left + dpi->width) <= te->x || |
|
299 |
(dpi->top + dpi->height) <= te->y) |
|
300 |
continue; |
|
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
649
diff
changeset
|
301 |
AddStringToDraw(te->x, te->y, (StringID)(te->string_id-1), te->params_1, te->params_2, 0); |
0 | 302 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
0
diff
changeset
|
303 |
|
0 | 304 |
} |
305 |
} |
|
306 |
||
307 |
void DeleteAnimatedTile(uint tile) |
|
308 |
{ |
|
309 |
TileIndex *ti; |
|
310 |
||
311 |
for(ti=_animated_tile_list; ti!=endof(_animated_tile_list); ti++) { |
|
312 |
if ( (TileIndex)tile == *ti) { |
|
313 |
/* remove the hole */ |
|
425 | 314 |
memmove(ti, ti+1, endof(_animated_tile_list) - 1 - ti); |
0 | 315 |
/* and clear last item */ |
316 |
endof(_animated_tile_list)[-1] = 0; |
|
317 |
MarkTileDirtyByTile(tile); |
|
318 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
0
diff
changeset
|
319 |
} |
0 | 320 |
} |
321 |
} |
|
322 |
||
323 |
bool AddAnimatedTile(uint tile) |
|
324 |
{ |
|
325 |
TileIndex *ti; |
|
326 |
||
327 |
for(ti=_animated_tile_list; ti!=endof(_animated_tile_list); ti++) { |
|
328 |
if ( (TileIndex)tile == *ti || *ti == 0) { |
|
329 |
*ti = tile; |
|
330 |
MarkTileDirtyByTile(tile); |
|
331 |
return true; |
|
332 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
0
diff
changeset
|
333 |
} |
0 | 334 |
|
335 |
return false; |
|
336 |
} |
|
337 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1022
diff
changeset
|
338 |
void AnimateAnimatedTiles(void) |
0 | 339 |
{ |
340 |
TileIndex *ti; |
|
341 |
uint tile; |
|
342 |
||
343 |
for(ti=_animated_tile_list; ti!=endof(_animated_tile_list) && (tile=*ti) != 0; ti++) { |
|
344 |
AnimateTile(tile); |
|
345 |
} |
|
346 |
} |
|
347 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1022
diff
changeset
|
348 |
void InitializeAnimatedTiles(void) |
0 | 349 |
{ |
350 |
memset(_animated_tile_list, 0, sizeof(_animated_tile_list)); |
|
351 |
} |
|
352 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1022
diff
changeset
|
353 |
static void SaveLoad_ANIT(void) |
0 | 354 |
{ |
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
|
355 |
if (_sl.version < 6) |
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
|
356 |
SlArray(_animated_tile_list, lengthof(_animated_tile_list), |
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
|
357 |
SLE_FILE_U16 | SLE_VAR_U32); |
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
|
358 |
else |
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
|
359 |
SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_UINT32); |
0 | 360 |
} |
361 |
||
362 |
||
363 |
const ChunkHandler _animated_tile_chunk_handlers[] = { |
|
364 |
{ 'ANIT', SaveLoad_ANIT, SaveLoad_ANIT, CH_RIFF | CH_LAST}, |
|
365 |
}; |
|
366 |
||
367 |