Merge pull request #509 from duncanspumpkin/window_shortcut

Window shortcut
This commit is contained in:
Ted John 2014-10-07 19:29:37 +01:00
commit b80abdc0c2
12 changed files with 442 additions and 4 deletions

View File

@ -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 :???

View File

@ -136,6 +136,8 @@
<ClCompile Include="..\src\window_ride.c" />
<ClCompile Include="..\src\window_ride_list.c" />
<ClCompile Include="..\src\window_save_prompt.c" />
<ClCompile Include="..\src\window_shortcut_keys.c" />
<ClCompile Include="..\src\window_shortcut_key_change.c" />
<ClCompile Include="..\src\window_staff.c" />
<ClCompile Include="..\src\window_staff_peep.c" />
<ClCompile Include="..\src\window_title_exit.c" />

View File

@ -431,6 +431,12 @@
<ClCompile Include="..\src\research.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\window_shortcut_keys.c">
<Filter>Windows</Filter>
</ClCompile>
<ClCompile Include="..\src\window_shortcut_key_change.c">
<Filter>Windows</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\openrct2.exe">

View File

@ -153,6 +153,11 @@ static const struct { const char *key; int value; } _currencyLookupTable[] = {
{ "\xB5", CURRENCY_EUROS }
};
typedef struct shortcut_entry{
uint8 key;
uint8 modifier;
}shortcut_entry;
//typedef struct hotkey_configuration{
//};

View File

@ -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.

View File

@ -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

View File

@ -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,
@ -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,

View File

@ -476,6 +476,8 @@ void window_staff_open();
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();

View File

@ -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;

View File

@ -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;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*****************************************************************************/
#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));
}

274
src/window_shortcut_keys.c Normal file
View File

@ -0,0 +1,274 @@
/*****************************************************************************
* 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 <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "addresses.h"
#include "config.h"
#include "window.h"
#include "widget.h"
#include "osinterface.h"
#define WW 340
#define WH 240
enum WINDOW_SHORTCUT_WIDGET_IDX {
WIDX_BACKGROUND,
WIDX_TITLE,
WIDX_CLOSE,
WIDX_SCROLL,
WIDX_RESET
};
// 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 },
{ 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_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_shortcut_events[] = {
window_shortcut_emptysub,
window_shortcut_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_scrollgetsize,
window_shortcut_scrollmousedown,
window_shortcut_emptysub,
window_shortcut_scrollmouseover,
window_shortcut_emptysub,
window_shortcut_emptysub,
window_shortcut_emptysub,
window_shortcut_tooltip,
window_shortcut_emptysub,
window_shortcut_emptysub,
window_shortcut_emptysub,
window_shortcut_paint,
window_shortcut_scrollpaint
};
/**
*
* 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*)window_shortcut_events, 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;
}
/**
*
* 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
}
/**
*
* 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;
window_shortcut_change_open(selected_item);
}
/**
*
* 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;
window_invalidate(w);
}
/**
*
* 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;
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;
gfx_fill_rect(dpi, 0, y, 800, y + 9, 0x2000031);
}
RCT2_GLOBAL(0x13CE954, uint16) = i + STR_SHORTCUT_DESCRIPTION_0;
RCT2_GLOBAL(0x13CE956, uint16) = 0;
RCT2_GLOBAL(0x13CE958, uint16) = 0;
// 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;
// }
// }
//}
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) = STR_SHORTCUT_ENTRY_FORMAT;
gfx_draw_string_left(dpi, format, (void*)0x13CE952, 0, 0, y - 1);
}
}