mirror of https://github.com/OpenTTD/OpenTTD
(svn r20070) -Feature: when none of the open windows handles a keypress, try all toolbars for global hotkeys
Users that have run a version between r20056 and r20068 should delete their hotkeys.cfg to reset the terraform toolbar hotkeys to defaultrelease/1.1
parent
9be9302cdb
commit
26be68ae98
|
@ -176,6 +176,15 @@ void ShowBuildAirToolbar()
|
||||||
AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
|
AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EventState AirportToolbarGlobalHotkeys(uint16 key, uint16 keycode)
|
||||||
|
{
|
||||||
|
int num = CheckHotkeyMatch<BuildAirToolbarWindow>(_airtoolbar_hotkeys, keycode, NULL, true);
|
||||||
|
if (num == -1) return ES_NOT_HANDLED;
|
||||||
|
ShowBuildAirToolbar();
|
||||||
|
Window *w = FindWindowByClass(WC_BUILD_TOOLBAR);
|
||||||
|
return w->OnKeyPress(key, keycode);
|
||||||
|
}
|
||||||
|
|
||||||
/** Airport widgets in the airport picker window. */
|
/** Airport widgets in the airport picker window. */
|
||||||
enum AirportPickerWidgets {
|
enum AirportPickerWidgets {
|
||||||
BAIRW_CLASS_DROPDOWN,
|
BAIRW_CLASS_DROPDOWN,
|
||||||
|
|
|
@ -302,6 +302,15 @@ void ShowBuildDocksToolbar()
|
||||||
AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
|
AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EventState DockToolbarGlobalHotkeys(uint16 key, uint16 keycode)
|
||||||
|
{
|
||||||
|
int num = CheckHotkeyMatch<BuildDocksToolbarWindow>(_dockstoolbar_hotkeys, keycode, NULL, true);
|
||||||
|
if (num == -1) return ES_NOT_HANDLED;
|
||||||
|
ShowBuildDocksToolbar();
|
||||||
|
Window *w = FindWindowByClass(WC_BUILD_TOOLBAR);
|
||||||
|
return w->OnKeyPress(key, keycode);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nested widget parts of docks toolbar, scenario editor version.
|
* Nested widget parts of docks toolbar, scenario editor version.
|
||||||
* Positions of #DTW_DEPOT, #DTW_STATION, and #DTW_BUOY widgets have changed.
|
* Positions of #DTW_DEPOT, #DTW_STATION, and #DTW_BUOY widgets have changed.
|
||||||
|
|
|
@ -10,10 +10,12 @@
|
||||||
/** @file hotkeys.cpp Implementation of hotkey related functions */
|
/** @file hotkeys.cpp Implementation of hotkey related functions */
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
#include "openttd.h"
|
||||||
#include "hotkeys.h"
|
#include "hotkeys.h"
|
||||||
#include "ini_type.h"
|
#include "ini_type.h"
|
||||||
#include "string_func.h"
|
#include "string_func.h"
|
||||||
#include "gfx_type.h"
|
#include "gfx_type.h"
|
||||||
|
#include "window_gui.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
char *_hotkeys_file;
|
char *_hotkeys_file;
|
||||||
|
@ -284,3 +286,37 @@ void SaveHotkeysToConfig()
|
||||||
SaveLoadHotkeys(true);
|
SaveLoadHotkeys(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef EventState GlobalHotkeyHandler(uint16, uint16);
|
||||||
|
|
||||||
|
GlobalHotkeyHandler RailToolbarGlobalHotkeys;
|
||||||
|
GlobalHotkeyHandler DockToolbarGlobalHotkeys;
|
||||||
|
GlobalHotkeyHandler AirportToolbarGlobalHotkeys;
|
||||||
|
GlobalHotkeyHandler TerraformToolbarGlobalHotkeys;
|
||||||
|
GlobalHotkeyHandler TerraformToolbarEditorGlobalHotkeys;
|
||||||
|
|
||||||
|
|
||||||
|
GlobalHotkeyHandler *_global_hotkey_handlers[] = {
|
||||||
|
RailToolbarGlobalHotkeys,
|
||||||
|
DockToolbarGlobalHotkeys,
|
||||||
|
AirportToolbarGlobalHotkeys,
|
||||||
|
TerraformToolbarGlobalHotkeys,
|
||||||
|
};
|
||||||
|
|
||||||
|
GlobalHotkeyHandler *_global_hotkey_handlers_editor[] = {
|
||||||
|
TerraformToolbarEditorGlobalHotkeys,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void HandleGlobalHotkeys(uint16 key, uint16 keycode)
|
||||||
|
{
|
||||||
|
if (_game_mode == GM_NORMAL) {
|
||||||
|
for (uint i = 0; i < lengthof(_global_hotkey_handlers); i++) {
|
||||||
|
if (_global_hotkey_handlers[i](key, keycode) == ES_HANDLED) return;
|
||||||
|
}
|
||||||
|
} else if (_game_mode == GM_EDITOR) {
|
||||||
|
for (uint i = 0; i < lengthof(_global_hotkey_handlers_editor); i++) {
|
||||||
|
if (_global_hotkey_handlers_editor[i](key, keycode) == ES_HANDLED) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#define HOTKEYS_H
|
#define HOTKEYS_H
|
||||||
|
|
||||||
#include "core/smallvec_type.hpp"
|
#include "core/smallvec_type.hpp"
|
||||||
|
#include "gfx_type.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All data for a single hotkey. The name (for saving/loading a configfile),
|
* All data for a single hotkey. The name (for saving/loading a configfile),
|
||||||
|
@ -115,7 +116,7 @@ int CheckHotkeyMatch(Hotkey<T> *list, uint16 keycode, T *w, bool global_only = f
|
||||||
{
|
{
|
||||||
while (list->num != -1) {
|
while (list->num != -1) {
|
||||||
if (list->keycodes.Contains(keycode | WKC_GLOBAL_HOTKEY) || (!global_only && list->keycodes.Contains(keycode))) {
|
if (list->keycodes.Contains(keycode | WKC_GLOBAL_HOTKEY) || (!global_only && list->keycodes.Contains(keycode))) {
|
||||||
if (list->callback != NULL) (w->*(list->callback->callback))(-1);
|
if (!global_only && list->callback != NULL) (w->*(list->callback->callback))(-1);
|
||||||
return list->num;
|
return list->num;
|
||||||
}
|
}
|
||||||
list++;
|
list++;
|
||||||
|
@ -126,4 +127,7 @@ int CheckHotkeyMatch(Hotkey<T> *list, uint16 keycode, T *w, bool global_only = f
|
||||||
void LoadHotkeysFromConfig();
|
void LoadHotkeysFromConfig();
|
||||||
void SaveHotkeysToConfig();
|
void SaveHotkeysToConfig();
|
||||||
|
|
||||||
|
|
||||||
|
void HandleGlobalHotkeys(uint16 key, uint16 keycode);
|
||||||
|
|
||||||
#endif /* HOTKEYS_H */
|
#endif /* HOTKEYS_H */
|
||||||
|
|
|
@ -910,6 +910,16 @@ void ShowBuildRailToolbar(RailType railtype)
|
||||||
_remove_button_clicked = false;
|
_remove_button_clicked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EventState RailToolbarGlobalHotkeys(uint16 key, uint16 keycode)
|
||||||
|
{
|
||||||
|
extern RailType _last_built_railtype;
|
||||||
|
int num = CheckHotkeyMatch<BuildRailToolbarWindow>(_railtoolbar_hotkeys, keycode, NULL, true);
|
||||||
|
if (num == -1) return ES_NOT_HANDLED;
|
||||||
|
ShowBuildRailToolbar(_last_built_railtype);
|
||||||
|
Window *w = FindWindowByClass(WC_BUILD_TOOLBAR);
|
||||||
|
return w->OnKeyPress(key, keycode);
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
|
/* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
|
||||||
* --pasky */
|
* --pasky */
|
||||||
|
|
||||||
|
|
|
@ -286,10 +286,10 @@ struct TerraformToolbarWindow : Window {
|
||||||
};
|
};
|
||||||
|
|
||||||
Hotkey<TerraformToolbarWindow> TerraformToolbarWindow::terraform_hotkeys[] = {
|
Hotkey<TerraformToolbarWindow> TerraformToolbarWindow::terraform_hotkeys[] = {
|
||||||
Hotkey<TerraformToolbarWindow>('Q', "lower", TTW_LOWER_LAND),
|
Hotkey<TerraformToolbarWindow>('Q' | WKC_GLOBAL_HOTKEY, "lower", TTW_LOWER_LAND),
|
||||||
Hotkey<TerraformToolbarWindow>('W', "raise", TTW_RAISE_LAND),
|
Hotkey<TerraformToolbarWindow>('W' | WKC_GLOBAL_HOTKEY, "raise", TTW_RAISE_LAND),
|
||||||
Hotkey<TerraformToolbarWindow>('E', "level", TTW_LEVEL_LAND),
|
Hotkey<TerraformToolbarWindow>('E' | WKC_GLOBAL_HOTKEY, "level", TTW_LEVEL_LAND),
|
||||||
Hotkey<TerraformToolbarWindow>('D', "dynamite", TTW_DEMOLISH),
|
Hotkey<TerraformToolbarWindow>('D' | WKC_GLOBAL_HOTKEY, "dynamite", TTW_DEMOLISH),
|
||||||
Hotkey<TerraformToolbarWindow>('U', "buyland", TTW_BUY_LAND),
|
Hotkey<TerraformToolbarWindow>('U', "buyland", TTW_BUY_LAND),
|
||||||
Hotkey<TerraformToolbarWindow>('I', "trees", TTW_PLANT_TREES),
|
Hotkey<TerraformToolbarWindow>('I', "trees", TTW_PLANT_TREES),
|
||||||
Hotkey<TerraformToolbarWindow>('O', "placesign", TTW_PLACE_SIGN),
|
Hotkey<TerraformToolbarWindow>('O', "placesign", TTW_PLACE_SIGN),
|
||||||
|
@ -355,14 +355,12 @@ Window *ShowTerraformToolbar(Window *link)
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowTerraformToolbarWithTool(uint16 key, uint16 keycode)
|
EventState TerraformToolbarGlobalHotkeys(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
Window *w = FindWindowById(WC_SCEN_LAND_GEN, 0);
|
int num = CheckHotkeyMatch<TerraformToolbarWindow>(_terraform_hotkeys, keycode, NULL, true);
|
||||||
|
if (num == -1) return ES_NOT_HANDLED;
|
||||||
if (w == NULL) w = ShowTerraformToolbar(NULL);
|
Window *w = ShowTerraformToolbar(NULL);
|
||||||
if (w == NULL) return;
|
return w->OnKeyPress(key, keycode);
|
||||||
|
|
||||||
w->OnKeyPress(key, keycode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte _terraform_size = 1;
|
static byte _terraform_size = 1;
|
||||||
|
@ -742,10 +740,10 @@ struct ScenarioEditorLandscapeGenerationWindow : Window {
|
||||||
};
|
};
|
||||||
|
|
||||||
Hotkey<ScenarioEditorLandscapeGenerationWindow> ScenarioEditorLandscapeGenerationWindow::terraform_editor_hotkeys[] = {
|
Hotkey<ScenarioEditorLandscapeGenerationWindow> ScenarioEditorLandscapeGenerationWindow::terraform_editor_hotkeys[] = {
|
||||||
Hotkey<ScenarioEditorLandscapeGenerationWindow>('D', "dynamite", ETTW_DEMOLISH),
|
Hotkey<ScenarioEditorLandscapeGenerationWindow>('D' | WKC_GLOBAL_HOTKEY, "dynamite", ETTW_DEMOLISH),
|
||||||
Hotkey<ScenarioEditorLandscapeGenerationWindow>('Q', "lower", ETTW_LOWER_LAND),
|
Hotkey<ScenarioEditorLandscapeGenerationWindow>('Q' | WKC_GLOBAL_HOTKEY, "lower", ETTW_LOWER_LAND),
|
||||||
Hotkey<ScenarioEditorLandscapeGenerationWindow>('W', "raise", ETTW_RAISE_LAND),
|
Hotkey<ScenarioEditorLandscapeGenerationWindow>('W' | WKC_GLOBAL_HOTKEY, "raise", ETTW_RAISE_LAND),
|
||||||
Hotkey<ScenarioEditorLandscapeGenerationWindow>('E', "level", ETTW_LEVEL_LAND),
|
Hotkey<ScenarioEditorLandscapeGenerationWindow>('E' | WKC_GLOBAL_HOTKEY, "level", ETTW_LEVEL_LAND),
|
||||||
Hotkey<ScenarioEditorLandscapeGenerationWindow>('R', "rocky", ETTW_PLACE_ROCKS),
|
Hotkey<ScenarioEditorLandscapeGenerationWindow>('R', "rocky", ETTW_PLACE_ROCKS),
|
||||||
Hotkey<ScenarioEditorLandscapeGenerationWindow>('T', "desertlighthouse", ETTW_PLACE_DESERT_LIGHTHOUSE),
|
Hotkey<ScenarioEditorLandscapeGenerationWindow>('T', "desertlighthouse", ETTW_PLACE_DESERT_LIGHTHOUSE),
|
||||||
Hotkey<ScenarioEditorLandscapeGenerationWindow>('Y', "transmitter", ETTW_PLACE_TRANSMITTER),
|
Hotkey<ScenarioEditorLandscapeGenerationWindow>('Y', "transmitter", ETTW_PLACE_TRANSMITTER),
|
||||||
|
@ -754,7 +752,6 @@ Hotkey<ScenarioEditorLandscapeGenerationWindow> ScenarioEditorLandscapeGeneratio
|
||||||
|
|
||||||
Hotkey<ScenarioEditorLandscapeGenerationWindow> *_terraform_editor_hotkeys = ScenarioEditorLandscapeGenerationWindow::terraform_editor_hotkeys;
|
Hotkey<ScenarioEditorLandscapeGenerationWindow> *_terraform_editor_hotkeys = ScenarioEditorLandscapeGenerationWindow::terraform_editor_hotkeys;
|
||||||
|
|
||||||
|
|
||||||
static const WindowDesc _scen_edit_land_gen_desc(
|
static const WindowDesc _scen_edit_land_gen_desc(
|
||||||
WDP_AUTO, 0, 0,
|
WDP_AUTO, 0, 0,
|
||||||
WC_SCEN_LAND_GEN, WC_NONE,
|
WC_SCEN_LAND_GEN, WC_NONE,
|
||||||
|
@ -767,12 +764,10 @@ Window *ShowEditorTerraformToolbar()
|
||||||
return AllocateWindowDescFront<ScenarioEditorLandscapeGenerationWindow>(&_scen_edit_land_gen_desc, 0);
|
return AllocateWindowDescFront<ScenarioEditorLandscapeGenerationWindow>(&_scen_edit_land_gen_desc, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowEditorTerraformToolbarWithTool(uint16 key, uint16 keycode)
|
EventState TerraformToolbarEditorGlobalHotkeys(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
Window *w = FindWindowById(WC_SCEN_LAND_GEN, 0);
|
int num = CheckHotkeyMatch<ScenarioEditorLandscapeGenerationWindow>(_terraform_editor_hotkeys, keycode, NULL, true);
|
||||||
|
if (num == -1) return ES_NOT_HANDLED;
|
||||||
if (w == NULL) w = ShowEditorTerraformToolbar();
|
Window *w = ShowEditorTerraformToolbar();
|
||||||
if (w == NULL) return;
|
return w->OnKeyPress(key, keycode);
|
||||||
|
|
||||||
w->OnKeyPress(key, keycode);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
#include "window_type.h"
|
#include "window_type.h"
|
||||||
|
|
||||||
Window *ShowTerraformToolbar(Window *link = NULL);
|
Window *ShowTerraformToolbar(Window *link = NULL);
|
||||||
void ShowTerraformToolbarWithTool(uint16 key, uint16 keycode);
|
|
||||||
Window *ShowEditorTerraformToolbar();
|
Window *ShowEditorTerraformToolbar();
|
||||||
void ShowEditorTerraformToolbarWithTool(uint16 key, uint16 keycode);
|
|
||||||
|
|
||||||
#endif /* GUI_H */
|
#endif /* GUI_H */
|
||||||
|
|
|
@ -1602,7 +1602,6 @@ public:
|
||||||
case WKC_SHIFT | WKC_F6: ToolbarZoomOutClick(this); break;
|
case WKC_SHIFT | WKC_F6: ToolbarZoomOutClick(this); break;
|
||||||
|
|
||||||
case 'L': ShowEditorTerraformToolbar(); break;
|
case 'L': ShowEditorTerraformToolbar(); break;
|
||||||
case 'Q': case 'W': case 'E': case 'D': ShowEditorTerraformToolbarWithTool(key, keycode); break;
|
|
||||||
case 'M': ShowSmallMap(); break;
|
case 'M': ShowSmallMap(); break;
|
||||||
case 'V': ShowExtraViewPortWindow(); break;
|
case 'V': ShowExtraViewPortWindow(); break;
|
||||||
default: return ES_NOT_HANDLED;
|
default: return ES_NOT_HANDLED;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "strings_func.h"
|
#include "strings_func.h"
|
||||||
#include "settings_type.h"
|
#include "settings_type.h"
|
||||||
#include "newgrf_debug.h"
|
#include "newgrf_debug.h"
|
||||||
|
#include "hotkeys.h"
|
||||||
|
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
|
|
||||||
|
@ -1955,7 +1956,9 @@ void HandleKeypress(uint32 raw_key)
|
||||||
|
|
||||||
w = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
w = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
||||||
/* When there is no toolbar w is null, check for that */
|
/* When there is no toolbar w is null, check for that */
|
||||||
if (w != NULL) w->OnKeyPress(key, keycode);
|
if (w != NULL && w->OnKeyPress(key, keycode) == ES_HANDLED) return;
|
||||||
|
|
||||||
|
HandleGlobalHotkeys(key, keycode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue