From 168537d338489ead154030fc9ca177a66c6757a1 Mon Sep 17 00:00:00 2001 From: qcz Date: Thu, 21 Aug 2014 21:53:17 +0200 Subject: [PATCH 01/30] Add window_scenery.c, start working on scenery window --- projects/openrct2.vcxproj | 1 + projects/openrct2.vcxproj.filters | 3 + src/string_ids.h | 4 + src/window.h | 1 + src/window_game_top_toolbar.c | 3 +- src/window_scenery.c | 230 ++++++++++++++++++++++++++++++ 6 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 src/window_scenery.c diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj index 76a1fdfc39..b145af069c 100644 --- a/projects/openrct2.vcxproj +++ b/projects/openrct2.vcxproj @@ -134,6 +134,7 @@ + diff --git a/projects/openrct2.vcxproj.filters b/projects/openrct2.vcxproj.filters index 7f24637b5d..363f9b199e 100644 --- a/projects/openrct2.vcxproj.filters +++ b/projects/openrct2.vcxproj.filters @@ -377,6 +377,9 @@ Source Files + + Windows + diff --git a/src/string_ids.h b/src/string_ids.h index aabbb8442c..1a367fccce 100644 --- a/src/string_ids.h +++ b/src/string_ids.h @@ -798,6 +798,10 @@ enum { STR_REAL_PARKS = STR_BEGINNER_PARKS + 3, STR_OTHER_PARKS = STR_BEGINNER_PARKS + 4, + STR_SELECT_COLOUR = 3099, + STR_SELECT_SECONDARY_COLOUR = 3100, + STR_SELECT_TERNARY_COLOUR = 3101, + STR_LIST_RIDES_TIP = 3104, STR_LIST_SHOPS_AND_STALLS_TIP = 3105, STR_LIST_KIOSKS_AND_FACILITIES_TIP = 3106, diff --git a/src/window.h b/src/window.h index e7880dc636..d879a4790a 100644 --- a/src/window.h +++ b/src/window.h @@ -379,6 +379,7 @@ void window_new_ride_open(); void window_banner_open(); void window_cheats_open(); void window_research_open(); +void window_scenery_open(); void window_guest_list_init_vars_a(); void window_guest_list_init_vars_b(); diff --git a/src/window_game_top_toolbar.c b/src/window_game_top_toolbar.c index b7f624a598..6f12939ed2 100644 --- a/src/window_game_top_toolbar.c +++ b/src/window_game_top_toolbar.c @@ -258,7 +258,8 @@ static void window_game_top_toolbar_mouseup() case WIDX_SCENERY: if (!tool_set(w, WIDX_SCENERY, 0)) { RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 6); - RCT2_CALLPROC_EBPSAFE(0x006E0FEF); + window_scenery_open(); + //RCT2_CALLPROC_EBPSAFE(006E0FEF); } break; case WIDX_PATH: diff --git a/src/window_scenery.c b/src/window_scenery.c new file mode 100644 index 0000000000..4415e9dcf0 --- /dev/null +++ b/src/window_scenery.c @@ -0,0 +1,230 @@ +/***************************************************************************** +* Copyright (c) 2014 Dániel Tar +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* This file is part of OpenRCT2. +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*****************************************************************************/ + +#include +#include "addresses.h" +#include "game.h" +#include "gfx.h" +#include "peep.h" +#include "sprite.h" +#include "string_ids.h" +#include "viewport.h" +#include "widget.h" +#include "window.h" + +#define WINDOW_SCENERY_WIDTH 0x27A +#define WINDOW_SCENERY_HEIGHT 0x8E + +enum { + WINDOW_SCENERY_TAB_1, + WINDOW_SCENERY_TAB_2, + WINDOW_SCENERY_TAB_3, + WINDOW_SCENERY_TAB_4, + WINDOW_SCENERY_TAB_5, + WINDOW_SCENERY_TAB_6, + WINDOW_SCENERY_TAB_7, + WINDOW_SCENERY_TAB_8, + WINDOW_SCENERY_TAB_9, + WINDOW_SCENERY_TAB_10, + WINDOW_SCENERY_TAB_11, + WINDOW_SCENERY_TAB_12, + WINDOW_SCENERY_TAB_13, + WINDOW_SCENERY_TAB_14, + WINDOW_SCENERY_TAB_15, + WINDOW_SCENERY_TAB_16, + WINDOW_SCENERY_TAB_17, + WINDOW_SCENERY_TAB_18, + WINDOW_SCENERY_TAB_19, + WINDOW_SCENERY_TAB_20 +} WINDOW_SCENERY_LIST_TAB; + +static void window_scenery_emptysub() { } + +static void* window_scenery_events[] = { + (void*)0x006E1A73, // window_scenery_close + (void*)0x006E19FC, // window_scenery_mouseup + (void*)0x006E1E48, // window_scenery_resize, + (void*)0x006E1A25, // window_scenery_mousedown, + (void*)0x006E1A54, // window_scenery_dropdown, + window_scenery_emptysub, + (void*)0x006E1CD3, // window_scenery_update, + (void*)0x006E1B9F, // window_scenery_emptysub, + window_scenery_emptysub, + window_scenery_emptysub, + window_scenery_emptysub, // window_scenery_tooldown + window_scenery_emptysub, + window_scenery_emptysub, + window_scenery_emptysub, + window_scenery_emptysub, + (void*)0x006E1A91, // window_scenery_scrollgetsize, + (void*)0x006E1C4A, // window_scenery_scrollmousedown, + window_scenery_emptysub, + (void*)0x006E1BB8, // window_scenery_scrollmouseover, + window_scenery_emptysub, + window_scenery_emptysub, + window_scenery_emptysub, + (void*)0x006E1C05, // window_scenery_tooltip, + window_scenery_emptysub, + window_scenery_emptysub, + (void*)0x006E118B, // window_scenery_invalidate, + (void*)0x006E1462, // window_scenery_paint, + (void*)0x006E15ED, // window_scenery_scrollpaint, +}; + + +enum WINDOW_SCENERY_LIST_WIDGET_IDX { + WIDX_SCENERY_BACKGROUND, // 1 + WIDX_SCENERY_TITLE, // 2 + WIDX_SCENERY_CLOSE, // 4 + WIDX_SCENERY_TAB_CONTENT_PANEL, // 8 + WIDX_SCENERY_TAB_1, // 10 + WIDX_SCENERY_TAB_2, // 20 + WIDX_SCENERY_TAB_3, // 40 + WIDX_SCENERY_TAB_4, // 80 + WIDX_SCENERY_TAB_5, // 100 + WIDX_SCENERY_TAB_6, // 200 + WIDX_SCENERY_TAB_7, // 400 + WIDX_SCENERY_TAB_8, // 800 + WIDX_SCENERY_TAB_9, // 1000 + WIDX_SCENERY_TAB_10, // 2000 + WIDX_SCENERY_TAB_11, // 4000 + WIDX_SCENERY_TAB_12, // 8000 + WIDX_SCENERY_TAB_13, // 10000 + WIDX_SCENERY_TAB_14, // 20000 + WIDX_SCENERY_TAB_15, // 40000 + WIDX_SCENERY_TAB_16, // 80000 + WIDX_SCENERY_TAB_17, // 100000 + WIDX_SCENERY_TAB_18, // 200000 + WIDX_SCENERY_TAB_19, // 400000 + WIDX_SCENERY_TAB_20, // 800000 + WIDX_SCENERY_LIST, // 1000000 + WIDX_SCENERY_FLATBUTTON1, // 2000000 + WIDX_SCENERY_FLATBUTTON2, // 4000000 + WIDX_SCENERY_COLORBUTTON1, // 8000000 + WIDX_SCENERY_COLORBUTTON2, // 10000000 + WIDX_SCENERY_COLORBUTTON3, // 20000000 + WIDX_SCENERY_FLATBUTTON3, // 40000000 +}; + +static rct_widget window_scenery_widgets[] = { + { WWT_FRAME, 0, 0, 633, 0, 141, 0xFFFFFFFF, STR_NONE }, // 1 + { WWT_CAPTION, 0, 1, 632, 1, 14, 0xFFFFFFFF, STR_WINDOW_TITLE_TIP }, // 2 + { WWT_CLOSEBOX, 0, 621, 631, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // 4 + { WWT_RESIZE, 1, 0, 633, 43, 141, 0xFFFFFFFF, STR_NONE }, // 8 + { WWT_TAB, 1, 3, 33, 17, 43, 0xFFFFFFFF, 1812 }, // 10 + { WWT_TAB, 1, 34, 64, 17, 43, 0xFFFFFFFF, 1812 }, // 20 + { WWT_TAB, 1, 65, 95, 17, 43, 0xFFFFFFFF, 1812 }, // 40 + { WWT_TAB, 1, 96, 126, 17, 43, 0xFFFFFFFF, 1812 }, // 80 + { WWT_TAB, 1, 127, 157, 17, 43, 0xFFFFFFFF, 1812 }, // 100 + { WWT_TAB, 1, 158, 188, 17, 43, 0xFFFFFFFF, 1812 }, // 200 + { WWT_TAB, 1, 189, 219, 17, 43, 0xFFFFFFFF, 1812 }, // 400 + { WWT_TAB, 1, 220, 250, 17, 43, 0xFFFFFFFF, 1812 }, // 800 + { WWT_TAB, 1, 251, 281, 17, 43, 0xFFFFFFFF, 1812 }, // 1000 + { WWT_TAB, 1, 282, 312, 17, 43, 0xFFFFFFFF, 1812 }, // 2000 + { WWT_TAB, 1, 313, 343, 17, 43, 0xFFFFFFFF, 1812 }, // 4000 + { WWT_TAB, 1, 344, 374, 17, 43, 0xFFFFFFFF, 1812 }, // 8000 + { WWT_TAB, 1, 375, 405, 17, 43, 0xFFFFFFFF, 1812 }, // 10000 + { WWT_TAB, 1, 406, 436, 17, 43, 0xFFFFFFFF, 1812 }, // 20000 + { WWT_TAB, 1, 437, 467, 17, 43, 0xFFFFFFFF, 1812 }, // 40000 + { WWT_TAB, 1, 468, 498, 17, 43, 0xFFFFFFFF, 1812 }, // 80000 + { WWT_TAB, 1, 468, 498, 17, 43, 0xFFFFFFFF, 1812 }, // 100000 + { WWT_TAB, 1, 468, 498, 17, 43, 0xFFFFFFFF, 1812 }, // 200000 + { WWT_TAB, 1, 468, 498, 17, 43, 0xFFFFFFFF, 1812 }, // 400000 + { WWT_TAB, 1, 468, 498, 17, 43, 0x20001598, 1812 }, // 800000 + { WWT_SCROLL, 1, 2, 608, 47, 126, 2, STR_NONE }, // 1000000 + { WWT_FLATBTN, 1, 609, 632, 44, 67, 5169, STR_ROTATE_OBJECTS_90 }, // 2000000 + { WWT_FLATBTN, 1, 609, 632, 68, 91, 5173, 3102 }, // 4000000 + { WWT_COLORBTN, 1, 615, 626, 93, 104, 0xFFFFFFFF, STR_SELECT_COLOUR }, // 8000000 + { WWT_COLORBTN, 1, 615, 626, 105, 116, 0xFFFFFFFF, STR_SELECT_SECONDARY_COLOUR }, // 10000000 + { WWT_COLORBTN, 1, 615, 626, 117, 128, 0xFFFFFFFF, STR_SELECT_TERNARY_COLOUR }, // 20000000 + { WWT_FLATBTN, 1, 609, 632, 117, 140, 5172, 3225 }, // 40000000 + { WIDGETS_END }, +}; + +/* +* rct2: 0x006E0FEF +**/ +void window_scenery_open() +{ + rct_window* window; + + // Check if window is already open + window = window_bring_to_front_by_id(WC_SCENERY, 0); + if (window != NULL) + return; + + RCT2_CALLPROC_EBPSAFE(0x006DFA00); + + window = window_create(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, sint16) - WINDOW_SCENERY_WIDTH, 0x1D, WINDOW_SCENERY_WIDTH, WINDOW_SCENERY_HEIGHT, + window_scenery_events, WC_SCENERY, WF_2); + window->widgets = window_scenery_widgets; + + window->enabled_widgets = + (1 << WIDX_SCENERY_CLOSE) | + (1 << WIDX_SCENERY_FLATBUTTON1) | + (1 << WIDX_SCENERY_TAB_1) | + (1 << WIDX_SCENERY_TAB_2) | + (1 << WIDX_SCENERY_TAB_3) | + (1 << WIDX_SCENERY_TAB_4) | + (1 << WIDX_SCENERY_TAB_5) | + (1 << WIDX_SCENERY_TAB_6) | + (1 << WIDX_SCENERY_TAB_7) | + (1 << WIDX_SCENERY_TAB_8) | + (1 << WIDX_SCENERY_TAB_9) | + (1 << WIDX_SCENERY_TAB_10) | + (1 << WIDX_SCENERY_TAB_11) | + (1 << WIDX_SCENERY_TAB_12) | + (1 << WIDX_SCENERY_TAB_13) | + (1 << WIDX_SCENERY_TAB_14) | + (1 << WIDX_SCENERY_TAB_15) | + (1 << WIDX_SCENERY_TAB_16) | + (1 << WIDX_SCENERY_TAB_17) | + (1 << WIDX_SCENERY_TAB_18) | + (1 << WIDX_SCENERY_TAB_19) | + (1 << WIDX_SCENERY_TAB_20) | + (1 << WIDX_SCENERY_COLORBUTTON1) | + (1 << WIDX_SCENERY_COLORBUTTON2) | + (1 << WIDX_SCENERY_FLATBUTTON2) | + (1 << WIDX_SCENERY_COLORBUTTON3) | + (1 << WIDX_SCENERY_FLATBUTTON3); + + window_init_scroll_widgets(window); + RCT2_CALLPROC_X(0x006E1EB4, 0, 0, 0, 0, (int)window, 0, 0); + show_gridlines(); + RCT2_GLOBAL(0x00F64F05, uint8) = 3; + RCT2_GLOBAL(0x00F64F12, uint8) = 0; + RCT2_GLOBAL(0x00F64F13, uint8) = 0; + window->var_480 = 0xFFFF; + window->var_482 = 0; + window_push_others_below(window); + RCT2_GLOBAL(0x00F64F0D, uint8) = 0; + RCT2_GLOBAL(0x00F64EB4, uint32) = 0x80000000; + RCT2_GLOBAL(0x00F64EC0, uint16) = 0; + RCT2_GLOBAL(0x00F64F19, uint8) = 0; + RCT2_GLOBAL(0x00F64F1A, uint8) = 0; + + window->min_width = WINDOW_SCENERY_WIDTH; + window->max_width = WINDOW_SCENERY_WIDTH; + window->min_height = WINDOW_SCENERY_HEIGHT; + window->max_height = WINDOW_SCENERY_HEIGHT; + window->colours[0] = 0x18; + window->colours[1] = 0x0C; + window->colours[2] = 0x0C; +} \ No newline at end of file From 4397822578b90348e3cfbae8516970cb08ebd540 Mon Sep 17 00:00:00 2001 From: qcz Date: Sat, 23 Aug 2014 20:17:22 +0200 Subject: [PATCH 02/30] Continue working on window_scenery --- src/window_scenery.c | 49 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index 4415e9dcf0..4de0dd9161 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -56,6 +56,9 @@ enum { } WINDOW_SCENERY_LIST_TAB; static void window_scenery_emptysub() { } +static void window_scenery_invalidate(); +static void window_scenery_paint(); +static void window_scenery_tooltip(); static void* window_scenery_events[] = { (void*)0x006E1A73, // window_scenery_close @@ -80,11 +83,11 @@ static void* window_scenery_events[] = { window_scenery_emptysub, window_scenery_emptysub, window_scenery_emptysub, - (void*)0x006E1C05, // window_scenery_tooltip, + window_scenery_tooltip, //(void*)0x006E1C05, // window_scenery_tooltip, window_scenery_emptysub, window_scenery_emptysub, - (void*)0x006E118B, // window_scenery_invalidate, - (void*)0x006E1462, // window_scenery_paint, + window_scenery_invalidate, //(void*)0x006E118B, // window_scenery_invalidate, + window_scenery_paint, // (void*)0x006E1462, // window_scenery_paint, (void*)0x006E15ED, // window_scenery_scrollpaint, }; @@ -227,4 +230,44 @@ void window_scenery_open() window->colours[0] = 0x18; window->colours[1] = 0x0C; window->colours[2] = 0x0C; +} + +/** +* +* rct2: 0x006E1C05 +*/ +void window_scenery_tooltip() { + RCT2_GLOBAL(0x013CE952, uint16) = STR_LIST; +} + +/** +* +* rct2: 0x006E118B +*/ +void window_senery_invalidate() { +} + +/** +* +* rct2: 0x006E1462 +*/ +void window_scenery_paint() { + int i; + uint8 selectedTab; + rct_window *w; + rct_drawpixelinfo *dpi; + + window_paint_get_registers(w, dpi); + + window_draw_widgets(w, dpi); + + uint32 selectedTab = RCT2_GLOBAL(0x00F64EDC, uint8) + 4; + uint32 image_id = ((w->colours[1] << 19) | window_scenery_widgets[selectedTab].image) + 1ul; + + gfx_draw_sprite(dpi, image_id, + window_scenery_widgets[selectedTab].left, + window_scenery_widgets[selectedTab].top, + selectedTab); + + } \ No newline at end of file From 0c0b3a752f7f55cb66b35b22fda61694928d244b Mon Sep 17 00:00:00 2001 From: qcz Date: Wed, 27 Aug 2014 22:50:33 +0200 Subject: [PATCH 03/30] window_scenery_paint and window_scenery invalidate is done --- src/addresses.h | 7 + src/window.h | 6 + src/window_game_top_toolbar.c | 4 +- src/window_new_ride.c | 2 +- src/window_scenery.c | 255 ++++++++++++++++++++++++++++------ 5 files changed, 230 insertions(+), 44 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 80ef4cbe20..f72f33086d 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -178,6 +178,13 @@ #define RCT2_ADDRESS_G1_ELEMENTS 0x009EBD28 #define RCT2_ADDRESS_PATH_TYPES 0x009ADA14 + +#define RCT2_ADDRESS_SMALL_SCENERY_ENTRIES 0x009AD1A4 +#define RCT2_ADDRESS_LARGE_SCENERY_ENTRIES 0x009AD594 +#define RCT2_ADDRESS_WALL_ENTRIES 0x009AD794 +#define RCT2_ADDRESS_BANNER_ENTRIES 0x009AD994 +#define RCT2_ADDRESS_PATH_BIT_ENTRIES 0x009ADA54 +#define RCT2_ADDRESS_SCENERY_SET_ENTRIES 0x009ADA90 //Every pixel changed by rain is stored. //32bit (pixel_offset 24 bit)(pixel_colour 8 bit) diff --git a/src/window.h b/src/window.h index 7e16e8faf0..5caefe5796 100644 --- a/src/window.h +++ b/src/window.h @@ -162,6 +162,11 @@ typedef struct { sint32 var_482; } ride_variables; +typedef struct { + sint16 var_480; + sint32 var_482; +} scenery_variables; + /** * Window structure * size: 0x4C0 @@ -199,6 +204,7 @@ typedef struct rct_window { news_variables news; map_variables map; ride_variables ride; + scenery_variables scenery; }; sint16 page; // 0x48A sint16 var_48C; diff --git a/src/window_game_top_toolbar.c b/src/window_game_top_toolbar.c index 6f12939ed2..e1cfd9304e 100644 --- a/src/window_game_top_toolbar.c +++ b/src/window_game_top_toolbar.c @@ -258,8 +258,8 @@ static void window_game_top_toolbar_mouseup() case WIDX_SCENERY: if (!tool_set(w, WIDX_SCENERY, 0)) { RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 6); - window_scenery_open(); - //RCT2_CALLPROC_EBPSAFE(006E0FEF); + //window_scenery_open(); + RCT2_CALLPROC_EBPSAFE(0x006E0FEF); } break; case WIDX_PATH: diff --git a/src/window_new_ride.c b/src/window_new_ride.c index 296aea59ce..f82e4e9c4c 100644 --- a/src/window_new_ride.c +++ b/src/window_new_ride.c @@ -761,7 +761,7 @@ static void window_new_ride_paint() rideEntry->name : (typeId & 0xFF00) + 2; } else { - uint8 *sceneryEntry = RCT2_GLOBAL(0x009ADA90 + (typeId & 0xFFFF) * 4, uint8*); + uint8 *sceneryEntry = RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_SET_ENTRIES + (typeId & 0xFFFF) * 4, uint8*); stringId = RCT2_GLOBAL(sceneryEntry, uint16); } } diff --git a/src/window_scenery.c b/src/window_scenery.c index 4de0dd9161..63cb0eacad 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -21,6 +21,7 @@ #include #include "addresses.h" #include "game.h" +#include "map.h" #include "gfx.h" #include "peep.h" #include "sprite.h" @@ -32,6 +33,19 @@ #define WINDOW_SCENERY_WIDTH 0x27A #define WINDOW_SCENERY_HEIGHT 0x8E +typedef struct { + rct_string_id name; + uint16 var_02; + uint16 var_04; + uint8 var_06; + uint8 var_07; + uint8 var_08; + uint8 var_09; + uint16 var_0A; + uint16 var_0C; + uint16 var_0E; +} rct_scenery_entry; + enum { WINDOW_SCENERY_TAB_1, WINDOW_SCENERY_TAB_2, @@ -127,37 +141,37 @@ enum WINDOW_SCENERY_LIST_WIDGET_IDX { }; static rct_widget window_scenery_widgets[] = { - { WWT_FRAME, 0, 0, 633, 0, 141, 0xFFFFFFFF, STR_NONE }, // 1 - { WWT_CAPTION, 0, 1, 632, 1, 14, 0xFFFFFFFF, STR_WINDOW_TITLE_TIP }, // 2 - { WWT_CLOSEBOX, 0, 621, 631, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // 4 - { WWT_RESIZE, 1, 0, 633, 43, 141, 0xFFFFFFFF, STR_NONE }, // 8 - { WWT_TAB, 1, 3, 33, 17, 43, 0xFFFFFFFF, 1812 }, // 10 - { WWT_TAB, 1, 34, 64, 17, 43, 0xFFFFFFFF, 1812 }, // 20 - { WWT_TAB, 1, 65, 95, 17, 43, 0xFFFFFFFF, 1812 }, // 40 - { WWT_TAB, 1, 96, 126, 17, 43, 0xFFFFFFFF, 1812 }, // 80 - { WWT_TAB, 1, 127, 157, 17, 43, 0xFFFFFFFF, 1812 }, // 100 - { WWT_TAB, 1, 158, 188, 17, 43, 0xFFFFFFFF, 1812 }, // 200 - { WWT_TAB, 1, 189, 219, 17, 43, 0xFFFFFFFF, 1812 }, // 400 - { WWT_TAB, 1, 220, 250, 17, 43, 0xFFFFFFFF, 1812 }, // 800 - { WWT_TAB, 1, 251, 281, 17, 43, 0xFFFFFFFF, 1812 }, // 1000 - { WWT_TAB, 1, 282, 312, 17, 43, 0xFFFFFFFF, 1812 }, // 2000 - { WWT_TAB, 1, 313, 343, 17, 43, 0xFFFFFFFF, 1812 }, // 4000 - { WWT_TAB, 1, 344, 374, 17, 43, 0xFFFFFFFF, 1812 }, // 8000 - { WWT_TAB, 1, 375, 405, 17, 43, 0xFFFFFFFF, 1812 }, // 10000 - { WWT_TAB, 1, 406, 436, 17, 43, 0xFFFFFFFF, 1812 }, // 20000 - { WWT_TAB, 1, 437, 467, 17, 43, 0xFFFFFFFF, 1812 }, // 40000 - { WWT_TAB, 1, 468, 498, 17, 43, 0xFFFFFFFF, 1812 }, // 80000 - { WWT_TAB, 1, 468, 498, 17, 43, 0xFFFFFFFF, 1812 }, // 100000 - { WWT_TAB, 1, 468, 498, 17, 43, 0xFFFFFFFF, 1812 }, // 200000 - { WWT_TAB, 1, 468, 498, 17, 43, 0xFFFFFFFF, 1812 }, // 400000 - { WWT_TAB, 1, 468, 498, 17, 43, 0x20001598, 1812 }, // 800000 - { WWT_SCROLL, 1, 2, 608, 47, 126, 2, STR_NONE }, // 1000000 - { WWT_FLATBTN, 1, 609, 632, 44, 67, 5169, STR_ROTATE_OBJECTS_90 }, // 2000000 - { WWT_FLATBTN, 1, 609, 632, 68, 91, 5173, 3102 }, // 4000000 - { WWT_COLORBTN, 1, 615, 626, 93, 104, 0xFFFFFFFF, STR_SELECT_COLOUR }, // 8000000 - { WWT_COLORBTN, 1, 615, 626, 105, 116, 0xFFFFFFFF, STR_SELECT_SECONDARY_COLOUR }, // 10000000 - { WWT_COLORBTN, 1, 615, 626, 117, 128, 0xFFFFFFFF, STR_SELECT_TERNARY_COLOUR }, // 20000000 - { WWT_FLATBTN, 1, 609, 632, 117, 140, 5172, 3225 }, // 40000000 + { WWT_FRAME, 0, 0, 633, 0, 141, 0xFFFFFFFF, STR_NONE }, // 1 0x009DE298 + { WWT_CAPTION, 0, 1, 632, 1, 14, 0xFFFFFFFF, STR_WINDOW_TITLE_TIP }, // 2 0x009DE2A8 + { WWT_CLOSEBOX, 0, 621, 631, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // 4 0x009DE2B8 + { WWT_RESIZE, 1, 0, 633, 43, 141, 0xFFFFFFFF, STR_NONE }, // 8 0x009DE2C8 + { WWT_TAB, 1, 3, 33, 17, 43, 0xFFFFFFFF, 1812 }, // 10 0x009DE2D8 + { WWT_TAB, 1, 34, 64, 17, 43, 0xFFFFFFFF, 1812 }, // 20 0x009DE2E8 + { WWT_TAB, 1, 65, 95, 17, 43, 0xFFFFFFFF, 1812 }, // 40 0x009DE2F8 + { WWT_TAB, 1, 96, 126, 17, 43, 0xFFFFFFFF, 1812 }, // 80 0x009DE308 + { WWT_TAB, 1, 127, 157, 17, 43, 0xFFFFFFFF, 1812 }, // 100 0x009DE318 + { WWT_TAB, 1, 158, 188, 17, 43, 0xFFFFFFFF, 1812 }, // 200 0x009DE328 + { WWT_TAB, 1, 189, 219, 17, 43, 0xFFFFFFFF, 1812 }, // 400 0x009DE338 + { WWT_TAB, 1, 220, 250, 17, 43, 0xFFFFFFFF, 1812 }, // 800 0x009DE348 + { WWT_TAB, 1, 251, 281, 17, 43, 0xFFFFFFFF, 1812 }, // 1000 0x009DE358 + { WWT_TAB, 1, 282, 312, 17, 43, 0xFFFFFFFF, 1812 }, // 2000 0x009DE368 + { WWT_TAB, 1, 313, 343, 17, 43, 0xFFFFFFFF, 1812 }, // 4000 0x009DE378 + { WWT_TAB, 1, 344, 374, 17, 43, 0xFFFFFFFF, 1812 }, // 8000 0x009DE388 + { WWT_TAB, 1, 375, 405, 17, 43, 0xFFFFFFFF, 1812 }, // 10000 0x009DE398 + { WWT_TAB, 1, 406, 436, 17, 43, 0xFFFFFFFF, 1812 }, // 20000 0x009DE3A8 + { WWT_TAB, 1, 437, 467, 17, 43, 0xFFFFFFFF, 1812 }, // 40000 0x009DE3B8 + { WWT_TAB, 1, 468, 498, 17, 43, 0xFFFFFFFF, 1812 }, // 80000 0x009DE3C8 + { WWT_TAB, 1, 468, 498, 17, 43, 0xFFFFFFFF, 1812 }, // 100000 0x009DE3D8 + { WWT_TAB, 1, 468, 498, 17, 43, 0xFFFFFFFF, 1812 }, // 200000 0x009DE3E8 + { WWT_TAB, 1, 468, 498, 17, 43, 0xFFFFFFFF, 1812 }, // 400000 0x009DE3F8 + { WWT_TAB, 1, 468, 498, 17, 43, 0x20001598, 1812 }, // 800000 0x009DE408 + { WWT_SCROLL, 1, 2, 608, 47, 126, 2, STR_NONE }, // 1000000 0x009DE418 + { WWT_FLATBTN, 1, 609, 632, 44, 67, 5169, STR_ROTATE_OBJECTS_90 }, // 2000000 0x009DE428 + { WWT_FLATBTN, 1, 609, 632, 68, 91, 5173, 3102 }, // 4000000 0x009DE438 + { WWT_COLORBTN, 1, 615, 626, 93, 104, 0xFFFFFFFF, STR_SELECT_COLOUR }, // 8000000 0x009DE448 + { WWT_COLORBTN, 1, 615, 626, 105, 116, 0xFFFFFFFF, STR_SELECT_SECONDARY_COLOUR }, // 10000000 0x009DE458 + { WWT_COLORBTN, 1, 615, 626, 117, 128, 0xFFFFFFFF, STR_SELECT_TERNARY_COLOUR }, // 20000000 0x009DE468 + { WWT_FLATBTN, 1, 609, 632, 117, 140, 5172, 3225 }, // 40000000 0x009DE478 { WIDGETS_END }, }; @@ -176,7 +190,7 @@ void window_scenery_open() RCT2_CALLPROC_EBPSAFE(0x006DFA00); window = window_create(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, sint16) - WINDOW_SCENERY_WIDTH, 0x1D, WINDOW_SCENERY_WIDTH, WINDOW_SCENERY_HEIGHT, - window_scenery_events, WC_SCENERY, WF_2); + (uint32*)window_scenery_events, WC_SCENERY, WF_2); window->widgets = window_scenery_widgets; window->enabled_widgets = @@ -214,13 +228,13 @@ void window_scenery_open() RCT2_GLOBAL(0x00F64F05, uint8) = 3; RCT2_GLOBAL(0x00F64F12, uint8) = 0; RCT2_GLOBAL(0x00F64F13, uint8) = 0; - window->var_480 = 0xFFFF; - window->var_482 = 0; + window->scenery.var_480 = 0xFFFF; + window->scenery.var_482 = 0; window_push_others_below(window); RCT2_GLOBAL(0x00F64F0D, uint8) = 0; RCT2_GLOBAL(0x00F64EB4, uint32) = 0x80000000; RCT2_GLOBAL(0x00F64EC0, uint16) = 0; - RCT2_GLOBAL(0x00F64F19, uint8) = 0; + RCT2_GLOBAL(0x00F64F19, uint8) = 0; // repaint colored scenery tool state RCT2_GLOBAL(0x00F64F1A, uint8) = 0; window->min_width = WINDOW_SCENERY_WIDTH; @@ -244,7 +258,123 @@ void window_scenery_tooltip() { * * rct2: 0x006E118B */ -void window_senery_invalidate() { +void window_scenery_invalidate() { + rct_window* w; + + window_get_register(w); + + uint16 typeId = RCT2_GLOBAL(0x00F64EDC, uint8); + uint32 edx = 0x715; + if (typeId >= 0x13) { + edx = *RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_SET_ENTRIES + (typeId & 0xFFFF) * 4, uint8*); + } + + w->pressed_widgets = ((w->pressed_widgets & 0xFF00000F) | (1 << (typeId + 4))) & 0xBBFFFFFF; + + if (RCT2_GLOBAL(0x00F64F19, uint8) != 1) { // repaint colored scenery tool is off + w->pressed_widgets |= 0x04000000; + } + + uint8 byte_9DE428 = 0; + uint8 byte_9DE478 = 0; + uint8 byte_9DE448 = 0; + + uint16 bp = RCT2_ADDRESS(0x00F64EDD, uint16)[typeId]; + if (bp == 0xFFFF) { + if (bp > 0x100) { + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_SCENARIO_EDITOR) && !(RCT2_GLOBAL(0x00F64F19, uint8) & 1)) { + byte_9DE478 = 9; + } + + rct_scenery_entry* ebx = RCT2_ADDRESS(RCT2_ADDRESS_SMALL_SCENERY_ENTRIES, rct_scenery_entry*)[typeId]; + if (!(ebx->var_06 & 0x600)) { + byte_9DE448 = 6; + } + int i = 0; + } + } + + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].image = + (RCT2_GLOBAL(0x00F64F06, uint8) << 19) + 0x600013C3; + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].image = + (RCT2_GLOBAL(0x00F64F07, uint8) << 19) + 0x600013C3; + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON3].image = + (RCT2_GLOBAL(0x00F64F08, uint8) << 19) + 0x600013C3; + + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_EMPTY; + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_EMPTY; + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON3].type = WWT_EMPTY; + + + if (RCT2_GLOBAL(0x00F64F19, uint8) & 1) { // repaint colored scenery tool is on + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_COLORBTN; + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON3].type = WWT_COLORBTN; + } else if (bp != 0xFFFF) { + rct_scenery_entry* sceneryEntry = NULL; + + if (bp >= 0x400) { + sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_BANNER_ENTRIES, rct_scenery_entry*)[bp - 0x400]; + + if (sceneryEntry->var_07 & 1) + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; + } + else if (bp >= 0x300) { + sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_LARGE_SCENERY_ENTRIES, rct_scenery_entry*)[bp - 0x300]; + + if (sceneryEntry->var_07 & 1) + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; + if (sceneryEntry->var_07 & 2) + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_COLORBTN; + } + else if (bp >= 0x200) { + sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_WALL_ENTRIES, rct_scenery_entry*)[bp - 0x200]; + if (sceneryEntry->var_07 & 1) + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; + if (sceneryEntry->var_07 & 0x40) { + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_COLORBTN; + + if (sceneryEntry->var_09 & 1) + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; + if (sceneryEntry->var_07 & 0x80) + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON3].type = WWT_COLORBTN; + } + } + else if (bp < 0x100) { + sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_SMALL_SCENERY_ENTRIES, rct_scenery_entry*)[bp]; + + if (sceneryEntry->var_06 & 0x600) { + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; + + if (sceneryEntry->var_07 & 0x8) + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_COLORBTN; + } + } + } + + window_scenery_widgets[WIDX_SCENERY_BACKGROUND].right = w->width - 1; + window_scenery_widgets[WIDX_SCENERY_BACKGROUND].bottom = w->height - 1; + window_scenery_widgets[WIDX_SCENERY_TAB_CONTENT_PANEL].right = w->width - 1; + window_scenery_widgets[WIDX_SCENERY_TAB_CONTENT_PANEL].bottom = w->height - 1; + window_scenery_widgets[WIDX_SCENERY_TITLE].right = w->width - 2; + window_scenery_widgets[WIDX_SCENERY_CLOSE].left = w->width - 13; + window_scenery_widgets[WIDX_SCENERY_CLOSE].right = window_scenery_widgets[WIDX_SCENERY_CLOSE].left + 10; + window_scenery_widgets[WIDX_SCENERY_LIST].right = w->width - 0x1A; + window_scenery_widgets[WIDX_SCENERY_LIST].bottom = w->height - 0x0E; + + window_scenery_widgets[WIDX_SCENERY_FLATBUTTON1].left = w->width - 25; + window_scenery_widgets[WIDX_SCENERY_FLATBUTTON2].left = w->width - 25; + window_scenery_widgets[WIDX_SCENERY_FLATBUTTON3].left = w->width - 25; + window_scenery_widgets[WIDX_SCENERY_FLATBUTTON1].right = w->width - 2; + window_scenery_widgets[WIDX_SCENERY_FLATBUTTON2].right = w->width - 2; + window_scenery_widgets[WIDX_SCENERY_FLATBUTTON3].right = w->width - 2; + + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].left = w->width - 19; + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].left = w->width - 19; + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON3].left = w->width - 19; + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].right = w->width - 8; + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].right = w->width - 8; + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON3].right = w->width - 8; } /** @@ -252,8 +382,6 @@ void window_senery_invalidate() { * rct2: 0x006E1462 */ void window_scenery_paint() { - int i; - uint8 selectedTab; rct_window *w; rct_drawpixelinfo *dpi; @@ -261,13 +389,58 @@ void window_scenery_paint() { window_draw_widgets(w, dpi); - uint32 selectedTab = RCT2_GLOBAL(0x00F64EDC, uint8) + 4; + uint16 typeId = RCT2_GLOBAL(0x00F64EDC, uint8); + uint16 selectedTab = typeId + 4; uint32 image_id = ((w->colours[1] << 19) | window_scenery_widgets[selectedTab].image) + 1ul; gfx_draw_sprite(dpi, image_id, - window_scenery_widgets[selectedTab].left, - window_scenery_widgets[selectedTab].top, + w->x + window_scenery_widgets[selectedTab].left, + w->y + window_scenery_widgets[selectedTab].top, selectedTab); + + uint16 bp = w->scenery.var_480; + if (bp == 0xFFFF) { + if (RCT2_GLOBAL(0x00F64F19, uint8) & 1) // repaint colored scenery tool is on + return; + bp = RCT2_ADDRESS(0x00F64EDD, uint16)[typeId]; + if (bp == 0xFFFF) + return; + } + + uint32 price = 0; + + rct_scenery_entry* sceneryEntry = NULL; + if (bp >= 0x400) { + sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_BANNER_ENTRIES, rct_scenery_entry*)[bp - 0x400]; + price = sceneryEntry->var_08; + } else if (bp >= 0x300) { + sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_LARGE_SCENERY_ENTRIES, rct_scenery_entry*)[bp - 0x300]; + price = sceneryEntry->var_08 * 10; + } else if (bp >= 0x200) { + sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_WALL_ENTRIES, rct_scenery_entry*)[bp - 0x200]; + price = sceneryEntry->var_0A; + } else if (bp >= 0x100) { + sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_PATH_BIT_ENTRIES, rct_scenery_entry*)[bp - 0x100]; + price = sceneryEntry->var_0A; + } else { + sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_SMALL_SCENERY_ENTRIES, rct_scenery_entry*)[bp]; + price = sceneryEntry->var_0C * 10; + } + + if (w->scenery.var_480 == 0xFFFF && RCT2_GLOBAL(0x00F64EB4, uint32) != 0x80000000) { + price = RCT2_GLOBAL(0x00F64EB4, uint32); + } + + RCT2_GLOBAL(0x013CE952, uint32) = price; + + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_11)) { + gfx_draw_string_right(dpi, STR_COST_LABEL, (void*)0x013CE952, 0, + w->x + w->width - 14, w->y + w->height - 13); + } + + RCT2_GLOBAL(0x013CE952, uint16) = sceneryEntry->name; + gfx_draw_string_left_clipped(dpi, 0x4A7, (void*)0x013CE952, 0, + w->x + 3, w->y + w->height - 13, w->width - 19); } \ No newline at end of file From 1ce9e6031073b3a46fe5bef2d5e007ed48ee3a3c Mon Sep 17 00:00:00 2001 From: qcz Date: Thu, 28 Aug 2014 18:51:24 +0200 Subject: [PATCH 04/30] Added window_scenery_close and implemented window_scenery_tooltip --- src/window_game_top_toolbar.c | 4 ++-- src/window_scenery.c | 41 +++++++++++++++++++++++++++++++++-- src/window_staff.c | 6 +---- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/window_game_top_toolbar.c b/src/window_game_top_toolbar.c index e1cfd9304e..6370e9caf4 100644 --- a/src/window_game_top_toolbar.c +++ b/src/window_game_top_toolbar.c @@ -258,8 +258,8 @@ static void window_game_top_toolbar_mouseup() case WIDX_SCENERY: if (!tool_set(w, WIDX_SCENERY, 0)) { RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 6); - //window_scenery_open(); - RCT2_CALLPROC_EBPSAFE(0x006E0FEF); + window_scenery_open(); + //RCT2_CALLPROC_EBPSAFE(0x006E0FEF); } break; case WIDX_PATH: diff --git a/src/window_scenery.c b/src/window_scenery.c index 63cb0eacad..69157b7724 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -70,12 +70,13 @@ enum { } WINDOW_SCENERY_LIST_TAB; static void window_scenery_emptysub() { } +static void window_scenery_close(); static void window_scenery_invalidate(); static void window_scenery_paint(); static void window_scenery_tooltip(); static void* window_scenery_events[] = { - (void*)0x006E1A73, // window_scenery_close + window_scenery_close, //(void*)0x006E1A73, // window_scenery_close (void*)0x006E19FC, // window_scenery_mouseup (void*)0x006E1E48, // window_scenery_resize, (void*)0x006E1A25, // window_scenery_mousedown, @@ -246,12 +247,48 @@ void window_scenery_open() window->colours[2] = 0x0C; } +/* +* rct2: 0x006E1A73 +**/ +void window_scenery_close() { + rct_window *w; + + window_get_register(w); + + RCT2_CALLPROC_EBPSAFE(0x6E2712); + hide_gridlines(); + RCT2_CALLPROC_X(0x006CB70A, 0, 0, 0, 0, 0, 0, 0); + + int toolWindowClassification = RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass); + int toolWidgetIndex = RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, rct_windownumber); + + if (RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3)) + if (toolWindowClassification == WC_TOP_TOOLBAR && toolWidgetIndex == 9) + tool_cancel(); +} + /** * * rct2: 0x006E1C05 */ void window_scenery_tooltip() { - RCT2_GLOBAL(0x013CE952, uint16) = STR_LIST; + uint16 tooltipIndex; + + #ifdef _MSC_VER + __asm mov tooltipIndex, ax + #else + __asm__("mov %[tooltipIndex], ax " : [tooltipIndex] "+m" (tooltipIndex)); + #endif + + if (tooltipIndex == 0x18) + { + RCT2_GLOBAL(0x013CE952, uint16) = 3159; + } + else if (tooltipIndex >= 4 && tooltipIndex < 0x17) + { + uint32* sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32*)[tooltipIndex - 4]; + RCT2_GLOBAL(0x013CE952, uint16) = RCT2_GLOBAL((int)sceneryEntry, uint16); + } } /** diff --git a/src/window_staff.c b/src/window_staff.c index 650dd10dc7..ff84d975f0 100644 --- a/src/window_staff.c +++ b/src/window_staff.c @@ -171,11 +171,7 @@ void window_staff_open() window->colours[2] = 4; } -void window_staff_cancel_tools() { - rct_window *w; - - window_get_register(w); - +void window_staff_cancel_tools(rct_window *w) { int toolWindowClassification = RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass); int toolWindowNumber = RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER, rct_windownumber); if (RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3)) From 3d7496c7c9e9a1ed58ad05cba74b98ad9eba65f3 Mon Sep 17 00:00:00 2001 From: qcz Date: Sun, 31 Aug 2014 13:24:20 +0200 Subject: [PATCH 05/30] Started to work on init_scenery, added structs for different scenery entries --- src/addresses.h | 6 +- src/window_scenery.c | 490 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 464 insertions(+), 32 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index f72f33086d..5166d56a99 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -181,9 +181,9 @@ #define RCT2_ADDRESS_SMALL_SCENERY_ENTRIES 0x009AD1A4 #define RCT2_ADDRESS_LARGE_SCENERY_ENTRIES 0x009AD594 -#define RCT2_ADDRESS_WALL_ENTRIES 0x009AD794 -#define RCT2_ADDRESS_BANNER_ENTRIES 0x009AD994 -#define RCT2_ADDRESS_PATH_BIT_ENTRIES 0x009ADA54 +#define RCT2_ADDRESS_WALL_SCENERY_ENTRIES 0x009AD794 +#define RCT2_ADDRESS_BANNER_SCENERY_ENTRIES 0x009AD994 +#define RCT2_ADDRESS_PATH_BIT_SCENERY_ENTRIES 0x009ADA54 #define RCT2_ADDRESS_SCENERY_SET_ENTRIES 0x009ADA90 //Every pixel changed by rain is stored. diff --git a/src/window_scenery.c b/src/window_scenery.c index 69157b7724..40a9c7df29 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -19,6 +19,7 @@ *****************************************************************************/ #include +#include #include "addresses.h" #include "game.h" #include "map.h" @@ -34,18 +35,80 @@ #define WINDOW_SCENERY_HEIGHT 0x8E typedef struct { - rct_string_id name; + uint8 pad_02[4]; + uint8 flags; // 0x06 + uint8 flags2; // 0x07 + uint8 pad_08[4]; + uint16 price; // 0x0C + uint8 pad_0E[12]; + uint8 var_1A; // 0x1A +} rct_small_scenery_entry; + +typedef struct { + uint8 pad_02[5]; + uint8 flags; // 0x07 + uint16 price; // 0x08 + uint8 pad_0A[6]; + uint8 var_10; // 0x10 +} rct_large_scenery_entry; + + +typedef struct { + uint8 pad_02[5]; + uint8 flags; // 0x07 + uint8 pad_08; + uint8 flags2; // 0x09 + uint16 price; // 0x0A + uint8 var_0C; // 0x0C +} rct_wall_scenery_entry; + +typedef struct { + uint8 pad_02[8]; + uint16 price; // 0x0A + uint8 var_0C; // 0x0C +} rct_path_bit_scenery_entry; + +typedef struct { uint16 var_02; uint16 var_04; uint8 var_06; + uint8 flags; // 0x07 + uint16 price; // 0x08 + uint8 var_0A; // 0x0A +} rct_banner_scenery_entry; + +typedef struct { + rct_string_id name; + union { + rct_small_scenery_entry small_scenery; + rct_large_scenery_entry large_scenery; + rct_wall_scenery_entry wall; + rct_path_bit_scenery_entry path_bit; + rct_banner_scenery_entry banner; + }; + /*uint16 var_02; + uint16 var_04; + uint8 var_06; uint8 var_07; uint8 var_08; uint8 var_09; uint16 var_0A; uint16 var_0C; uint16 var_0E; + uint16 var_10; + uint16 var_12; + uint16 var_14; + uint16 var_16; + uint16 var_18; + uint16 var_1A;*/ } rct_scenery_entry; +#define g_smallSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_SMALL_SCENERY_ENTRIES, rct_scenery_entry*) +#define g_largeSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_LARGE_SCENERY_ENTRIES, rct_scenery_entry*) +#define g_wallSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_WALL_SCENERY_ENTRIES, rct_scenery_entry*) +#define g_bannerSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_BANNER_SCENERY_ENTRIES, rct_scenery_entry*) +#define g_pathBitSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_PATH_BIT_SCENERY_ENTRIES, rct_scenery_entry*) + enum { WINDOW_SCENERY_TAB_1, WINDOW_SCENERY_TAB_2, @@ -71,6 +134,7 @@ enum { static void window_scenery_emptysub() { } static void window_scenery_close(); +static void window_scenery_update(rct_window *w); static void window_scenery_invalidate(); static void window_scenery_paint(); static void window_scenery_tooltip(); @@ -82,7 +146,7 @@ static void* window_scenery_events[] = { (void*)0x006E1A25, // window_scenery_mousedown, (void*)0x006E1A54, // window_scenery_dropdown, window_scenery_emptysub, - (void*)0x006E1CD3, // window_scenery_update, + /*window_scenery_update,/*/(void*)0x006E1CD3, // window_scenery_update, (void*)0x006E1B9F, // window_scenery_emptysub, window_scenery_emptysub, window_scenery_emptysub, @@ -176,6 +240,356 @@ static rct_widget window_scenery_widgets[] = { { WIDGETS_END }, }; +/* +* rct2: 0x006DFA00 +**/ +void init_scenery() { + uint32 edi = 0; + uint32 baseAddress = 0x00F64F7C; + + for (int i = 0; i < 0x14; i++) { + RCT2_ADDRESS(0x00F64F2C, uint32)[i] = baseAddress; + baseAddress += 0x102; + } + + uint32 dword_F663A4 = 0; + + for (int edi = 0; edi < 0x14; edi++) { + int esi = RCT2_ADDRESS(0x00F64F2C, uint32)[edi]; + RCT2_GLOBAL(esi, uint16) = 0xFFFF; + if (edi != 13) { + uint32 ebp = RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32)[edi]; + + if (ebp != 0xFFFFFFFF) { + + for (int ebx = 0;; ebx++) { + if (ebx == RCT2_GLOBAL(ebp + 0x106, uint8)) + break; + + uint16 ax = RCT2_GLOBAL(ebp + ebx * 2 + 6, uint16); + if (RCT2_ADDRESS(0x01357BD0, sint32)[ax >> 5] & (1 << (ax & 0x1F))) { + RCT2_GLOBAL(esi, uint16) = ax; + esi += 2; + RCT2_GLOBAL(esi, uint16) = 0xFFFF; + } + else { + dword_F663A4 &= (1 << edi); + } + } + + } + } + } + + // small scenery + for (uint16 edi = 0; edi < 0xFC; edi++) { + if ((uint32)g_smallSceneryEntries[edi] == 0xFFFFFFFF) + continue; + + rct_scenery_entry* sceneryEntry = g_smallSceneryEntries[edi]; + + if (RCT2_ADDRESS(0x01357BD0, sint32)[edi >> 5] & (1 << (edi & 0x1F))) { + if (sceneryEntry->small_scenery.var_1A != 0xFF) { + uint32 esi = RCT2_ADDRESS(0x00F64F2C, uint32)[sceneryEntry->small_scenery.var_1A]; + + bool found = false; + for (int ebx = 0; ebx < 0x80; ebx++) { + if (RCT2_ADDRESS(esi, uint16)[ebx] == 0xFFFF) + { + RCT2_ADDRESS(esi, uint16)[ebx] = edi; + RCT2_ADDRESS(esi, uint16)[ebx + 1] = 0xFFFF; + found = true; + break; + } + } + + if (found == true) + continue; + } + + bool found2 = false; + + for (int ecx = 0; ecx < 0x13; ecx++) { + int baseEdx = RCT2_ADDRESS(0x00F64F2C, uint32)[ecx]; + int counter = 0; + + while (RCT2_ADDRESS(baseEdx, uint16)[counter] != 0xFFFF) + { + if (RCT2_ADDRESS(baseEdx, uint16)[counter] == edi) { + ecx = 0x13; + found2 = true; + break; + } + + counter++; + } + } + + if (found2 == true) + continue; + + uint32 edx = RCT2_GLOBAL(0x00F64F78, uint32); + for (int ecx = 0; ecx < 0x80; ecx++) { + if (RCT2_ADDRESS(edx, uint16)[ecx] == 0xFFFF) + { + RCT2_ADDRESS(edx, uint16)[ecx] = edi; + RCT2_ADDRESS(edx, uint16)[ecx + 1] = 0xFFFF; + break; + } + } + } + } + + // large scenery + for (int edi = 0x300; edi < 0x380; edi++) { + int largeSceneryIndex = edi - 0x300; + + if ((uint32)g_largeSceneryEntries[largeSceneryIndex] == 0xFFFFFFFF) + continue; + + rct_scenery_entry* sceneryEntry = g_largeSceneryEntries[largeSceneryIndex]; + + if (RCT2_ADDRESS(0x01357BD0, sint32)[edi >> 5] & (1 << (edi + 0x1F))) { + if (sceneryEntry->large_scenery.var_10 != 0xFF) { + uint32 esi = RCT2_ADDRESS(0x00F64F2C, uint32)[sceneryEntry->large_scenery.var_10]; + + bool found = false; + for (int ebx = 0; ebx < 0x80; ebx++) { + if (RCT2_ADDRESS(esi, uint16)[ebx] == 0xFFFF) + { + RCT2_ADDRESS(esi, uint16)[ebx] = edi; + RCT2_ADDRESS(esi, uint16)[ebx + 1] = 0xFFFF; + found = true; + break; + } + } + + if (found == true) + continue; + } + + bool found2 = false; + + for (int ecx = 0; ecx < 0x13; ecx++) { + int baseEdx = RCT2_ADDRESS(0x00F64F2C, uint32)[ecx]; + int counter = 0; + + while (RCT2_ADDRESS(baseEdx, uint16)[counter] != 0xFFFF) + { + if (RCT2_ADDRESS(baseEdx, uint16)[counter] == edi) { + ecx = 0x13; + found2 = true; + break; + } + + counter++; + } + } + + if (found2 == true) + continue; + + uint32 edx = RCT2_GLOBAL(0x00F64F78, uint32); + for (int ecx = 0; ecx < 0x80; ecx++) { + if (RCT2_ADDRESS(edx, uint16)[ecx] == 0xFFFF) + { + RCT2_ADDRESS(edx, uint16)[ecx] = edi; + RCT2_ADDRESS(edx, uint16)[ecx + 1] = 0xFFFF; + break; + } + } + } + } + + // walls + for (int edi = 0x200; edi < 0x280; edi++) { + int wallSceneryIndex = edi - 0x200; + + if ((uint32)g_wallSceneryEntries[wallSceneryIndex] == 0xFFFFFFFF) + continue; + + rct_scenery_entry* sceneryEntry = g_wallSceneryEntries[wallSceneryIndex]; + + if (RCT2_ADDRESS(0x01357BD0, sint32)[edi >> 5] & (1 << (edi + 0x1F))) { + if (sceneryEntry->wall.var_0C != 0xFF) { + uint32 esi = RCT2_ADDRESS(0x00F64F2C, uint32)[sceneryEntry->wall.var_0C]; + + bool found = false; + for (int ebx = 0; ebx < 0x80; ebx++) { + if (RCT2_ADDRESS(esi, uint16)[ebx] == 0xFFFF) + { + RCT2_ADDRESS(esi, uint16)[ebx] = edi; + RCT2_ADDRESS(esi, uint16)[ebx + 1] = 0xFFFF; + found = true; + break; + } + } + + if (found == true) + continue; + } + + bool found2 = false; + + for (int ecx = 0; ecx < 0x13; ecx++) { + int baseEdx = RCT2_ADDRESS(0x00F64F2C, uint32)[ecx]; + int counter = 0; + + while (RCT2_ADDRESS(baseEdx, uint16)[counter] != 0xFFFF) + { + if (RCT2_ADDRESS(baseEdx, uint16)[counter] == edi) { + ecx = 0x13; + found2 = true; + break; + } + + counter++; + } + } + + if (found2 == true) + continue; + + uint32 edx = RCT2_GLOBAL(0x00F64F78, uint32); + for (int ecx = 0; ecx < 0x80; ecx++) { + if (RCT2_ADDRESS(edx, uint16)[ecx] == 0xFFFF) + { + RCT2_ADDRESS(edx, uint16)[ecx] = edi; + RCT2_ADDRESS(edx, uint16)[ecx + 1] = 0xFFFF; + break; + } + } + } + } + + // banners + for (int edi = 0x400; edi < 0x420; edi++) { + int bannerIndex = edi - 0x400; + + if ((uint32)g_bannerSceneryEntries[bannerIndex] == 0xFFFFFFFF) + continue; + + rct_scenery_entry* sceneryEntry = g_bannerSceneryEntries[bannerIndex]; + + if (RCT2_ADDRESS(0x01357BD0, sint32)[edi >> 5] & (1 << (edi + 0x1F))) { + if (sceneryEntry->banner.var_0A != 0xFF) { + uint32 esi = RCT2_ADDRESS(0x00F64F2C, uint32)[sceneryEntry->banner.var_0A]; + + bool found = false; + for (int ebx = 0; ebx < 0x80; ebx++) { + if (RCT2_ADDRESS(esi, uint16)[ebx] == 0xFFFF) + { + RCT2_ADDRESS(esi, uint16)[ebx] = edi; + RCT2_ADDRESS(esi, uint16)[ebx + 1] = 0xFFFF; + found = true; + break; + } + } + + if (found == true) + continue; + } + + bool found2 = false; + + for (int ecx = 0; ecx < 0x13; ecx++) { + int baseEdx = RCT2_ADDRESS(0x00F64F2C, uint32)[ecx]; + int counter = 0; + + while (RCT2_ADDRESS(baseEdx, uint16)[counter] != 0xFFFF) + { + if (RCT2_ADDRESS(baseEdx, uint16)[counter] == edi) { + ecx = 0x13; + found2 = true; + break; + } + + counter++; + } + } + + if (found2 == true) + continue; + + uint32 edx = RCT2_GLOBAL(0x00F64F78, uint32); + for (int ecx = 0; ecx < 0x80; ecx++) { + if (RCT2_ADDRESS(edx, uint16)[ecx] == 0xFFFF) + { + RCT2_ADDRESS(edx, uint16)[ecx] = edi; + RCT2_ADDRESS(edx, uint16)[ecx + 1] = 0xFFFF; + break; + } + } + } + } + + // path bits + for (int edi = 0x100; edi < 0x10F; edi++) { + int bannerIndex = edi - 0x100; + + if ((uint32)g_pathBitSceneryEntries[bannerIndex] == 0xFFFFFFFF) + continue; + + rct_scenery_entry* sceneryEntry = g_pathBitSceneryEntries[bannerIndex]; + + if (RCT2_ADDRESS(0x01357BD0, sint32)[edi >> 5] & (1 << (edi + 0x1F))) { + if (sceneryEntry->path_bit.var_0C != 0xFF) { + uint32 esi = RCT2_ADDRESS(0x00F64F2C, uint32)[sceneryEntry->path_bit.var_0C]; + + bool found = false; + for (int ebx = 0; ebx < 0x80; ebx++) { + if (RCT2_ADDRESS(esi, uint16)[ebx] == 0xFFFF) + { + RCT2_ADDRESS(esi, uint16)[ebx] = edi; + RCT2_ADDRESS(esi, uint16)[ebx + 1] = 0xFFFF; + found = true; + break; + } + } + + if (found == true) + continue; + } + + bool found2 = false; + + for (int ecx = 0; ecx < 0x13; ecx++) { + int baseEdx = RCT2_ADDRESS(0x00F64F2C, uint32)[ecx]; + int counter = 0; + + while (RCT2_ADDRESS(baseEdx, uint16)[counter] != 0xFFFF) + { + if (RCT2_ADDRESS(baseEdx, uint16)[counter] == edi) { + ecx = 0x13; + found2 = true; + break; + } + + counter++; + } + } + + if (found2 == true) + continue; + + uint32 edx = RCT2_GLOBAL(0x00F64F78, uint32); + for (int ecx = 0; ecx < 0x80; ecx++) { + if (RCT2_ADDRESS(edx, uint16)[ecx] == 0xFFFF) + { + RCT2_ADDRESS(edx, uint16)[ecx] = edi; + RCT2_ADDRESS(edx, uint16)[ecx + 1] = 0xFFFF; + break; + } + } + } + } + + for (int esi = WIDX_SCENERY_TAB_1; esi < WIDX_SCENERY_LIST; esi++) + window_scenery_widgets[esi].type = 0; + + // todo: 0x006DFDF7 +} + /* * rct2: 0x006E0FEF **/ @@ -188,7 +602,8 @@ void window_scenery_open() if (window != NULL) return; - RCT2_CALLPROC_EBPSAFE(0x006DFA00); + init_scenery(); + //RCT2_CALLPROC_EBPSAFE(0x006DFA00); window = window_create(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, sint16) - WINDOW_SCENERY_WIDTH, 0x1D, WINDOW_SCENERY_WIDTH, WINDOW_SCENERY_HEIGHT, (uint32*)window_scenery_events, WC_SCENERY, WF_2); @@ -267,6 +682,23 @@ void window_scenery_close() { tool_cancel(); } +/** +* +* rct2: 0x006E1CD3 +*/ +static void window_scenery_update(rct_window *w) +{ + rct_window* other = window_find_from_point(RCT2_GLOBAL(0x0142406C, int), RCT2_GLOBAL(0x01424070, int)); + if (other == w) { + int window_x = RCT2_GLOBAL(0x0142406C, int) - w->x + 0x1A; + int window_y = RCT2_GLOBAL(0x01424070, int) - w->y; + + if (window_y >= 0x2C) { + + } + } +} + /** * * rct2: 0x006E1C05 @@ -306,7 +738,7 @@ void window_scenery_invalidate() { edx = *RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_SET_ENTRIES + (typeId & 0xFFFF) * 4, uint8*); } - w->pressed_widgets = ((w->pressed_widgets & 0xFF00000F) | (1 << (typeId + 4))) & 0xBBFFFFFF; + w->pressed_widgets = (((uint32)w->pressed_widgets & 0xFF00000F) | (1 << (typeId + 4))) & 0xBBFFFFFF; if (RCT2_GLOBAL(0x00F64F19, uint8) != 1) { // repaint colored scenery tool is off w->pressed_widgets |= 0x04000000; @@ -323,8 +755,8 @@ void window_scenery_invalidate() { byte_9DE478 = 9; } - rct_scenery_entry* ebx = RCT2_ADDRESS(RCT2_ADDRESS_SMALL_SCENERY_ENTRIES, rct_scenery_entry*)[typeId]; - if (!(ebx->var_06 & 0x600)) { + rct_scenery_entry* ebx = g_smallSceneryEntries[typeId]; + if (!(ebx->small_scenery.flags & 0x600)) { byte_9DE448 = 6; } int i = 0; @@ -351,39 +783,39 @@ void window_scenery_invalidate() { rct_scenery_entry* sceneryEntry = NULL; if (bp >= 0x400) { - sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_BANNER_ENTRIES, rct_scenery_entry*)[bp - 0x400]; + sceneryEntry = g_bannerSceneryEntries[bp - 0x400]; - if (sceneryEntry->var_07 & 1) + if (sceneryEntry->banner.flags & 1) window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; } else if (bp >= 0x300) { - sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_LARGE_SCENERY_ENTRIES, rct_scenery_entry*)[bp - 0x300]; + sceneryEntry = g_largeSceneryEntries[bp - 0x300]; - if (sceneryEntry->var_07 & 1) + if (sceneryEntry->large_scenery.flags & 1) window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; - if (sceneryEntry->var_07 & 2) + if (sceneryEntry->large_scenery.flags & 2) window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_COLORBTN; } else if (bp >= 0x200) { - sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_WALL_ENTRIES, rct_scenery_entry*)[bp - 0x200]; - if (sceneryEntry->var_07 & 1) + sceneryEntry = g_wallSceneryEntries[bp - 0x200]; + if (sceneryEntry->wall.flags & 1) window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; - if (sceneryEntry->var_07 & 0x40) { + if (sceneryEntry->wall.flags & 0x40) { window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_COLORBTN; - if (sceneryEntry->var_09 & 1) + if (sceneryEntry->wall.flags2 & 1) window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; - if (sceneryEntry->var_07 & 0x80) + if (sceneryEntry->wall.flags & 0x80) window_scenery_widgets[WIDX_SCENERY_COLORBUTTON3].type = WWT_COLORBTN; } } else if (bp < 0x100) { - sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_SMALL_SCENERY_ENTRIES, rct_scenery_entry*)[bp]; + sceneryEntry = g_smallSceneryEntries[bp]; - if (sceneryEntry->var_06 & 0x600) { + if (sceneryEntry->small_scenery.flags & 0x600) { window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; - if (sceneryEntry->var_07 & 0x8) + if (sceneryEntry->small_scenery.flags2 & 0x8) window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_COLORBTN; } } @@ -450,20 +882,20 @@ void window_scenery_paint() { rct_scenery_entry* sceneryEntry = NULL; if (bp >= 0x400) { - sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_BANNER_ENTRIES, rct_scenery_entry*)[bp - 0x400]; - price = sceneryEntry->var_08; + sceneryEntry = g_bannerSceneryEntries[bp - 0x400]; + price = sceneryEntry->banner.price; } else if (bp >= 0x300) { - sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_LARGE_SCENERY_ENTRIES, rct_scenery_entry*)[bp - 0x300]; - price = sceneryEntry->var_08 * 10; + sceneryEntry = g_largeSceneryEntries[bp - 0x300]; + price = sceneryEntry->large_scenery.price * 10; } else if (bp >= 0x200) { - sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_WALL_ENTRIES, rct_scenery_entry*)[bp - 0x200]; - price = sceneryEntry->var_0A; + sceneryEntry = g_wallSceneryEntries[bp - 0x200]; + price = sceneryEntry->wall.price; } else if (bp >= 0x100) { - sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_PATH_BIT_ENTRIES, rct_scenery_entry*)[bp - 0x100]; - price = sceneryEntry->var_0A; + sceneryEntry = g_pathBitSceneryEntries[bp - 0x100]; + price = sceneryEntry->path_bit.price; } else { - sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_SMALL_SCENERY_ENTRIES, rct_scenery_entry*)[bp]; - price = sceneryEntry->var_0C * 10; + sceneryEntry = g_smallSceneryEntries[bp]; + price = sceneryEntry->small_scenery.price * 10; } if (w->scenery.var_480 == 0xFFFF && RCT2_GLOBAL(0x00F64EB4, uint32) != 0x80000000) { From e2d1321de7032081be15a2e33c3a3befd04d8afd Mon Sep 17 00:00:00 2001 From: qcz Date: Sun, 31 Aug 2014 13:27:28 +0200 Subject: [PATCH 06/30] Use PARK_FLAGS_NO_MONEY instead of PARK_FLAGS_11 --- src/window_scenery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index 40a9c7df29..733d289a01 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -904,7 +904,7 @@ void window_scenery_paint() { RCT2_GLOBAL(0x013CE952, uint32) = price; - if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_11)) { + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) { gfx_draw_string_right(dpi, STR_COST_LABEL, (void*)0x013CE952, 0, w->x + w->width - 14, w->y + w->height - 13); } From c192f383f446938a662ad89a6e5980d7589ef601 Mon Sep 17 00:00:00 2001 From: qcz Date: Sun, 31 Aug 2014 21:11:38 +0200 Subject: [PATCH 07/30] finish init_scenery --- src/window_scenery.c | 96 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 77 insertions(+), 19 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index 733d289a01..92a475888e 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -257,26 +257,27 @@ void init_scenery() { for (int edi = 0; edi < 0x14; edi++) { int esi = RCT2_ADDRESS(0x00F64F2C, uint32)[edi]; RCT2_GLOBAL(esi, uint16) = 0xFFFF; - if (edi != 13) { - uint32 ebp = RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32)[edi]; + if (edi == 13) + continue; - if (ebp != 0xFFFFFFFF) { + uint32 ebp = RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32)[edi]; + if (ebp == 0xFFFFFFFF) + continue; - for (int ebx = 0;; ebx++) { - if (ebx == RCT2_GLOBAL(ebp + 0x106, uint8)) - break; + for (int ebx = 0;; ebx++) { + if (ebx >= RCT2_GLOBAL(ebp + 0x106, uint8)) + break; - uint16 ax = RCT2_GLOBAL(ebp + ebx * 2 + 6, uint16); - if (RCT2_ADDRESS(0x01357BD0, sint32)[ax >> 5] & (1 << (ax & 0x1F))) { - RCT2_GLOBAL(esi, uint16) = ax; - esi += 2; - RCT2_GLOBAL(esi, uint16) = 0xFFFF; - } - else { - dword_F663A4 &= (1 << edi); - } - } + uint16 ax = RCT2_GLOBAL(ebp + ebx * 2 + 6, uint16); + uint32 ecx = RCT2_ADDRESS(0x01357BD0, uint32)[ax >> 5]; + uint32 edx = 1 << (ax & 0x1F); + if (ecx & edx) { + RCT2_GLOBAL(esi, uint16) = ax; + esi += 2; + RCT2_GLOBAL(esi, uint16) = 0xFFFF; + } else { + dword_F663A4 |= (1 << edi); } } } @@ -584,10 +585,67 @@ void init_scenery() { } } - for (int esi = WIDX_SCENERY_TAB_1; esi < WIDX_SCENERY_LIST; esi++) - window_scenery_widgets[esi].type = 0; + for (int widgetIndex = WIDX_SCENERY_TAB_1; widgetIndex < WIDX_SCENERY_LIST; widgetIndex++) + window_scenery_widgets[widgetIndex].type = 0; - // todo: 0x006DFDF7 + uint8 stuff[0x50]; + int ebp = 0; + + for (int ebx = 0; ebx < 0x13; ebx++) { + uint32 scenerySetAddress = RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32)[edi]; + if (scenerySetAddress == 0xFFFFFFFF) + continue; + + stuff[ebp] = ebx; + stuff[ebp + 1] = RCT2_GLOBAL(scenerySetAddress + 0x108, uint8); + + ebp += 4; + int prev_edi = ebp - 4; + + while (true) { + if (prev_edi <= 0) + break; + + prev_edi -= 4; + if (stuff[prev_edi + 5] >= stuff[prev_edi + 1]) + break; + + int eax = stuff[prev_edi + 4]; + stuff[prev_edi + 4] = stuff[prev_edi]; + stuff[prev_edi] = eax; + } + } + + stuff[ebp] = 0x13; + ebp += 4; + + uint16 cx = 3; + for (int ebx = 0; ebx < ebp; ebx += 4) { + uint32 tabIndex = stuff[ebx]; + rct_widget* currentTab = &window_scenery_widgets[tabIndex + WIDX_SCENERY_TAB_1]; + int eax = RCT2_ADDRESS(0x00F64F2C, uint32)[tabIndex]; + + if (cx != 3 || tabIndex == 0x13) { + if (RCT2_GLOBAL(eax, uint16) == 0xFFFF) + continue; + + if (dword_F663A4 & (1 << tabIndex)) + continue; + } + + currentTab->type = WWT_TAB; + currentTab->left = cx; + currentTab->right = cx + 0x1E; + cx += 0x1F; + + if (edi >= 0x13) + continue; + + int sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32)[tabIndex]; + currentTab->image = RCT2_GLOBAL(sceneryEntry + 2, uint32) | 0x20000000; + } + + window_invalidate_by_id(WC_SCENERY, 0); } /* From 013144115d608257608369e9c0145d02bba1cd3c Mon Sep 17 00:00:00 2001 From: qcz Date: Sun, 31 Aug 2014 21:21:30 +0200 Subject: [PATCH 08/30] move repeated scenery initialization code to a function --- src/window_scenery.c | 303 +++++++------------------------------------ 1 file changed, 48 insertions(+), 255 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index 92a475888e..ae63d9e7b9 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -240,6 +240,49 @@ static rct_widget window_scenery_widgets[] = { { WIDGETS_END }, }; + +void init_scenery_entry(rct_scenery_entry *sceneryEntry, int index, uint8 unknownVar) { + if (RCT2_ADDRESS(0x01357BD0, sint32)[index >> 5] & (1 << (index & 0x1F))) { + if (unknownVar != 0xFF) { + uint32 esi = RCT2_ADDRESS(0x00F64F2C, uint32)[unknownVar]; + + for (int ebx = 0; ebx < 0x80; ebx++) { + if (RCT2_ADDRESS(esi, uint16)[ebx] == 0xFFFF) + { + RCT2_ADDRESS(esi, uint16)[ebx] = index; + RCT2_ADDRESS(esi, uint16)[ebx + 1] = 0xFFFF; + return; + } + } + } + + for (int ecx = 0; ecx < 0x13; ecx++) { + int baseEdx = RCT2_ADDRESS(0x00F64F2C, uint32)[ecx]; + int counter = 0; + + while (RCT2_ADDRESS(baseEdx, uint16)[counter] != 0xFFFF) + { + if (RCT2_ADDRESS(baseEdx, uint16)[counter] == index) { + ecx = 0x13; + return; + } + + counter++; + } + } + + uint32 edx = RCT2_GLOBAL(0x00F64F78, uint32); + for (int ecx = 0; ecx < 0x80; ecx++) { + if (RCT2_ADDRESS(edx, uint16)[ecx] == 0xFFFF) + { + RCT2_ADDRESS(edx, uint16)[ecx] = index; + RCT2_ADDRESS(edx, uint16)[ecx + 1] = 0xFFFF; + break; + } + } + } +} + /* * rct2: 0x006DFA00 **/ @@ -288,57 +331,7 @@ void init_scenery() { continue; rct_scenery_entry* sceneryEntry = g_smallSceneryEntries[edi]; - - if (RCT2_ADDRESS(0x01357BD0, sint32)[edi >> 5] & (1 << (edi & 0x1F))) { - if (sceneryEntry->small_scenery.var_1A != 0xFF) { - uint32 esi = RCT2_ADDRESS(0x00F64F2C, uint32)[sceneryEntry->small_scenery.var_1A]; - - bool found = false; - for (int ebx = 0; ebx < 0x80; ebx++) { - if (RCT2_ADDRESS(esi, uint16)[ebx] == 0xFFFF) - { - RCT2_ADDRESS(esi, uint16)[ebx] = edi; - RCT2_ADDRESS(esi, uint16)[ebx + 1] = 0xFFFF; - found = true; - break; - } - } - - if (found == true) - continue; - } - - bool found2 = false; - - for (int ecx = 0; ecx < 0x13; ecx++) { - int baseEdx = RCT2_ADDRESS(0x00F64F2C, uint32)[ecx]; - int counter = 0; - - while (RCT2_ADDRESS(baseEdx, uint16)[counter] != 0xFFFF) - { - if (RCT2_ADDRESS(baseEdx, uint16)[counter] == edi) { - ecx = 0x13; - found2 = true; - break; - } - - counter++; - } - } - - if (found2 == true) - continue; - - uint32 edx = RCT2_GLOBAL(0x00F64F78, uint32); - for (int ecx = 0; ecx < 0x80; ecx++) { - if (RCT2_ADDRESS(edx, uint16)[ecx] == 0xFFFF) - { - RCT2_ADDRESS(edx, uint16)[ecx] = edi; - RCT2_ADDRESS(edx, uint16)[ecx + 1] = 0xFFFF; - break; - } - } - } + init_scenery_entry(sceneryEntry, edi, sceneryEntry->small_scenery.var_1A); } // large scenery @@ -349,57 +342,7 @@ void init_scenery() { continue; rct_scenery_entry* sceneryEntry = g_largeSceneryEntries[largeSceneryIndex]; - - if (RCT2_ADDRESS(0x01357BD0, sint32)[edi >> 5] & (1 << (edi + 0x1F))) { - if (sceneryEntry->large_scenery.var_10 != 0xFF) { - uint32 esi = RCT2_ADDRESS(0x00F64F2C, uint32)[sceneryEntry->large_scenery.var_10]; - - bool found = false; - for (int ebx = 0; ebx < 0x80; ebx++) { - if (RCT2_ADDRESS(esi, uint16)[ebx] == 0xFFFF) - { - RCT2_ADDRESS(esi, uint16)[ebx] = edi; - RCT2_ADDRESS(esi, uint16)[ebx + 1] = 0xFFFF; - found = true; - break; - } - } - - if (found == true) - continue; - } - - bool found2 = false; - - for (int ecx = 0; ecx < 0x13; ecx++) { - int baseEdx = RCT2_ADDRESS(0x00F64F2C, uint32)[ecx]; - int counter = 0; - - while (RCT2_ADDRESS(baseEdx, uint16)[counter] != 0xFFFF) - { - if (RCT2_ADDRESS(baseEdx, uint16)[counter] == edi) { - ecx = 0x13; - found2 = true; - break; - } - - counter++; - } - } - - if (found2 == true) - continue; - - uint32 edx = RCT2_GLOBAL(0x00F64F78, uint32); - for (int ecx = 0; ecx < 0x80; ecx++) { - if (RCT2_ADDRESS(edx, uint16)[ecx] == 0xFFFF) - { - RCT2_ADDRESS(edx, uint16)[ecx] = edi; - RCT2_ADDRESS(edx, uint16)[ecx + 1] = 0xFFFF; - break; - } - } - } + init_scenery_entry(sceneryEntry, edi, sceneryEntry->large_scenery.var_10); } // walls @@ -410,57 +353,7 @@ void init_scenery() { continue; rct_scenery_entry* sceneryEntry = g_wallSceneryEntries[wallSceneryIndex]; - - if (RCT2_ADDRESS(0x01357BD0, sint32)[edi >> 5] & (1 << (edi + 0x1F))) { - if (sceneryEntry->wall.var_0C != 0xFF) { - uint32 esi = RCT2_ADDRESS(0x00F64F2C, uint32)[sceneryEntry->wall.var_0C]; - - bool found = false; - for (int ebx = 0; ebx < 0x80; ebx++) { - if (RCT2_ADDRESS(esi, uint16)[ebx] == 0xFFFF) - { - RCT2_ADDRESS(esi, uint16)[ebx] = edi; - RCT2_ADDRESS(esi, uint16)[ebx + 1] = 0xFFFF; - found = true; - break; - } - } - - if (found == true) - continue; - } - - bool found2 = false; - - for (int ecx = 0; ecx < 0x13; ecx++) { - int baseEdx = RCT2_ADDRESS(0x00F64F2C, uint32)[ecx]; - int counter = 0; - - while (RCT2_ADDRESS(baseEdx, uint16)[counter] != 0xFFFF) - { - if (RCT2_ADDRESS(baseEdx, uint16)[counter] == edi) { - ecx = 0x13; - found2 = true; - break; - } - - counter++; - } - } - - if (found2 == true) - continue; - - uint32 edx = RCT2_GLOBAL(0x00F64F78, uint32); - for (int ecx = 0; ecx < 0x80; ecx++) { - if (RCT2_ADDRESS(edx, uint16)[ecx] == 0xFFFF) - { - RCT2_ADDRESS(edx, uint16)[ecx] = edi; - RCT2_ADDRESS(edx, uint16)[ecx + 1] = 0xFFFF; - break; - } - } - } + init_scenery_entry(sceneryEntry, edi, sceneryEntry->wall.var_0C); } // banners @@ -471,57 +364,7 @@ void init_scenery() { continue; rct_scenery_entry* sceneryEntry = g_bannerSceneryEntries[bannerIndex]; - - if (RCT2_ADDRESS(0x01357BD0, sint32)[edi >> 5] & (1 << (edi + 0x1F))) { - if (sceneryEntry->banner.var_0A != 0xFF) { - uint32 esi = RCT2_ADDRESS(0x00F64F2C, uint32)[sceneryEntry->banner.var_0A]; - - bool found = false; - for (int ebx = 0; ebx < 0x80; ebx++) { - if (RCT2_ADDRESS(esi, uint16)[ebx] == 0xFFFF) - { - RCT2_ADDRESS(esi, uint16)[ebx] = edi; - RCT2_ADDRESS(esi, uint16)[ebx + 1] = 0xFFFF; - found = true; - break; - } - } - - if (found == true) - continue; - } - - bool found2 = false; - - for (int ecx = 0; ecx < 0x13; ecx++) { - int baseEdx = RCT2_ADDRESS(0x00F64F2C, uint32)[ecx]; - int counter = 0; - - while (RCT2_ADDRESS(baseEdx, uint16)[counter] != 0xFFFF) - { - if (RCT2_ADDRESS(baseEdx, uint16)[counter] == edi) { - ecx = 0x13; - found2 = true; - break; - } - - counter++; - } - } - - if (found2 == true) - continue; - - uint32 edx = RCT2_GLOBAL(0x00F64F78, uint32); - for (int ecx = 0; ecx < 0x80; ecx++) { - if (RCT2_ADDRESS(edx, uint16)[ecx] == 0xFFFF) - { - RCT2_ADDRESS(edx, uint16)[ecx] = edi; - RCT2_ADDRESS(edx, uint16)[ecx + 1] = 0xFFFF; - break; - } - } - } + init_scenery_entry(sceneryEntry, edi, sceneryEntry->banner.var_0A); } // path bits @@ -532,57 +375,7 @@ void init_scenery() { continue; rct_scenery_entry* sceneryEntry = g_pathBitSceneryEntries[bannerIndex]; - - if (RCT2_ADDRESS(0x01357BD0, sint32)[edi >> 5] & (1 << (edi + 0x1F))) { - if (sceneryEntry->path_bit.var_0C != 0xFF) { - uint32 esi = RCT2_ADDRESS(0x00F64F2C, uint32)[sceneryEntry->path_bit.var_0C]; - - bool found = false; - for (int ebx = 0; ebx < 0x80; ebx++) { - if (RCT2_ADDRESS(esi, uint16)[ebx] == 0xFFFF) - { - RCT2_ADDRESS(esi, uint16)[ebx] = edi; - RCT2_ADDRESS(esi, uint16)[ebx + 1] = 0xFFFF; - found = true; - break; - } - } - - if (found == true) - continue; - } - - bool found2 = false; - - for (int ecx = 0; ecx < 0x13; ecx++) { - int baseEdx = RCT2_ADDRESS(0x00F64F2C, uint32)[ecx]; - int counter = 0; - - while (RCT2_ADDRESS(baseEdx, uint16)[counter] != 0xFFFF) - { - if (RCT2_ADDRESS(baseEdx, uint16)[counter] == edi) { - ecx = 0x13; - found2 = true; - break; - } - - counter++; - } - } - - if (found2 == true) - continue; - - uint32 edx = RCT2_GLOBAL(0x00F64F78, uint32); - for (int ecx = 0; ecx < 0x80; ecx++) { - if (RCT2_ADDRESS(edx, uint16)[ecx] == 0xFFFF) - { - RCT2_ADDRESS(edx, uint16)[ecx] = edi; - RCT2_ADDRESS(edx, uint16)[ecx + 1] = 0xFFFF; - break; - } - } - } + init_scenery_entry(sceneryEntry, edi, sceneryEntry->path_bit.var_0C); } for (int widgetIndex = WIDX_SCENERY_TAB_1; widgetIndex < WIDX_SCENERY_LIST; widgetIndex++) From cedeb0d4b34dff1d6f837697ac5ff5e4a86b87ec Mon Sep 17 00:00:00 2001 From: qcz Date: Sun, 31 Aug 2014 22:21:39 +0200 Subject: [PATCH 09/30] window_update is almost done --- src/window_scenery.c | 105 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 93 insertions(+), 12 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index ae63d9e7b9..608dbc4bb0 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -38,14 +38,16 @@ typedef struct { uint8 pad_02[4]; uint8 flags; // 0x06 uint8 flags2; // 0x07 - uint8 pad_08[4]; + uint8 pad_08[3]; + uint8 tool_id; // 0x0B uint16 price; // 0x0C uint8 pad_0E[12]; uint8 var_1A; // 0x1A } rct_small_scenery_entry; typedef struct { - uint8 pad_02[5]; + uint8 pad_02[4]; + uint8 tool_id; // 0x06 uint8 flags; // 0x07 uint16 price; // 0x08 uint8 pad_0A[6]; @@ -54,7 +56,8 @@ typedef struct { typedef struct { - uint8 pad_02[5]; + uint8 pad_02[4]; + uint8 tool_id; // 0x06 uint8 flags; // 0x07 uint8 pad_08; uint8 flags2; // 0x09 @@ -63,7 +66,8 @@ typedef struct { } rct_wall_scenery_entry; typedef struct { - uint8 pad_02[8]; + uint8 pad_02[7]; + uint8 tool_id; // 0x09 uint16 price; // 0x0A uint8 var_0C; // 0x0C } rct_path_bit_scenery_entry; @@ -146,7 +150,7 @@ static void* window_scenery_events[] = { (void*)0x006E1A25, // window_scenery_mousedown, (void*)0x006E1A54, // window_scenery_dropdown, window_scenery_emptysub, - /*window_scenery_update,/*/(void*)0x006E1CD3, // window_scenery_update, + window_scenery_update,//(void*)0x006E1CD3, // window_scenery_update, (void*)0x006E1B9F, // window_scenery_emptysub, window_scenery_emptysub, window_scenery_emptysub, @@ -513,6 +517,21 @@ void window_scenery_open() window->colours[2] = 0x0C; } +/* + * rct2: 0x0066DB3D +*/ +bool window_scenery_is_tool_active() { + int toolWindowClassification = RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass); + int toolWidgetIndex = RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, rct_windownumber); + + if (RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3)) + if (toolWindowClassification == WC_TOP_TOOLBAR && toolWidgetIndex == 9) + return true; + + return false; +} + + /* * rct2: 0x006E1A73 **/ @@ -525,12 +544,8 @@ void window_scenery_close() { hide_gridlines(); RCT2_CALLPROC_X(0x006CB70A, 0, 0, 0, 0, 0, 0, 0); - int toolWindowClassification = RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass); - int toolWidgetIndex = RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, rct_windownumber); - - if (RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3)) - if (toolWindowClassification == WC_TOP_TOOLBAR && toolWidgetIndex == 9) - tool_cancel(); + if (window_scenery_is_tool_active()) + tool_cancel(); } /** @@ -544,10 +559,76 @@ static void window_scenery_update(rct_window *w) int window_x = RCT2_GLOBAL(0x0142406C, int) - w->x + 0x1A; int window_y = RCT2_GLOBAL(0x01424070, int) - w->y; - if (window_y >= 0x2C) { + if (window_y < 0x2C && window_x <= w->width) { + int widgetIndex = window_find_widget_from_point(w, + RCT2_GLOBAL(0x0142406C, int), RCT2_GLOBAL(0x01424070, int)); + if (widgetIndex >= 3) { + w->scenery.var_482++; + if (w->scenery.var_482 < 8) { + w->scenery.var_482 = 0; + if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, sint8) != INPUT_STATE_SCROLL_LEFT) { + w->min_width = WINDOW_SCENERY_WIDTH; + w->max_width = WINDOW_SCENERY_WIDTH; + w->min_height = WINDOW_SCENERY_HEIGHT; + w->max_height = WINDOW_SCENERY_HEIGHT; + } + } else { + int windowHeight = w->scrolls[0].v_bottom - 1 + 0x3E; + if (windowHeight > 0x1C6) + windowHeight = 0x1C6; + if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) < 0x258){ + if (windowHeight > 0x176) + windowHeight = 0x176; + } + + w->min_width = WINDOW_SCENERY_WIDTH; + w->max_width = WINDOW_SCENERY_WIDTH; + w->min_height = windowHeight; + w->max_height = windowHeight; + } + } + } + } else { + w->scenery.var_482 = 0; + if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, sint8) != INPUT_STATE_SCROLL_LEFT) { + w->min_width = WINDOW_SCENERY_WIDTH; + w->max_width = WINDOW_SCENERY_WIDTH; + w->min_height = WINDOW_SCENERY_HEIGHT; + w->max_height = WINDOW_SCENERY_HEIGHT; } } + + // todo + //if (window_scenery_is_tool_active()) + //window_close(w); + + if (RCT2_GLOBAL(0x00F64F19, uint8) != 1) { + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = 0x17; + return; + } + + uint16 typeId = RCT2_GLOBAL(0x00F64EDC, uint8); + uint16 sceneryIndex = RCT2_ADDRESS(0x00F64EDD, uint16)[typeId]; + if (sceneryIndex == 0xFFFF) + return; + + if (sceneryIndex > 0x400) { // banner + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = 0x18; + } else if (sceneryIndex > 0x300) { // large scenery + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = + g_largeSceneryEntries[sceneryIndex - 0x300]->large_scenery.tool_id; + } else if (sceneryIndex > 0x200) { // wall + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = + g_wallSceneryEntries[sceneryIndex - 0x200]->wall.tool_id; + } else if (sceneryIndex > 0x100) { // path bit + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = + g_pathBitSceneryEntries[sceneryIndex - 0x100]->path_bit.tool_id; + } else { // small scenery + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = + g_smallSceneryEntries[sceneryIndex]->small_scenery.tool_id; + } + } /** From 8d9488f4e4ed5c7daa7dea778734adb89a7361fc Mon Sep 17 00:00:00 2001 From: qcz Date: Mon, 1 Sep 2014 20:50:53 +0200 Subject: [PATCH 10/30] add window_scenery_event_07 --- src/window_scenery.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index 608dbc4bb0..9f62e58689 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -139,6 +139,7 @@ enum { static void window_scenery_emptysub() { } static void window_scenery_close(); static void window_scenery_update(rct_window *w); +static void window_scenery_event_07(); static void window_scenery_invalidate(); static void window_scenery_paint(); static void window_scenery_tooltip(); @@ -151,7 +152,7 @@ static void* window_scenery_events[] = { (void*)0x006E1A54, // window_scenery_dropdown, window_scenery_emptysub, window_scenery_update,//(void*)0x006E1CD3, // window_scenery_update, - (void*)0x006E1B9F, // window_scenery_emptysub, + window_scenery_event_07, //(void*)0x006E1B9F, // window_scenery_emptysub, window_scenery_emptysub, window_scenery_emptysub, window_scenery_emptysub, // window_scenery_tooldown @@ -548,6 +549,20 @@ void window_scenery_close() { tool_cancel(); } +/** +* +* rct2: 0x006E1B9F +*/ +static void window_scenery_event_07() { + rct_window *w; + + window_get_register(w); + + if (w->scenery.var_480 != 0xFFFF) { + w->scenery.var_480 = 0xFFFF; + } +} + /** * * rct2: 0x006E1CD3 From 2d7881c2a232b26dc57cdd78ec41fbde282b6172 Mon Sep 17 00:00:00 2001 From: qcz Date: Mon, 1 Sep 2014 21:02:48 +0200 Subject: [PATCH 11/30] add window_scenery_dropdown, fix var_480 default value and conditions --- src/window_scenery.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index 9f62e58689..a9f6739a8b 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -138,6 +138,7 @@ enum { static void window_scenery_emptysub() { } static void window_scenery_close(); +static void window_scenery_dropdown(); static void window_scenery_update(rct_window *w); static void window_scenery_event_07(); static void window_scenery_invalidate(); @@ -149,7 +150,7 @@ static void* window_scenery_events[] = { (void*)0x006E19FC, // window_scenery_mouseup (void*)0x006E1E48, // window_scenery_resize, (void*)0x006E1A25, // window_scenery_mousedown, - (void*)0x006E1A54, // window_scenery_dropdown, + window_scenery_dropdown, //(void*)0x006E1A54, // window_scenery_dropdown, window_scenery_emptysub, window_scenery_update,//(void*)0x006E1CD3, // window_scenery_update, window_scenery_event_07, //(void*)0x006E1B9F, // window_scenery_emptysub, @@ -500,7 +501,7 @@ void window_scenery_open() RCT2_GLOBAL(0x00F64F05, uint8) = 3; RCT2_GLOBAL(0x00F64F12, uint8) = 0; RCT2_GLOBAL(0x00F64F13, uint8) = 0; - window->scenery.var_480 = 0xFFFF; + window->scenery.var_480 = -1; window->scenery.var_482 = 0; window_push_others_below(window); RCT2_GLOBAL(0x00F64F0D, uint8) = 0; @@ -549,6 +550,31 @@ void window_scenery_close() { tool_cancel(); } +/** +* +* rct2: 0x006E1A54 +*/ +static void window_scenery_dropdown() { + rct_window* w; + short widgetIndex, dropdownIndex; + window_dropdown_get_registers(w, widgetIndex, dropdownIndex); + + if (dropdownIndex == -1) + return; + + if (widgetIndex == WIDX_SCENERY_COLORBUTTON1) { + RCT2_GLOBAL(0x00F64F06, uint8) = dropdownIndex; + } + else if (widgetIndex == WIDX_SCENERY_COLORBUTTON2) { + RCT2_GLOBAL(0x00F64F07, uint8) = dropdownIndex; + } + else if (widgetIndex == WIDX_SCENERY_COLORBUTTON3) { + RCT2_GLOBAL(0x00F64F08, uint8) = dropdownIndex; + } + + window_invalidate(w); +} + /** * * rct2: 0x006E1B9F @@ -558,8 +584,8 @@ static void window_scenery_event_07() { window_get_register(w); - if (w->scenery.var_480 != 0xFFFF) { - w->scenery.var_480 = 0xFFFF; + if (w->scenery.var_480 != -1) { + w->scenery.var_480 = -1; } } @@ -815,7 +841,7 @@ void window_scenery_paint() { selectedTab); uint16 bp = w->scenery.var_480; - if (bp == 0xFFFF) { + if (bp == -1) { if (RCT2_GLOBAL(0x00F64F19, uint8) & 1) // repaint colored scenery tool is on return; @@ -845,7 +871,7 @@ void window_scenery_paint() { price = sceneryEntry->small_scenery.price * 10; } - if (w->scenery.var_480 == 0xFFFF && RCT2_GLOBAL(0x00F64EB4, uint32) != 0x80000000) { + if (w->scenery.var_480 == -1 && RCT2_GLOBAL(0x00F64EB4, uint32) != 0x80000000) { price = RCT2_GLOBAL(0x00F64EB4, uint32); } From 804765f8ad710376613c76660567af8883a8eefc Mon Sep 17 00:00:00 2001 From: qcz Date: Mon, 1 Sep 2014 21:38:35 +0200 Subject: [PATCH 12/30] add window_scenery_mouseup and window_scenery_resize --- src/window_scenery.c | 77 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index a9f6739a8b..234638b7e6 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -138,6 +138,8 @@ enum { static void window_scenery_emptysub() { } static void window_scenery_close(); +static void window_scenery_mouseup(); +static void window_scenery_resize(); static void window_scenery_dropdown(); static void window_scenery_update(rct_window *w); static void window_scenery_event_07(); @@ -147,8 +149,8 @@ static void window_scenery_tooltip(); static void* window_scenery_events[] = { window_scenery_close, //(void*)0x006E1A73, // window_scenery_close - (void*)0x006E19FC, // window_scenery_mouseup - (void*)0x006E1E48, // window_scenery_resize, + window_scenery_mouseup, //(void*)0x006E19FC, // window_scenery_mouseup + window_scenery_resize, //(void*)0x006E1E48, // window_scenery_resize, (void*)0x006E1A25, // window_scenery_mousedown, window_scenery_dropdown, //(void*)0x006E1A54, // window_scenery_dropdown, window_scenery_emptysub, @@ -542,7 +544,7 @@ void window_scenery_close() { window_get_register(w); - RCT2_CALLPROC_EBPSAFE(0x6E2712); + RCT2_CALLPROC_EBPSAFE(0x006E2712); hide_gridlines(); RCT2_CALLPROC_X(0x006CB70A, 0, 0, 0, 0, 0, 0, 0); @@ -550,6 +552,71 @@ void window_scenery_close() { tool_cancel(); } +/** +* +* rct2: 0x006BD94C +*/ +static void window_scenery_mouseup() +{ + short widgetIndex; + rct_window *w; + + window_widget_get_registers(w, widgetIndex); + + switch (widgetIndex) { + case WIDX_SCENERY_CLOSE: + window_close(w); + break; + case WIDX_SCENERY_FLATBUTTON1: + RCT2_GLOBAL(0x00F64F05, uint8)++; + RCT2_GLOBAL(0x00F64F05, uint8) &= 3; + RCT2_CALLPROC_EBPSAFE(0x006E2712); + window_invalidate(w); + break; + case WIDX_SCENERY_FLATBUTTON2: + RCT2_GLOBAL(0x00F64F19, uint8) ^= 1; + window_invalidate(w); + break; + case WIDX_SCENERY_FLATBUTTON3: + RCT2_GLOBAL(0x00F64F1A, uint8) ^= 1; + window_invalidate(w); + break; + } +} + +/** +* +* rct2: 0x006E1E48 +*/ +static void window_scenery_resize() +{ + rct_window *w; + + window_get_register(w); + + if (w->width < w->min_width) { + w->width = w->min_width; + window_invalidate(w); + } + + if (w->width > w->max_width) { + w->width = w->max_width; + window_invalidate(w); + } + + if (w->height < w->min_height) { + w->height = w->min_height; + window_invalidate(w); + RCT2_CALLPROC_X(0x006E1EB4, 0, 0, 0, 0, (int)w, 0, 0); + } + + if (w->height > w->max_height) { + w->height = w->max_height; + window_invalidate(w); + RCT2_CALLPROC_X(0x006E1EB4, 0, 0, 0, 0, (int)w, 0, 0); + } +} + /** * * rct2: 0x006E1A54 @@ -840,14 +907,14 @@ void window_scenery_paint() { w->y + window_scenery_widgets[selectedTab].top, selectedTab); - uint16 bp = w->scenery.var_480; + sint16 bp = w->scenery.var_480; if (bp == -1) { if (RCT2_GLOBAL(0x00F64F19, uint8) & 1) // repaint colored scenery tool is on return; bp = RCT2_ADDRESS(0x00F64EDD, uint16)[typeId]; - if (bp == 0xFFFF) + if (bp == -1) return; } From 087b56babe4e25f9f4a8c63b2b8c6c13511266f1 Mon Sep 17 00:00:00 2001 From: qcz Date: Mon, 1 Sep 2014 21:55:08 +0200 Subject: [PATCH 13/30] add window_scenery_mousedown --- src/window_scenery.c | 29 ++++++++++++++++++++++++++++- src/window_staff.c | 2 +- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index 234638b7e6..f8d344d7d4 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -140,6 +140,7 @@ static void window_scenery_emptysub() { } static void window_scenery_close(); static void window_scenery_mouseup(); static void window_scenery_resize(); +static void window_scenery_mousedown(int widgetIndex, rct_window* w, rct_widget* widget); static void window_scenery_dropdown(); static void window_scenery_update(rct_window *w); static void window_scenery_event_07(); @@ -151,7 +152,7 @@ static void* window_scenery_events[] = { window_scenery_close, //(void*)0x006E1A73, // window_scenery_close window_scenery_mouseup, //(void*)0x006E19FC, // window_scenery_mouseup window_scenery_resize, //(void*)0x006E1E48, // window_scenery_resize, - (void*)0x006E1A25, // window_scenery_mousedown, + window_scenery_mousedown,//(void*)0x006E1A25, // window_scenery_mousedown, window_scenery_dropdown, //(void*)0x006E1A54, // window_scenery_dropdown, window_scenery_emptysub, window_scenery_update,//(void*)0x006E1CD3, // window_scenery_update, @@ -617,6 +618,32 @@ static void window_scenery_resize() } } +/** +* +* rct2: 0x006E1A25 +*/ +static void window_scenery_mousedown(int widgetIndex, rct_window* w, rct_widget* widget) { + int eax; + + switch (widgetIndex) { + case WIDX_SCENERY_COLORBUTTON1: + eax = (RCT2_GLOBAL(0xF64F06, uint8) << 8) + 0x80 + w->colours[1]; + RCT2_CALLPROC_X(0x006ED43D, eax, 0, 0, widgetIndex, (int)w, (int)widgetIndex, 0xFFFFFFFF); + break; + case WIDX_SCENERY_COLORBUTTON2: + eax = (RCT2_GLOBAL(0xF64F07, uint8) << 8) + 0x80 + w->colours[1]; + RCT2_CALLPROC_X(0x006ED43D, eax, 0, 0, widgetIndex, (int)w, (int)widgetIndex, 0xFFFFFFFF); + break; + } + + if (widgetIndex >= WIDX_SCENERY_TAB_1 && widgetIndex <= WIDX_SCENERY_TAB_20) { + RCT2_GLOBAL(0x00F64EDC, uint8) = widgetIndex - WIDX_SCENERY_TAB_1; + window_invalidate(w); + RCT2_GLOBAL(0x00F64EB4, uint32) = 0x80000000; + RCT2_CALLPROC_X(0x006E1EB4, 0, 0, 0, 0, (int)w, 0, 0); + } +} + /** * * rct2: 0x006E1A54 diff --git a/src/window_staff.c b/src/window_staff.c index 810667b679..4fc0b0888c 100644 --- a/src/window_staff.c +++ b/src/window_staff.c @@ -260,7 +260,7 @@ static void window_staff_resize() * * rct2: 0x006BD971 */ -static void window_staff_mousedown(int widgetIndex, rct_window*w, rct_widget* widget) +static void window_staff_mousedown(int widgetIndex, rct_window* w, rct_widget* widget) { short newSelectedTab; int eax; From 6b92eb0d725306fd28e7e6917cc41e4292957f49 Mon Sep 17 00:00:00 2001 From: qcz Date: Mon, 1 Sep 2014 22:20:27 +0200 Subject: [PATCH 14/30] add window_scenery_scrollgetsize, identify scenery entry field --- src/window_scenery.c | 101 ++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index f8d344d7d4..aa2a438932 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -36,49 +36,49 @@ typedef struct { uint8 pad_02[4]; - uint8 flags; // 0x06 - uint8 flags2; // 0x07 + uint8 flags; // 0x06 + uint8 flags2; // 0x07 uint8 pad_08[3]; - uint8 tool_id; // 0x0B - uint16 price; // 0x0C + uint8 tool_id; // 0x0B + uint16 price; // 0x0C uint8 pad_0E[12]; - uint8 var_1A; // 0x1A + uint8 scenery_tab_id; // 0x1A } rct_small_scenery_entry; typedef struct { uint8 pad_02[4]; - uint8 tool_id; // 0x06 - uint8 flags; // 0x07 - uint16 price; // 0x08 + uint8 tool_id; // 0x06 + uint8 flags; // 0x07 + uint16 price; // 0x08 uint8 pad_0A[6]; - uint8 var_10; // 0x10 + uint8 scenery_tab_id; // 0x10 } rct_large_scenery_entry; typedef struct { uint8 pad_02[4]; - uint8 tool_id; // 0x06 - uint8 flags; // 0x07 + uint8 tool_id; // 0x06 + uint8 flags; // 0x07 uint8 pad_08; - uint8 flags2; // 0x09 - uint16 price; // 0x0A - uint8 var_0C; // 0x0C + uint8 flags2; // 0x09 + uint16 price; // 0x0A + uint8 scenery_tab_id; // 0x0C } rct_wall_scenery_entry; typedef struct { uint8 pad_02[7]; - uint8 tool_id; // 0x09 - uint16 price; // 0x0A - uint8 var_0C; // 0x0C + uint8 tool_id; // 0x09 + uint16 price; // 0x0A + uint8 scenery_tab_id; // 0x0C } rct_path_bit_scenery_entry; typedef struct { uint16 var_02; uint16 var_04; uint8 var_06; - uint8 flags; // 0x07 - uint16 price; // 0x08 - uint8 var_0A; // 0x0A + uint8 flags; // 0x07 + uint16 price; // 0x08 + uint8 scenery_tab_id; // 0x0A } rct_banner_scenery_entry; typedef struct { @@ -90,21 +90,6 @@ typedef struct { rct_path_bit_scenery_entry path_bit; rct_banner_scenery_entry banner; }; - /*uint16 var_02; - uint16 var_04; - uint8 var_06; - uint8 var_07; - uint8 var_08; - uint8 var_09; - uint16 var_0A; - uint16 var_0C; - uint16 var_0E; - uint16 var_10; - uint16 var_12; - uint16 var_14; - uint16 var_16; - uint16 var_18; - uint16 var_1A;*/ } rct_scenery_entry; #define g_smallSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_SMALL_SCENERY_ENTRIES, rct_scenery_entry*) @@ -144,9 +129,10 @@ static void window_scenery_mousedown(int widgetIndex, rct_window* w, rct_widget* static void window_scenery_dropdown(); static void window_scenery_update(rct_window *w); static void window_scenery_event_07(); +static void window_scenery_scrollgetsize(); +static void window_scenery_tooltip(); static void window_scenery_invalidate(); static void window_scenery_paint(); -static void window_scenery_tooltip(); static void* window_scenery_events[] = { window_scenery_close, //(void*)0x006E1A73, // window_scenery_close @@ -164,7 +150,7 @@ static void* window_scenery_events[] = { window_scenery_emptysub, window_scenery_emptysub, window_scenery_emptysub, - (void*)0x006E1A91, // window_scenery_scrollgetsize, + window_scenery_scrollgetsize, //(void*)0x006E1A91, // window_scenery_scrollgetsize, (void*)0x006E1C4A, // window_scenery_scrollmousedown, window_scenery_emptysub, (void*)0x006E1BB8, // window_scenery_scrollmouseover, @@ -250,10 +236,10 @@ static rct_widget window_scenery_widgets[] = { }; -void init_scenery_entry(rct_scenery_entry *sceneryEntry, int index, uint8 unknownVar) { +void init_scenery_entry(rct_scenery_entry *sceneryEntry, int index, uint8 sceneryTabId) { if (RCT2_ADDRESS(0x01357BD0, sint32)[index >> 5] & (1 << (index & 0x1F))) { - if (unknownVar != 0xFF) { - uint32 esi = RCT2_ADDRESS(0x00F64F2C, uint32)[unknownVar]; + if (sceneryTabId != 0xFF) { + uint32 esi = RCT2_ADDRESS(0x00F64F2C, uint32)[sceneryTabId]; for (int ebx = 0; ebx < 0x80; ebx++) { if (RCT2_ADDRESS(esi, uint16)[ebx] == 0xFFFF) @@ -340,7 +326,7 @@ void init_scenery() { continue; rct_scenery_entry* sceneryEntry = g_smallSceneryEntries[edi]; - init_scenery_entry(sceneryEntry, edi, sceneryEntry->small_scenery.var_1A); + init_scenery_entry(sceneryEntry, edi, sceneryEntry->small_scenery.scenery_tab_id); } // large scenery @@ -351,7 +337,7 @@ void init_scenery() { continue; rct_scenery_entry* sceneryEntry = g_largeSceneryEntries[largeSceneryIndex]; - init_scenery_entry(sceneryEntry, edi, sceneryEntry->large_scenery.var_10); + init_scenery_entry(sceneryEntry, edi, sceneryEntry->large_scenery.scenery_tab_id); } // walls @@ -362,7 +348,7 @@ void init_scenery() { continue; rct_scenery_entry* sceneryEntry = g_wallSceneryEntries[wallSceneryIndex]; - init_scenery_entry(sceneryEntry, edi, sceneryEntry->wall.var_0C); + init_scenery_entry(sceneryEntry, edi, sceneryEntry->wall.scenery_tab_id); } // banners @@ -373,7 +359,7 @@ void init_scenery() { continue; rct_scenery_entry* sceneryEntry = g_bannerSceneryEntries[bannerIndex]; - init_scenery_entry(sceneryEntry, edi, sceneryEntry->banner.var_0A); + init_scenery_entry(sceneryEntry, edi, sceneryEntry->banner.scenery_tab_id); } // path bits @@ -384,7 +370,7 @@ void init_scenery() { continue; rct_scenery_entry* sceneryEntry = g_pathBitSceneryEntries[bannerIndex]; - init_scenery_entry(sceneryEntry, edi, sceneryEntry->path_bit.var_0C); + init_scenery_entry(sceneryEntry, edi, sceneryEntry->path_bit.scenery_tab_id); } for (int widgetIndex = WIDX_SCENERY_TAB_1; widgetIndex < WIDX_SCENERY_LIST; widgetIndex++) @@ -766,6 +752,31 @@ static void window_scenery_update(rct_window *w) } +void window_scenery_scrollgetsize() { + rct_window *w; + + window_get_register(w); + + uint32 sceneryTabId = RCT2_ADDRESS(0x00F64F2C, uint32)[RCT2_GLOBAL(0x00F64EDC, uint8)]; + + int items = 0; + while (RCT2_ADDRESS(sceneryTabId, sint16)[items] != -1) + items++; + + items += 8; + int rows = items / 9; + if (rows == 0) + rows++; + + int scrollHeight = rows * 80; + +#ifdef _MSC_VER + __asm mov edx, scrollHeight +#else + __asm__("mov edx, %[scrollHeight] " : [scrollHeight] "+m" (scrollHeight)); +#endif +} + /** * * rct2: 0x006E1C05 From 49485376543ff3640230ed8629a4cae05a94fe3c Mon Sep 17 00:00:00 2001 From: qcz Date: Mon, 1 Sep 2014 22:56:22 +0200 Subject: [PATCH 15/30] add window_scenery_scrollmousedown, fix scenery_mousedown crash --- src/window_scenery.c | 54 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index aa2a438932..4edf54b04f 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -21,6 +21,7 @@ #include #include #include "addresses.h" +#include "audio.h" #include "game.h" #include "map.h" #include "gfx.h" @@ -130,6 +131,7 @@ static void window_scenery_dropdown(); static void window_scenery_update(rct_window *w); static void window_scenery_event_07(); static void window_scenery_scrollgetsize(); +static void window_scenery_scrollmousedown(); static void window_scenery_tooltip(); static void window_scenery_invalidate(); static void window_scenery_paint(); @@ -151,7 +153,7 @@ static void* window_scenery_events[] = { window_scenery_emptysub, window_scenery_emptysub, window_scenery_scrollgetsize, //(void*)0x006E1A91, // window_scenery_scrollgetsize, - (void*)0x006E1C4A, // window_scenery_scrollmousedown, + window_scenery_scrollmousedown,//(void*)0x006E1C4A, // window_scenery_scrollmousedown, window_scenery_emptysub, (void*)0x006E1BB8, // window_scenery_scrollmouseover, window_scenery_emptysub, @@ -614,11 +616,15 @@ static void window_scenery_mousedown(int widgetIndex, rct_window* w, rct_widget* switch (widgetIndex) { case WIDX_SCENERY_COLORBUTTON1: eax = (RCT2_GLOBAL(0xF64F06, uint8) << 8) + 0x80 + w->colours[1]; - RCT2_CALLPROC_X(0x006ED43D, eax, 0, 0, widgetIndex, (int)w, (int)widgetIndex, 0xFFFFFFFF); + RCT2_CALLPROC_X(0x006ED43D, eax, 0, 0, widgetIndex, (int)w, (int)widget, 0xFFFFFFFF); break; case WIDX_SCENERY_COLORBUTTON2: eax = (RCT2_GLOBAL(0xF64F07, uint8) << 8) + 0x80 + w->colours[1]; - RCT2_CALLPROC_X(0x006ED43D, eax, 0, 0, widgetIndex, (int)w, (int)widgetIndex, 0xFFFFFFFF); + RCT2_CALLPROC_X(0x006ED43D, eax, 0, 0, widgetIndex, (int)w, (int)widget, 0xFFFFFFFF); + break; + case WIDX_SCENERY_COLORBUTTON3: + eax = (RCT2_GLOBAL(0xF64F08, uint8) << 8) + 0x80 + w->colours[1]; + RCT2_CALLPROC_X(0x006ED43D, eax, 0, 0, widgetIndex, (int)w, (int)widget, 0xFFFFFFFF); break; } @@ -752,15 +758,19 @@ static void window_scenery_update(rct_window *w) } +/** +* +* rct2: 0x006E1A91 +*/ void window_scenery_scrollgetsize() { rct_window *w; window_get_register(w); - uint32 sceneryTabId = RCT2_ADDRESS(0x00F64F2C, uint32)[RCT2_GLOBAL(0x00F64EDC, uint8)]; + uint32 sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[RCT2_GLOBAL(0x00F64EDC, uint8)]; int items = 0; - while (RCT2_ADDRESS(sceneryTabId, sint16)[items] != -1) + while (RCT2_ADDRESS(sceneryTabItems, sint16)[items] != -1) items++; items += 8; @@ -777,6 +787,40 @@ void window_scenery_scrollgetsize() { #endif } +/** +* +* rct2: 0x006E1C4A +*/ +void window_scenery_scrollmousedown() { + short x, y; + rct_window *w; + rct_peep *peep; + + window_scrollmouse_get_registers(w, x, y); + + int tabSceneryIndex = x / 66 + (y / 80) * 9; + uint8 tabIndex = RCT2_GLOBAL(0x00F64EDC, uint8); + uint32 sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[tabIndex]; + + int itemCounter = 0; + sint16 sceneryIndex = 0; + while (itemCounter <= tabSceneryIndex) { + sceneryIndex = RCT2_ADDRESS(sceneryTabItems, sint16)[itemCounter]; + if (sceneryIndex == -1) + return; + + itemCounter++; + } + + RCT2_ADDRESS(0x00F64EDD, uint16)[tabIndex] = sceneryIndex; + + RCT2_GLOBAL(0x00F64F19, uint8) &= 0xFE; + sound_play_panned(4, (w->width >> 1) + w->x); + w->scenery.var_482 = 0xFFF0; + RCT2_GLOBAL(0x00F64EB4, uint32) = 0x80000000; + window_invalidate(w); +} + /** * * rct2: 0x006E1C05 From ac04de3e3ce42bef3f816834bf565fc53bbde9e7 Mon Sep 17 00:00:00 2001 From: qcz Date: Mon, 1 Sep 2014 23:09:22 +0200 Subject: [PATCH 16/30] add window_scenery_scrollmouseover, move common code with scrollmousedown to a function --- src/window.h | 2 +- src/window_scenery.c | 68 ++++++++++++++++++++++++++++++-------------- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/window.h b/src/window.h index e6c79619e6..53f6459e9a 100644 --- a/src/window.h +++ b/src/window.h @@ -163,7 +163,7 @@ typedef struct { } ride_variables; typedef struct { - sint16 var_480; + sint16 selected_scenery_id; sint32 var_482; } scenery_variables; diff --git a/src/window_scenery.c b/src/window_scenery.c index 4edf54b04f..2919b59b82 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -132,6 +132,7 @@ static void window_scenery_update(rct_window *w); static void window_scenery_event_07(); static void window_scenery_scrollgetsize(); static void window_scenery_scrollmousedown(); +static void window_scenery_scrollmouseover(); static void window_scenery_tooltip(); static void window_scenery_invalidate(); static void window_scenery_paint(); @@ -155,7 +156,7 @@ static void* window_scenery_events[] = { window_scenery_scrollgetsize, //(void*)0x006E1A91, // window_scenery_scrollgetsize, window_scenery_scrollmousedown,//(void*)0x006E1C4A, // window_scenery_scrollmousedown, window_scenery_emptysub, - (void*)0x006E1BB8, // window_scenery_scrollmouseover, + window_scenery_scrollmouseover, //(void*)0x006E1BB8, // window_scenery_scrollmouseover, window_scenery_emptysub, window_scenery_emptysub, window_scenery_emptysub, @@ -492,7 +493,7 @@ void window_scenery_open() RCT2_GLOBAL(0x00F64F05, uint8) = 3; RCT2_GLOBAL(0x00F64F12, uint8) = 0; RCT2_GLOBAL(0x00F64F13, uint8) = 0; - window->scenery.var_480 = -1; + window->scenery.selected_scenery_id = -1; window->scenery.var_482 = 0; window_push_others_below(window); RCT2_GLOBAL(0x00F64F0D, uint8) = 0; @@ -670,8 +671,8 @@ static void window_scenery_event_07() { window_get_register(w); - if (w->scenery.var_480 != -1) { - w->scenery.var_480 = -1; + if (w->scenery.selected_scenery_id != -1) { + w->scenery.selected_scenery_id = -1; } } @@ -787,6 +788,24 @@ void window_scenery_scrollgetsize() { #endif } +short get_scenery_id_by_cursor_pos(short x, short y) { + int tabSceneryIndex = x / 66 + (y / 80) * 9; + uint8 tabIndex = RCT2_GLOBAL(0x00F64EDC, uint8); + uint32 sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[tabIndex]; + + int itemCounter = 0; + sint16 sceneryId = 0; + while (itemCounter <= tabSceneryIndex) { + sceneryId = RCT2_ADDRESS(sceneryTabItems, sint16)[itemCounter]; + if (sceneryId == -1) + return -1; + + itemCounter++; + } + + return sceneryId; +} + /** * * rct2: 0x006E1C4A @@ -794,25 +813,15 @@ void window_scenery_scrollgetsize() { void window_scenery_scrollmousedown() { short x, y; rct_window *w; - rct_peep *peep; window_scrollmouse_get_registers(w, x, y); - int tabSceneryIndex = x / 66 + (y / 80) * 9; + short sceneryId = get_scenery_id_by_cursor_pos(x, y); + if (sceneryId = -1) + return; + uint8 tabIndex = RCT2_GLOBAL(0x00F64EDC, uint8); - uint32 sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[tabIndex]; - - int itemCounter = 0; - sint16 sceneryIndex = 0; - while (itemCounter <= tabSceneryIndex) { - sceneryIndex = RCT2_ADDRESS(sceneryTabItems, sint16)[itemCounter]; - if (sceneryIndex == -1) - return; - - itemCounter++; - } - - RCT2_ADDRESS(0x00F64EDD, uint16)[tabIndex] = sceneryIndex; + RCT2_ADDRESS(0x00F64EDD, uint16)[tabIndex] = sceneryId; RCT2_GLOBAL(0x00F64F19, uint8) &= 0xFE; sound_play_panned(4, (w->width >> 1) + w->x); @@ -821,6 +830,23 @@ void window_scenery_scrollmousedown() { window_invalidate(w); } +/** +* +* rct2: 0x006E1BB8 +*/ +void window_scenery_scrollmouseover() { + short x, y; + rct_window *w; + + window_scrollmouse_get_registers(w, x, y); + short sceneryId = get_scenery_id_by_cursor_pos(x, y); + if (sceneryId != -1) { + w->scenery.selected_scenery_id = sceneryId; + window_invalidate(w); + } + +} + /** * * rct2: 0x006E1C05 @@ -989,7 +1015,7 @@ void window_scenery_paint() { w->y + window_scenery_widgets[selectedTab].top, selectedTab); - sint16 bp = w->scenery.var_480; + sint16 bp = w->scenery.selected_scenery_id; if (bp == -1) { if (RCT2_GLOBAL(0x00F64F19, uint8) & 1) // repaint colored scenery tool is on return; @@ -1020,7 +1046,7 @@ void window_scenery_paint() { price = sceneryEntry->small_scenery.price * 10; } - if (w->scenery.var_480 == -1 && RCT2_GLOBAL(0x00F64EB4, uint32) != 0x80000000) { + if (w->scenery.selected_scenery_id == -1 && RCT2_GLOBAL(0x00F64EB4, uint32) != 0x80000000) { price = RCT2_GLOBAL(0x00F64EB4, uint32); } From c996dba32a06348583f9a425ee2ca3318d0af94e Mon Sep 17 00:00:00 2001 From: qcz Date: Wed, 3 Sep 2014 18:59:03 +0200 Subject: [PATCH 17/30] Fix the final bug in clip_drawpixelinfo --- src/gfx.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index fae14f1a7e..ffdb445fdb 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -2265,14 +2265,13 @@ rct_drawpixelinfo* clip_drawpixelinfo(rct_drawpixelinfo* dpi, int left, int widt newDrawPixelInfo->height = dpi->height; newDrawPixelInfo->pitch = dpi->pitch; newDrawPixelInfo->zoom_level = 0; - newDrawPixelInfo->var_0F = dpi->var_0F; if (left > newDrawPixelInfo->x) { - uint16 newWidth = left - newDrawPixelInfo->x; - newDrawPixelInfo->width -= newWidth; + uint16 clippedFromLeft = left - newDrawPixelInfo->x; + newDrawPixelInfo->width -= clippedFromLeft; newDrawPixelInfo->x = left; - newDrawPixelInfo->pitch += newWidth; - newDrawPixelInfo->bits += newWidth; + newDrawPixelInfo->pitch += clippedFromLeft; + newDrawPixelInfo->bits += clippedFromLeft; } int stickOutWidth = newDrawPixelInfo->x + newDrawPixelInfo->width - right; @@ -2282,10 +2281,10 @@ rct_drawpixelinfo* clip_drawpixelinfo(rct_drawpixelinfo* dpi, int left, int widt } if (top > newDrawPixelInfo->y) { - uint16 newHeight = top - newDrawPixelInfo->y; - newDrawPixelInfo->height = newHeight; + uint16 clippedFromTop = top - newDrawPixelInfo->y; + newDrawPixelInfo->height -= clippedFromTop; newDrawPixelInfo->y = top; - int bitsPlus = (newDrawPixelInfo->pitch + newDrawPixelInfo->width) * newHeight; + uint32 bitsPlus = (newDrawPixelInfo->pitch + newDrawPixelInfo->width) * clippedFromTop; newDrawPixelInfo->bits += bitsPlus; } From 9742ccc64bda7873ee72f4359cf8732a64530b15 Mon Sep 17 00:00:00 2001 From: qcz Date: Wed, 3 Sep 2014 21:13:42 +0200 Subject: [PATCH 18/30] implement window_scenery_scrollpaint --- src/window_scenery.c | 240 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 205 insertions(+), 35 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index 2919b59b82..b4131fc1bc 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -36,18 +36,38 @@ #define WINDOW_SCENERY_HEIGHT 0x8E typedef struct { - uint8 pad_02[4]; - uint8 flags; // 0x06 - uint8 flags2; // 0x07 - uint8 pad_08[3]; + uint32 flags; // 0x06 + uint8 height; // 0x0A uint8 tool_id; // 0x0B uint16 price; // 0x0C uint8 pad_0E[12]; uint8 scenery_tab_id; // 0x1A } rct_small_scenery_entry; +typedef enum { + SMALL_SCENERY_FLAG1 = (1 << 0), // 0x1 + SMALL_SCENERY_FLAG2 = (1 << 1), // 0x2 + SMALL_SCENERY_FLAG3 = (1 << 2) , // 0x4 + SMALL_SCENERY_FLAG4 = (1 << 3), // 0x8 + SMALL_SCENERY_FLAG5 = (1 << 4), // 0x10 + SMALL_SCENERY_FLAG6 = (1 << 5), // 0x20 + SMALL_SCENERY_FLAG7 = (1 << 6), // 0x40 + SMALL_SCENERY_FLAG8 = (1 << 7), // 0x80 + SMALL_SCENERY_FLAG9 = (1 << 8), // 0x100 + SMALL_SCENERY_FLAG10 = (1 << 9), // 0x200 + SMALL_SCENERY_HAS_PRIMARY_COLOUR = (1 << 10), // 0x400 + SMALL_SCENERY_FLAG12 = (1 << 11), // 0x800 + SMALL_SCENERY_FLAG13 = (1 << 12), // 0x1000 + SMALL_SCENERY_FLAG14 = (1 << 13), // 0x2000 + SMALL_SCENERY_FLAG15 = (1 << 14), // 0x4000 + SMALL_SCENERY_FLAG16 = (1 << 15), // 0x8000 + SMALL_SCENERY_FLAG17 = (1 << 16), // 0x10000 + SMALL_SCENERY_FLAG18 = (1 << 17), // 0x20000 + SMALL_SCENERY_FLAG19 = (1 << 18), // 0x40000 + SMALL_SCENERY_HAS_SECONDARY_COLOUR = (1 << 19), // 0x80000 +} SMALL_SCENERY_FLAGS; + typedef struct { - uint8 pad_02[4]; uint8 tool_id; // 0x06 uint8 flags; // 0x07 uint16 price; // 0x08 @@ -57,25 +77,33 @@ typedef struct { typedef struct { - uint8 pad_02[4]; uint8 tool_id; // 0x06 uint8 flags; // 0x07 - uint8 pad_08; + uint8 height; // 0x08 uint8 flags2; // 0x09 uint16 price; // 0x0A uint8 scenery_tab_id; // 0x0C } rct_wall_scenery_entry; +typedef enum { + WALL_SCENERY_FLAG1 = (1 << 0), // 0x1 + WALL_SCENERY_FLAG2 = (1 << 1), // 0x2 + WALL_SCENERY_FLAG3 = (1 << 2), // 0x4 + WALL_SCENERY_FLAG4 = (1 << 3), // 0x8 + WALL_SCENERY_FLAG5 = (1 << 4), // 0x10 + WALL_SCENERY_FLAG6 = (1 << 5), // 0x20 + WALL_SCENERY_HAS_SECONDARY_COLOUR = (1 << 6), // 0x40 + WALL_SCENERY_HAS_TERNARY_COLOUR = (1 << 7), // 0x80 +} WALL_SCENERY_FLAGS; + typedef struct { - uint8 pad_02[7]; + uint8 pad_02[3]; uint8 tool_id; // 0x09 uint16 price; // 0x0A uint8 scenery_tab_id; // 0x0C } rct_path_bit_scenery_entry; typedef struct { - uint16 var_02; - uint16 var_04; uint8 var_06; uint8 flags; // 0x07 uint16 price; // 0x08 @@ -83,7 +111,8 @@ typedef struct { } rct_banner_scenery_entry; typedef struct { - rct_string_id name; + rct_string_id name; // 0x00 + uint32 image; // 0x02 union { rct_small_scenery_entry small_scenery; rct_large_scenery_entry large_scenery; @@ -136,6 +165,7 @@ static void window_scenery_scrollmouseover(); static void window_scenery_tooltip(); static void window_scenery_invalidate(); static void window_scenery_paint(); +static void window_scenery_scrollpaint(); static void* window_scenery_events[] = { window_scenery_close, //(void*)0x006E1A73, // window_scenery_close @@ -165,7 +195,7 @@ static void* window_scenery_events[] = { window_scenery_emptysub, window_scenery_invalidate, //(void*)0x006E118B, // window_scenery_invalidate, window_scenery_paint, // (void*)0x006E1462, // window_scenery_paint, - (void*)0x006E15ED, // window_scenery_scrollpaint, + window_scenery_scrollpaint,//(void*)0x006E15ED, // window_scenery_scrollpaint, }; @@ -242,25 +272,25 @@ static rct_widget window_scenery_widgets[] = { void init_scenery_entry(rct_scenery_entry *sceneryEntry, int index, uint8 sceneryTabId) { if (RCT2_ADDRESS(0x01357BD0, sint32)[index >> 5] & (1 << (index & 0x1F))) { if (sceneryTabId != 0xFF) { - uint32 esi = RCT2_ADDRESS(0x00F64F2C, uint32)[sceneryTabId]; + uint32 sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[sceneryTabId]; for (int ebx = 0; ebx < 0x80; ebx++) { - if (RCT2_ADDRESS(esi, uint16)[ebx] == 0xFFFF) + if (RCT2_ADDRESS(sceneryTabItems, uint16)[ebx] == 0xFFFF) { - RCT2_ADDRESS(esi, uint16)[ebx] = index; - RCT2_ADDRESS(esi, uint16)[ebx + 1] = 0xFFFF; + RCT2_ADDRESS(sceneryTabItems, uint16)[ebx] = index; + RCT2_ADDRESS(sceneryTabItems, uint16)[ebx + 1] = 0xFFFF; return; } } } for (int ecx = 0; ecx < 0x13; ecx++) { - int baseEdx = RCT2_ADDRESS(0x00F64F2C, uint32)[ecx]; + int sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[ecx]; int counter = 0; - while (RCT2_ADDRESS(baseEdx, uint16)[counter] != 0xFFFF) + while (RCT2_ADDRESS(sceneryTabItems, uint16)[counter] != 0xFFFF) { - if (RCT2_ADDRESS(baseEdx, uint16)[counter] == index) { + if (RCT2_ADDRESS(sceneryTabItems, uint16)[counter] == index) { ecx = 0x13; return; } @@ -296,8 +326,8 @@ void init_scenery() { uint32 dword_F663A4 = 0; for (int edi = 0; edi < 0x14; edi++) { - int esi = RCT2_ADDRESS(0x00F64F2C, uint32)[edi]; - RCT2_GLOBAL(esi, uint16) = 0xFFFF; + int sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[edi]; + RCT2_GLOBAL(sceneryTabItems, uint16) = 0xFFFF; if (edi == 13) continue; @@ -314,9 +344,9 @@ void init_scenery() { uint32 ecx = RCT2_ADDRESS(0x01357BD0, uint32)[ax >> 5]; uint32 edx = 1 << (ax & 0x1F); if (ecx & edx) { - RCT2_GLOBAL(esi, uint16) = ax; - esi += 2; - RCT2_GLOBAL(esi, uint16) = 0xFFFF; + RCT2_GLOBAL(sceneryTabItems, uint16) = ax; + sceneryTabItems += 2; + RCT2_GLOBAL(sceneryTabItems, uint16) = 0xFFFF; } else { dword_F663A4 |= (1 << edi); } @@ -414,10 +444,10 @@ void init_scenery() { for (int ebx = 0; ebx < ebp; ebx += 4) { uint32 tabIndex = stuff[ebx]; rct_widget* currentTab = &window_scenery_widgets[tabIndex + WIDX_SCENERY_TAB_1]; - int eax = RCT2_ADDRESS(0x00F64F2C, uint32)[tabIndex]; + int sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[tabIndex]; if (cx != 3 || tabIndex == 0x13) { - if (RCT2_GLOBAL(eax, uint16) == 0xFFFF) + if (RCT2_GLOBAL(sceneryTabItems, uint16) == 0xFFFF) continue; if (dword_F663A4 & (1 << tabIndex)) @@ -490,7 +520,7 @@ void window_scenery_open() window_init_scroll_widgets(window); RCT2_CALLPROC_X(0x006E1EB4, 0, 0, 0, 0, (int)window, 0, 0); show_gridlines(); - RCT2_GLOBAL(0x00F64F05, uint8) = 3; + RCT2_GLOBAL(0x00F64F05, uint8) = 3; // rotation RCT2_GLOBAL(0x00F64F12, uint8) = 0; RCT2_GLOBAL(0x00F64F13, uint8) = 0; window->scenery.selected_scenery_id = -1; @@ -817,7 +847,7 @@ void window_scenery_scrollmousedown() { window_scrollmouse_get_registers(w, x, y); short sceneryId = get_scenery_id_by_cursor_pos(x, y); - if (sceneryId = -1) + if (sceneryId == -1) return; uint8 tabIndex = RCT2_GLOBAL(0x00F64EDC, uint8); @@ -946,24 +976,24 @@ void window_scenery_invalidate() { } else if (bp >= 0x200) { sceneryEntry = g_wallSceneryEntries[bp - 0x200]; - if (sceneryEntry->wall.flags & 1) + if (sceneryEntry->wall.flags & (WALL_SCENERY_FLAG1 | WALL_SCENERY_FLAG2)) window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; - if (sceneryEntry->wall.flags & 0x40) { + if (sceneryEntry->wall.flags & WALL_SCENERY_HAS_SECONDARY_COLOUR) { window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_COLORBTN; if (sceneryEntry->wall.flags2 & 1) - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; - if (sceneryEntry->wall.flags & 0x80) + window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_EMPTY; + if (sceneryEntry->wall.flags & WALL_SCENERY_HAS_TERNARY_COLOUR) window_scenery_widgets[WIDX_SCENERY_COLORBUTTON3].type = WWT_COLORBTN; } } else if (bp < 0x100) { sceneryEntry = g_smallSceneryEntries[bp]; - - if (sceneryEntry->small_scenery.flags & 0x600) { + + if (sceneryEntry->small_scenery.flags & (SMALL_SCENERY_HAS_PRIMARY_COLOUR | SMALL_SCENERY_FLAG10)) { window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; - if (sceneryEntry->small_scenery.flags2 & 0x8) + if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_HAS_SECONDARY_COLOUR) window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_COLORBTN; } } @@ -1060,4 +1090,144 @@ void window_scenery_paint() { RCT2_GLOBAL(0x013CE952, uint16) = sceneryEntry->name; gfx_draw_string_left_clipped(dpi, 0x4A7, (void*)0x013CE952, 0, w->x + 3, w->y + w->height - 13, w->width - 19); +} + +/** +* +* rct2: 0x006E15ED +*/ +void window_scenery_scrollpaint() +{ + rct_window *w; + rct_drawpixelinfo *dpi; + + window_paint_get_registers(w, dpi); + + gfx_clear(dpi, ((char*)0x0141FC48)[w->colours[1] * 8] * 0x1010101); + + uint8 tabIndex = RCT2_GLOBAL(0x00F64EDC, uint8); + uint32 sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[tabIndex]; + + int sceneryTabItemIndex = 0; + sint16 currentSceneryGlobalId = -1; + sint16 left = 0, top = 0; + uint8 sceneryRotation = RCT2_GLOBAL(0x00F64F05, uint8); + while ((currentSceneryGlobalId = RCT2_ADDRESS(sceneryTabItems, sint16)[sceneryTabItemIndex]) != -1) { + uint16 sceneryTabIndex = RCT2_ADDRESS(0x00F64EDD, uint16)[currentSceneryGlobalId]; + + if (RCT2_GLOBAL(0x00F64F19, uint8) == 1) + { + if (w->scenery.selected_scenery_id == currentSceneryGlobalId) { + gfx_fill_rect_inset(dpi, left, top, left + 65, top + 79, w->colours[1], 0x80); + } + } else { + if (sceneryTabIndex == currentSceneryGlobalId) { + gfx_fill_rect_inset(dpi, left, top, left + 65, top + 79, w->colours[1], 0xA0); + } + else if (w->scenery.selected_scenery_id == currentSceneryGlobalId) { + gfx_fill_rect_inset(dpi, left, top, left + 65, top + 79, w->colours[1], 0x80); + } + } + + rct_scenery_entry* sceneryEntry; + if (currentSceneryGlobalId >= 0x400) { + sceneryEntry = g_bannerSceneryEntries[currentSceneryGlobalId - 0x400]; + uint32 imageId = sceneryEntry->image + sceneryRotation * 2; + imageId |= (RCT2_GLOBAL(0x00F64F06, uint8) << 19) | 0x20000000; + + gfx_draw_sprite(dpi, imageId, left + 0x21, top + 0x28, w->colours[1]); + gfx_draw_sprite(dpi, imageId + 1, left + 0x21, top + 0x28, w->colours[1]); + } + else if (currentSceneryGlobalId >= 0x300) { + sceneryEntry = g_largeSceneryEntries[currentSceneryGlobalId - 0x300]; + uint32 imageId = sceneryEntry->image + sceneryRotation; + imageId |= (RCT2_GLOBAL(0x00F64F06, uint8) << 19) | 0x20000000; + imageId |= (RCT2_GLOBAL(0x00F64F07, uint8) << 24) | 0x80000000; + + gfx_draw_sprite(dpi, imageId, left + 0x21, top, w->colours[1]); + } + else if (currentSceneryGlobalId >= 0x200) { + sceneryEntry = g_wallSceneryEntries[currentSceneryGlobalId - 0x200]; + rct_drawpixelinfo* clipdpi = clip_drawpixelinfo(dpi, left + 1, 64, top + 1, 78); + if (clipdpi != NULL) { + uint32 imageId = sceneryEntry->image; + uint8 tertiaryColour = w->colours[1]; + + if (sceneryEntry->wall.flags & WALL_SCENERY_FLAG2) { + imageId |= (RCT2_GLOBAL(0x00F64F06, uint8) << 19) | 0x20000000; + + if (sceneryEntry->wall.flags & WALL_SCENERY_HAS_SECONDARY_COLOUR) { + imageId |= (RCT2_GLOBAL(0x00F64F07, uint8) << 24) | 0x80000000; + } + } + else { + imageId |= (RCT2_GLOBAL(0x00F64F06, uint8) << 19) | 0x20000000; + + if (sceneryEntry->wall.flags & WALL_SCENERY_HAS_SECONDARY_COLOUR) { + imageId |= (RCT2_GLOBAL(0x00F64F07, uint8) << 24) | 0x80000000; + + if (sceneryEntry->wall.flags & WALL_SCENERY_HAS_TERNARY_COLOUR) { + imageId &= 0xDFFFFFFF; + tertiaryColour = RCT2_GLOBAL(0x00F64F08, uint8); + } + + } + } + + gfx_draw_sprite(clipdpi, imageId, 0x2F, (sceneryEntry->wall.height * 2) + 0x32, + w->colours[1]); + } + } + else if (currentSceneryGlobalId >= 0x100) { + sceneryEntry = g_pathBitSceneryEntries[currentSceneryGlobalId - 0x100]; + uint32 imageId = sceneryEntry->image; + + gfx_draw_sprite(dpi, imageId, left + 0x0B, top + 0x10, w->colours[1]); + } else { + sceneryEntry = g_smallSceneryEntries[currentSceneryGlobalId]; + rct_drawpixelinfo* clipdpi = clip_drawpixelinfo(dpi, left + 1, 64, top + 1, 78); + if (clipdpi != NULL) { + + uint32 imageId = sceneryEntry->image + sceneryRotation; + + if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_HAS_PRIMARY_COLOUR) { + imageId |= (RCT2_GLOBAL(0x00F64F06, uint8) << 19) | 0x20000000; + + if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_HAS_SECONDARY_COLOUR) { + imageId |= (RCT2_GLOBAL(0x00F64F07, uint8) << 24) | 0x80000000; + } + } + + uint16 spriteTop = (sceneryEntry->small_scenery.height / 4) + 0x2B; + + if (sceneryEntry->small_scenery.flags == (SMALL_SCENERY_FLAG1 | SMALL_SCENERY_FLAG2)) { + spriteTop -= 0x0C; + } + + gfx_draw_sprite(clipdpi, imageId, 0x20, spriteTop, w->colours[1]); + + if (sceneryEntry->small_scenery.flags & 0x200) { + imageId = ((sceneryEntry->image + sceneryRotation) | 0x40000004) + + ((RCT2_GLOBAL(0x00F64F06, uint8) + 0x70) << 19); + + gfx_draw_sprite(clipdpi, imageId, 0x20, spriteTop, w->colours[1]); + } + + if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG8) { + //imageId = (sceneryEntry->image + sceneryRotation) + 4; + imageId = 4; + gfx_draw_sprite(clipdpi, imageId, 0x20, spriteTop, w->colours[1]); + } + + rct2_free(clipdpi); + } + } + + left += 66; + if (left >= 594) { + top += 80; + left = 0; + } + sceneryTabItemIndex++; + } } \ No newline at end of file From de734d49cc56f5831c3bada62e77ead3614cd796 Mon Sep 17 00:00:00 2001 From: qcz Date: Wed, 3 Sep 2014 21:18:08 +0200 Subject: [PATCH 19/30] move scenery related types and enums to scenery.h --- src/scenery.h | 117 +++++++++++++++++++++++++++++++++++++++++++ src/window_scenery.c | 94 +--------------------------------- 2 files changed, 118 insertions(+), 93 deletions(-) create mode 100644 src/scenery.h diff --git a/src/scenery.h b/src/scenery.h new file mode 100644 index 0000000000..f33f34d428 --- /dev/null +++ b/src/scenery.h @@ -0,0 +1,117 @@ +/***************************************************************************** +* Copyright (c) 2014 Dániel Tar +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* This file is part of OpenRCT2. +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*****************************************************************************/ + +#ifndef _SCENERY_H_ +#define _SCENERY_H_ + +typedef struct { + uint32 flags; // 0x06 + uint8 height; // 0x0A + uint8 tool_id; // 0x0B + uint16 price; // 0x0C + uint8 pad_0E[12]; + uint8 scenery_tab_id; // 0x1A +} rct_small_scenery_entry; + +typedef enum { + SMALL_SCENERY_FLAG1 = (1 << 0), // 0x1 + SMALL_SCENERY_FLAG2 = (1 << 1), // 0x2 + SMALL_SCENERY_FLAG3 = (1 << 2), // 0x4 + SMALL_SCENERY_FLAG4 = (1 << 3), // 0x8 + SMALL_SCENERY_FLAG5 = (1 << 4), // 0x10 + SMALL_SCENERY_FLAG6 = (1 << 5), // 0x20 + SMALL_SCENERY_FLAG7 = (1 << 6), // 0x40 + SMALL_SCENERY_FLAG8 = (1 << 7), // 0x80 + SMALL_SCENERY_FLAG9 = (1 << 8), // 0x100 + SMALL_SCENERY_FLAG10 = (1 << 9), // 0x200 + SMALL_SCENERY_HAS_PRIMARY_COLOUR = (1 << 10), // 0x400 + SMALL_SCENERY_FLAG12 = (1 << 11), // 0x800 + SMALL_SCENERY_FLAG13 = (1 << 12), // 0x1000 + SMALL_SCENERY_FLAG14 = (1 << 13), // 0x2000 + SMALL_SCENERY_FLAG15 = (1 << 14), // 0x4000 + SMALL_SCENERY_FLAG16 = (1 << 15), // 0x8000 + SMALL_SCENERY_FLAG17 = (1 << 16), // 0x10000 + SMALL_SCENERY_FLAG18 = (1 << 17), // 0x20000 + SMALL_SCENERY_FLAG19 = (1 << 18), // 0x40000 + SMALL_SCENERY_HAS_SECONDARY_COLOUR = (1 << 19), // 0x80000 +} SMALL_SCENERY_FLAGS; + +typedef struct { + uint8 tool_id; // 0x06 + uint8 flags; // 0x07 + uint16 price; // 0x08 + uint8 pad_0A[6]; + uint8 scenery_tab_id; // 0x10 +} rct_large_scenery_entry; + + +typedef struct { + uint8 tool_id; // 0x06 + uint8 flags; // 0x07 + uint8 height; // 0x08 + uint8 flags2; // 0x09 + uint16 price; // 0x0A + uint8 scenery_tab_id; // 0x0C +} rct_wall_scenery_entry; + +typedef enum { + WALL_SCENERY_FLAG1 = (1 << 0), // 0x1 + WALL_SCENERY_FLAG2 = (1 << 1), // 0x2 + WALL_SCENERY_FLAG3 = (1 << 2), // 0x4 + WALL_SCENERY_FLAG4 = (1 << 3), // 0x8 + WALL_SCENERY_FLAG5 = (1 << 4), // 0x10 + WALL_SCENERY_FLAG6 = (1 << 5), // 0x20 + WALL_SCENERY_HAS_SECONDARY_COLOUR = (1 << 6), // 0x40 + WALL_SCENERY_HAS_TERNARY_COLOUR = (1 << 7), // 0x80 +} WALL_SCENERY_FLAGS; + +typedef struct { + uint8 pad_02[3]; + uint8 tool_id; // 0x09 + uint16 price; // 0x0A + uint8 scenery_tab_id; // 0x0C +} rct_path_bit_scenery_entry; + +typedef struct { + uint8 var_06; + uint8 flags; // 0x07 + uint16 price; // 0x08 + uint8 scenery_tab_id; // 0x0A +} rct_banner_scenery_entry; + +typedef struct { + rct_string_id name; // 0x00 + uint32 image; // 0x02 + union { + rct_small_scenery_entry small_scenery; + rct_large_scenery_entry large_scenery; + rct_wall_scenery_entry wall; + rct_path_bit_scenery_entry path_bit; + rct_banner_scenery_entry banner; + }; +} rct_scenery_entry; + +#define g_smallSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_SMALL_SCENERY_ENTRIES, rct_scenery_entry*) +#define g_largeSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_LARGE_SCENERY_ENTRIES, rct_scenery_entry*) +#define g_wallSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_WALL_SCENERY_ENTRIES, rct_scenery_entry*) +#define g_bannerSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_BANNER_SCENERY_ENTRIES, rct_scenery_entry*) +#define g_pathBitSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_PATH_BIT_SCENERY_ENTRIES, rct_scenery_entry*) + +#endif \ No newline at end of file diff --git a/src/window_scenery.c b/src/window_scenery.c index b4131fc1bc..a0136a92ce 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -27,6 +27,7 @@ #include "gfx.h" #include "peep.h" #include "sprite.h" +#include "scenery.h" #include "string_ids.h" #include "viewport.h" #include "widget.h" @@ -35,99 +36,6 @@ #define WINDOW_SCENERY_WIDTH 0x27A #define WINDOW_SCENERY_HEIGHT 0x8E -typedef struct { - uint32 flags; // 0x06 - uint8 height; // 0x0A - uint8 tool_id; // 0x0B - uint16 price; // 0x0C - uint8 pad_0E[12]; - uint8 scenery_tab_id; // 0x1A -} rct_small_scenery_entry; - -typedef enum { - SMALL_SCENERY_FLAG1 = (1 << 0), // 0x1 - SMALL_SCENERY_FLAG2 = (1 << 1), // 0x2 - SMALL_SCENERY_FLAG3 = (1 << 2) , // 0x4 - SMALL_SCENERY_FLAG4 = (1 << 3), // 0x8 - SMALL_SCENERY_FLAG5 = (1 << 4), // 0x10 - SMALL_SCENERY_FLAG6 = (1 << 5), // 0x20 - SMALL_SCENERY_FLAG7 = (1 << 6), // 0x40 - SMALL_SCENERY_FLAG8 = (1 << 7), // 0x80 - SMALL_SCENERY_FLAG9 = (1 << 8), // 0x100 - SMALL_SCENERY_FLAG10 = (1 << 9), // 0x200 - SMALL_SCENERY_HAS_PRIMARY_COLOUR = (1 << 10), // 0x400 - SMALL_SCENERY_FLAG12 = (1 << 11), // 0x800 - SMALL_SCENERY_FLAG13 = (1 << 12), // 0x1000 - SMALL_SCENERY_FLAG14 = (1 << 13), // 0x2000 - SMALL_SCENERY_FLAG15 = (1 << 14), // 0x4000 - SMALL_SCENERY_FLAG16 = (1 << 15), // 0x8000 - SMALL_SCENERY_FLAG17 = (1 << 16), // 0x10000 - SMALL_SCENERY_FLAG18 = (1 << 17), // 0x20000 - SMALL_SCENERY_FLAG19 = (1 << 18), // 0x40000 - SMALL_SCENERY_HAS_SECONDARY_COLOUR = (1 << 19), // 0x80000 -} SMALL_SCENERY_FLAGS; - -typedef struct { - uint8 tool_id; // 0x06 - uint8 flags; // 0x07 - uint16 price; // 0x08 - uint8 pad_0A[6]; - uint8 scenery_tab_id; // 0x10 -} rct_large_scenery_entry; - - -typedef struct { - uint8 tool_id; // 0x06 - uint8 flags; // 0x07 - uint8 height; // 0x08 - uint8 flags2; // 0x09 - uint16 price; // 0x0A - uint8 scenery_tab_id; // 0x0C -} rct_wall_scenery_entry; - -typedef enum { - WALL_SCENERY_FLAG1 = (1 << 0), // 0x1 - WALL_SCENERY_FLAG2 = (1 << 1), // 0x2 - WALL_SCENERY_FLAG3 = (1 << 2), // 0x4 - WALL_SCENERY_FLAG4 = (1 << 3), // 0x8 - WALL_SCENERY_FLAG5 = (1 << 4), // 0x10 - WALL_SCENERY_FLAG6 = (1 << 5), // 0x20 - WALL_SCENERY_HAS_SECONDARY_COLOUR = (1 << 6), // 0x40 - WALL_SCENERY_HAS_TERNARY_COLOUR = (1 << 7), // 0x80 -} WALL_SCENERY_FLAGS; - -typedef struct { - uint8 pad_02[3]; - uint8 tool_id; // 0x09 - uint16 price; // 0x0A - uint8 scenery_tab_id; // 0x0C -} rct_path_bit_scenery_entry; - -typedef struct { - uint8 var_06; - uint8 flags; // 0x07 - uint16 price; // 0x08 - uint8 scenery_tab_id; // 0x0A -} rct_banner_scenery_entry; - -typedef struct { - rct_string_id name; // 0x00 - uint32 image; // 0x02 - union { - rct_small_scenery_entry small_scenery; - rct_large_scenery_entry large_scenery; - rct_wall_scenery_entry wall; - rct_path_bit_scenery_entry path_bit; - rct_banner_scenery_entry banner; - }; -} rct_scenery_entry; - -#define g_smallSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_SMALL_SCENERY_ENTRIES, rct_scenery_entry*) -#define g_largeSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_LARGE_SCENERY_ENTRIES, rct_scenery_entry*) -#define g_wallSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_WALL_SCENERY_ENTRIES, rct_scenery_entry*) -#define g_bannerSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_BANNER_SCENERY_ENTRIES, rct_scenery_entry*) -#define g_pathBitSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_PATH_BIT_SCENERY_ENTRIES, rct_scenery_entry*) - enum { WINDOW_SCENERY_TAB_1, WINDOW_SCENERY_TAB_2, From 446620610d0890440f5a6d93ba6109170d995d0a Mon Sep 17 00:00:00 2001 From: qcz Date: Wed, 3 Sep 2014 21:19:54 +0200 Subject: [PATCH 20/30] free dat clipdpi --- src/window_scenery.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/window_scenery.c b/src/window_scenery.c index a0136a92ce..3c4f33fcc0 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -1084,6 +1084,7 @@ void window_scenery_scrollpaint() gfx_draw_sprite(clipdpi, imageId, 0x2F, (sceneryEntry->wall.height * 2) + 0x32, w->colours[1]); + rct2_free(clipdpi); } } else if (currentSceneryGlobalId >= 0x100) { From a172d5a5d5e70362179246a1e6f00bc96a320ede Mon Sep 17 00:00:00 2001 From: qcz Date: Wed, 3 Sep 2014 22:13:19 +0200 Subject: [PATCH 21/30] decompile window_scenery_update_scroll, some fixes --- projects/openrct2.vcxproj | 1 + projects/openrct2.vcxproj.filters | 3 ++ src/scenery.h | 3 ++ src/window_scenery.c | 73 +++++++++++++++++++++---------- 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj index 676319ad62..766836ca29 100644 --- a/projects/openrct2.vcxproj +++ b/projects/openrct2.vcxproj @@ -44,6 +44,7 @@ + diff --git a/projects/openrct2.vcxproj.filters b/projects/openrct2.vcxproj.filters index ff318b7ad2..921dc2ecbc 100644 --- a/projects/openrct2.vcxproj.filters +++ b/projects/openrct2.vcxproj.filters @@ -162,6 +162,9 @@ Header Files + + Header Files + diff --git a/src/scenery.h b/src/scenery.h index f33f34d428..20630cc912 100644 --- a/src/scenery.h +++ b/src/scenery.h @@ -21,6 +21,9 @@ #ifndef _SCENERY_H_ #define _SCENERY_H_ +#include "rct2.h" +#include "string_ids.h" + typedef struct { uint32 flags; // 0x06 uint8 height; // 0x0A diff --git a/src/window_scenery.c b/src/window_scenery.c index 3c4f33fcc0..ced3e594a0 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -480,6 +480,21 @@ void window_scenery_close() { tool_cancel(); } +int window_scenery_scrollgetsize_num() { + uint32 sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[RCT2_GLOBAL(0x00F64EDC, uint8)]; + + int items = 0; + while (RCT2_ADDRESS(sceneryTabItems, sint16)[items] != -1) + items++; + + items += 8; + int rows = items / 9; + if (rows == 0) + rows++; + + return rows * 80; +} + /** * * rct2: 0x006BD94C @@ -512,6 +527,36 @@ static void window_scenery_mouseup() } } +/* +* +* rct2: 0x006E1EB4 +*/ +void window_scenery_update_scroll(rct_window *w) { + int scrollsize = window_scenery_scrollgetsize_num(); + w->scrolls[0].v_bottom = scrollsize; + + int typeId = RCT2_GLOBAL(0x00F64EDC, uint8); + uint32 sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[typeId]; + + int itemIndex = 0; + sint16 sceneryId; + while ((sceneryId = RCT2_ADDRESS(sceneryTabItems, sint16)[itemIndex]) != -1) { + if (sceneryId == RCT2_ADDRESS(0x00F64EDD, uint16)[typeId]) + break; + itemIndex++; + } + + if (sceneryId == -1) { + itemIndex = 0; + sint16 sceneryId = RCT2_ADDRESS(sceneryTabItems, sint16)[itemIndex]; + if (sceneryId != -1) + RCT2_ADDRESS(0x00F64EDD, uint16)[typeId] = sceneryId; + } + + w->scrolls[0].v_top = (itemIndex / 9) * 80; + widget_scroll_update_thumbs(w, WIDX_SCENERY_LIST); +} + /** * * rct2: 0x006E1E48 @@ -535,13 +580,13 @@ static void window_scenery_resize() if (w->height < w->min_height) { w->height = w->min_height; window_invalidate(w); - RCT2_CALLPROC_X(0x006E1EB4, 0, 0, 0, 0, (int)w, 0, 0); + window_scenery_update_scroll(w); } if (w->height > w->max_height) { w->height = w->max_height; window_invalidate(w); - RCT2_CALLPROC_X(0x006E1EB4, 0, 0, 0, 0, (int)w, 0, 0); + window_scenery_update_scroll(w); } } @@ -571,7 +616,7 @@ static void window_scenery_mousedown(int widgetIndex, rct_window* w, rct_widget* RCT2_GLOBAL(0x00F64EDC, uint8) = widgetIndex - WIDX_SCENERY_TAB_1; window_invalidate(w); RCT2_GLOBAL(0x00F64EB4, uint32) = 0x80000000; - RCT2_CALLPROC_X(0x006E1EB4, 0, 0, 0, 0, (int)w, 0, 0); + window_scenery_update_scroll(w); } } @@ -702,22 +747,7 @@ static void window_scenery_update(rct_window *w) * rct2: 0x006E1A91 */ void window_scenery_scrollgetsize() { - rct_window *w; - - window_get_register(w); - - uint32 sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[RCT2_GLOBAL(0x00F64EDC, uint8)]; - - int items = 0; - while (RCT2_ADDRESS(sceneryTabItems, sint16)[items] != -1) - items++; - - items += 8; - int rows = items / 9; - if (rows == 0) - rows++; - - int scrollHeight = rows * 80; + int scrollHeight = window_scenery_scrollgetsize_num(); #ifdef _MSC_VER __asm mov edx, scrollHeight @@ -1116,15 +1146,14 @@ void window_scenery_scrollpaint() gfx_draw_sprite(clipdpi, imageId, 0x20, spriteTop, w->colours[1]); if (sceneryEntry->small_scenery.flags & 0x200) { - imageId = ((sceneryEntry->image + sceneryRotation) | 0x40000004) + + imageId = ((sceneryEntry->image + sceneryRotation) + 0x40000004) + ((RCT2_GLOBAL(0x00F64F06, uint8) + 0x70) << 19); gfx_draw_sprite(clipdpi, imageId, 0x20, spriteTop, w->colours[1]); } if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG8) { - //imageId = (sceneryEntry->image + sceneryRotation) + 4; - imageId = 4; + imageId = (sceneryEntry->image + sceneryRotation) + 4; gfx_draw_sprite(clipdpi, imageId, 0x20, spriteTop, w->colours[1]); } From f6da2edc1c792d52d5515f75e8ca532cc65cba9f Mon Sep 17 00:00:00 2001 From: qcz Date: Thu, 4 Sep 2014 22:37:03 +0200 Subject: [PATCH 22/30] fix most of the bugs, rename widget ids --- src/scenery.h | 2 +- src/window.h | 2 +- src/window_scenery.c | 226 ++++++++++++++++++++++--------------------- 3 files changed, 119 insertions(+), 111 deletions(-) diff --git a/src/scenery.h b/src/scenery.h index 20630cc912..f5fceef805 100644 --- a/src/scenery.h +++ b/src/scenery.h @@ -36,7 +36,7 @@ typedef struct { typedef enum { SMALL_SCENERY_FLAG1 = (1 << 0), // 0x1 SMALL_SCENERY_FLAG2 = (1 << 1), // 0x2 - SMALL_SCENERY_FLAG3 = (1 << 2), // 0x4 + SMALL_SCENERY_FLAG3 = (1 << 2), // 0x4 SMALL_SCENERY_FLAG4 = (1 << 3), // 0x8 SMALL_SCENERY_FLAG5 = (1 << 4), // 0x10 SMALL_SCENERY_FLAG6 = (1 << 5), // 0x20 diff --git a/src/window.h b/src/window.h index 53f6459e9a..50667937c0 100644 --- a/src/window.h +++ b/src/window.h @@ -164,7 +164,7 @@ typedef struct { typedef struct { sint16 selected_scenery_id; - sint32 var_482; + uint16 var_482; } scenery_variables; /** diff --git a/src/window_scenery.c b/src/window_scenery.c index ced3e594a0..25325cbea9 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -76,34 +76,34 @@ static void window_scenery_paint(); static void window_scenery_scrollpaint(); static void* window_scenery_events[] = { - window_scenery_close, //(void*)0x006E1A73, // window_scenery_close - window_scenery_mouseup, //(void*)0x006E19FC, // window_scenery_mouseup - window_scenery_resize, //(void*)0x006E1E48, // window_scenery_resize, - window_scenery_mousedown,//(void*)0x006E1A25, // window_scenery_mousedown, - window_scenery_dropdown, //(void*)0x006E1A54, // window_scenery_dropdown, + window_scenery_close, + window_scenery_mouseup, + window_scenery_resize, + window_scenery_mousedown, + window_scenery_dropdown, window_scenery_emptysub, - window_scenery_update,//(void*)0x006E1CD3, // window_scenery_update, - window_scenery_event_07, //(void*)0x006E1B9F, // window_scenery_emptysub, - window_scenery_emptysub, - window_scenery_emptysub, - window_scenery_emptysub, // window_scenery_tooldown + window_scenery_update, + window_scenery_event_07, window_scenery_emptysub, window_scenery_emptysub, window_scenery_emptysub, window_scenery_emptysub, - window_scenery_scrollgetsize, //(void*)0x006E1A91, // window_scenery_scrollgetsize, - window_scenery_scrollmousedown,//(void*)0x006E1C4A, // window_scenery_scrollmousedown, - window_scenery_emptysub, - window_scenery_scrollmouseover, //(void*)0x006E1BB8, // window_scenery_scrollmouseover, window_scenery_emptysub, window_scenery_emptysub, window_scenery_emptysub, - window_scenery_tooltip, //(void*)0x006E1C05, // window_scenery_tooltip, + window_scenery_scrollgetsize, + window_scenery_scrollmousedown, + window_scenery_emptysub, + window_scenery_scrollmouseover, window_scenery_emptysub, window_scenery_emptysub, - window_scenery_invalidate, //(void*)0x006E118B, // window_scenery_invalidate, - window_scenery_paint, // (void*)0x006E1462, // window_scenery_paint, - window_scenery_scrollpaint,//(void*)0x006E15ED, // window_scenery_scrollpaint, + window_scenery_emptysub, + window_scenery_tooltip, + window_scenery_emptysub, + window_scenery_emptysub, + window_scenery_invalidate, + window_scenery_paint, + window_scenery_scrollpaint, }; @@ -133,12 +133,12 @@ enum WINDOW_SCENERY_LIST_WIDGET_IDX { WIDX_SCENERY_TAB_19, // 400000 WIDX_SCENERY_TAB_20, // 800000 WIDX_SCENERY_LIST, // 1000000 - WIDX_SCENERY_FLATBUTTON1, // 2000000 - WIDX_SCENERY_FLATBUTTON2, // 4000000 - WIDX_SCENERY_COLORBUTTON1, // 8000000 - WIDX_SCENERY_COLORBUTTON2, // 10000000 - WIDX_SCENERY_COLORBUTTON3, // 20000000 - WIDX_SCENERY_FLATBUTTON3, // 40000000 + WIDX_SCENERY_ROTATE_OBJECTS_BUTTON, // 2000000 + WIDX_SCENERY_REPAINT_SCENERY_BUTTON, // 4000000 + WIDX_SCENERY_PRIMARY_COLOUR_BUTTON, // 8000000 + WIDX_SCENERY_SECONDARY_COLOUR_BUTTON, // 10000000 + WIDX_SCENERY_TERTIARY_COLOUR_BUTTON, // 20000000 + WIDX_SCENERY_BUILD_CLUSTER_BUTTON, // 40000000 }; static rct_widget window_scenery_widgets[] = { @@ -398,7 +398,7 @@ void window_scenery_open() window->enabled_widgets = (1 << WIDX_SCENERY_CLOSE) | - (1 << WIDX_SCENERY_FLATBUTTON1) | + (1 << WIDX_SCENERY_ROTATE_OBJECTS_BUTTON) | (1 << WIDX_SCENERY_TAB_1) | (1 << WIDX_SCENERY_TAB_2) | (1 << WIDX_SCENERY_TAB_3) | @@ -419,11 +419,11 @@ void window_scenery_open() (1 << WIDX_SCENERY_TAB_18) | (1 << WIDX_SCENERY_TAB_19) | (1 << WIDX_SCENERY_TAB_20) | - (1 << WIDX_SCENERY_COLORBUTTON1) | - (1 << WIDX_SCENERY_COLORBUTTON2) | - (1 << WIDX_SCENERY_FLATBUTTON2) | - (1 << WIDX_SCENERY_COLORBUTTON3) | - (1 << WIDX_SCENERY_FLATBUTTON3); + (1 << WIDX_SCENERY_PRIMARY_COLOUR_BUTTON) | + (1 << WIDX_SCENERY_SECONDARY_COLOUR_BUTTON) | + (1 << WIDX_SCENERY_REPAINT_SCENERY_BUTTON) | + (1 << WIDX_SCENERY_TERTIARY_COLOUR_BUTTON) | + (1 << WIDX_SCENERY_BUILD_CLUSTER_BUTTON); window_init_scroll_widgets(window); RCT2_CALLPROC_X(0x006E1EB4, 0, 0, 0, 0, (int)window, 0, 0); @@ -510,17 +510,17 @@ static void window_scenery_mouseup() case WIDX_SCENERY_CLOSE: window_close(w); break; - case WIDX_SCENERY_FLATBUTTON1: + case WIDX_SCENERY_ROTATE_OBJECTS_BUTTON: RCT2_GLOBAL(0x00F64F05, uint8)++; RCT2_GLOBAL(0x00F64F05, uint8) &= 3; RCT2_CALLPROC_EBPSAFE(0x006E2712); window_invalidate(w); break; - case WIDX_SCENERY_FLATBUTTON2: + case WIDX_SCENERY_REPAINT_SCENERY_BUTTON: RCT2_GLOBAL(0x00F64F19, uint8) ^= 1; window_invalidate(w); break; - case WIDX_SCENERY_FLATBUTTON3: + case WIDX_SCENERY_BUILD_CLUSTER_BUTTON: RCT2_GLOBAL(0x00F64F1A, uint8) ^= 1; window_invalidate(w); break; @@ -598,15 +598,15 @@ static void window_scenery_mousedown(int widgetIndex, rct_window* w, rct_widget* int eax; switch (widgetIndex) { - case WIDX_SCENERY_COLORBUTTON1: + case WIDX_SCENERY_PRIMARY_COLOUR_BUTTON: eax = (RCT2_GLOBAL(0xF64F06, uint8) << 8) + 0x80 + w->colours[1]; RCT2_CALLPROC_X(0x006ED43D, eax, 0, 0, widgetIndex, (int)w, (int)widget, 0xFFFFFFFF); break; - case WIDX_SCENERY_COLORBUTTON2: + case WIDX_SCENERY_SECONDARY_COLOUR_BUTTON: eax = (RCT2_GLOBAL(0xF64F07, uint8) << 8) + 0x80 + w->colours[1]; RCT2_CALLPROC_X(0x006ED43D, eax, 0, 0, widgetIndex, (int)w, (int)widget, 0xFFFFFFFF); break; - case WIDX_SCENERY_COLORBUTTON3: + case WIDX_SCENERY_TERTIARY_COLOUR_BUTTON: eax = (RCT2_GLOBAL(0xF64F08, uint8) << 8) + 0x80 + w->colours[1]; RCT2_CALLPROC_X(0x006ED43D, eax, 0, 0, widgetIndex, (int)w, (int)widget, 0xFFFFFFFF); break; @@ -632,13 +632,13 @@ static void window_scenery_dropdown() { if (dropdownIndex == -1) return; - if (widgetIndex == WIDX_SCENERY_COLORBUTTON1) { + if (widgetIndex == WIDX_SCENERY_PRIMARY_COLOUR_BUTTON) { RCT2_GLOBAL(0x00F64F06, uint8) = dropdownIndex; } - else if (widgetIndex == WIDX_SCENERY_COLORBUTTON2) { + else if (widgetIndex == WIDX_SCENERY_SECONDARY_COLOUR_BUTTON) { RCT2_GLOBAL(0x00F64F07, uint8) = dropdownIndex; } - else if (widgetIndex == WIDX_SCENERY_COLORBUTTON3) { + else if (widgetIndex == WIDX_SCENERY_TERTIARY_COLOUR_BUTTON) { RCT2_GLOBAL(0x00F64F08, uint8) = dropdownIndex; } @@ -677,7 +677,6 @@ static void window_scenery_update(rct_window *w) if (widgetIndex >= 3) { w->scenery.var_482++; if (w->scenery.var_482 < 8) { - w->scenery.var_482 = 0; if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, sint8) != INPUT_STATE_SCROLL_LEFT) { w->min_width = WINDOW_SCENERY_WIDTH; w->max_width = WINDOW_SCENERY_WIDTH; @@ -685,7 +684,7 @@ static void window_scenery_update(rct_window *w) w->max_height = WINDOW_SCENERY_HEIGHT; } } else { - int windowHeight = w->scrolls[0].v_bottom - 1 + 0x3E; + int windowHeight = w->scrolls[0].v_bottom + 0x3E; if (windowHeight > 0x1C6) windowHeight = 0x1C6; if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) < 0x258){ @@ -693,6 +692,8 @@ static void window_scenery_update(rct_window *w) windowHeight = 0x176; } + printf("update: %d\n", w->scrolls[0].v_bottom); + w->min_width = WINDOW_SCENERY_WIDTH; w->max_width = WINDOW_SCENERY_WIDTH; w->min_height = windowHeight; @@ -739,7 +740,6 @@ static void window_scenery_update(rct_window *w) RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = g_smallSceneryEntries[sceneryIndex]->small_scenery.tool_id; } - } /** @@ -749,6 +749,8 @@ static void window_scenery_update(rct_window *w) void window_scenery_scrollgetsize() { int scrollHeight = window_scenery_scrollgetsize_num(); + printf("scrollgetsize: %d\n", scrollHeight); + #ifdef _MSC_VER __asm mov edx, scrollHeight #else @@ -849,90 +851,94 @@ void window_scenery_invalidate() { window_get_register(w); uint16 typeId = RCT2_GLOBAL(0x00F64EDC, uint8); - uint32 edx = 0x715; - if (typeId >= 0x13) { - edx = *RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_SET_ENTRIES + (typeId & 0xFFFF) * 4, uint8*); + uint32 title_string_id = 0x715; + if (typeId <= 0x13) { + title_string_id = *(RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32*)[typeId]); } + window_scenery_widgets[WIDX_SCENERY_TITLE].image = title_string_id; w->pressed_widgets = (((uint32)w->pressed_widgets & 0xFF00000F) | (1 << (typeId + 4))) & 0xBBFFFFFF; - if (RCT2_GLOBAL(0x00F64F19, uint8) != 1) { // repaint colored scenery tool is off + if (RCT2_GLOBAL(0x00F64F19, uint8) == 1) { // repaint colored scenery tool is off w->pressed_widgets |= 0x04000000; } + + window_scenery_widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].type = WWT_EMPTY; + window_scenery_widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].type = WWT_EMPTY; + + uint16 globalSceneryId = RCT2_ADDRESS(0x00F64EDD, uint16)[typeId]; + if (globalSceneryId != 0xFFFF) { + if (globalSceneryId < 0x100) { + if (!(RCT2_GLOBAL(0x00F64F19, uint8) & 1)) + window_scenery_widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].type = WWT_FLATBTN; - uint8 byte_9DE428 = 0; - uint8 byte_9DE478 = 0; - uint8 byte_9DE448 = 0; - - uint16 bp = RCT2_ADDRESS(0x00F64EDD, uint16)[typeId]; - if (bp == 0xFFFF) { - if (bp > 0x100) { - if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_SCENARIO_EDITOR) && !(RCT2_GLOBAL(0x00F64F19, uint8) & 1)) { - byte_9DE478 = 9; + rct_scenery_entry* sceneryEntry = g_smallSceneryEntries[globalSceneryId]; + if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG4) { + window_scenery_widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].type = WWT_FLATBTN; } - - rct_scenery_entry* ebx = g_smallSceneryEntries[typeId]; - if (!(ebx->small_scenery.flags & 0x600)) { - byte_9DE448 = 6; - } - int i = 0; + } + else if (globalSceneryId > 0x300) { + window_scenery_widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].type = WWT_FLATBTN; } } - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].image = + window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].image = (RCT2_GLOBAL(0x00F64F06, uint8) << 19) + 0x600013C3; - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].image = + window_scenery_widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].image = (RCT2_GLOBAL(0x00F64F07, uint8) << 19) + 0x600013C3; - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON3].image = + window_scenery_widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].image = (RCT2_GLOBAL(0x00F64F08, uint8) << 19) + 0x600013C3; - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_EMPTY; - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_EMPTY; - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON3].type = WWT_EMPTY; - + window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WWT_EMPTY; + window_scenery_widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].type = WWT_EMPTY; + window_scenery_widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].type = WWT_EMPTY; if (RCT2_GLOBAL(0x00F64F19, uint8) & 1) { // repaint colored scenery tool is on - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_COLORBTN; - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON3].type = WWT_COLORBTN; - } else if (bp != 0xFFFF) { + window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WWT_COLORBTN; + window_scenery_widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].type = WWT_COLORBTN; + window_scenery_widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].type = WWT_COLORBTN; + window_scenery_widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].type = WWT_EMPTY; + } + else if (globalSceneryId != 0xFFFF) { rct_scenery_entry* sceneryEntry = NULL; - if (bp >= 0x400) { - sceneryEntry = g_bannerSceneryEntries[bp - 0x400]; + if (globalSceneryId >= 0x400) { + sceneryEntry = g_bannerSceneryEntries[globalSceneryId - 0x400]; if (sceneryEntry->banner.flags & 1) - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; + window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WWT_COLORBTN; } - else if (bp >= 0x300) { - sceneryEntry = g_largeSceneryEntries[bp - 0x300]; + else if (globalSceneryId >= 0x300) { + sceneryEntry = g_largeSceneryEntries[globalSceneryId - 0x300]; if (sceneryEntry->large_scenery.flags & 1) - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; + window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WWT_COLORBTN; if (sceneryEntry->large_scenery.flags & 2) - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_COLORBTN; + window_scenery_widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].type = WWT_COLORBTN; } - else if (bp >= 0x200) { - sceneryEntry = g_wallSceneryEntries[bp - 0x200]; - if (sceneryEntry->wall.flags & (WALL_SCENERY_FLAG1 | WALL_SCENERY_FLAG2)) - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; - if (sceneryEntry->wall.flags & WALL_SCENERY_HAS_SECONDARY_COLOUR) { - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_COLORBTN; + else if (globalSceneryId >= 0x200) { + sceneryEntry = g_wallSceneryEntries[globalSceneryId - 0x200]; + if (sceneryEntry->wall.flags & (WALL_SCENERY_FLAG1 | WALL_SCENERY_FLAG2)) { + window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WWT_COLORBTN; - if (sceneryEntry->wall.flags2 & 1) - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_EMPTY; - if (sceneryEntry->wall.flags & WALL_SCENERY_HAS_TERNARY_COLOUR) - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON3].type = WWT_COLORBTN; + if (sceneryEntry->wall.flags & WALL_SCENERY_HAS_SECONDARY_COLOUR) { + window_scenery_widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].type = WWT_COLORBTN; + + if (sceneryEntry->wall.flags2 & WALL_SCENERY_FLAG1) + window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WWT_EMPTY; + if (sceneryEntry->wall.flags & WALL_SCENERY_HAS_TERNARY_COLOUR) + window_scenery_widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].type = WWT_COLORBTN; + } } } - else if (bp < 0x100) { - sceneryEntry = g_smallSceneryEntries[bp]; + else if (globalSceneryId < 0x100) { + sceneryEntry = g_smallSceneryEntries[globalSceneryId]; if (sceneryEntry->small_scenery.flags & (SMALL_SCENERY_HAS_PRIMARY_COLOUR | SMALL_SCENERY_FLAG10)) { - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].type = WWT_COLORBTN; + window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WWT_COLORBTN; if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_HAS_SECONDARY_COLOUR) - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].type = WWT_COLORBTN; + window_scenery_widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].type = WWT_COLORBTN; } } } @@ -947,19 +953,19 @@ void window_scenery_invalidate() { window_scenery_widgets[WIDX_SCENERY_LIST].right = w->width - 0x1A; window_scenery_widgets[WIDX_SCENERY_LIST].bottom = w->height - 0x0E; - window_scenery_widgets[WIDX_SCENERY_FLATBUTTON1].left = w->width - 25; - window_scenery_widgets[WIDX_SCENERY_FLATBUTTON2].left = w->width - 25; - window_scenery_widgets[WIDX_SCENERY_FLATBUTTON3].left = w->width - 25; - window_scenery_widgets[WIDX_SCENERY_FLATBUTTON1].right = w->width - 2; - window_scenery_widgets[WIDX_SCENERY_FLATBUTTON2].right = w->width - 2; - window_scenery_widgets[WIDX_SCENERY_FLATBUTTON3].right = w->width - 2; + window_scenery_widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].left = w->width - 25; + window_scenery_widgets[WIDX_SCENERY_REPAINT_SCENERY_BUTTON].left = w->width - 25; + window_scenery_widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].left = w->width - 25; + window_scenery_widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].right = w->width - 2; + window_scenery_widgets[WIDX_SCENERY_REPAINT_SCENERY_BUTTON].right = w->width - 2; + window_scenery_widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].right = w->width - 2; - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].left = w->width - 19; - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].left = w->width - 19; - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON3].left = w->width - 19; - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON1].right = w->width - 8; - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON2].right = w->width - 8; - window_scenery_widgets[WIDX_SCENERY_COLORBUTTON3].right = w->width - 8; + window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].left = w->width - 19; + window_scenery_widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].left = w->width - 19; + window_scenery_widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].left = w->width - 19; + window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].right = w->width - 8; + window_scenery_widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].right = w->width - 8; + window_scenery_widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].right = w->width - 8; } /** @@ -1021,8 +1027,9 @@ void window_scenery_paint() { RCT2_GLOBAL(0x013CE952, uint32) = price; if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) { + // -14 gfx_draw_string_right(dpi, STR_COST_LABEL, (void*)0x013CE952, 0, - w->x + w->width - 14, w->y + w->height - 13); + w->x + w->width - 0x1A, w->y + w->height - 13); } RCT2_GLOBAL(0x013CE952, uint16) = sceneryEntry->name; @@ -1051,7 +1058,7 @@ void window_scenery_scrollpaint() sint16 left = 0, top = 0; uint8 sceneryRotation = RCT2_GLOBAL(0x00F64F05, uint8); while ((currentSceneryGlobalId = RCT2_ADDRESS(sceneryTabItems, sint16)[sceneryTabItemIndex]) != -1) { - uint16 sceneryTabIndex = RCT2_ADDRESS(0x00F64EDD, uint16)[currentSceneryGlobalId]; + uint16 sceneryTabIndex = RCT2_ADDRESS(0x00F64EDD, uint16)[tabIndex]; if (RCT2_GLOBAL(0x00F64F19, uint8) == 1) { @@ -1113,7 +1120,7 @@ void window_scenery_scrollpaint() } gfx_draw_sprite(clipdpi, imageId, 0x2F, (sceneryEntry->wall.height * 2) + 0x32, - w->colours[1]); + tertiaryColour); rct2_free(clipdpi); } } @@ -1139,7 +1146,8 @@ void window_scenery_scrollpaint() uint16 spriteTop = (sceneryEntry->small_scenery.height / 4) + 0x2B; - if (sceneryEntry->small_scenery.flags == (SMALL_SCENERY_FLAG1 | SMALL_SCENERY_FLAG2)) { + if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG1 && + sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG2) { spriteTop -= 0x0C; } From 9b39a211e49a6f60acf0a855f8633591dfbdd1d5 Mon Sep 17 00:00:00 2001 From: qcz Date: Thu, 4 Sep 2014 22:38:38 +0200 Subject: [PATCH 23/30] remove debug printf --- src/window_scenery.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index 25325cbea9..ee8cf72328 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -692,8 +692,6 @@ static void window_scenery_update(rct_window *w) windowHeight = 0x176; } - printf("update: %d\n", w->scrolls[0].v_bottom); - w->min_width = WINDOW_SCENERY_WIDTH; w->max_width = WINDOW_SCENERY_WIDTH; w->min_height = windowHeight; @@ -749,8 +747,6 @@ static void window_scenery_update(rct_window *w) void window_scenery_scrollgetsize() { int scrollHeight = window_scenery_scrollgetsize_num(); - printf("scrollgetsize: %d\n", scrollHeight); - #ifdef _MSC_VER __asm mov edx, scrollHeight #else From 90b0ec02b30543341f2592f2f3cc839d2357cfda Mon Sep 17 00:00:00 2001 From: qcz Date: Fri, 5 Sep 2014 21:32:08 +0200 Subject: [PATCH 24/30] fix tab ordering, add pressed state for cluster button --- src/window_scenery.c | 66 +++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index ee8cf72328..c0872100ae 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -317,40 +317,50 @@ void init_scenery() { for (int widgetIndex = WIDX_SCENERY_TAB_1; widgetIndex < WIDX_SCENERY_LIST; widgetIndex++) window_scenery_widgets[widgetIndex].type = 0; - uint8 stuff[0x50]; - int ebp = 0; + uint8 indices[0x13]; + uint8 ids[0x13]; + int usedValues = 0; for (int ebx = 0; ebx < 0x13; ebx++) { - uint32 scenerySetAddress = RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32)[edi]; + uint32 scenerySetAddress = RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32)[ebx]; if (scenerySetAddress == 0xFFFFFFFF) continue; - stuff[ebp] = ebx; - stuff[ebp + 1] = RCT2_GLOBAL(scenerySetAddress + 0x108, uint8); + indices[usedValues] = ebx; + ids[usedValues] = RCT2_GLOBAL(scenerySetAddress + 0x108, uint8); - ebp += 4; - int prev_edi = ebp - 4; - - while (true) { - if (prev_edi <= 0) - break; - - prev_edi -= 4; - if (stuff[prev_edi + 5] >= stuff[prev_edi + 1]) - break; - - int eax = stuff[prev_edi + 4]; - stuff[prev_edi + 4] = stuff[prev_edi]; - stuff[prev_edi] = eax; - } + usedValues++; } - stuff[ebp] = 0x13; - ebp += 4; + while (true) { + bool finished = true; + for (int ebx = 1; ebx < usedValues; ebx++) { + if (ids[ebx - 1] > ids[ebx]) { + uint8 tmp = ids[ebx - 1]; + ids[ebx - 1] = ids[ebx]; + ids[ebx] = tmp; + tmp = indices[ebx - 1]; + indices[ebx - 1] = indices[ebx]; + indices[ebx] = tmp; + finished = false; + } + } + + if (finished) + break; + } + + + /*for (int ebx = 0; ebx * 4 < ebp; ebx++) { + printf("%d : %d : %d\n", stuff[ebx * 4], ebx, stuff[ebx * 4 + 1]); + }*/ + + indices[usedValues] = 0x13; + usedValues++; uint16 cx = 3; - for (int ebx = 0; ebx < ebp; ebx += 4) { - uint32 tabIndex = stuff[ebx]; + for (int ebx = 0; ebx < usedValues; ebx ++) { + uint32 tabIndex = indices[ebx]; rct_widget* currentTab = &window_scenery_widgets[tabIndex + WIDX_SCENERY_TAB_1]; int sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[tabIndex]; @@ -367,7 +377,7 @@ void init_scenery() { currentTab->right = cx + 0x1E; cx += 0x1F; - if (edi >= 0x13) + if (tabIndex >= 0x13) continue; int sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32)[tabIndex]; @@ -855,9 +865,13 @@ void window_scenery_invalidate() { w->pressed_widgets = (((uint32)w->pressed_widgets & 0xFF00000F) | (1 << (typeId + 4))) & 0xBBFFFFFF; - if (RCT2_GLOBAL(0x00F64F19, uint8) == 1) { // repaint colored scenery tool is off + if (RCT2_GLOBAL(0x00F64F19, uint8) == 1) { // repaint colored scenery tool is on w->pressed_widgets |= 0x04000000; } + + if (RCT2_GLOBAL(0x00F64F1A, uint8) == 1) { // build cluster tool is on + w->pressed_widgets |= 0x040000000; + } window_scenery_widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].type = WWT_EMPTY; window_scenery_widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].type = WWT_EMPTY; From d4201a7eb7ae4fa4e88f43e18447f28e5f8d1a38 Mon Sep 17 00:00:00 2001 From: qcz Date: Fri, 5 Sep 2014 23:08:51 +0200 Subject: [PATCH 25/30] add rct_scenery_set_entry struct, use it everywhere where referenced, continue to unify code in scenery window --- src/scenery.h | 10 ++++ src/window_new_ride.c | 7 +-- src/window_research.c | 7 +-- src/window_scenery.c | 126 +++++++++++++++++++----------------------- 4 files changed, 73 insertions(+), 77 deletions(-) diff --git a/src/scenery.h b/src/scenery.h index f5fceef805..e14283761a 100644 --- a/src/scenery.h +++ b/src/scenery.h @@ -111,10 +111,20 @@ typedef struct { }; } rct_scenery_entry; +typedef struct { + rct_string_id name; // 0x00 + uint32 image; // 0x02 + uint16 scenery_entries[0x80]; // 0x06 + uint8 entry_count; // 0x106 + uint8 pad_107; + uint8 var_108; // 0x108, order? +} rct_scenery_set_entry; + #define g_smallSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_SMALL_SCENERY_ENTRIES, rct_scenery_entry*) #define g_largeSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_LARGE_SCENERY_ENTRIES, rct_scenery_entry*) #define g_wallSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_WALL_SCENERY_ENTRIES, rct_scenery_entry*) #define g_bannerSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_BANNER_SCENERY_ENTRIES, rct_scenery_entry*) #define g_pathBitSceneryEntries RCT2_ADDRESS(RCT2_ADDRESS_PATH_BIT_SCENERY_ENTRIES, rct_scenery_entry*) +#define g_scenerySetEntries RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, rct_scenery_set_entry*) #endif \ No newline at end of file diff --git a/src/window_new_ride.c b/src/window_new_ride.c index 610b53f1a8..0c8585f1ab 100644 --- a/src/window_new_ride.c +++ b/src/window_new_ride.c @@ -25,6 +25,7 @@ #include "news_item.h" #include "ride.h" #include "string_ids.h" +#include "scenery.h" #include "track.h" #include "widget.h" #include "window.h" @@ -761,8 +762,7 @@ static void window_new_ride_paint() rideEntry->name : (typeId & 0xFF00) + 2; } else { - uint8 *sceneryEntry = RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_SET_ENTRIES + (typeId & 0xFFFF) * 4, uint8*); - stringId = RCT2_GLOBAL(sceneryEntry, uint16); + stringId = g_scenerySetEntries[typeId]->name; } } } @@ -798,8 +798,7 @@ static void window_new_ride_paint() rideEntry->name : (typeId & 0xFF00) + 2; } else { - uint8 *sceneryEntry = RCT2_GLOBAL(0x009ADA90 + (typeId & 0xFFFF) * 4, uint8*); - stringId = RCT2_GLOBAL(sceneryEntry, uint16); + stringId = g_scenerySetEntries[typeId]->name; } gfx_draw_string_left_wrapped(dpi, &stringId, x, y, 266, STR_RESEARCH_RIDE_LABEL, 0); } diff --git a/src/window_research.c b/src/window_research.c index b65fc7dba4..5685c80da1 100644 --- a/src/window_research.c +++ b/src/window_research.c @@ -23,6 +23,7 @@ #include "game.h" #include "news_item.h" #include "ride.h" +#include "scenery.h" #include "string_ids.h" #include "sprites.h" #include "widget.h" @@ -348,8 +349,7 @@ static void window_research_development_paint() rideEntry->name : ((typeId >> 8) & 0xFF) + 2; } else { - uint8 *sceneryEntry = RCT2_GLOBAL(0x009ADA90 + (typeId & 0xFFFF) * 4, uint8*); - stringId = RCT2_GLOBAL(sceneryEntry, uint16); + stringId = g_scenerySetEntries[typeId]->name; } } } @@ -388,8 +388,7 @@ static void window_research_development_paint() lastDevelopmentFormat = STR_RESEARCH_RIDE_LABEL; } else { - uint8 *sceneryEntry = RCT2_GLOBAL(0x009ADA90 + (typeId & 0xFFFF) * 4, uint8*); - stringId = RCT2_GLOBAL(sceneryEntry, uint16); + stringId = g_scenerySetEntries[typeId]->name; lastDevelopmentFormat = STR_RESEARCH_SCENERY_LABEL; } gfx_draw_string_left_wrapped(dpi, &stringId, x, y, 266, lastDevelopmentFormat, 0); diff --git a/src/window_scenery.c b/src/window_scenery.c index c0872100ae..1f3dde68e7 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -223,7 +223,6 @@ void init_scenery_entry(rct_scenery_entry *sceneryEntry, int index, uint8 scener * rct2: 0x006DFA00 **/ void init_scenery() { - uint32 edi = 0; uint32 baseAddress = 0x00F64F7C; for (int i = 0; i < 0x14; i++) { @@ -231,103 +230,99 @@ void init_scenery() { baseAddress += 0x102; } - uint32 dword_F663A4 = 0; + bool enabledScenerySets[0x13] = { false }; - for (int edi = 0; edi < 0x14; edi++) { - int sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[edi]; + for (int scenerySetIndex = 0; scenerySetIndex < 0x14; scenerySetIndex++) { + int sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[scenerySetIndex]; RCT2_GLOBAL(sceneryTabItems, uint16) = 0xFFFF; - if (edi == 13) + if (scenerySetIndex == 0x13) continue; - uint32 ebp = RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32)[edi]; - if (ebp == 0xFFFFFFFF) + rct_scenery_set_entry* scenerySetEntry = g_scenerySetEntries[scenerySetIndex]; + if ((uint32)scenerySetEntry == 0xFFFFFFFF) continue; - for (int ebx = 0;; ebx++) { - if (ebx >= RCT2_GLOBAL(ebp + 0x106, uint8)) - break; - - uint16 ax = RCT2_GLOBAL(ebp + ebx * 2 + 6, uint16); - - uint32 ecx = RCT2_ADDRESS(0x01357BD0, uint32)[ax >> 5]; - uint32 edx = 1 << (ax & 0x1F); + for (int i = 0; i < scenerySetEntry->entry_count; i++) { + uint16 sceneryEntryId = scenerySetEntry->scenery_entries[i]; + uint32 ecx = RCT2_ADDRESS(0x01357BD0, uint32)[sceneryEntryId >> 5]; + uint32 edx = 1 << (sceneryEntryId & 0x1F); if (ecx & edx) { - RCT2_GLOBAL(sceneryTabItems, uint16) = ax; + RCT2_GLOBAL(sceneryTabItems, uint16) = sceneryEntryId; sceneryTabItems += 2; RCT2_GLOBAL(sceneryTabItems, uint16) = 0xFFFF; } else { - dword_F663A4 |= (1 << edi); + enabledScenerySets[scenerySetIndex] = true; } } } // small scenery - for (uint16 edi = 0; edi < 0xFC; edi++) { - if ((uint32)g_smallSceneryEntries[edi] == 0xFFFFFFFF) + for (uint16 sceneryId = 0; sceneryId < 0xFC; sceneryId++) { + if ((uint32)g_smallSceneryEntries[sceneryId] == 0xFFFFFFFF) continue; - rct_scenery_entry* sceneryEntry = g_smallSceneryEntries[edi]; - init_scenery_entry(sceneryEntry, edi, sceneryEntry->small_scenery.scenery_tab_id); + rct_scenery_entry* sceneryEntry = g_smallSceneryEntries[sceneryId]; + init_scenery_entry(sceneryEntry, sceneryId, sceneryEntry->small_scenery.scenery_tab_id); } // large scenery - for (int edi = 0x300; edi < 0x380; edi++) { - int largeSceneryIndex = edi - 0x300; + for (int sceneryId = 0x300; sceneryId < 0x380; sceneryId++) { + int largeSceneryIndex = sceneryId - 0x300; if ((uint32)g_largeSceneryEntries[largeSceneryIndex] == 0xFFFFFFFF) continue; rct_scenery_entry* sceneryEntry = g_largeSceneryEntries[largeSceneryIndex]; - init_scenery_entry(sceneryEntry, edi, sceneryEntry->large_scenery.scenery_tab_id); + init_scenery_entry(sceneryEntry, sceneryId, sceneryEntry->large_scenery.scenery_tab_id); } // walls - for (int edi = 0x200; edi < 0x280; edi++) { - int wallSceneryIndex = edi - 0x200; + for (int sceneryId = 0x200; sceneryId < 0x280; sceneryId++) { + int wallSceneryIndex = sceneryId - 0x200; if ((uint32)g_wallSceneryEntries[wallSceneryIndex] == 0xFFFFFFFF) continue; rct_scenery_entry* sceneryEntry = g_wallSceneryEntries[wallSceneryIndex]; - init_scenery_entry(sceneryEntry, edi, sceneryEntry->wall.scenery_tab_id); + init_scenery_entry(sceneryEntry, sceneryId, sceneryEntry->wall.scenery_tab_id); } // banners - for (int edi = 0x400; edi < 0x420; edi++) { - int bannerIndex = edi - 0x400; + for (int sceneryId = 0x400; sceneryId < 0x420; sceneryId++) { + int bannerIndex = sceneryId - 0x400; if ((uint32)g_bannerSceneryEntries[bannerIndex] == 0xFFFFFFFF) continue; rct_scenery_entry* sceneryEntry = g_bannerSceneryEntries[bannerIndex]; - init_scenery_entry(sceneryEntry, edi, sceneryEntry->banner.scenery_tab_id); + init_scenery_entry(sceneryEntry, sceneryId, sceneryEntry->banner.scenery_tab_id); } // path bits - for (int edi = 0x100; edi < 0x10F; edi++) { - int bannerIndex = edi - 0x100; + for (int sceneryId = 0x100; sceneryId < 0x10F; sceneryId++) { + int pathBitIndex = sceneryId - 0x100; - if ((uint32)g_pathBitSceneryEntries[bannerIndex] == 0xFFFFFFFF) + if ((uint32)g_pathBitSceneryEntries[pathBitIndex] == 0xFFFFFFFF) continue; - rct_scenery_entry* sceneryEntry = g_pathBitSceneryEntries[bannerIndex]; - init_scenery_entry(sceneryEntry, edi, sceneryEntry->path_bit.scenery_tab_id); + rct_scenery_entry* sceneryEntry = g_pathBitSceneryEntries[pathBitIndex]; + init_scenery_entry(sceneryEntry, sceneryId, sceneryEntry->path_bit.scenery_tab_id); } for (int widgetIndex = WIDX_SCENERY_TAB_1; widgetIndex < WIDX_SCENERY_LIST; widgetIndex++) window_scenery_widgets[widgetIndex].type = 0; - uint8 indices[0x13]; - uint8 ids[0x13]; + uint8 tabIndexes[0x13]; + uint8 order[0x13]; int usedValues = 0; - for (int ebx = 0; ebx < 0x13; ebx++) { - uint32 scenerySetAddress = RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32)[ebx]; - if (scenerySetAddress == 0xFFFFFFFF) + for (int scenerySetId = 0; scenerySetId < 0x13; scenerySetId++) { + rct_scenery_set_entry* sceneryEntry = g_scenerySetEntries[scenerySetId]; + if ((uint32)sceneryEntry == 0xFFFFFFFF) continue; - indices[usedValues] = ebx; - ids[usedValues] = RCT2_GLOBAL(scenerySetAddress + 0x108, uint8); + tabIndexes[usedValues] = scenerySetId; + order[usedValues] = sceneryEntry->var_108; usedValues++; } @@ -335,13 +330,13 @@ void init_scenery() { while (true) { bool finished = true; for (int ebx = 1; ebx < usedValues; ebx++) { - if (ids[ebx - 1] > ids[ebx]) { - uint8 tmp = ids[ebx - 1]; - ids[ebx - 1] = ids[ebx]; - ids[ebx] = tmp; - tmp = indices[ebx - 1]; - indices[ebx - 1] = indices[ebx]; - indices[ebx] = tmp; + if (order[ebx - 1] > order[ebx]) { + uint8 tmp = tabIndexes[ebx - 1]; + tabIndexes[ebx - 1] = tabIndexes[ebx]; + tabIndexes[ebx] = tmp; + tmp = order[ebx - 1]; + order[ebx - 1] = order[ebx]; + order[ebx] = tmp; finished = false; } } @@ -350,38 +345,32 @@ void init_scenery() { break; } - - /*for (int ebx = 0; ebx * 4 < ebp; ebx++) { - printf("%d : %d : %d\n", stuff[ebx * 4], ebx, stuff[ebx * 4 + 1]); - }*/ - - indices[usedValues] = 0x13; + tabIndexes[usedValues] = 0x13; usedValues++; - uint16 cx = 3; + uint16 left = 3; for (int ebx = 0; ebx < usedValues; ebx ++) { - uint32 tabIndex = indices[ebx]; - rct_widget* currentTab = &window_scenery_widgets[tabIndex + WIDX_SCENERY_TAB_1]; + uint32 tabIndex = tabIndexes[ebx]; + rct_widget* tabWidget = &window_scenery_widgets[tabIndex + WIDX_SCENERY_TAB_1]; int sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[tabIndex]; - if (cx != 3 || tabIndex == 0x13) { + if (left != 3 || tabIndex == 0x13) { if (RCT2_GLOBAL(sceneryTabItems, uint16) == 0xFFFF) continue; - if (dword_F663A4 & (1 << tabIndex)) + if (enabledScenerySets[tabIndex]) continue; } - currentTab->type = WWT_TAB; - currentTab->left = cx; - currentTab->right = cx + 0x1E; - cx += 0x1F; + tabWidget->type = WWT_TAB; + tabWidget->left = left; + tabWidget->right = left + 0x1E; + left += 0x1F; if (tabIndex >= 0x13) continue; - int sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32)[tabIndex]; - currentTab->image = RCT2_GLOBAL(sceneryEntry + 2, uint32) | 0x20000000; + tabWidget->image = g_scenerySetEntries[tabIndex]->image | 0x20000000; } window_invalidate_by_id(WC_SCENERY, 0); @@ -842,8 +831,7 @@ void window_scenery_tooltip() { } else if (tooltipIndex >= 4 && tooltipIndex < 0x17) { - uint32* sceneryEntry = RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32*)[tooltipIndex - 4]; - RCT2_GLOBAL(0x013CE952, uint16) = RCT2_GLOBAL((int)sceneryEntry, uint16); + RCT2_GLOBAL(0x013CE952, uint16) = g_scenerySetEntries[tooltipIndex - 4]->name; } } @@ -859,7 +847,7 @@ void window_scenery_invalidate() { uint16 typeId = RCT2_GLOBAL(0x00F64EDC, uint8); uint32 title_string_id = 0x715; if (typeId <= 0x13) { - title_string_id = *(RCT2_ADDRESS(RCT2_ADDRESS_SCENERY_SET_ENTRIES, uint32*)[typeId]); + title_string_id = g_scenerySetEntries[typeId]->name; } window_scenery_widgets[WIDX_SCENERY_TITLE].image = title_string_id; From 01986241de95820cdd7f73ac650bee2697c0127d Mon Sep 17 00:00:00 2001 From: qcz Date: Fri, 5 Sep 2014 23:40:42 +0200 Subject: [PATCH 26/30] use local variable for scenery tab entries instead of the old location --- src/window_scenery.c | 63 ++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index 1f3dde68e7..22d2b79caa 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -176,30 +176,27 @@ static rct_widget window_scenery_widgets[] = { { WIDGETS_END }, }; +static sint16 window_scenery_tab_entries[0x13][0x81]; void init_scenery_entry(rct_scenery_entry *sceneryEntry, int index, uint8 sceneryTabId) { if (RCT2_ADDRESS(0x01357BD0, sint32)[index >> 5] & (1 << (index & 0x1F))) { if (sceneryTabId != 0xFF) { - uint32 sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[sceneryTabId]; - - for (int ebx = 0; ebx < 0x80; ebx++) { - if (RCT2_ADDRESS(sceneryTabItems, uint16)[ebx] == 0xFFFF) + for (int i = 0; i < 0x80; i++) { + if (window_scenery_tab_entries[sceneryTabId][i] == -1) { - RCT2_ADDRESS(sceneryTabItems, uint16)[ebx] = index; - RCT2_ADDRESS(sceneryTabItems, uint16)[ebx + 1] = 0xFFFF; + window_scenery_tab_entries[sceneryTabId][i] = index; + window_scenery_tab_entries[sceneryTabId][i + 1] = -1; return; } } } - for (int ecx = 0; ecx < 0x13; ecx++) { - int sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[ecx]; + for (int i = 0; i < 0x13; i++) { int counter = 0; - while (RCT2_ADDRESS(sceneryTabItems, uint16)[counter] != 0xFFFF) + while (window_scenery_tab_entries[i][counter] != -1) { - if (RCT2_ADDRESS(sceneryTabItems, uint16)[counter] == index) { - ecx = 0x13; + if (window_scenery_tab_entries[i][counter] == index) { return; } @@ -207,12 +204,11 @@ void init_scenery_entry(rct_scenery_entry *sceneryEntry, int index, uint8 scener } } - uint32 edx = RCT2_GLOBAL(0x00F64F78, uint32); - for (int ecx = 0; ecx < 0x80; ecx++) { - if (RCT2_ADDRESS(edx, uint16)[ecx] == 0xFFFF) + for (int i = 0; i < 0x80; i++) { + if (window_scenery_tab_entries[0x13][i] == -1) { - RCT2_ADDRESS(edx, uint16)[ecx] = index; - RCT2_ADDRESS(edx, uint16)[ecx + 1] = 0xFFFF; + window_scenery_tab_entries[0x13][i] = index; + window_scenery_tab_entries[0x13][i + 1] = -1; break; } } @@ -223,18 +219,10 @@ void init_scenery_entry(rct_scenery_entry *sceneryEntry, int index, uint8 scener * rct2: 0x006DFA00 **/ void init_scenery() { - uint32 baseAddress = 0x00F64F7C; - - for (int i = 0; i < 0x14; i++) { - RCT2_ADDRESS(0x00F64F2C, uint32)[i] = baseAddress; - baseAddress += 0x102; - } - bool enabledScenerySets[0x13] = { false }; for (int scenerySetIndex = 0; scenerySetIndex < 0x14; scenerySetIndex++) { - int sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[scenerySetIndex]; - RCT2_GLOBAL(sceneryTabItems, uint16) = 0xFFFF; + window_scenery_tab_entries[scenerySetIndex][0] = -1; if (scenerySetIndex == 0x13) continue; @@ -242,14 +230,15 @@ void init_scenery() { if ((uint32)scenerySetEntry == 0xFFFFFFFF) continue; + int sceneryTabEntryCount = 0; + for (int i = 0; i < scenerySetEntry->entry_count; i++) { uint16 sceneryEntryId = scenerySetEntry->scenery_entries[i]; uint32 ecx = RCT2_ADDRESS(0x01357BD0, uint32)[sceneryEntryId >> 5]; uint32 edx = 1 << (sceneryEntryId & 0x1F); if (ecx & edx) { - RCT2_GLOBAL(sceneryTabItems, uint16) = sceneryEntryId; - sceneryTabItems += 2; - RCT2_GLOBAL(sceneryTabItems, uint16) = 0xFFFF; + window_scenery_tab_entries[scenerySetIndex][sceneryTabEntryCount] = sceneryEntryId; + window_scenery_tab_entries[scenerySetIndex][++sceneryTabEntryCount] = -1; } else { enabledScenerySets[scenerySetIndex] = true; } @@ -352,10 +341,9 @@ void init_scenery() { for (int ebx = 0; ebx < usedValues; ebx ++) { uint32 tabIndex = tabIndexes[ebx]; rct_widget* tabWidget = &window_scenery_widgets[tabIndex + WIDX_SCENERY_TAB_1]; - int sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[tabIndex]; if (left != 3 || tabIndex == 0x13) { - if (RCT2_GLOBAL(sceneryTabItems, uint16) == 0xFFFF) + if (window_scenery_tab_entries[tabIndex][0] == -1) continue; if (enabledScenerySets[tabIndex]) @@ -480,10 +468,8 @@ void window_scenery_close() { } int window_scenery_scrollgetsize_num() { - uint32 sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[RCT2_GLOBAL(0x00F64EDC, uint8)]; - int items = 0; - while (RCT2_ADDRESS(sceneryTabItems, sint16)[items] != -1) + while (window_scenery_tab_entries[RCT2_GLOBAL(0x00F64EDC, uint8)][items] != -1) items++; items += 8; @@ -535,11 +521,10 @@ void window_scenery_update_scroll(rct_window *w) { w->scrolls[0].v_bottom = scrollsize; int typeId = RCT2_GLOBAL(0x00F64EDC, uint8); - uint32 sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[typeId]; int itemIndex = 0; sint16 sceneryId; - while ((sceneryId = RCT2_ADDRESS(sceneryTabItems, sint16)[itemIndex]) != -1) { + while ((sceneryId = window_scenery_tab_entries[typeId][itemIndex]) != -1) { if (sceneryId == RCT2_ADDRESS(0x00F64EDD, uint16)[typeId]) break; itemIndex++; @@ -547,7 +532,7 @@ void window_scenery_update_scroll(rct_window *w) { if (sceneryId == -1) { itemIndex = 0; - sint16 sceneryId = RCT2_ADDRESS(sceneryTabItems, sint16)[itemIndex]; + sint16 sceneryId = window_scenery_tab_entries[typeId][itemIndex]; if (sceneryId != -1) RCT2_ADDRESS(0x00F64EDD, uint16)[typeId] = sceneryId; } @@ -756,12 +741,11 @@ void window_scenery_scrollgetsize() { short get_scenery_id_by_cursor_pos(short x, short y) { int tabSceneryIndex = x / 66 + (y / 80) * 9; uint8 tabIndex = RCT2_GLOBAL(0x00F64EDC, uint8); - uint32 sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[tabIndex]; int itemCounter = 0; sint16 sceneryId = 0; while (itemCounter <= tabSceneryIndex) { - sceneryId = RCT2_ADDRESS(sceneryTabItems, sint16)[itemCounter]; + sceneryId = window_scenery_tab_entries[tabIndex][itemCounter]; if (sceneryId == -1) return -1; @@ -1049,13 +1033,12 @@ void window_scenery_scrollpaint() gfx_clear(dpi, ((char*)0x0141FC48)[w->colours[1] * 8] * 0x1010101); uint8 tabIndex = RCT2_GLOBAL(0x00F64EDC, uint8); - uint32 sceneryTabItems = RCT2_ADDRESS(0x00F64F2C, uint32)[tabIndex]; int sceneryTabItemIndex = 0; sint16 currentSceneryGlobalId = -1; sint16 left = 0, top = 0; uint8 sceneryRotation = RCT2_GLOBAL(0x00F64F05, uint8); - while ((currentSceneryGlobalId = RCT2_ADDRESS(sceneryTabItems, sint16)[sceneryTabItemIndex]) != -1) { + while ((currentSceneryGlobalId = window_scenery_tab_entries[tabIndex][sceneryTabItemIndex]) != -1) { uint16 sceneryTabIndex = RCT2_ADDRESS(0x00F64EDD, uint16)[tabIndex]; if (RCT2_GLOBAL(0x00F64F19, uint8) == 1) From 6abc2327af6a6e20155da075bcdea3e321c815ce Mon Sep 17 00:00:00 2001 From: qcz Date: Sat, 6 Sep 2014 00:30:08 +0200 Subject: [PATCH 27/30] added constants for frequently used variables, renamed register named variables where the purpose is known --- src/window_scenery.c | 85 ++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index 22d2b79caa..382c610fe0 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -35,6 +35,9 @@ #define WINDOW_SCENERY_WIDTH 0x27A #define WINDOW_SCENERY_HEIGHT 0x8E +#define SCENERY_BUTTON_WIDTH 66 +#define SCENERY_BUTTON_HEIGHT 80 +#define SCENERY_ENTRIES_BY_TAB 128 enum { WINDOW_SCENERY_TAB_1, @@ -176,12 +179,12 @@ static rct_widget window_scenery_widgets[] = { { WIDGETS_END }, }; -static sint16 window_scenery_tab_entries[0x13][0x81]; +static sint16 window_scenery_tab_entries[0x13][SCENERY_ENTRIES_BY_TAB + 1]; void init_scenery_entry(rct_scenery_entry *sceneryEntry, int index, uint8 sceneryTabId) { if (RCT2_ADDRESS(0x01357BD0, sint32)[index >> 5] & (1 << (index & 0x1F))) { if (sceneryTabId != 0xFF) { - for (int i = 0; i < 0x80; i++) { + for (int i = 0; i < SCENERY_ENTRIES_BY_TAB; i++) { if (window_scenery_tab_entries[sceneryTabId][i] == -1) { window_scenery_tab_entries[sceneryTabId][i] = index; @@ -204,7 +207,7 @@ void init_scenery_entry(rct_scenery_entry *sceneryEntry, int index, uint8 scener } } - for (int i = 0; i < 0x80; i++) { + for (int i = 0; i < SCENERY_ENTRIES_BY_TAB; i++) { if (window_scenery_tab_entries[0x13][i] == -1) { window_scenery_tab_entries[0x13][i] = index; @@ -318,14 +321,14 @@ void init_scenery() { while (true) { bool finished = true; - for (int ebx = 1; ebx < usedValues; ebx++) { - if (order[ebx - 1] > order[ebx]) { - uint8 tmp = tabIndexes[ebx - 1]; - tabIndexes[ebx - 1] = tabIndexes[ebx]; - tabIndexes[ebx] = tmp; - tmp = order[ebx - 1]; - order[ebx - 1] = order[ebx]; - order[ebx] = tmp; + for (int i = 1; i < usedValues; i++) { + if (order[i - 1] > order[i]) { + uint8 tmp = tabIndexes[i - 1]; + tabIndexes[i - 1] = tabIndexes[i]; + tabIndexes[i] = tmp; + tmp = order[i - 1]; + order[i - 1] = order[i]; + order[i] = tmp; finished = false; } } @@ -338,8 +341,8 @@ void init_scenery() { usedValues++; uint16 left = 3; - for (int ebx = 0; ebx < usedValues; ebx ++) { - uint32 tabIndex = tabIndexes[ebx]; + for (int i = 0; i < usedValues; i ++) { + uint32 tabIndex = tabIndexes[i]; rct_widget* tabWidget = &window_scenery_widgets[tabIndex + WIDX_SCENERY_TAB_1]; if (left != 3 || tabIndex == 0x13) { @@ -377,7 +380,6 @@ void window_scenery_open() return; init_scenery(); - //RCT2_CALLPROC_EBPSAFE(0x006DFA00); window = window_create(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, sint16) - WINDOW_SCENERY_WIDTH, 0x1D, WINDOW_SCENERY_WIDTH, WINDOW_SCENERY_HEIGHT, (uint32*)window_scenery_events, WC_SCENERY, WF_2); @@ -415,7 +417,7 @@ void window_scenery_open() window_init_scroll_widgets(window); RCT2_CALLPROC_X(0x006E1EB4, 0, 0, 0, 0, (int)window, 0, 0); show_gridlines(); - RCT2_GLOBAL(0x00F64F05, uint8) = 3; // rotation + RCT2_GLOBAL(0x00F64F05, uint8) = 3; // scenery rotation RCT2_GLOBAL(0x00F64F12, uint8) = 0; RCT2_GLOBAL(0x00F64F13, uint8) = 0; window->scenery.selected_scenery_id = -1; @@ -425,7 +427,7 @@ void window_scenery_open() RCT2_GLOBAL(0x00F64EB4, uint32) = 0x80000000; RCT2_GLOBAL(0x00F64EC0, uint16) = 0; RCT2_GLOBAL(0x00F64F19, uint8) = 0; // repaint colored scenery tool state - RCT2_GLOBAL(0x00F64F1A, uint8) = 0; + RCT2_GLOBAL(0x00F64F1A, uint8) = 0; // build cluster tool state window->min_width = WINDOW_SCENERY_WIDTH; window->max_width = WINDOW_SCENERY_WIDTH; @@ -477,7 +479,7 @@ int window_scenery_scrollgetsize_num() { if (rows == 0) rows++; - return rows * 80; + return rows * SCENERY_BUTTON_HEIGHT; } /** @@ -497,7 +499,7 @@ static void window_scenery_mouseup() break; case WIDX_SCENERY_ROTATE_OBJECTS_BUTTON: RCT2_GLOBAL(0x00F64F05, uint8)++; - RCT2_GLOBAL(0x00F64F05, uint8) &= 3; + RCT2_GLOBAL(0x00F64F05, uint8) = RCT2_GLOBAL(0x00F64F05, uint8) % 4; RCT2_CALLPROC_EBPSAFE(0x006E2712); window_invalidate(w); break; @@ -537,7 +539,7 @@ void window_scenery_update_scroll(rct_window *w) { RCT2_ADDRESS(0x00F64EDD, uint16)[typeId] = sceneryId; } - w->scrolls[0].v_top = (itemIndex / 9) * 80; + w->scrolls[0].v_top = (itemIndex / 9) * SCENERY_BUTTON_HEIGHT; widget_scroll_update_thumbs(w, WIDX_SCENERY_LIST); } @@ -692,6 +694,8 @@ static void window_scenery_update(rct_window *w) w->max_height = WINDOW_SCENERY_HEIGHT; } } + + gfx_invalidate_screen(); // todo //if (window_scenery_is_tool_active()) @@ -739,7 +743,7 @@ void window_scenery_scrollgetsize() { } short get_scenery_id_by_cursor_pos(short x, short y) { - int tabSceneryIndex = x / 66 + (y / 80) * 9; + int tabSceneryIndex = x / SCENERY_BUTTON_WIDTH + (y / SCENERY_BUTTON_HEIGHT) * 9; uint8 tabIndex = RCT2_GLOBAL(0x00F64EDC, uint8); int itemCounter = 0; @@ -971,34 +975,34 @@ void window_scenery_paint() { w->y + window_scenery_widgets[selectedTab].top, selectedTab); - sint16 bp = w->scenery.selected_scenery_id; - if (bp == -1) { + sint16 selectedSceneryEntryId = w->scenery.selected_scenery_id; + if (selectedSceneryEntryId == -1) { if (RCT2_GLOBAL(0x00F64F19, uint8) & 1) // repaint colored scenery tool is on return; - bp = RCT2_ADDRESS(0x00F64EDD, uint16)[typeId]; + selectedSceneryEntryId = RCT2_ADDRESS(0x00F64EDD, uint16)[typeId]; - if (bp == -1) + if (selectedSceneryEntryId == -1) return; } uint32 price = 0; rct_scenery_entry* sceneryEntry = NULL; - if (bp >= 0x400) { - sceneryEntry = g_bannerSceneryEntries[bp - 0x400]; + if (selectedSceneryEntryId >= 0x400) { + sceneryEntry = g_bannerSceneryEntries[selectedSceneryEntryId - 0x400]; price = sceneryEntry->banner.price; - } else if (bp >= 0x300) { - sceneryEntry = g_largeSceneryEntries[bp - 0x300]; + } else if (selectedSceneryEntryId >= 0x300) { + sceneryEntry = g_largeSceneryEntries[selectedSceneryEntryId - 0x300]; price = sceneryEntry->large_scenery.price * 10; - } else if (bp >= 0x200) { - sceneryEntry = g_wallSceneryEntries[bp - 0x200]; + } else if (selectedSceneryEntryId >= 0x200) { + sceneryEntry = g_wallSceneryEntries[selectedSceneryEntryId - 0x200]; price = sceneryEntry->wall.price; - } else if (bp >= 0x100) { - sceneryEntry = g_pathBitSceneryEntries[bp - 0x100]; + } else if (selectedSceneryEntryId >= 0x100) { + sceneryEntry = g_pathBitSceneryEntries[selectedSceneryEntryId - 0x100]; price = sceneryEntry->path_bit.price; } else { - sceneryEntry = g_smallSceneryEntries[bp]; + sceneryEntry = g_smallSceneryEntries[selectedSceneryEntryId]; price = sceneryEntry->small_scenery.price * 10; } @@ -1044,14 +1048,17 @@ void window_scenery_scrollpaint() if (RCT2_GLOBAL(0x00F64F19, uint8) == 1) { if (w->scenery.selected_scenery_id == currentSceneryGlobalId) { - gfx_fill_rect_inset(dpi, left, top, left + 65, top + 79, w->colours[1], 0x80); + gfx_fill_rect_inset(dpi, left, top, left + SCENERY_BUTTON_WIDTH - 1, + top + SCENERY_BUTTON_HEIGHT - 1, w->colours[1], 0x80); } } else { if (sceneryTabIndex == currentSceneryGlobalId) { - gfx_fill_rect_inset(dpi, left, top, left + 65, top + 79, w->colours[1], 0xA0); + gfx_fill_rect_inset(dpi, left, top, left + SCENERY_BUTTON_WIDTH - 1, + top + SCENERY_BUTTON_HEIGHT - 1, w->colours[1], 0xA0); } else if (w->scenery.selected_scenery_id == currentSceneryGlobalId) { - gfx_fill_rect_inset(dpi, left, top, left + 65, top + 79, w->colours[1], 0x80); + gfx_fill_rect_inset(dpi, left, top, left + SCENERY_BUTTON_WIDTH - 1, + top + SCENERY_BUTTON_HEIGHT - 1, w->colours[1], 0x80); } } @@ -1112,7 +1119,7 @@ void window_scenery_scrollpaint() gfx_draw_sprite(dpi, imageId, left + 0x0B, top + 0x10, w->colours[1]); } else { sceneryEntry = g_smallSceneryEntries[currentSceneryGlobalId]; - rct_drawpixelinfo* clipdpi = clip_drawpixelinfo(dpi, left + 1, 64, top + 1, 78); + rct_drawpixelinfo* clipdpi = clip_drawpixelinfo(dpi, left + 1, SCENERY_BUTTON_WIDTH - 2, top + 1, SCENERY_BUTTON_HEIGHT - 2); if (clipdpi != NULL) { uint32 imageId = sceneryEntry->image + sceneryRotation; @@ -1150,9 +1157,9 @@ void window_scenery_scrollpaint() } } - left += 66; + left += SCENERY_BUTTON_WIDTH; if (left >= 594) { - top += 80; + top += SCENERY_BUTTON_HEIGHT; left = 0; } sceneryTabItemIndex++; From 6b3c39655fea8e3a5880eea737d22207333cc8f0 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Fri, 5 Sep 2014 23:46:35 +0100 Subject: [PATCH 28/30] fixes #279, WWT_24 no longer shows a checkbox --- src/widget.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/widget.c b/src/widget.c index 22226cd78f..003e86597a 100644 --- a/src/widget.c +++ b/src/widget.c @@ -736,13 +736,15 @@ static void widget_checkbox_draw(rct_drawpixelinfo *dpi, rct_window *w, int widg // Get the colour colour = w->colours[widget->colour]; - // checkbox - gfx_fill_rect_inset(dpi, l, t, l + 9, b - 1, colour, 0x60); + if (widget->type != WWT_24) { + // checkbox + gfx_fill_rect_inset(dpi, l, t, l + 9, b - 1, colour, 0x60); - // fill it when checkbox is pressed - if (widget_is_pressed(w, widgetIndex)) { - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224; - gfx_draw_string(dpi, (char*)0x009DED72, colour & 0x7F, l, t); + // fill it when checkbox is pressed + if (widget_is_pressed(w, widgetIndex)) { + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224; + gfx_draw_string(dpi, (char*)0x009DED72, colour & 0x7F, l, t); + } } // draw the text From 7b2b9e5859da6c0f541fa4aecf373272f5dedd48 Mon Sep 17 00:00:00 2001 From: qcz Date: Sat, 6 Sep 2014 01:09:12 +0200 Subject: [PATCH 29/30] Finalize scenery window, fix encoding --- src/scenery.h | 2 +- src/window.h | 2 +- src/window_scenery.c | 109 +++++++++++++++++++++---------------------- src/window_staff.c | 4 +- 4 files changed, 58 insertions(+), 59 deletions(-) diff --git a/src/scenery.h b/src/scenery.h index e14283761a..59704d94c0 100644 --- a/src/scenery.h +++ b/src/scenery.h @@ -1,5 +1,5 @@ /***************************************************************************** -* Copyright (c) 2014 Dániel Tar +* Copyright (c) 2014 Dániel Tar * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. * * This file is part of OpenRCT2. diff --git a/src/window.h b/src/window.h index 50667937c0..0270e5cdc3 100644 --- a/src/window.h +++ b/src/window.h @@ -164,7 +164,7 @@ typedef struct { typedef struct { sint16 selected_scenery_id; - uint16 var_482; + sint16 hover_counter; } scenery_variables; /** diff --git a/src/window_scenery.c b/src/window_scenery.c index 382c610fe0..bf5cd32722 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -1,5 +1,5 @@ /***************************************************************************** -* Copyright (c) 2014 Dániel Tar +* Copyright (c) 2014 Dániel Tar * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. * * This file is part of OpenRCT2. @@ -421,7 +421,7 @@ void window_scenery_open() RCT2_GLOBAL(0x00F64F12, uint8) = 0; RCT2_GLOBAL(0x00F64F13, uint8) = 0; window->scenery.selected_scenery_id = -1; - window->scenery.var_482 = 0; + window->scenery.hover_counter = 0; window_push_others_below(window); RCT2_GLOBAL(0x00F64F0D, uint8) = 0; RCT2_GLOBAL(0x00F64EB4, uint32) = 0x80000000; @@ -522,21 +522,21 @@ void window_scenery_update_scroll(rct_window *w) { int scrollsize = window_scenery_scrollgetsize_num(); w->scrolls[0].v_bottom = scrollsize; - int typeId = RCT2_GLOBAL(0x00F64EDC, uint8); + int tabIndex = RCT2_GLOBAL(0x00F64EDC, uint8); int itemIndex = 0; sint16 sceneryId; - while ((sceneryId = window_scenery_tab_entries[typeId][itemIndex]) != -1) { - if (sceneryId == RCT2_ADDRESS(0x00F64EDD, uint16)[typeId]) + while ((sceneryId = window_scenery_tab_entries[tabIndex][itemIndex]) != -1) { + if (sceneryId == RCT2_ADDRESS(0x00F64EDD, sint16)[tabIndex]) break; itemIndex++; } if (sceneryId == -1) { itemIndex = 0; - sint16 sceneryId = window_scenery_tab_entries[typeId][itemIndex]; + sint16 sceneryId = window_scenery_tab_entries[tabIndex][itemIndex]; if (sceneryId != -1) - RCT2_ADDRESS(0x00F64EDD, uint16)[typeId] = sceneryId; + RCT2_ADDRESS(0x00F64EDD, sint16)[tabIndex] = sceneryId; } w->scrolls[0].v_top = (itemIndex / 9) * SCENERY_BUTTON_HEIGHT; @@ -656,13 +656,13 @@ static void window_scenery_update(rct_window *w) int window_x = RCT2_GLOBAL(0x0142406C, int) - w->x + 0x1A; int window_y = RCT2_GLOBAL(0x01424070, int) - w->y; - if (window_y < 0x2C && window_x <= w->width) { + if (window_y < 0x2C || window_x <= w->width) { int widgetIndex = window_find_widget_from_point(w, RCT2_GLOBAL(0x0142406C, int), RCT2_GLOBAL(0x01424070, int)); if (widgetIndex >= 3) { - w->scenery.var_482++; - if (w->scenery.var_482 < 8) { + w->scenery.hover_counter++; + if (w->scenery.hover_counter < 8) { if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, sint8) != INPUT_STATE_SCROLL_LEFT) { w->min_width = WINDOW_SCENERY_WIDTH; w->max_width = WINDOW_SCENERY_WIDTH; @@ -686,7 +686,7 @@ static void window_scenery_update(rct_window *w) } } } else { - w->scenery.var_482 = 0; + w->scenery.hover_counter = 0; if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, sint8) != INPUT_STATE_SCROLL_LEFT) { w->min_width = WINDOW_SCENERY_WIDTH; w->max_width = WINDOW_SCENERY_WIDTH; @@ -706,25 +706,25 @@ static void window_scenery_update(rct_window *w) return; } - uint16 typeId = RCT2_GLOBAL(0x00F64EDC, uint8); - uint16 sceneryIndex = RCT2_ADDRESS(0x00F64EDD, uint16)[typeId]; - if (sceneryIndex == 0xFFFF) + uint16 tabIndex = RCT2_GLOBAL(0x00F64EDC, uint8); + sint16 tabSelectedSceneryId = RCT2_ADDRESS(0x00F64EDD, sint16)[tabIndex]; + if (tabSelectedSceneryId == -1) return; - if (sceneryIndex > 0x400) { // banner + if (tabSelectedSceneryId > 0x400) { // banner RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = 0x18; - } else if (sceneryIndex > 0x300) { // large scenery + } else if (tabSelectedSceneryId > 0x300) { // large scenery RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = - g_largeSceneryEntries[sceneryIndex - 0x300]->large_scenery.tool_id; - } else if (sceneryIndex > 0x200) { // wall + g_largeSceneryEntries[tabSelectedSceneryId - 0x300]->large_scenery.tool_id; + } else if (tabSelectedSceneryId > 0x200) { // wall RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = - g_wallSceneryEntries[sceneryIndex - 0x200]->wall.tool_id; - } else if (sceneryIndex > 0x100) { // path bit + g_wallSceneryEntries[tabSelectedSceneryId - 0x200]->wall.tool_id; + } else if (tabSelectedSceneryId > 0x100) { // path bit RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = - g_pathBitSceneryEntries[sceneryIndex - 0x100]->path_bit.tool_id; + g_pathBitSceneryEntries[tabSelectedSceneryId - 0x100]->path_bit.tool_id; } else { // small scenery RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = - g_smallSceneryEntries[sceneryIndex]->small_scenery.tool_id; + g_smallSceneryEntries[tabSelectedSceneryId]->small_scenery.tool_id; } } @@ -774,11 +774,11 @@ void window_scenery_scrollmousedown() { return; uint8 tabIndex = RCT2_GLOBAL(0x00F64EDC, uint8); - RCT2_ADDRESS(0x00F64EDD, uint16)[tabIndex] = sceneryId; + RCT2_ADDRESS(0x00F64EDD, sint16)[tabIndex] = sceneryId; RCT2_GLOBAL(0x00F64F19, uint8) &= 0xFE; sound_play_panned(4, (w->width >> 1) + w->x); - w->scenery.var_482 = 0xFFF0; + w->scenery.hover_counter = -16; RCT2_GLOBAL(0x00F64EB4, uint32) = 0x80000000; window_invalidate(w); } @@ -797,7 +797,6 @@ void window_scenery_scrollmouseover() { w->scenery.selected_scenery_id = sceneryId; window_invalidate(w); } - } /** @@ -832,14 +831,14 @@ void window_scenery_invalidate() { window_get_register(w); - uint16 typeId = RCT2_GLOBAL(0x00F64EDC, uint8); - uint32 title_string_id = 0x715; - if (typeId <= 0x13) { - title_string_id = g_scenerySetEntries[typeId]->name; + uint16 tabIndex = RCT2_GLOBAL(0x00F64EDC, uint8); + uint32 titleStringId = 0x715; + if (tabIndex <= 0x13) { + titleStringId = g_scenerySetEntries[tabIndex]->name; } - window_scenery_widgets[WIDX_SCENERY_TITLE].image = title_string_id; + window_scenery_widgets[WIDX_SCENERY_TITLE].image = titleStringId; - w->pressed_widgets = (((uint32)w->pressed_widgets & 0xFF00000F) | (1 << (typeId + 4))) & 0xBBFFFFFF; + w->pressed_widgets = (((uint32)w->pressed_widgets & 0xFF00000F) | (1 << (tabIndex + 4))) & 0xBBFFFFFF; if (RCT2_GLOBAL(0x00F64F19, uint8) == 1) { // repaint colored scenery tool is on w->pressed_widgets |= 0x04000000; @@ -852,18 +851,18 @@ void window_scenery_invalidate() { window_scenery_widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].type = WWT_EMPTY; window_scenery_widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].type = WWT_EMPTY; - uint16 globalSceneryId = RCT2_ADDRESS(0x00F64EDD, uint16)[typeId]; - if (globalSceneryId != 0xFFFF) { - if (globalSceneryId < 0x100) { + sint16 tabSelectedSceneryId = RCT2_ADDRESS(0x00F64EDD, sint16)[tabIndex]; + if (tabSelectedSceneryId != -1) { + if (tabSelectedSceneryId < 0x100) { if (!(RCT2_GLOBAL(0x00F64F19, uint8) & 1)) window_scenery_widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].type = WWT_FLATBTN; - rct_scenery_entry* sceneryEntry = g_smallSceneryEntries[globalSceneryId]; + rct_scenery_entry* sceneryEntry = g_smallSceneryEntries[tabSelectedSceneryId]; if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG4) { window_scenery_widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].type = WWT_FLATBTN; } } - else if (globalSceneryId > 0x300) { + else if (tabSelectedSceneryId > 0x300) { window_scenery_widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].type = WWT_FLATBTN; } } @@ -885,25 +884,25 @@ void window_scenery_invalidate() { window_scenery_widgets[WIDX_SCENERY_TERTIARY_COLOUR_BUTTON].type = WWT_COLORBTN; window_scenery_widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].type = WWT_EMPTY; } - else if (globalSceneryId != 0xFFFF) { + else if (tabSelectedSceneryId != -1) { rct_scenery_entry* sceneryEntry = NULL; - if (globalSceneryId >= 0x400) { - sceneryEntry = g_bannerSceneryEntries[globalSceneryId - 0x400]; + if (tabSelectedSceneryId >= 0x400) { + sceneryEntry = g_bannerSceneryEntries[tabSelectedSceneryId - 0x400]; if (sceneryEntry->banner.flags & 1) window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WWT_COLORBTN; } - else if (globalSceneryId >= 0x300) { - sceneryEntry = g_largeSceneryEntries[globalSceneryId - 0x300]; + else if (tabSelectedSceneryId >= 0x300) { + sceneryEntry = g_largeSceneryEntries[tabSelectedSceneryId - 0x300]; if (sceneryEntry->large_scenery.flags & 1) window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WWT_COLORBTN; if (sceneryEntry->large_scenery.flags & 2) window_scenery_widgets[WIDX_SCENERY_SECONDARY_COLOUR_BUTTON].type = WWT_COLORBTN; } - else if (globalSceneryId >= 0x200) { - sceneryEntry = g_wallSceneryEntries[globalSceneryId - 0x200]; + else if (tabSelectedSceneryId >= 0x200) { + sceneryEntry = g_wallSceneryEntries[tabSelectedSceneryId - 0x200]; if (sceneryEntry->wall.flags & (WALL_SCENERY_FLAG1 | WALL_SCENERY_FLAG2)) { window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WWT_COLORBTN; @@ -917,8 +916,8 @@ void window_scenery_invalidate() { } } } - else if (globalSceneryId < 0x100) { - sceneryEntry = g_smallSceneryEntries[globalSceneryId]; + else if (tabSelectedSceneryId < 0x100) { + sceneryEntry = g_smallSceneryEntries[tabSelectedSceneryId]; if (sceneryEntry->small_scenery.flags & (SMALL_SCENERY_HAS_PRIMARY_COLOUR | SMALL_SCENERY_FLAG10)) { window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WWT_COLORBTN; @@ -966,21 +965,21 @@ void window_scenery_paint() { window_draw_widgets(w, dpi); - uint16 typeId = RCT2_GLOBAL(0x00F64EDC, uint8); - uint16 selectedTab = typeId + 4; - uint32 image_id = ((w->colours[1] << 19) | window_scenery_widgets[selectedTab].image) + 1ul; + uint16 tabIndex = RCT2_GLOBAL(0x00F64EDC, uint8); + uint16 selectedWidgetId = tabIndex + 4; + uint32 imageId = ((w->colours[1] << 19) | window_scenery_widgets[selectedWidgetId].image) + 1ul; - gfx_draw_sprite(dpi, image_id, - w->x + window_scenery_widgets[selectedTab].left, - w->y + window_scenery_widgets[selectedTab].top, - selectedTab); + gfx_draw_sprite(dpi, imageId, + w->x + window_scenery_widgets[selectedWidgetId].left, + w->y + window_scenery_widgets[selectedWidgetId].top, + selectedWidgetId); sint16 selectedSceneryEntryId = w->scenery.selected_scenery_id; if (selectedSceneryEntryId == -1) { if (RCT2_GLOBAL(0x00F64F19, uint8) & 1) // repaint colored scenery tool is on return; - selectedSceneryEntryId = RCT2_ADDRESS(0x00F64EDD, uint16)[typeId]; + selectedSceneryEntryId = RCT2_ADDRESS(0x00F64EDD, sint16)[tabIndex]; if (selectedSceneryEntryId == -1) return; @@ -1043,7 +1042,7 @@ void window_scenery_scrollpaint() sint16 left = 0, top = 0; uint8 sceneryRotation = RCT2_GLOBAL(0x00F64F05, uint8); while ((currentSceneryGlobalId = window_scenery_tab_entries[tabIndex][sceneryTabItemIndex]) != -1) { - uint16 sceneryTabIndex = RCT2_ADDRESS(0x00F64EDD, uint16)[tabIndex]; + uint16 tabSelectedSceneryId = RCT2_ADDRESS(0x00F64EDD, uint16)[tabIndex]; if (RCT2_GLOBAL(0x00F64F19, uint8) == 1) { @@ -1052,7 +1051,7 @@ void window_scenery_scrollpaint() top + SCENERY_BUTTON_HEIGHT - 1, w->colours[1], 0x80); } } else { - if (sceneryTabIndex == currentSceneryGlobalId) { + if (tabSelectedSceneryId == currentSceneryGlobalId) { gfx_fill_rect_inset(dpi, left, top, left + SCENERY_BUTTON_WIDTH - 1, top + SCENERY_BUTTON_HEIGHT - 1, w->colours[1], 0xA0); } diff --git a/src/window_staff.c b/src/window_staff.c index 4fc0b0888c..eed1574ee7 100644 --- a/src/window_staff.c +++ b/src/window_staff.c @@ -1,5 +1,5 @@ -/***************************************************************************** -* Copyright (c) 2014 Maciek Baron, Daniel Tar +/***************************************************************************** +* Copyright (c) 2014 Maciek Baron, Dániel Tar * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. * * This file is part of OpenRCT2. From b4c772336875169ebd3eb23b46ebf4cf9e6a903c Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sat, 6 Sep 2014 01:06:31 +0100 Subject: [PATCH 30/30] fix warnings in window_scenery.c --- src/window_scenery.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/window_scenery.c b/src/window_scenery.c index bf5cd32722..17c8ee2b2b 100644 --- a/src/window_scenery.c +++ b/src/window_scenery.c @@ -619,13 +619,13 @@ static void window_scenery_dropdown() { return; if (widgetIndex == WIDX_SCENERY_PRIMARY_COLOUR_BUTTON) { - RCT2_GLOBAL(0x00F64F06, uint8) = dropdownIndex; + RCT2_GLOBAL(0x00F64F06, uint8) = (uint8)dropdownIndex; } else if (widgetIndex == WIDX_SCENERY_SECONDARY_COLOUR_BUTTON) { - RCT2_GLOBAL(0x00F64F07, uint8) = dropdownIndex; + RCT2_GLOBAL(0x00F64F07, uint8) = (uint8)dropdownIndex; } else if (widgetIndex == WIDX_SCENERY_TERTIARY_COLOUR_BUTTON) { - RCT2_GLOBAL(0x00F64F08, uint8) = dropdownIndex; + RCT2_GLOBAL(0x00F64F08, uint8) = (uint8)dropdownIndex; } window_invalidate(w);