texteff.c
changeset 2639 8a7342eb3a78
parent 2549 f1d3b383d557
child 2685 00111d5ca47f
equal deleted inserted replaced
2638:0c9b00251fce 2639:8a7342eb3a78
    93 	_textmessage_dirty = true;
    93 	_textmessage_dirty = true;
    94 }
    94 }
    95 
    95 
    96 void InitTextMessage(void)
    96 void InitTextMessage(void)
    97 {
    97 {
    98 	int i;
    98 	uint i;
    99 	for (i = 0; i < MAX_CHAT_MESSAGES; i++)
    99 
       
   100 	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
   100 		_text_message_list[i].message[0] = '\0';
   101 		_text_message_list[i].message[0] = '\0';
       
   102 	}
   101 
   103 
   102 	_textmessage_width = _textmessage_box_max_width;
   104 	_textmessage_width = _textmessage_box_max_width;
   103 }
   105 }
   104 
   106 
   105 // Hide the textbox
   107 // Hide the textbox
   140 }
   142 }
   141 
   143 
   142 // Check if a message is expired every day
   144 // Check if a message is expired every day
   143 void TextMessageDailyLoop(void)
   145 void TextMessageDailyLoop(void)
   144 {
   146 {
   145 	int i;
   147 	uint i;
       
   148 
   146 	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
   149 	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
   147 		if (_text_message_list[i].message[0] == '\0')
   150 		if (_text_message_list[i].message[0] == '\0') continue;
   148 			continue;
       
   149 
   151 
   150 		if (_date > _text_message_list[i].end_date) {
   152 		if (_date > _text_message_list[i].end_date) {
   151 			/* Move the remaining messages over the current message */
   153 			/* Move the remaining messages over the current message */
   152 			if (i != MAX_CHAT_MESSAGES - 1)
   154 			if (i != MAX_CHAT_MESSAGES - 1)
   153 				memmove(&_text_message_list[i], &_text_message_list[i + 1], sizeof(_text_message_list[i]) * (MAX_CHAT_MESSAGES - i - 1));
   155 				memmove(&_text_message_list[i], &_text_message_list[i + 1], sizeof(_text_message_list[i]) * (MAX_CHAT_MESSAGES - i - 1));
   166 void DrawTextMessage(void)
   168 void DrawTextMessage(void)
   167 {
   169 {
   168 	int i, j;
   170 	int i, j;
   169 	bool has_message;
   171 	bool has_message;
   170 
   172 
   171 	if (!_textmessage_dirty)
   173 	if (!_textmessage_dirty) return;
   172 		return;
       
   173 
   174 
   174 	// First undraw if needed
   175 	// First undraw if needed
   175 	UndrawTextMessage();
   176 	UndrawTextMessage();
   176 
   177 
   177 	if (_iconsole_mode == ICONSOLE_FULL)
   178 	if (_iconsole_mode == ICONSOLE_FULL)
   178 		return;
   179 		return;
   179 
   180 
   180 	/* Check if we have anything to draw at all */
   181 	/* Check if we have anything to draw at all */
   181 	has_message = false;
   182 	has_message = false;
   182 	for ( i = 0; i < MAX_CHAT_MESSAGES; i++) {
   183 	for ( i = 0; i < MAX_CHAT_MESSAGES; i++) {
   183 		if (_text_message_list[i].message[0] == '\0')
   184 		if (_text_message_list[i].message[0] == '\0') break;
   184 			break;
       
   185 
   185 
   186 		has_message = true;
   186 		has_message = true;
   187 	}
   187 	}
   188 	if (!has_message)
   188 	if (!has_message) return;
   189 		return;
       
   190 
   189 
   191 	// Make a copy of the screen as it is before painting (for undraw)
   190 	// Make a copy of the screen as it is before painting (for undraw)
   192 	memcpy_pitch(
   191 	memcpy_pitch(
   193 		_textmessage_backup,
   192 		_textmessage_backup,
   194 		_screen.dst_ptr + _textmessage_box_left + (_screen.height-_textmessage_box_bottom-_textmessage_box_y) * _screen.pitch,
   193 		_screen.dst_ptr + _textmessage_box_left + (_screen.height-_textmessage_box_bottom-_textmessage_box_y) * _screen.pitch,
   198 	_cur_dpi = &_screen;
   197 	_cur_dpi = &_screen;
   199 
   198 
   200 	j = 0;
   199 	j = 0;
   201 	// Paint the messages
   200 	// Paint the messages
   202 	for (i = MAX_CHAT_MESSAGES - 1; i >= 0; i--) {
   201 	for (i = MAX_CHAT_MESSAGES - 1; i >= 0; i--) {
   203 		if (_text_message_list[i].message[0] == '\0')
   202 		if (_text_message_list[i].message[0] == '\0') continue;
   204 			continue;
       
   205 
   203 
   206 		j++;
   204 		j++;
   207 		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 */ 0x322 | USE_COLORTABLE);
   205 		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 */ 0x322 | USE_COLORTABLE);
   208 
   206 
   209 		DoDrawString(_text_message_list[i].message, _textmessage_box_left + 2, _screen.height - _textmessage_box_bottom - j * 13 - 1, 0x10);
   207 		DoDrawString(_text_message_list[i].message, _textmessage_box_left + 2, _screen.height - _textmessage_box_bottom - j * 13 - 1, 0x10);
   235 
   233 
   236 	if (_game_mode == GM_MENU)
   234 	if (_game_mode == GM_MENU)
   237 		return;
   235 		return;
   238 
   236 
   239 	for (te = _text_effect_list; te->string_id != INVALID_STRING_ID; ) {
   237 	for (te = _text_effect_list; te->string_id != INVALID_STRING_ID; ) {
   240 		if (++te == endof(_text_effect_list))
   238 		if (++te == endof(_text_effect_list)) return;
   241 			return;
       
   242 	}
   239 	}
   243 
   240 
   244 	te->string_id = msg;
   241 	te->string_id = msg;
   245 	te->duration = duration;
   242 	te->duration = duration;
   246 	te->y = y - 5;
   243 	te->y = y - 5;