From c51b9d7cb070cecf12bfbffcbcf64a3484609b34 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Tue, 7 Oct 2014 12:16:17 -0600 Subject: [PATCH 1/6] mixer fix --- src/audio.h | 2 +- src/mixer.cpp | 24 +++++++++++++++++++----- src/vehicle.c | 4 ++-- src/window_options.c | 6 +++++- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/audio.h b/src/audio.h index 9e12285098..4a9e30a221 100644 --- a/src/audio.h +++ b/src/audio.h @@ -31,7 +31,7 @@ typedef struct { extern int gAudioDeviceCount; extern audio_device *gAudioDevices; -#define AUDIO_MAX_VEHICLE_SOUNDS 50 +#define AUDIO_MAX_VEHICLE_SOUNDS 14 void audio_init(); void audio_quit(); diff --git a/src/mixer.cpp b/src/mixer.cpp index f23093d804..ccf0d8fa44 100644 --- a/src/mixer.cpp +++ b/src/mixer.cpp @@ -272,6 +272,11 @@ void Mixer::Init(const char* device) void Mixer::Close() { + Lock(); + while (channels.begin() != channels.end()) { + Stop(*(*channels.begin())); + } + Unlock(); SDL_CloseAudioDevice(deviceid); delete[] effectbuffer; } @@ -329,7 +334,11 @@ void Mixer::MixChannel(Channel& channel, uint8* data, int length) int samplesize = format.channels * format.BytesPerSample(); int samples = length / samplesize; int samplesloaded = loaded / samplesize; - int samplestoread = (int)ceil((samples - samplesloaded) * channel.rate); + double rate = 1; + if (format.format == AUDIO_S16SYS) { + rate = channel.rate; + } + int samplestoread = (int)ceil((samples - samplesloaded) * rate); int lengthloaded = 0; if (channel.offset < channel.stream->Length()) { bool mustconvert = false; @@ -363,11 +372,10 @@ void Mixer::MixChannel(Channel& channel, uint8* data, int length) } bool effectbufferloaded = false; - - if (channel.rate != 1 && format.format == AUDIO_S16SYS) { + if (rate != 1 && format.format == AUDIO_S16SYS) { int in_len = (int)(ceil((double)lengthloaded / samplesize)); int out_len = samples + 20; // needs some extra, otherwise resampler sometimes doesn't process all the input samples - speex_resampler_set_rate(channel.resampler, format.freq, (int)(format.freq * (1 / channel.rate))); + speex_resampler_set_rate(channel.resampler, format.freq, (int)(format.freq * (1 / rate))); speex_resampler_process_interleaved_int(channel.resampler, (const spx_int16_t*)tomix, (spx_uint32_t*)&in_len, (spx_int16_t*)effectbuffer, (spx_uint32_t*)&out_len); effectbufferloaded = true; tomix = effectbuffer; @@ -386,7 +394,7 @@ void Mixer::MixChannel(Channel& channel, uint8* data, int length) break; case AUDIO_U8: EffectPanU8(channel, (uint8*)effectbuffer, lengthloaded / samplesize); - break; + break; } } @@ -493,15 +501,21 @@ void Mixer_Stop_Channel(void* channel) void Mixer_Channel_Volume(void* channel, int volume) { + gMixer.Lock(); ((Channel*)channel)->SetVolume(volume); + gMixer.Unlock(); } void Mixer_Channel_Pan(void* channel, float pan) { + gMixer.Lock(); ((Channel*)channel)->SetPan(pan); + gMixer.Unlock(); } void Mixer_Channel_Rate(void* channel, double rate) { + gMixer.Lock(); ((Channel*)channel)->SetRate(rate); + gMixer.Unlock(); } \ No newline at end of file diff --git a/src/vehicle.c b/src/vehicle.c index 770e074986..1b45f7154b 100644 --- a/src/vehicle.c +++ b/src/vehicle.c @@ -364,7 +364,7 @@ void vehicle_sounds_update() vehicle_sound->sound1_id = sprite->vehicle.sound1_id; #ifndef USE_MIXER RCT2_GLOBAL(0x014241BC, uint32) = 1; - sound_prepare(sprite->vehicle.var_BB, &vehicle_sound->sound1, 1, RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER, uint32)); + sound_prepare(sprite->vehicle.sound1_id, &vehicle_sound->sound1, 1, RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER, uint32)); RCT2_GLOBAL(0x014241BC, uint32) = 0; #endif vehicle_sound->sound1_pan = vehicle_sound_params->pan; @@ -461,7 +461,7 @@ void vehicle_sounds_update() vehicle_sound->sound2_id = sprite->vehicle.sound2_id; #ifndef USE_MIXER RCT2_GLOBAL(0x014241BC, uint32) = 1; - sound_prepare(sprite->vehicle.var_BD, &vehicle_sound->sound2, 1, RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER, uint32)); + sound_prepare(sprite->vehicle.sound2_id, &vehicle_sound->sound2, 1, RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER, uint32)); RCT2_GLOBAL(0x014241BC, uint32) = 0; #endif vehicle_sound->sound2_pan = vehicle_sound_params->pan; diff --git a/src/window_options.c b/src/window_options.c index 4df489aa0f..20de231050 100644 --- a/src/window_options.c +++ b/src/window_options.c @@ -505,7 +505,11 @@ static void window_options_dropdown() case WIDX_SOUND_DROPDOWN: audio_init2(dropdownIndex); if (dropdownIndex < gAudioDeviceCount) { - Mixer_Init(gAudioDevices[dropdownIndex].name); + int devicenum = dropdownIndex; + if (devicenum == 0) { + devicenum = 1; + } + Mixer_Init(gAudioDevices[devicenum].name); } /*#ifdef _MSC_VER __asm movzx ax, dropdownIndex From ff1b124572dae5e4ff28003f6e64773ef3b2f470 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 5 Oct 2014 14:21:35 +0100 Subject: [PATCH 2/6] Added start of shortcut window --- projects/openrct2.vcxproj | 1 + projects/openrct2.vcxproj.filters | 3 + src/window.h | 1 + src/window_options.c | 2 +- src/window_shortcut_keys.c | 101 ++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/window_shortcut_keys.c diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj index 38e1118dbe..7d2141ddcc 100644 --- a/projects/openrct2.vcxproj +++ b/projects/openrct2.vcxproj @@ -136,6 +136,7 @@ + diff --git a/projects/openrct2.vcxproj.filters b/projects/openrct2.vcxproj.filters index b1610b9290..cfc27fe39c 100644 --- a/projects/openrct2.vcxproj.filters +++ b/projects/openrct2.vcxproj.filters @@ -431,6 +431,9 @@ Source Files + + Windows + diff --git a/src/window.h b/src/window.h index f7c27d7b1d..6e59bc1cd0 100644 --- a/src/window.h +++ b/src/window.h @@ -476,6 +476,7 @@ void window_staff_open(); void window_guest_list_open(); void window_map_open(); void window_options_open(); +void window_shortcut_keys_open(); void window_peep_open(rct_peep* peep); void window_staff_peep_open(rct_peep* peep); void window_park_awards_open(); diff --git a/src/window_options.c b/src/window_options.c index 4df489aa0f..b2a1325b43 100644 --- a/src/window_options.c +++ b/src/window_options.c @@ -286,7 +286,7 @@ static void window_options_mouseup() window_options_set_page(w, widgetIndex - WIDX_TAB_1); break; case WIDX_HOTKEY_DROPDOWN: - RCT2_CALLPROC_EBPSAFE(0x006E3884); + window_shortcut_keys_open(); break; case WIDX_SCREEN_EDGE_SCROLLING: RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_EDGE_SCROLLING, uint8) ^= 1; diff --git a/src/window_shortcut_keys.c b/src/window_shortcut_keys.c new file mode 100644 index 0000000000..27c63021d4 --- /dev/null +++ b/src/window_shortcut_keys.c @@ -0,0 +1,101 @@ +/***************************************************************************** +* Copyright (c) 2014 Ted John, Duncan Frost +* 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 "window.h" +#include "widget.h" + +#define WW 340 +#define WH 240 + +enum WINDOW_SHORTCUT_WIDGET_IDX { + WIDX_BACKGROUND, + WIDX_TITLE, + WIDX_CLOSE, + WIDX_SCROLL, + WIDX_RESET +}; + +// 9DE48C +static rct_widget window_shortcut_widgets[] = { + { WWT_FRAME, 0, 0, WW - 1, 0, WH - 1, STR_NONE, STR_NONE }, + { WWT_CAPTION, 0, 1, WW - 2, 1, 14, STR_OPTIONS, STR_WINDOW_TITLE_TIP }, + { WWT_CLOSEBOX, 0, WW-13, WW - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, + { WWT_SCROLL, 0, 4, WW - 5, 18, WH - 18, 2, 2786 }, + { WWT_DROPDOWN_BUTTON, 0, 4, 153, WH-15, WH - 4, 2491, 2492 }, + { WIDGETS_END } +}; + +void window_shortcut_emptysub() { } + +static void* window_options_events[] = { + window_shortcut_emptysub, + (void*)0x6E39E4, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + (void*)0x6E3A07, + (void*)0x6E3A3E, + window_shortcut_emptysub, + (void*)0x6E3A16, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + (void*)0x6E3A0C, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + (void*)0x6E38E0, + (void*)0x6E38E6 +}; + +/** + * + * rct2: 0x006E3884 + */ +void window_shortcut_keys_open() +{ + rct_window* w; + + w = window_bring_to_front_by_id(WC_KEYBOARD_SHORTCUT_LIST, 0); + + if (w) return; + + w = window_create_auto_pos(WW, WH, (uint32*)0x9A3F0C, WC_KEYBOARD_SHORTCUT_LIST, 0); + + w->widgets = window_shortcut_widgets; + w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_RESET); + window_init_scroll_widgets(w); + + w->colours[0] = 7; + w->colours[1] = 7; + w->colours[2] = 7; + w->no_list_items = 32; + w->selected_list_item = -1; +} \ No newline at end of file From 160a1f8ddaeb22056d53352014d88f95bfeb6653 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 5 Oct 2014 14:38:15 +0100 Subject: [PATCH 3/6] Added the smaller shortcut functions --- src/window_shortcut_keys.c | 79 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/src/window_shortcut_keys.c b/src/window_shortcut_keys.c index 27c63021d4..8d6fb5df46 100644 --- a/src/window_shortcut_keys.c +++ b/src/window_shortcut_keys.c @@ -18,6 +18,8 @@ * along with this program. If not, see . *****************************************************************************/ +#include "addresses.h" +#include "config.h" #include "window.h" #include "widget.h" @@ -43,10 +45,14 @@ static rct_widget window_shortcut_widgets[] = { }; void window_shortcut_emptysub() { } +static void window_shortcut_mouseup(); +static void window_shortcut_paint(); +static void window_shortcut_tooltip(); +static void window_shortcut_scrollgetsize(); static void* window_options_events[] = { window_shortcut_emptysub, - (void*)0x6E39E4, + window_shortcut_mouseup, window_shortcut_emptysub, window_shortcut_emptysub, window_shortcut_emptysub, @@ -60,18 +66,18 @@ static void* window_options_events[] = { window_shortcut_emptysub, window_shortcut_emptysub, window_shortcut_emptysub, - (void*)0x6E3A07, + window_shortcut_scrollgetsize, (void*)0x6E3A3E, window_shortcut_emptysub, (void*)0x6E3A16, window_shortcut_emptysub, window_shortcut_emptysub, window_shortcut_emptysub, - (void*)0x6E3A0C, + window_shortcut_tooltip, window_shortcut_emptysub, window_shortcut_emptysub, window_shortcut_emptysub, - (void*)0x6E38E0, + window_shortcut_paint, (void*)0x6E38E6 }; @@ -98,4 +104,69 @@ void window_shortcut_keys_open() w->colours[2] = 7; w->no_list_items = 32; w->selected_list_item = -1; +} + +/** +* +* rct2: 0x006E39E4 +*/ +static void window_shortcut_mouseup() +{ + short widgetIndex; + rct_window *w; + + window_widget_get_registers(w, widgetIndex); + + switch (widgetIndex){ + case WIDX_CLOSE: + window_close(w); + break; + case WIDX_RESET: + config_reset_shortcut_keys(); + config_save(); + window_invalidate(w); + break; + } +} + +/** +* +* rct2: 0x006E38E0 +*/ +static void window_shortcut_paint() +{ + rct_window *w; + rct_drawpixelinfo *dpi; + + window_paint_get_registers(w, dpi); + + window_draw_widgets(w, dpi); +} + +/** +* +* rct2: 0x006E3A0C +*/ +static void window_shortcut_tooltip() +{ + RCT2_GLOBAL(0x013CE952, uint16) = STR_LIST; +} + +/** +* +* rct2: 0x006E3A07 +*/ +static void window_shortcut_scrollgetsize() +{ + int y; + rct_window *w; + window_get_register(w); + + y = 32 * 10; + +#ifdef _MSC_VER + __asm mov edx, y +#else + __asm__("mov edx, %[y] " : [y] "+m" (y)); +#endif } \ No newline at end of file From 75f71de53ac002a720d5265af5a7ffe52fdcd5da Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 5 Oct 2014 20:56:26 +0100 Subject: [PATCH 4/6] Added missing functions and window_shortcut_change --- src/config.h | 5 + src/string_ids.h | 4 +- src/window_ride.c | 2 +- src/window_shortcut_keys.c | 194 +++++++++++++++++++++++++++++++++++-- 4 files changed, 196 insertions(+), 9 deletions(-) diff --git a/src/config.h b/src/config.h index 1c200ec09c..8bd7510ad4 100644 --- a/src/config.h +++ b/src/config.h @@ -153,6 +153,11 @@ static const struct { const char *key; int value; } _currencyLookupTable[] = { { "\xB5", CURRENCY_EUROS } }; +typedef struct shortcut_entry{ + uint8 shortcut; + uint8 key; +}shortcut_entry; + //typedef struct hotkey_configuration{ //}; diff --git a/src/string_ids.h b/src/string_ids.h index f4bd4f45bc..6613531b67 100644 --- a/src/string_ids.h +++ b/src/string_ids.h @@ -398,9 +398,9 @@ enum { STR_SLOPE_UP_TIP = 1188, STR_CONSTRUCT_THE_SELECTED_FOOTPATH_SECTION_TIP = 1189, STR_REMOVE_PREVIOUS_FOOTPATH_SECTION_TIP = 1190, - STR_COST = 1191, + STR_BLACK_STRING = 1191, STR_LOSS = 1192, - + STR_WINDOW_COLOUR_2_STRING = 1193, STR_CLOSED = 1194, STR_TEST_RUN = 1195, STR_OPEN = 1196, diff --git a/src/window_ride.c b/src/window_ride.c index 008ca07884..357b9f3481 100644 --- a/src/window_ride.c +++ b/src/window_ride.c @@ -1891,7 +1891,7 @@ static rct_string_id window_ride_get_status_overall_view(rct_window *w, void *ar RCT2_GLOBAL((int)arguments + 2, uint32) = argument; stringId = STR_LOSS; if (formatSecondary != STR_BROKEN_DOWN && formatSecondary != STR_CRASHED) - stringId = STR_COST; + stringId = STR_BLACK_STRING; return stringId; } diff --git a/src/window_shortcut_keys.c b/src/window_shortcut_keys.c index 8d6fb5df46..80a978ce19 100644 --- a/src/window_shortcut_keys.c +++ b/src/window_shortcut_keys.c @@ -26,6 +26,9 @@ #define WW 340 #define WH 240 +#define WW_C 250 +#define WH_C 60 + enum WINDOW_SHORTCUT_WIDGET_IDX { WIDX_BACKGROUND, WIDX_TITLE, @@ -34,7 +37,13 @@ enum WINDOW_SHORTCUT_WIDGET_IDX { WIDX_RESET }; -// 9DE48C +enum WINDOW_SHORTCUT_CHANGE_WIDGET_IDX { + WIDX_CHANGE_BACKGROUND, + WIDX_CHANGE_TITLE, + WIDX_CHANGE_CLOSE, +}; + +// 0x9DE48C static rct_widget window_shortcut_widgets[] = { { WWT_FRAME, 0, 0, WW - 1, 0, WH - 1, STR_NONE, STR_NONE }, { WWT_CAPTION, 0, 1, WW - 2, 1, 14, STR_OPTIONS, STR_WINDOW_TITLE_TIP }, @@ -44,13 +53,24 @@ static rct_widget window_shortcut_widgets[] = { { WIDGETS_END } }; +// 0x9DE4E0 +static rct_widget window_shortcut_change_widgets[] = { + { WWT_FRAME, 0, 0, WW_C - 1, 0, WH_C - 1, STR_NONE, STR_NONE }, + { WWT_CAPTION, 0, 1, WW_C - 2, 1, 14, STR_OPTIONS, STR_WINDOW_TITLE_TIP }, + { WWT_CLOSEBOX, 0, WW_C-13, WW_C - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, + { WIDGETS_END } +}; + void window_shortcut_emptysub() { } static void window_shortcut_mouseup(); static void window_shortcut_paint(); static void window_shortcut_tooltip(); static void window_shortcut_scrollgetsize(); +static void window_shortcut_scrollmousedown(); +static void window_shortcut_scrollmouseover(); +static void window_shortcut_scrollpaint(); -static void* window_options_events[] = { +static void* window_shortcut_events[] = { window_shortcut_emptysub, window_shortcut_mouseup, window_shortcut_emptysub, @@ -67,9 +87,9 @@ static void* window_options_events[] = { window_shortcut_emptysub, window_shortcut_emptysub, window_shortcut_scrollgetsize, - (void*)0x6E3A3E, + window_shortcut_scrollmousedown, window_shortcut_emptysub, - (void*)0x6E3A16, + window_shortcut_scrollmouseover, window_shortcut_emptysub, window_shortcut_emptysub, window_shortcut_emptysub, @@ -78,9 +98,45 @@ static void* window_options_events[] = { window_shortcut_emptysub, window_shortcut_emptysub, window_shortcut_paint, - (void*)0x6E38E6 + window_shortcut_scrollpaint }; +static void window_shortcut_change_mouseup(); +static void window_shortcut_change_paint(); + +//0x9A3F7C +static void* window_shortcut_change_events[] = { + window_shortcut_emptysub, + window_shortcut_change_mouseup, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_emptysub, + window_shortcut_change_paint, + window_shortcut_emptysub +}; + + /** * * rct2: 0x006E3884 @@ -93,7 +149,7 @@ void window_shortcut_keys_open() if (w) return; - w = window_create_auto_pos(WW, WH, (uint32*)0x9A3F0C, WC_KEYBOARD_SHORTCUT_LIST, 0); + w = window_create_auto_pos(WW, WH, (uint32*)window_shortcut_events, WC_KEYBOARD_SHORTCUT_LIST, 0); w->widgets = window_shortcut_widgets; w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_RESET); @@ -169,4 +225,130 @@ static void window_shortcut_scrollgetsize() #else __asm__("mov edx, %[y] " : [y] "+m" (y)); #endif +} + +/** +* +* rct2: 0x006E3A3E +*/ +static void window_shortcut_scrollmousedown() +{ + short x, y; + rct_window *w; + + window_scrollmouse_get_registers(w, x, y); + + int selected_item = y / 10; + + if (selected_item >= w->no_list_items)return; + + // Move this to window_shortcut_change_open + window_close_by_id(WC_CHANGE_KEYBOARD_SHORTCUT, 0); + // Save the item we are selecting for new window + RCT2_GLOBAL(0x9DE511, uint8) = selected_item; + rct_window* change_w = window_create_auto_pos(WW_C, WH_C, (uint32*)window_shortcut_change_events, WC_CHANGE_KEYBOARD_SHORTCUT, 0); + + w->widgets = window_shortcut_change_widgets; + w->enabled_widgets = (1 << 2); + window_init_scroll_widgets(w); + w->colours[0] = 7; + w->colours[1] = 7; + w->colours[2] = 7; + +} + +/** +* +* rct2: 0x006E3A16 +*/ +static void window_shortcut_scrollmouseover() +{ + short x, y; + rct_window *w; + + window_scrollmouse_get_registers(w, x, y); + + int selected_item = y / 10; + + if (selected_item >= w->no_list_items)return; + + w->selected_list_item = selected_item; +} + +/** + * + * rct2: 0x006E38E6 + */ +static void window_shortcut_scrollpaint() +{ + rct_window *w; + rct_drawpixelinfo *dpi; + + window_paint_get_registers(w, dpi); + + gfx_fill_rect(dpi, dpi->x, dpi->y, dpi->x + dpi->width - 1, dpi->y + dpi->height - 1, RCT2_ADDRESS(0x0141FC48,uint8)[w->colours[1] * 8]); + + for (int i = 0; i < w->no_list_items; ++i){ + int y = i * 10; + int format = STR_BLACK_STRING; + if (i == w->selected_list_item){ + format = STR_WINDOW_COLOUR_2_STRING; + gfx_fill_rect(dpi, 0, y, 800, y + 9, 0x2000031); + } + + RCT2_GLOBAL(0x13CE954, uint16) = i + 2493; + RCT2_GLOBAL(0x13CE956, uint16) = 0; + RCT2_GLOBAL(0x13CE958, uint16) = 0; + + + shortcut_entry sc_entry = RCT2_ADDRESS(RCT2_ADDRESS_CONFIG_KEYBOARD_SHORTCUTS, shortcut_entry)[i]; + + if (sc_entry.shortcut != 255){ + RCT2_GLOBAL(0x13CE958, uint16) = sc_entry.shortcut + 2525; + if (sc_entry.key){ + RCT2_GLOBAL(0x13CE956, uint16) = 2782; + if (sc_entry.key != 1){ + RCT2_GLOBAL(0x13CE956, uint16) = 2783; + } + } + } + RCT2_GLOBAL(0x13CE952, uint16) = 2781; + + gfx_draw_string_left(dpi, format, (void*)0x13CE952, 0, 0, y - 1); + } +} + +/** + * + * rct2: 0x006E3AE0 + */ +static void window_shortcut_change_mouseup(){ + short widgetIndex; + rct_window *w; + + window_widget_get_registers(w, widgetIndex); + + switch (widgetIndex){ + case WIDX_CHANGE_CLOSE: + window_close(w); + } +} + +/** + * + * rct2: 0x006E3A9F + */ +static void window_shortcut_change_paint(){ + rct_window *w; + rct_drawpixelinfo *dpi; + + window_paint_get_registers(w, dpi); + + window_draw_widgets(w, dpi); + + int x = w->x + 125; + int y = w->y + 30; + + RCT2_GLOBAL(0x13CE952, uint16) = 2493 + RCT2_GLOBAL(0x9DE511, uint8); + gfx_draw_string_centred_wrapped(dpi, (void*)0x13CE952, x, y, 242, 2785, RCT2_GLOBAL(0x9DEB8D, uint8)); } \ No newline at end of file From f2ec0a4bb76c21ecf31af3cd44c60adfb2603ac3 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 7 Oct 2014 17:57:38 +0100 Subject: [PATCH 5/6] Moved mini window into seperate file. Fixed all bugs --- projects/openrct2.vcxproj | 1 + projects/openrct2.vcxproj.filters | 3 + src/window.h | 1 + src/window_shortcut_key_change.c | 127 ++++++++++++++++++++++++++++++ src/window_shortcut_keys.c | 110 ++------------------------ 5 files changed, 140 insertions(+), 102 deletions(-) create mode 100644 src/window_shortcut_key_change.c diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj index 7d2141ddcc..2ec0e1cadd 100644 --- a/projects/openrct2.vcxproj +++ b/projects/openrct2.vcxproj @@ -137,6 +137,7 @@ + diff --git a/projects/openrct2.vcxproj.filters b/projects/openrct2.vcxproj.filters index cfc27fe39c..de03c0bbde 100644 --- a/projects/openrct2.vcxproj.filters +++ b/projects/openrct2.vcxproj.filters @@ -434,6 +434,9 @@ Windows + + Windows + diff --git a/src/window.h b/src/window.h index 6e59bc1cd0..e097a1a237 100644 --- a/src/window.h +++ b/src/window.h @@ -477,6 +477,7 @@ void window_guest_list_open(); void window_map_open(); void window_options_open(); void window_shortcut_keys_open(); +void window_shortcut_change_open(int selected_key); void window_peep_open(rct_peep* peep); void window_staff_peep_open(rct_peep* peep); void window_park_awards_open(); diff --git a/src/window_shortcut_key_change.c b/src/window_shortcut_key_change.c new file mode 100644 index 0000000000..a6f070bf2e --- /dev/null +++ b/src/window_shortcut_key_change.c @@ -0,0 +1,127 @@ +/***************************************************************************** +* Copyright (c) 2014 Ted John, Duncan Frost +* 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 "addresses.h" +#include "config.h" +#include "window.h" +#include "widget.h" + +#define WW 250 +#define WH 60 + +enum WINDOW_SHORTCUT_CHANGE_WIDGET_IDX { + WIDX_BACKGROUND, + WIDX_TITLE, + WIDX_CLOSE, +}; + +// 0x9DE4E0 +static rct_widget window_shortcut_change_widgets[] = { + { WWT_FRAME, 0, 0, WW - 1, 0, WH - 1, STR_NONE, STR_NONE }, + { WWT_CAPTION, 0, 1, WW - 2, 1, 14, STR_OPTIONS, STR_WINDOW_TITLE_TIP }, + { WWT_CLOSEBOX, 0, WW-13, WW - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, + { WIDGETS_END } +}; + +static void window_shortcut_change_emptysub(){} +static void window_shortcut_change_mouseup(); +static void window_shortcut_change_paint(); + +//0x9A3F7C +static void* window_shortcut_change_events[] = { + window_shortcut_change_emptysub, + window_shortcut_change_mouseup, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_emptysub, + window_shortcut_change_paint, + window_shortcut_change_emptysub +}; + +void window_shortcut_change_open(int selected_key){ + // Move this to window_shortcut_change_open + window_close_by_id(WC_CHANGE_KEYBOARD_SHORTCUT, 0); + // Save the item we are selecting for new window + RCT2_GLOBAL(0x9DE511, uint8) = selected_key; + rct_window* w = window_create_auto_pos(WW, WH, (uint32*)window_shortcut_change_events, WC_CHANGE_KEYBOARD_SHORTCUT, 0); + + w->widgets = window_shortcut_change_widgets; + w->enabled_widgets = (1 << 2); + window_init_scroll_widgets(w); + w->colours[0] = 7; + w->colours[1] = 7; + w->colours[2] = 7; +} + +/** +* +* rct2: 0x006E3AE0 +*/ +static void window_shortcut_change_mouseup(){ + short widgetIndex; + rct_window *w; + + window_widget_get_registers(w, widgetIndex); + + switch (widgetIndex){ + case WIDX_CLOSE: + window_close(w); + } +} + +/** +* +* rct2: 0x006E3A9F +*/ +static void window_shortcut_change_paint(){ + rct_window *w; + rct_drawpixelinfo *dpi; + + window_paint_get_registers(w, dpi); + + window_draw_widgets(w, dpi); + + int x = w->x + 125; + int y = w->y + 30; + + RCT2_GLOBAL(0x13CE952, uint16) = 2493 + RCT2_GLOBAL(0x9DE511, uint8); + gfx_draw_string_centred_wrapped(dpi, (void*)0x13CE952, x, y, 242, 2785, RCT2_GLOBAL(0x9DEB8D, uint8)); +} \ No newline at end of file diff --git a/src/window_shortcut_keys.c b/src/window_shortcut_keys.c index 80a978ce19..54e2710781 100644 --- a/src/window_shortcut_keys.c +++ b/src/window_shortcut_keys.c @@ -26,9 +26,6 @@ #define WW 340 #define WH 240 -#define WW_C 250 -#define WH_C 60 - enum WINDOW_SHORTCUT_WIDGET_IDX { WIDX_BACKGROUND, WIDX_TITLE, @@ -37,12 +34,6 @@ enum WINDOW_SHORTCUT_WIDGET_IDX { WIDX_RESET }; -enum WINDOW_SHORTCUT_CHANGE_WIDGET_IDX { - WIDX_CHANGE_BACKGROUND, - WIDX_CHANGE_TITLE, - WIDX_CHANGE_CLOSE, -}; - // 0x9DE48C static rct_widget window_shortcut_widgets[] = { { WWT_FRAME, 0, 0, WW - 1, 0, WH - 1, STR_NONE, STR_NONE }, @@ -53,14 +44,6 @@ static rct_widget window_shortcut_widgets[] = { { WIDGETS_END } }; -// 0x9DE4E0 -static rct_widget window_shortcut_change_widgets[] = { - { WWT_FRAME, 0, 0, WW_C - 1, 0, WH_C - 1, STR_NONE, STR_NONE }, - { WWT_CAPTION, 0, 1, WW_C - 2, 1, 14, STR_OPTIONS, STR_WINDOW_TITLE_TIP }, - { WWT_CLOSEBOX, 0, WW_C-13, WW_C - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, - { WIDGETS_END } -}; - void window_shortcut_emptysub() { } static void window_shortcut_mouseup(); static void window_shortcut_paint(); @@ -101,42 +84,6 @@ static void* window_shortcut_events[] = { window_shortcut_scrollpaint }; -static void window_shortcut_change_mouseup(); -static void window_shortcut_change_paint(); - -//0x9A3F7C -static void* window_shortcut_change_events[] = { - window_shortcut_emptysub, - window_shortcut_change_mouseup, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_emptysub, - window_shortcut_change_paint, - window_shortcut_emptysub -}; - - /** * * rct2: 0x006E3884 @@ -242,19 +189,7 @@ static void window_shortcut_scrollmousedown() if (selected_item >= w->no_list_items)return; - // Move this to window_shortcut_change_open - window_close_by_id(WC_CHANGE_KEYBOARD_SHORTCUT, 0); - // Save the item we are selecting for new window - RCT2_GLOBAL(0x9DE511, uint8) = selected_item; - rct_window* change_w = window_create_auto_pos(WW_C, WH_C, (uint32*)window_shortcut_change_events, WC_CHANGE_KEYBOARD_SHORTCUT, 0); - - w->widgets = window_shortcut_change_widgets; - w->enabled_widgets = (1 << 2); - window_init_scroll_widgets(w); - w->colours[0] = 7; - w->colours[1] = 7; - w->colours[2] = 7; - + window_shortcut_change_open(selected_item); } /** @@ -273,6 +208,8 @@ static void window_shortcut_scrollmouseover() if (selected_item >= w->no_list_items)return; w->selected_list_item = selected_item; + + window_invalidate(w); } /** @@ -287,9 +224,13 @@ static void window_shortcut_scrollpaint() window_paint_get_registers(w, dpi); gfx_fill_rect(dpi, dpi->x, dpi->y, dpi->x + dpi->width - 1, dpi->y + dpi->height - 1, RCT2_ADDRESS(0x0141FC48,uint8)[w->colours[1] * 8]); - + for (int i = 0; i < w->no_list_items; ++i){ int y = i * 10; + if (y > dpi->y + dpi->height) { + break; + } + if (y + 10 < dpi->y)continue; int format = STR_BLACK_STRING; if (i == w->selected_list_item){ format = STR_WINDOW_COLOUR_2_STRING; @@ -316,39 +257,4 @@ static void window_shortcut_scrollpaint() gfx_draw_string_left(dpi, format, (void*)0x13CE952, 0, 0, y - 1); } -} - -/** - * - * rct2: 0x006E3AE0 - */ -static void window_shortcut_change_mouseup(){ - short widgetIndex; - rct_window *w; - - window_widget_get_registers(w, widgetIndex); - - switch (widgetIndex){ - case WIDX_CHANGE_CLOSE: - window_close(w); - } -} - -/** - * - * rct2: 0x006E3A9F - */ -static void window_shortcut_change_paint(){ - rct_window *w; - rct_drawpixelinfo *dpi; - - window_paint_get_registers(w, dpi); - - window_draw_widgets(w, dpi); - - int x = w->x + 125; - int y = w->y + 30; - - RCT2_GLOBAL(0x13CE952, uint16) = 2493 + RCT2_GLOBAL(0x9DE511, uint8); - gfx_draw_string_centred_wrapped(dpi, (void*)0x13CE952, x, y, 242, 2785, RCT2_GLOBAL(0x9DEB8D, uint8)); } \ No newline at end of file From 880ae7cb940d95422151cb1d7c94ebf4f94127c3 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 7 Oct 2014 19:12:19 +0100 Subject: [PATCH 6/6] Added the ability to read the current keyboard assignment --- data/language/english_uk.txt | 1 + src/config.h | 2 +- src/osinterface.c | 11 +++++++++++ src/osinterface.h | 1 + src/string_ids.h | 9 +++++++++ src/window_shortcut_keys.c | 36 +++++++++++++++++++++++++----------- 6 files changed, 48 insertions(+), 12 deletions(-) diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index 23535f2a06..a6b4cc889a 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -2526,6 +2526,7 @@ STR_2521 :Show staff list STR_2522 :Show recent messages STR_2523 :Show map STR_2524 :Screenshot +### The following need to be reordered to match SDL_keycode layout. STR_2525 :??? STR_2526 :??? STR_2527 :??? diff --git a/src/config.h b/src/config.h index 8bd7510ad4..49d5f2c1ac 100644 --- a/src/config.h +++ b/src/config.h @@ -154,8 +154,8 @@ static const struct { const char *key; int value; } _currencyLookupTable[] = { }; typedef struct shortcut_entry{ - uint8 shortcut; uint8 key; + uint8 modifier; }shortcut_entry; //typedef struct hotkey_configuration{ diff --git a/src/osinterface.c b/src/osinterface.c index 59b5a887c0..f1e5a8207d 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -70,6 +70,17 @@ void osinterface_init() // RCT2_CALLPROC(0x00404584); // dinput_init() } +int osinterface_scancode_to_rct_keycode(int sdl_key){ + char keycode = (char)SDL_GetKeyFromScancode((SDL_Scancode)sdl_key); + + // Until we reshufle the text files to use the new positions + // this will suffice to move the majority to the correct positions. + // Note any special buttons PgUp PgDwn are mapped wrong. + if (keycode >= 'a' && keycode <= 'z')keycode = toupper(keycode); + + return keycode; +} + /** * This is not quite the same as the below function as we don't want to * derfererence the cursor before the function. diff --git a/src/osinterface.h b/src/osinterface.h index 7c08580483..14b08d4251 100644 --- a/src/osinterface.h +++ b/src/osinterface.h @@ -112,5 +112,6 @@ int osinterface_directory_exists(const char *path); int osinterface_ensure_directory_exists(const char *path); char osinterface_get_path_separator(); +int osinterface_scancode_to_rct_keycode(int sdl_key); #endif diff --git a/src/string_ids.h b/src/string_ids.h index 6613531b67..2a2612ceee 100644 --- a/src/string_ids.h +++ b/src/string_ids.h @@ -997,6 +997,15 @@ enum { STR_REAL_NAME_TIP = 2488, STR_HOTKEY = 2489, + STR_SHORTCUT_DESCRIPTION_0 = 2493, + + STR_SHORTCUT_DESCRIPTION_31 = 2524, + STR_INDIVIDUAL_KEYS_BASE = 2525, + + STR_SHORTCUT_ENTRY_FORMAT = 2781, + STR_SHIFT_PLUS = 2782, + STR_CTRL_PLUS = 2783, + STR_FINACNES_PARK_VALUE = 2787, STR_ENTER_NAME_INTO_SCENARIO_CHART = 2790, diff --git a/src/window_shortcut_keys.c b/src/window_shortcut_keys.c index 54e2710781..52ed422a8a 100644 --- a/src/window_shortcut_keys.c +++ b/src/window_shortcut_keys.c @@ -22,6 +22,7 @@ #include "config.h" #include "window.h" #include "widget.h" +#include "osinterface.h" #define WW 340 #define WH 240 @@ -237,23 +238,36 @@ static void window_shortcut_scrollpaint() gfx_fill_rect(dpi, 0, y, 800, y + 9, 0x2000031); } - RCT2_GLOBAL(0x13CE954, uint16) = i + 2493; + RCT2_GLOBAL(0x13CE954, uint16) = i + STR_SHORTCUT_DESCRIPTION_0; RCT2_GLOBAL(0x13CE956, uint16) = 0; RCT2_GLOBAL(0x13CE958, uint16) = 0; - - shortcut_entry sc_entry = RCT2_ADDRESS(RCT2_ADDRESS_CONFIG_KEYBOARD_SHORTCUTS, shortcut_entry)[i]; + // This is the original version that will not take into account remapped keys. + //shortcut_entry sc_entry = RCT2_ADDRESS(RCT2_ADDRESS_CONFIG_KEYBOARD_SHORTCUTS, shortcut_entry)[i]; + //if (sc_entry.key != 255){ + // RCT2_GLOBAL(0x13CE958, uint16) = sc_entry.key + 2525; + // if (sc_entry.modifier){ + // RCT2_GLOBAL(0x13CE956, uint16) = 2782; + // if (sc_entry.key != 1){ + // RCT2_GLOBAL(0x13CE956, uint16) = 2783; + // } + // } + //} - if (sc_entry.shortcut != 255){ - RCT2_GLOBAL(0x13CE958, uint16) = sc_entry.shortcut + 2525; - if (sc_entry.key){ - RCT2_GLOBAL(0x13CE956, uint16) = 2782; - if (sc_entry.key != 1){ - RCT2_GLOBAL(0x13CE956, uint16) = 2783; - } + uint16 shortcut_entry = gShortcutKeys[i]; + if (shortcut_entry != 0xFFFF){ + RCT2_GLOBAL(0x13CE958, uint16) = STR_INDIVIDUAL_KEYS_BASE + osinterface_scancode_to_rct_keycode(shortcut_entry & 0xFF); + //Display the modifer + if (shortcut_entry & 0x100){ + RCT2_GLOBAL(0x13CE956, uint16) = STR_SHIFT_PLUS; + } + else if (shortcut_entry & 0x200){ + RCT2_GLOBAL(0x13CE956, uint16) = STR_CTRL_PLUS; } } - RCT2_GLOBAL(0x13CE952, uint16) = 2781; + + + RCT2_GLOBAL(0x13CE952, uint16) = STR_SHORTCUT_ENTRY_FORMAT; gfx_draw_string_left(dpi, format, (void*)0x13CE952, 0, 0, y - 1); }