summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-06-15 15:28:09 +0000
committerfrosch <frosch@openttd.org>2013-06-15 15:28:09 +0000
commit1b8b1f3f6cbd65b73399b1d39aacb7fb674a091c (patch)
tree555791c9e1370b2caba036286b98f64efe970bd3 /src
parent40c2864e4dd478693ef6c108cc95cd2e6b5e70d0 (diff)
downloadopenttd-1b8b1f3f6cbd65b73399b1d39aacb7fb674a091c.tar.xz
(svn r25410) -Codechange: Put all hotkeys of a window into a static HotkeyList member.
Diffstat (limited to 'src')
-rw-r--r--src/ai/ai_gui.cpp10
-rw-r--r--src/airport_gui.cpp10
-rw-r--r--src/dock_gui.cpp10
-rw-r--r--src/hotkeys.cpp81
-rw-r--r--src/hotkeys.h25
-rw-r--r--src/main_gui.cpp10
-rw-r--r--src/order_gui.cpp8
-rw-r--r--src/rail_gui.cpp10
-rw-r--r--src/road_gui.cpp12
-rw-r--r--src/signs_gui.cpp10
-rw-r--r--src/terraform_gui.cpp20
-rw-r--r--src/toolbar_gui.cpp16
12 files changed, 123 insertions, 99 deletions
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp
index d49657bd8..acaaff710 100644
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -1309,7 +1309,7 @@ struct AIDebugWindow : public Window {
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
EventState state = ES_NOT_HANDLED;
- int num = CheckHotkeyMatch(aidebug_hotkeys, keycode);
+ int num = this->hotkeys.CheckMatch(keycode);
if (num != -1) {
if (this->show_break_box && num == WID_AID_BREAK_STR_EDIT_BOX) {
this->SetFocusedWidget(WID_AID_BREAK_STR_EDIT_BOX);
@@ -1400,7 +1400,7 @@ struct AIDebugWindow : public Window {
this->vscroll->SetCapacityFromWidget(this, WID_AID_LOG_PANEL);
}
- static Hotkey aidebug_hotkeys[];
+ static HotkeyList hotkeys;
};
const int AIDebugWindow::top_offset = WD_FRAMERECT_TOP + 2;
@@ -1417,7 +1417,7 @@ NWidgetBase *MakeCompanyButtonRowsAIDebug(int *biggest_index)
return MakeCompanyButtonRows(biggest_index, WID_AID_COMPANY_BUTTON_START, WID_AID_COMPANY_BUTTON_END, 8, STR_AI_DEBUG_SELECT_AI_TOOLTIP);
}
-Hotkey AIDebugWindow::aidebug_hotkeys[] = {
+static Hotkey aidebug_hotkeys[] = {
Hotkey('1', "company_1", WID_AID_COMPANY_BUTTON_START),
Hotkey('2', "company_2", WID_AID_COMPANY_BUTTON_START + 1),
Hotkey('3', "company_3", WID_AID_COMPANY_BUTTON_START + 2),
@@ -1442,7 +1442,7 @@ Hotkey AIDebugWindow::aidebug_hotkeys[] = {
Hotkey(WKC_RETURN, "continue", WID_AID_CONTINUE_BTN),
HOTKEY_LIST_END
};
-Hotkey *_aidebug_hotkeys = AIDebugWindow::aidebug_hotkeys;
+HotkeyList AIDebugWindow::hotkeys("aidebug", aidebug_hotkeys);
/** Widgets for the AI debug window. */
static const NWidgetPart _nested_ai_debug_widgets[] = {
@@ -1520,7 +1520,7 @@ Window *ShowAIDebugWindow(CompanyID show_company)
*/
EventState AIDebugGlobalHotkeys(uint16 key, uint16 keycode)
{
- int num = CheckHotkeyMatch(_aidebug_hotkeys, keycode, true);
+ int num = AIDebugWindow::hotkeys.CheckMatch(keycode, true);
if (num == -1) return ES_NOT_HANDLED;
Window *w = ShowAIDebugWindow(INVALID_COMPANY);
if (w == NULL) return ES_NOT_HANDLED;
diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp
index 564941d24..81c873ad1 100644
--- a/src/airport_gui.cpp
+++ b/src/airport_gui.cpp
@@ -102,7 +102,7 @@ struct BuildAirToolbarWindow : Window {
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
- int num = CheckHotkeyMatch(airtoolbar_hotkeys, keycode);
+ int num = this->hotkeys.CheckMatch(keycode);
if (num == -1) return ES_NOT_HANDLED;
this->OnClick(Point(), num, 1);
return ES_HANDLED;
@@ -143,15 +143,15 @@ struct BuildAirToolbarWindow : Window {
DeleteWindowById(WC_SELECT_STATION, 0);
}
- static Hotkey airtoolbar_hotkeys[];
+ static HotkeyList hotkeys;
};
-Hotkey BuildAirToolbarWindow::airtoolbar_hotkeys[] = {
+static Hotkey airtoolbar_hotkeys[] = {
Hotkey('1', "airport", WID_AT_AIRPORT),
Hotkey('2', "demolish", WID_AT_DEMOLISH),
HOTKEY_LIST_END
};
-Hotkey *_airtoolbar_hotkeys = BuildAirToolbarWindow::airtoolbar_hotkeys;
+HotkeyList BuildAirToolbarWindow::hotkeys("airtoolbar", airtoolbar_hotkeys);
static const NWidgetPart _nested_air_toolbar_widgets[] = {
NWidget(NWID_HORIZONTAL),
@@ -191,7 +191,7 @@ Window *ShowBuildAirToolbar()
EventState AirportToolbarGlobalHotkeys(uint16 key, uint16 keycode)
{
if (!CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) return ES_NOT_HANDLED;
- int num = CheckHotkeyMatch(_airtoolbar_hotkeys, keycode, true);
+ int num = BuildAirToolbarWindow::hotkeys.CheckMatch(keycode, true);
if (num == -1) return ES_NOT_HANDLED;
Window *w = ShowBuildAirToolbar();
if (w == NULL) return ES_NOT_HANDLED;
diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp
index 56f426a41..19b8f1bc1 100644
--- a/src/dock_gui.cpp
+++ b/src/dock_gui.cpp
@@ -166,7 +166,7 @@ struct BuildDocksToolbarWindow : Window {
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
- int num = CheckHotkeyMatch(dockstoolbar_hotkeys, keycode);
+ int num = this->hotkeys.CheckMatch(keycode);
if (num == -1) return ES_NOT_HANDLED;
this->OnClick(Point(), num, 1);
return ES_HANDLED;
@@ -274,12 +274,12 @@ struct BuildDocksToolbarWindow : Window {
VpSetPresizeRange(tile_from, tile_to);
}
- static Hotkey dockstoolbar_hotkeys[];
+ static HotkeyList hotkeys;
};
const uint16 _dockstoolbar_aqueduct_keys[] = {'B', '8', 0};
-Hotkey BuildDocksToolbarWindow::dockstoolbar_hotkeys[] = {
+static Hotkey dockstoolbar_hotkeys[] = {
Hotkey('1', "canal", WID_DT_CANAL),
Hotkey('2', "lock", WID_DT_LOCK),
Hotkey('3', "demolish", WID_DT_DEMOLISH),
@@ -290,7 +290,7 @@ Hotkey BuildDocksToolbarWindow::dockstoolbar_hotkeys[] = {
Hotkey(_dockstoolbar_aqueduct_keys, "aqueduct", WID_DT_BUILD_AQUEDUCT),
HOTKEY_LIST_END
};
-Hotkey *_dockstoolbar_hotkeys = BuildDocksToolbarWindow::dockstoolbar_hotkeys;
+HotkeyList BuildDocksToolbarWindow::hotkeys("dockstoolbar", dockstoolbar_hotkeys);
/**
* Nested widget parts of docks toolbar, game version.
@@ -338,7 +338,7 @@ Window *ShowBuildDocksToolbar()
EventState DockToolbarGlobalHotkeys(uint16 key, uint16 keycode)
{
- int num = CheckHotkeyMatch(_dockstoolbar_hotkeys, keycode, true);
+ int num = BuildDocksToolbarWindow::hotkeys.CheckMatch(keycode, true);
if (num == -1) return ES_NOT_HANDLED;
Window *w = ShowBuildDocksToolbar();
if (w == NULL) return ES_NOT_HANDLED;
diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp
index 38fa662ca..f4a48331a 100644
--- a/src/hotkeys.cpp
+++ b/src/hotkeys.cpp
@@ -18,6 +18,12 @@
char *_hotkeys_file;
+/**
+ * List of all HotkeyLists.
+ * This is a pointer to ensure initialisation order with the various static HotkeyList instances.
+ */
+static SmallVector<HotkeyList*, 16> *_hotkey_lists = NULL;
+
/** String representation of a keycode */
struct KeycodeNames {
const char *name; ///< Name of the keycode
@@ -243,10 +249,26 @@ void Hotkey::AddKeycode(uint16 keycode)
this->keycodes.Include(keycode);
}
-void LoadHotkeyGroup(IniGroup *group, Hotkey *hotkey_list)
+HotkeyList::HotkeyList(const char *ini_group, Hotkey *items) :
+ ini_group(ini_group), items(items)
+{
+ if (_hotkey_lists == NULL) _hotkey_lists = new SmallVector<HotkeyList*, 16>();
+ *_hotkey_lists->Append() = this;
+}
+
+HotkeyList::~HotkeyList()
{
- for (uint i = 0; hotkey_list[i].num != -1; i++) {
- Hotkey *hotkey = &hotkey_list[i];
+ _hotkey_lists->Erase(_hotkey_lists->Find(this));
+}
+
+/**
+ * Load HotkeyList from IniFile.
+ * @param ini IniFile to load from.
+ */
+void HotkeyList::Load(IniFile *ini)
+{
+ IniGroup *group = ini->GetGroup(this->ini_group);
+ for (Hotkey *hotkey = this->items; hotkey->name != NULL; ++hotkey) {
IniItem *item = group->GetItem(hotkey->name, false);
if (item != NULL) {
hotkey->keycodes.Clear();
@@ -255,38 +277,31 @@ void LoadHotkeyGroup(IniGroup *group, Hotkey *hotkey_list)
}
}
-void SaveHotkeyGroup(IniGroup *group, const Hotkey *hotkey_list)
+/**
+ * Save HotkeyList to IniFile.
+ * @param ini IniFile to save to.
+ */
+void HotkeyList::Save(IniFile *ini) const
{
- for (uint i = 0; hotkey_list[i].num != -1; i++) {
- const Hotkey *hotkey = &hotkey_list[i];
+ IniGroup *group = ini->GetGroup(this->ini_group);
+ for (const Hotkey *hotkey = this->items; hotkey->name != NULL; ++hotkey) {
IniItem *item = group->GetItem(hotkey->name, true);
item->SetValue(SaveKeycodes(hotkey));
}
}
-void SaveLoadHotkeyGroup(IniGroup *group, Hotkey *hotkey_list, bool save)
-{
- if (save) {
- SaveHotkeyGroup(group, hotkey_list);
- } else {
- LoadHotkeyGroup(group, hotkey_list);
- }
-}
-
/**
* Check if a keycode is bound to something.
- * @param list The list with hotkeys to check
* @param keycode The keycode that was pressed
* @param global_only Limit the search to hotkeys defined as 'global'.
* @return The number of the matching hotkey or -1.
*/
-int CheckHotkeyMatch(Hotkey *list, uint16 keycode, bool global_only)
+int HotkeyList::CheckMatch(uint16 keycode, bool global_only) const
{
- while (list->num != -1) {
+ for (const Hotkey *list = this->items; list->name != NULL; ++list) {
if (list->keycodes.Contains(keycode | WKC_GLOBAL_HOTKEY) || (!global_only && list->keycodes.Contains(keycode))) {
return list->num;
}
- list++;
}
return -1;
}
@@ -297,28 +312,14 @@ static void SaveLoadHotkeys(bool save)
IniFile *ini = new IniFile();
ini->LoadFromDisk(_hotkeys_file, BASE_DIR);
- IniGroup *group;
-
-#define SL_HOTKEYS(name) \
- extern Hotkey *_##name##_hotkeys;\
- group = ini->GetGroup(#name);\
- SaveLoadHotkeyGroup(group, _##name##_hotkeys, save);
-
- SL_HOTKEYS(global);
- SL_HOTKEYS(maintoolbar);
- SL_HOTKEYS(scenedit_maintoolbar);
- SL_HOTKEYS(terraform);
- SL_HOTKEYS(terraform_editor);
- SL_HOTKEYS(order);
- SL_HOTKEYS(airtoolbar);
- SL_HOTKEYS(dockstoolbar);
- SL_HOTKEYS(railtoolbar);
- SL_HOTKEYS(roadtoolbar);
- SL_HOTKEYS(signlist);
- SL_HOTKEYS(aidebug);
-
+ for (HotkeyList **list = _hotkey_lists->Begin(); list != _hotkey_lists->End(); ++list) {
+ if (save) {
+ (*list)->Save(ini);
+ } else {
+ (*list)->Load(ini);
+ }
+ }
-#undef SL_HOTKEYS
if (save) ini->SaveToDisk(_hotkeys_file);
delete ini;
}
diff --git a/src/hotkeys.h b/src/hotkeys.h
index 87fafe2a1..ce57de6f6 100644
--- a/src/hotkeys.h
+++ b/src/hotkeys.h
@@ -32,7 +32,30 @@ struct Hotkey {
#define HOTKEY_LIST_END Hotkey((uint16)0, NULL, -1)
-int CheckHotkeyMatch(Hotkey *list, uint16 keycode, bool global_only = false);
+struct IniFile;
+
+/**
+ * List of hotkeys for a window.
+ */
+struct HotkeyList {
+ HotkeyList(const char *ini_group, Hotkey *items);
+ ~HotkeyList();
+
+ void Load(IniFile *ini);
+ void Save(IniFile *ini) const;
+
+ int CheckMatch(uint16 keycode, bool global_only = false) const;
+
+private:
+ const char *ini_group;
+ Hotkey *items;
+
+ /**
+ * Dummy private copy constructor to prevent compilers from
+ * copying the structure, which fails due to _hotkey_lists.
+ */
+ HotkeyList(const HotkeyList &other);
+};
bool IsQuitKey(uint16 keycode);
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index ae1b3c1b7..dcecfce27 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -289,7 +289,7 @@ struct MainWindow : Window
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
- int num = CheckHotkeyMatch(global_hotkeys, keycode);
+ int num = this->hotkeys.CheckMatch(keycode);
if (num == GHK_QUIT) {
HandleExitGameRequest();
return ES_HANDLED;
@@ -465,7 +465,7 @@ struct MainWindow : Window
InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data, true);
}
- static Hotkey global_hotkeys[];
+ static HotkeyList hotkeys;
};
const uint16 _ghk_quit_keys[] = {'Q' | WKC_CTRL, 'Q' | WKC_META, 0};
@@ -475,7 +475,7 @@ const uint16 _ghk_chat_all_keys[] = {WKC_SHIFT | WKC_RETURN, WKC_SHIFT | 'T', 0}
const uint16 _ghk_chat_company_keys[] = {WKC_CTRL | WKC_RETURN, WKC_CTRL | 'T', 0};
const uint16 _ghk_chat_server_keys[] = {WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT | 'T', 0};
-Hotkey MainWindow::global_hotkeys[] = {
+static Hotkey global_hotkeys[] = {
Hotkey(_ghk_quit_keys, "quit", GHK_QUIT),
Hotkey(_ghk_abandon_keys, "abandon", GHK_ABANDON),
Hotkey(WKC_BACKQUOTE, "console", GHK_CONSOLE),
@@ -519,7 +519,7 @@ Hotkey MainWindow::global_hotkeys[] = {
#endif
HOTKEY_LIST_END
};
-Hotkey *_global_hotkeys = MainWindow::global_hotkeys;
+HotkeyList MainWindow::hotkeys("global", global_hotkeys);
/**
* Does the given keycode match one of the keycodes bound to 'quit game'?
@@ -528,7 +528,7 @@ Hotkey *_global_hotkeys = MainWindow::global_hotkeys;
*/
bool IsQuitKey(uint16 keycode)
{
- int num = CheckHotkeyMatch(_global_hotkeys, keycode);
+ int num = MainWindow::hotkeys.CheckMatch(keycode);
return num == GHK_QUIT;
}
diff --git a/src/order_gui.cpp b/src/order_gui.cpp
index daa3462dd..ada3f5ed9 100644
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -1440,7 +1440,7 @@ public:
{
if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
- switch (CheckHotkeyMatch(order_hotkeys, keycode)) {
+ switch (this->hotkeys.CheckMatch(keycode)) {
case OHK_SKIP: this->OrderClick_Skip(); break;
case OHK_DELETE: this->OrderClick_Delete(); break;
case OHK_GOTO: this->OrderClick_Goto(); break;
@@ -1526,10 +1526,10 @@ public:
this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST);
}
- static Hotkey order_hotkeys[];
+ static HotkeyList hotkeys;
};
-Hotkey OrdersWindow::order_hotkeys[] = {
+static Hotkey order_hotkeys[] = {
Hotkey('D', "skip", OHK_SKIP),
Hotkey('F', "delete", OHK_DELETE),
Hotkey('G', "goto", OHK_GOTO),
@@ -1543,7 +1543,7 @@ Hotkey OrdersWindow::order_hotkeys[] = {
Hotkey((uint16)0, "no_load", OHK_NO_LOAD),
HOTKEY_LIST_END
};
-Hotkey *_order_hotkeys = OrdersWindow::order_hotkeys;
+HotkeyList OrdersWindow::hotkeys("order", order_hotkeys);
/** Nested widget definition for "your" train orders. */
static const NWidgetPart _nested_orders_train_widgets[] = {
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index eee4e26bf..e1b94b6bc 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -599,7 +599,7 @@ struct BuildRailToolbarWindow : Window {
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
- int num = CheckHotkeyMatch(railtoolbar_hotkeys, keycode);
+ int num = this->hotkeys.CheckMatch(keycode);
if (num == -1) return ES_NOT_HANDLED;
this->OnClick(Point(), num, 1);
MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
@@ -755,12 +755,12 @@ struct BuildRailToolbarWindow : Window {
return ES_NOT_HANDLED;
}
- static Hotkey railtoolbar_hotkeys[];
+ static HotkeyList hotkeys;
};
const uint16 _railtoolbar_autorail_keys[] = {'5', 'A' | WKC_GLOBAL_HOTKEY, 0};
-Hotkey BuildRailToolbarWindow::railtoolbar_hotkeys[] = {
+static Hotkey railtoolbar_hotkeys[] = {
Hotkey('1', "build_ns", WID_RAT_BUILD_NS),
Hotkey('2', "build_x", WID_RAT_BUILD_X),
Hotkey('3', "build_ew", WID_RAT_BUILD_EW),
@@ -777,7 +777,7 @@ Hotkey BuildRailToolbarWindow::railtoolbar_hotkeys[] = {
Hotkey('C', "convert", WID_RAT_CONVERT_RAIL),
HOTKEY_LIST_END
};
-Hotkey *_railtoolbar_hotkeys = BuildRailToolbarWindow::railtoolbar_hotkeys;
+HotkeyList BuildRailToolbarWindow::hotkeys("railtoolbar", railtoolbar_hotkeys);
static const NWidgetPart _nested_build_rail_widgets[] = {
NWidget(NWID_HORIZONTAL),
@@ -851,7 +851,7 @@ EventState RailToolbarGlobalHotkeys(uint16 key, uint16 keycode)
{
if (!CanBuildVehicleInfrastructure(VEH_TRAIN)) return ES_NOT_HANDLED;
extern RailType _last_built_railtype;
- int num = CheckHotkeyMatch(_railtoolbar_hotkeys, keycode, true);
+ int num = BuildRailToolbarWindow::hotkeys.CheckMatch(keycode, true);
if (num == -1) return ES_NOT_HANDLED;
Window *w = ShowBuildRailToolbar(_last_built_railtype);
if (w == NULL) return ES_NOT_HANDLED;
diff --git a/src/road_gui.cpp b/src/road_gui.cpp
index d98df7f9e..ae0c40c32 100644
--- a/src/road_gui.cpp
+++ b/src/road_gui.cpp
@@ -475,7 +475,7 @@ struct BuildRoadToolbarWindow : Window {
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
- int num = CheckHotkeyMatch(roadtoolbar_hotkeys, keycode);
+ int num = this->hotkeys.CheckMatch(keycode);
if (num == -1 || this->GetWidget<NWidgetBase>(num) == NULL) return ES_NOT_HANDLED;
this->OnClick(Point(), num, 1);
MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
@@ -660,10 +660,10 @@ struct BuildRoadToolbarWindow : Window {
return ES_NOT_HANDLED;
}
- static Hotkey roadtoolbar_hotkeys[];
+ static HotkeyList hotkeys;
};
-Hotkey BuildRoadToolbarWindow::roadtoolbar_hotkeys[] = {
+static Hotkey roadtoolbar_hotkeys[] = {
Hotkey('1', "build_x", WID_ROT_ROAD_X),
Hotkey('2', "build_y", WID_ROT_ROAD_Y),
Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
@@ -677,7 +677,7 @@ Hotkey BuildRoadToolbarWindow::roadtoolbar_hotkeys[] = {
Hotkey('R', "remove", WID_ROT_REMOVE),
HOTKEY_LIST_END
};
-Hotkey *_roadtoolbar_hotkeys = BuildRoadToolbarWindow::roadtoolbar_hotkeys;
+HotkeyList BuildRoadToolbarWindow::hotkeys("roadtoolbar", roadtoolbar_hotkeys);
static const NWidgetPart _nested_build_road_widgets[] = {
@@ -778,7 +778,7 @@ Window *ShowBuildRoadToolbar(RoadType roadtype)
EventState RoadToolbarGlobalHotkeys(uint16 key, uint16 keycode)
{
extern RoadType _last_built_roadtype;
- int num = CheckHotkeyMatch(_roadtoolbar_hotkeys, keycode, true);
+ int num = BuildRoadToolbarWindow::hotkeys.CheckMatch(keycode, true);
if (num == -1) return ES_NOT_HANDLED;
Window *w = ShowBuildRoadToolbar(_last_built_roadtype);
if (w == NULL) return ES_NOT_HANDLED;
@@ -831,7 +831,7 @@ Window *ShowBuildRoadScenToolbar()
EventState RoadToolbarEditorGlobalHotkeys(uint16 key, uint16 keycode)
{
- int num = CheckHotkeyMatch(_roadtoolbar_hotkeys, keycode, true);
+ int num = BuildRoadToolbarWindow::hotkeys.CheckMatch(keycode, true);
if (num == -1) return ES_NOT_HANDLED;
Window *w = ShowBuildRoadScenToolbar();
if (w == NULL) return ES_NOT_HANDLED;
diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp
index 433165f3d..7e4cdfba4 100644
--- a/src/signs_gui.cpp
+++ b/src/signs_gui.cpp
@@ -284,7 +284,7 @@ struct SignListWindow : Window, SignList {
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
EventState state = ES_NOT_HANDLED;
- if (CheckHotkeyMatch(signlist_hotkeys, keycode) == SLHK_FOCUS_FILTER_BOX) {
+ if (this->hotkeys.CheckMatch(keycode) == SLHK_FOCUS_FILTER_BOX) {
this->SetFocusedWidget(WID_SIL_FILTER_TEXT);
SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
state = ES_HANDLED;
@@ -332,14 +332,14 @@ struct SignListWindow : Window, SignList {
}
}
- static Hotkey signlist_hotkeys[];
+ static HotkeyList hotkeys;
};
-Hotkey SignListWindow::signlist_hotkeys[] = {
+static Hotkey signlist_hotkeys[] = {
Hotkey('F', "focus_filter_box", SLHK_FOCUS_FILTER_BOX),
HOTKEY_LIST_END
};
-Hotkey *_signlist_hotkeys = SignListWindow::signlist_hotkeys;
+HotkeyList SignListWindow::hotkeys("signlist", signlist_hotkeys);
static const NWidgetPart _nested_sign_list_widgets[] = {
NWidget(NWID_HORIZONTAL),
@@ -389,7 +389,7 @@ Window *ShowSignList()
EventState SignListGlobalHotkeys(uint16 key, uint16 keycode)
{
- int num = CheckHotkeyMatch(_signlist_hotkeys, keycode, true);
+ int num = SignListWindow::hotkeys.CheckMatch(keycode, true);
if (num == -1) return ES_NOT_HANDLED;
Window *w = ShowSignList();
if (w == NULL) return ES_NOT_HANDLED;
diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp
index 932d6b989..ba3d24025 100644
--- a/src/terraform_gui.cpp
+++ b/src/terraform_gui.cpp
@@ -221,7 +221,7 @@ struct TerraformToolbarWindow : Window {
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
- int num = CheckHotkeyMatch(terraform_hotkeys, keycode);
+ int num = this->hotkeys.CheckMatch(keycode);
if (num == -1) return ES_NOT_HANDLED;
this->OnClick(Point(), num, 1);
return ES_HANDLED;
@@ -295,10 +295,10 @@ struct TerraformToolbarWindow : Window {
this->RaiseButtons();
}
- static Hotkey terraform_hotkeys[];
+ static HotkeyList hotkeys;
};
-Hotkey TerraformToolbarWindow::terraform_hotkeys[] = {
+static Hotkey terraform_hotkeys[] = {
Hotkey('Q' | WKC_GLOBAL_HOTKEY, "lower", WID_TT_LOWER_LAND),
Hotkey('W' | WKC_GLOBAL_HOTKEY, "raise", WID_TT_RAISE_LAND),
Hotkey('E' | WKC_GLOBAL_HOTKEY, "level", WID_TT_LEVEL_LAND),
@@ -309,7 +309,7 @@ Hotkey TerraformToolbarWindow::terraform_hotkeys[] = {
Hotkey('P', "placeobject", WID_TT_PLACE_OBJECT),
HOTKEY_LIST_END
};
-Hotkey *_terraform_hotkeys = TerraformToolbarWindow::terraform_hotkeys;
+HotkeyList TerraformToolbarWindow::hotkeys("terraform", terraform_hotkeys);
static const NWidgetPart _nested_terraform_widgets[] = {
NWidget(NWID_HORIZONTAL),
@@ -380,7 +380,7 @@ Window *ShowTerraformToolbar(Window *link)
EventState TerraformToolbarGlobalHotkeys(uint16 key, uint16 keycode)
{
- int num = CheckHotkeyMatch(_terraform_hotkeys, keycode, true);
+ int num = TerraformToolbarWindow::hotkeys.CheckMatch(keycode, true);
if (num == -1) return ES_NOT_HANDLED;
Window *w = ShowTerraformToolbar(NULL);
if (w == NULL) return ES_NOT_HANDLED;
@@ -574,7 +574,7 @@ struct ScenarioEditorLandscapeGenerationWindow : Window {
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
- int num = CheckHotkeyMatch(terraform_editor_hotkeys, keycode);
+ int num = this->hotkeys.CheckMatch(keycode);
if (num == -1) return ES_NOT_HANDLED;
this->OnClick(Point(), num, 1);
return ES_HANDLED;
@@ -724,10 +724,10 @@ struct ScenarioEditorLandscapeGenerationWindow : Window {
DeleteWindowById(WC_BUILD_OBJECT, 0);
}
- static Hotkey terraform_editor_hotkeys[];
+ static HotkeyList hotkeys;
};
-Hotkey ScenarioEditorLandscapeGenerationWindow::terraform_editor_hotkeys[] = {
+static Hotkey terraform_editor_hotkeys[] = {
Hotkey('D' | WKC_GLOBAL_HOTKEY, "dynamite", WID_ETT_DEMOLISH),
Hotkey('Q' | WKC_GLOBAL_HOTKEY, "lower", WID_ETT_LOWER_LAND),
Hotkey('W' | WKC_GLOBAL_HOTKEY, "raise", WID_ETT_RAISE_LAND),
@@ -738,7 +738,7 @@ Hotkey ScenarioEditorLandscapeGenerationWindow::terraform_editor_hotkeys[] = {
HOTKEY_LIST_END
};
-Hotkey *_terraform_editor_hotkeys = ScenarioEditorLandscapeGenerationWindow::terraform_editor_hotkeys;
+HotkeyList ScenarioEditorLandscapeGenerationWindow::hotkeys("terraform_editor", terraform_editor_hotkeys);
static WindowDesc _scen_edit_land_gen_desc(
WDP_AUTO, "toolbar_landscape_scen", 0, 0,
@@ -758,7 +758,7 @@ Window *ShowEditorTerraformToolbar()
EventState TerraformToolbarEditorGlobalHotkeys(uint16 key, uint16 keycode)
{
- int num = CheckHotkeyMatch(_terraform_editor_hotkeys, keycode, true);
+ int num = ScenarioEditorLandscapeGenerationWindow::hotkeys.CheckMatch(keycode, true);
if (num == -1) return ES_NOT_HANDLED;
Window *w = ShowEditorTerraformToolbar();
if (w == NULL) return ES_NOT_HANDLED;
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index 9c5d72b2d..30287b76c 100644
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -1662,7 +1662,7 @@ struct MainToolbarWindow : Window {
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
- switch (CheckHotkeyMatch(maintoolbar_hotkeys, keycode)) {
+ switch (this->hotkeys.CheckMatch(keycode)) {
case MTHK_PAUSE: ToolbarPauseClick(this); break;
case MTHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
case MTHK_SETTINGS: ShowGameOptions(); break;
@@ -1759,7 +1759,7 @@ struct MainToolbarWindow : Window {
if (FindWindowById(WC_MAIN_WINDOW, 0) != NULL) HandleZoomMessage(this, FindWindowById(WC_MAIN_WINDOW, 0)->viewport, WID_TN_ZOOM_IN, WID_TN_ZOOM_OUT);
}
- static Hotkey maintoolbar_hotkeys[];
+ static HotkeyList hotkeys;
};
const uint16 _maintoolbar_pause_keys[] = {WKC_F1, WKC_PAUSE, 0};
@@ -1767,7 +1767,7 @@ const uint16 _maintoolbar_zoomin_keys[] = {WKC_NUM_PLUS, WKC_EQUALS, WKC_SHIFT |
const uint16 _maintoolbar_zoomout_keys[] = {WKC_NUM_MINUS, WKC_MINUS, WKC_SHIFT | WKC_MINUS, WKC_SHIFT | WKC_F6, 0};
const uint16 _maintoolbar_smallmap_keys[] = {WKC_F4, 'M', 0};
-Hotkey MainToolbarWindow::maintoolbar_hotkeys[] = {
+static Hotkey maintoolbar_hotkeys[] = {
Hotkey(_maintoolbar_pause_keys, "pause", MTHK_PAUSE),
Hotkey((uint16)0, "fastforward", MTHK_FASTFORWARD),
Hotkey(WKC_F2, "settings", MTHK_SETTINGS),
@@ -1810,7 +1810,7 @@ Hotkey MainToolbarWindow::maintoolbar_hotkeys[] = {
Hotkey((uint16)0, "sign_list", MTHK_SIGN_LIST),
HOTKEY_LIST_END
};
-Hotkey *_maintoolbar_hotkeys = MainToolbarWindow::maintoolbar_hotkeys;
+HotkeyList MainToolbarWindow::hotkeys("maintoolbar", maintoolbar_hotkeys);
static NWidgetBase *MakeMainToolbar(int *biggest_index)
{
@@ -2009,7 +2009,7 @@ struct ScenarioEditorToolbarWindow : Window {
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
CallBackFunction cbf = CBF_NONE;
- switch (CheckHotkeyMatch(scenedit_maintoolbar_hotkeys, keycode)) {
+ switch (this->hotkeys.CheckMatch(keycode)) {
case MTEHK_PAUSE: ToolbarPauseClick(this); break;
case MTEHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
case MTEHK_SETTINGS: ShowGameOptions(); break;
@@ -2102,10 +2102,10 @@ struct ScenarioEditorToolbarWindow : Window {
this->SetDirty();
}
- static Hotkey scenedit_maintoolbar_hotkeys[];
+ static HotkeyList hotkeys;
};
-Hotkey ScenarioEditorToolbarWindow::scenedit_maintoolbar_hotkeys[] = {
+static Hotkey scenedit_maintoolbar_hotkeys[] = {
Hotkey(_maintoolbar_pause_keys, "pause", MTEHK_PAUSE),
Hotkey((uint16)0, "fastforward", MTEHK_FASTFORWARD),
Hotkey(WKC_F2, "settings", MTEHK_SETTINGS),
@@ -2130,7 +2130,7 @@ Hotkey ScenarioEditorToolbarWindow::scenedit_maintoolbar_hotkeys[] = {
Hotkey('V', "extra_viewport", MTEHK_EXTRA_VIEWPORT),
HOTKEY_LIST_END
};
-Hotkey *_scenedit_maintoolbar_hotkeys = ScenarioEditorToolbarWindow::scenedit_maintoolbar_hotkeys;
+HotkeyList ScenarioEditorToolbarWindow::hotkeys("scenedit_maintoolbar", scenedit_maintoolbar_hotkeys);
static const NWidgetPart _nested_toolb_scen_inner_widgets[] = {
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_PAUSE), SetDataTip(SPR_IMG_PAUSE, STR_TOOLBAR_TOOLTIP_PAUSE_GAME),