Merge pull request #544 from duncanspumpkin/fix_540

Fix 540 (sort of)
This commit is contained in:
Ted John 2014-11-01 14:22:51 +00:00
commit 97fef72f07
8 changed files with 103 additions and 30 deletions

View File

@ -372,6 +372,10 @@
#define RCT2_ADDRESS_CURRENT_WINDOW_COLOUR_3 0x0141F742
#define RCT2_ADDRESS_CURRENT_WINDOW_COLOUR_4 0x0141F743
// size: 500 chars
#define RCT2_ADDRESS_TOOLTIP_TEXT_BUFFER 0x0141FE44
#define RCT2_ADDRESS_TOOLTIP_TEXT_HEIGHT 0x01420044
#define RCT2_ADDRESS_WINDOW_LIST 0x01420078
#define RCT2_ADDRESS_NEW_WINDOW_PTR 0x014234B8
#define RCT2_ADDRESS_VIEWPORT_LIST 0x014234BC

View File

@ -486,13 +486,13 @@ void redraw_peep_and_rain()
if (RCT2_GLOBAL(0x009ABDF2, uint32) != 0) {
int sprite = RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE, sint32);
if (sprite != -1) {
sprite = (sprite & 0x7FFFF) * 16;
sprite = sprite & 0x7FFFF;
rct_g1_element *g1_elements = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element);
int left = RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_X, sint32) + g1_elements[sprite].x_offset;
int top = RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_Y, sint32) + g1_elements[sprite].y_offset;
int right = left + g1_elements[sprite].width;
int bottom = top + g1_elements[sprite].height;
rct_g1_element *g1_elements = &RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[sprite];
int left = RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_X, sint16) + g1_elements->x_offset;
int top = RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_Y, sint16) + g1_elements->y_offset;
int right = left + g1_elements->width;
int bottom = top + g1_elements->height;
gfx_set_dirty_blocks(left, top, right, bottom);
}
@ -511,6 +511,6 @@ void redraw_peep_and_rain()
}
RCT2_GLOBAL(0x009E2C78, uint32) = 1;
}
RCT2_GLOBAL(RCT2_ADDRESS_NO_RAIN_PIXELS, uint32) = 0;
}
RCT2_GLOBAL(RCT2_ADDRESS_NO_RAIN_PIXELS, uint32) = 0;
}

View File

@ -100,6 +100,7 @@ void gfx_load_character_widths();
int clip_text(char *buffer, int width);
int gfx_wrap_string(char* buffer, int width, int* num_lines, int* font_height);
int gfx_get_string_width(char *buffer);
int gfx_get_string_width_new_lined(char* buffer);
void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, int y);
void gfx_draw_string_left(rct_drawpixelinfo *dpi, int format, void *args, int colour, int x, int y);
void gfx_draw_string_left_clipped(rct_drawpixelinfo *dpi, int format, void *args, int colour, int x, int y, int width);

View File

@ -85,6 +85,79 @@ void gfx_load_character_widths(){
}
}
/* rct2: 0x006C23B1 */
int gfx_get_string_width_new_lined(char* buffer){
// Current font sprites
uint16* current_font_sprite_base;
// Width of string
int width = 0, max_width = 0, no_lines = 1;
rct_g1_element g1_element;
current_font_sprite_base = RCT2_ADDRESS(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16);
for (uint8* curr_char = (uint8*)buffer; *curr_char != (uint8)0; curr_char++) {
if (*curr_char >= 0x20) {
width += RCT2_ADDRESS(RCT2_ADDRESS_FONT_CHAR_WIDTH, uint8)[*current_font_sprite_base + (*curr_char - 0x20)];
continue;
}
switch (*curr_char) {
case FORMAT_MOVE_X:
curr_char++;
width = *curr_char;
break;
case FORMAT_ADJUST_PALETTE:
case 3:
case 4:
curr_char++;
break;
case FORMAT_NEWLINE:
case FORMAT_NEWLINE_SMALLER:
no_lines++;
max_width = max(max_width, width);
width = 0;
break;
case FORMAT_TINYFONT:
*current_font_sprite_base = 0x1C0;
break;
case FORMAT_BIGFONT:
*current_font_sprite_base = 0x2A0;
break;
case FORMAT_MEDIUMFONT:
*current_font_sprite_base = 0x0E0;
break;
case FORMAT_SMALLFONT:
*current_font_sprite_base = 0;
break;
case FORMAT_OUTLINE:
case FORMAT_OUTLINE_OFF:
case FORMAT_WINDOW_COLOUR_1:
case FORMAT_WINDOW_COLOUR_2:
case FORMAT_WINDOW_COLOUR_3:
case 0x10:
continue;
case FORMAT_INLINE_SPRITE:
g1_element = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[*((uint32*)(curr_char + 1)) & 0x7FFFF];
width += g1_element.width;
curr_char += 4;
break;
default:
if (*curr_char <= 0x16) { //case 0x11? FORMAT_NEW_LINE_X_Y
curr_char += 2;
continue;
}
curr_char += 4;//never happens?
break;
}
}
if (width > max_width)
return width;
return max_width;
}
/**
* Return the width of the string in buffer
*

View File

@ -276,6 +276,13 @@ void game_logic_update()
if (RCT2_GLOBAL(0x009DEA66, sint16) == 0)
RCT2_GLOBAL(0x009DEA66, sint16)--;
// This is a hack for now to force a complete rerender of the screen to
// stop viewports from failing. Remove this when real bug cause has been
// found.
// ***********
gfx_invalidate_screen();
// ***********
sub_68B089();
scenario_update();
climate_update();

View File

@ -289,7 +289,6 @@ void viewport_update_position(rct_window *window)
center_2d_coordinates(sprite->unknown.x, sprite->unknown.y, sprite->unknown.z, &center_x, &center_y, window->viewport);
RCT2_CALLPROC_X(0x6E7DE1, center_x, center_y, 0, 0, (int)window, (int)viewport, 0);
window_invalidate(window);//Added to force a redraw.
return;
}

View File

@ -72,18 +72,6 @@ static void* window_error_events[] = {
static char _window_error_text[512];
static uint16 _window_error_num_lines;
/**
*
* rct2: 0x006C23B1
*/
int sub_6C23B1(char *text)
{
int eax, ebx, ecx, edx, esi, edi, ebp;
esi = (int)text;
RCT2_CALLFUNC_X(0x006C23B1, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp);
return *((sint16*)&ecx);
}
/**
*
* rct2: 0x0066792F
@ -120,7 +108,7 @@ void window_error_open(rct_string_id title, rct_string_id message)
return;
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224;
width = sub_6C23B1(_window_error_text);
width = gfx_get_string_width_new_lined(_window_error_text);
width = min(196, width);
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224;

View File

@ -73,14 +73,15 @@ static void* window_tooltip_events[] = {
void window_tooltip_reset(int x, int y)
{
RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_X, uint8) = x;
RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_Y, uint8) = y;
RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TIMEOUT, uint8) = 0;
RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_X, uint16) = x;
RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_Y, uint16) = y;
RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TIMEOUT, uint16) = 0;
RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WINDOW_CLASS, uint8) = 255;
RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = 1;
RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) &= ~(1 << 4);
}
extern uint8* gTooltip_text_buffer = RCT2_ADDRESS(RCT2_ADDRESS_TOOLTIP_TEXT_BUFFER, uint8);
/**
*
* rct2: 0x006EA10D
@ -120,9 +121,9 @@ void window_tooltip_open(rct_window *widgetWindow, int widgetIndex, int x, int y
format_string(buffer, widget->tooltip, (void*)0x013CE952);
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224;
int tooltip_text_width = ecx, tooltip_text_height = 0;
//gfx_get_string_width_new_lined
RCT2_CALLFUNC_X(0x006C23B1, &eax, &ebx, &tooltip_text_width, &edx, (int*)(&buffer), &edi, &ebp);
int tooltip_text_width = 0, tooltip_text_height = 0;
tooltip_text_width = gfx_get_string_width_new_lined(buffer);
buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char);
tooltip_text_width &= 0xFFFF;
if (tooltip_text_width > 196)
@ -131,13 +132,13 @@ void window_tooltip_open(rct_window *widgetWindow, int widgetIndex, int x, int y
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224;
tooltip_text_width = gfx_wrap_string(buffer, tooltip_text_width + 1, &tooltip_text_height, &ebx);
RCT2_GLOBAL(0x01420044, sint16) = tooltip_text_height;
RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TEXT_HEIGHT, sint16) = tooltip_text_height;
width = tooltip_text_width + 3;
height = ((tooltip_text_height + 1) * 10) + 4;
window_tooltip_widgets[WIDX_BACKGROUND].right = width;
window_tooltip_widgets[WIDX_BACKGROUND].bottom = height;
memcpy((void*)0x0141FE44, (void*)buffer, 512);
memcpy(gTooltip_text_buffer, buffer, 512);
x = clamp(0, x - (width / 2), RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16) - width);
y = clamp(22, y + 26, RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) - height - 40);
@ -215,5 +216,5 @@ static void window_tooltip_paint()
// Text
left = w->x + ((w->width + 1) / 2) - 1;
top = w->y + 1;
draw_string_centred_raw(dpi, left, top, RCT2_GLOBAL(0x01420044, uint16), (char*)0x0141FE44);
draw_string_centred_raw(dpi, left, top, RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TEXT_HEIGHT, uint16), gTooltip_text_buffer);
}