summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hotkeys.cpp7
-rw-r--r--src/rail_gui.cpp102
-rw-r--r--src/rail_gui.h2
-rw-r--r--src/toolbar_gui.cpp4
4 files changed, 59 insertions, 56 deletions
diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp
index 41a809bb9..4bb12503e 100644
--- a/src/hotkeys.cpp
+++ b/src/hotkeys.cpp
@@ -140,7 +140,12 @@ static const char *KeycodeToString(uint16 keycode)
static char buf[32];
buf[0] = '\0';
bool first = true;
+ if (keycode & WKC_GLOBAL_HOTKEY) {
+ strecat(buf, "GLOBAL", lastof(buf));
+ first = false;
+ }
if (keycode & WKC_SHIFT) {
+ if (!first) strecat(buf, "+", lastof(buf));
strecat(buf, "SHIFT", lastof(buf));
first = false;
}
@@ -239,6 +244,7 @@ struct OrdersWindow;
struct BuildAirToolbarWindow;
struct BuildDocksToolbarWindow;
struct MainToolbarWindow;
+struct BuildRailToolbarWindow;
static void SaveLoadHotkeys(bool save)
{
@@ -259,6 +265,7 @@ static void SaveLoadHotkeys(bool save)
SL_HOTKEYS(airtoolbar, BuildAirToolbarWindow);
SL_HOTKEYS(dockstoolbar, BuildDocksToolbarWindow);
SL_HOTKEYS(maintoolbar, MainToolbarWindow);
+ SL_HOTKEYS(railtoolbar, BuildRailToolbarWindow);
#undef SL_HOTKEYS
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index 81c95e5a1..66e8528d0 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -30,6 +30,7 @@
#include "tilehighlight_func.h"
#include "spritecache.h"
#include "core/geometry_func.hpp"
+#include "hotkeys.h"
#include "station_map.h"
#include "tunnelbridge_map.h"
@@ -591,31 +592,25 @@ static void HandleAutoSignalPlacement()
typedef void OnButtonClick(Window *w);
-/** Data associated with a push button in the build rail toolbar window */
-struct RailBuildingGUIButtonData {
- uint16 keycode; ///< Keycode associated with the button
- OnButtonClick *click_proc; ///< Procedure to call when button is clicked
-};
-
/**
- * GUI rail-building button data constants.
+ * Procedure to call when button in rail toolbar is clicked.
* Offsets match widget order, starting at RTW_BUILD_NS
*/
-static const RailBuildingGUIButtonData _rail_build_button_data[] = {
- {'1', BuildRailClick_N },
- {'2', BuildRailClick_NE },
- {'3', BuildRailClick_E },
- {'4', BuildRailClick_NW },
- {'5', BuildRailClick_AutoRail },
- {'6', BuildRailClick_Demolish },
- {'7', BuildRailClick_Depot },
- {'8', BuildRailClick_Waypoint },
- {'9', BuildRailClick_Station },
- {'S', BuildRailClick_AutoSignals},
- {'B', BuildRailClick_Bridge },
- {'T', BuildRailClick_Tunnel },
- {'R', BuildRailClick_Remove },
- {'C', BuildRailClick_Convert }
+static OnButtonClick *_rail_build_button[] = {
+ BuildRailClick_N,
+ BuildRailClick_NE,
+ BuildRailClick_E,
+ BuildRailClick_NW,
+ BuildRailClick_AutoRail,
+ BuildRailClick_Demolish,
+ BuildRailClick_Depot,
+ BuildRailClick_Waypoint,
+ BuildRailClick_Station,
+ BuildRailClick_AutoSignals,
+ BuildRailClick_Bridge,
+ BuildRailClick_Tunnel,
+ BuildRailClick_Remove,
+ BuildRailClick_Convert
};
/**
@@ -717,7 +712,7 @@ struct BuildRailToolbarWindow : Window {
{
if (widget >= RTW_BUILD_NS) {
_remove_button_clicked = false;
- _rail_build_button_data[widget - RTW_BUILD_NS].click_proc(this);
+ _rail_build_button[widget - RTW_BUILD_NS](this);
}
this->UpdateRemoveWidgetStatus(widget);
if (_ctrl_pressed) RailToolbar_CtrlChanged(this);
@@ -725,19 +720,11 @@ struct BuildRailToolbarWindow : Window {
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
- EventState state = ES_NOT_HANDLED;
- for (uint8 i = 0; i != lengthof(_rail_build_button_data); i++) {
- if (keycode == _rail_build_button_data[i].keycode) {
- _remove_button_clicked = false;
- _rail_build_button_data[i].click_proc(this);
- this->UpdateRemoveWidgetStatus(i + RTW_BUILD_NS);
- if (_ctrl_pressed) RailToolbar_CtrlChanged(this);
- state = ES_HANDLED;
- break;
- }
- }
+ int num = CheckHotkeyMatch(railtoolbar_hotkeys, keycode, this);
+ if (num == -1) return ES_NOT_HANDLED;
+ this->OnClick(Point(), num, 1);
MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
- return state;
+ return ES_HANDLED;
}
virtual void OnPlaceObject(Point pt, TileIndex tile)
@@ -831,8 +818,31 @@ struct BuildRailToolbarWindow : Window {
if (!this->IsWidgetLowered(RTW_BUILD_STATION) && !this->IsWidgetLowered(RTW_BUILD_WAYPOINT) && RailToolbar_CtrlChanged(this)) return ES_HANDLED;
return ES_NOT_HANDLED;
}
+
+ static Hotkey<BuildRailToolbarWindow> railtoolbar_hotkeys[];
};
+const uint16 _railtoolbar_autorail_keys[] = {'5', 'A' | WKC_GLOBAL_HOTKEY, 0};
+
+Hotkey<BuildRailToolbarWindow> BuildRailToolbarWindow::railtoolbar_hotkeys[] = {
+ Hotkey<BuildRailToolbarWindow>('1', "build_ns", RTW_BUILD_NS),
+ Hotkey<BuildRailToolbarWindow>('2', "build_x", RTW_BUILD_X),
+ Hotkey<BuildRailToolbarWindow>('3', "build_ew", RTW_BUILD_EW),
+ Hotkey<BuildRailToolbarWindow>('4', "build_y", RTW_BUILD_Y),
+ Hotkey<BuildRailToolbarWindow>(_railtoolbar_autorail_keys, "autorail", RTW_AUTORAIL),
+ Hotkey<BuildRailToolbarWindow>('6', "demolish", RTW_DEMOLISH),
+ Hotkey<BuildRailToolbarWindow>('7', "depot", RTW_BUILD_DEPOT),
+ Hotkey<BuildRailToolbarWindow>('8', "waypoint", RTW_BUILD_WAYPOINT),
+ Hotkey<BuildRailToolbarWindow>('9', "station", RTW_BUILD_STATION),
+ Hotkey<BuildRailToolbarWindow>('S', "signal", RTW_BUILD_SIGNALS),
+ Hotkey<BuildRailToolbarWindow>('B', "bridge", RTW_BUILD_BRIDGE),
+ Hotkey<BuildRailToolbarWindow>('T', "tunnel", RTW_BUILD_TUNNEL),
+ Hotkey<BuildRailToolbarWindow>('R', "remove", RTW_REMOVE),
+ Hotkey<BuildRailToolbarWindow>('C', "convert", RTW_CONVERT_RAIL),
+ HOTKEY_LIST_END(BuildRailToolbarWindow)
+};
+Hotkey<BuildRailToolbarWindow> *_railtoolbar_hotkeys = BuildRailToolbarWindow::railtoolbar_hotkeys;
+
static const NWidgetPart _nested_build_rail_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
@@ -884,34 +894,20 @@ static const WindowDesc _build_rail_desc(
/**
* Open the build rail toolbar window for a specific rail type.
- * The window may be opened in the 'normal' way by clicking at the rail icon in
- * the main toolbar, or by means of selecting one of the functions of the
- * toolbar. In the latter case, the corresponding widget is also selected.
*
* If the terraform toolbar is linked to the toolbar, that window is also opened.
*
* @param railtype Rail type to open the window for
- * @param button Widget clicked (\c -1 means no button clicked)
*/
-void ShowBuildRailToolbar(RailType railtype, int button)
+void ShowBuildRailToolbar(RailType railtype)
{
if (!Company::IsValidID(_local_company)) return;
if (!ValParamRailtype(railtype)) return;
- BuildRailToolbarWindow *w = (BuildRailToolbarWindow *)FindWindowById(WC_BUILD_TOOLBAR, TRANSPORT_RAIL);
-
- /* don't recreate the window if we're clicking on a button and the window exists. */
- if (button < 0 || w == NULL) {
- DeleteWindowByClass(WC_BUILD_TOOLBAR);
- _cur_railtype = railtype;
- w = new BuildRailToolbarWindow(&_build_rail_desc, TRANSPORT_RAIL, railtype);
- }
-
+ DeleteWindowByClass(WC_BUILD_TOOLBAR);
+ _cur_railtype = railtype;
+ BuildRailToolbarWindow *w = new BuildRailToolbarWindow(&_build_rail_desc, TRANSPORT_RAIL, railtype);
_remove_button_clicked = false;
- if (w != NULL && button >= 0) {
- _rail_build_button_data[button].click_proc(w);
- w->UpdateRemoveWidgetStatus(button + RTW_BUILD_NS);
- }
}
/* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
diff --git a/src/rail_gui.h b/src/rail_gui.h
index 2708bf466..9d124036b 100644
--- a/src/rail_gui.h
+++ b/src/rail_gui.h
@@ -14,7 +14,7 @@
#include "rail_type.h"
-void ShowBuildRailToolbar(RailType railtype, int button);
+void ShowBuildRailToolbar(RailType railtype);
void ReinitGuiAfterToggleElrail(bool disable);
bool ResetSignalVariant(int32 = 0);
void InitializeRailGUI();
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index cd7a216fc..a7b036471 100644
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -664,7 +664,7 @@ static void ToolbarBuildRailClick(Window *w)
static void MenuClickBuildRail(int index)
{
_last_built_railtype = (RailType)index;
- ShowBuildRailToolbar(_last_built_railtype, -1);
+ ShowBuildRailToolbar(_last_built_railtype);
}
/* --- Road button menu --- */
@@ -1317,7 +1317,7 @@ struct MainToolbarWindow : Window {
case MTHK_AIRCRAFT_LIST: ShowVehicleListWindow(_local_company, VEH_AIRCRAFT); break;
case MTHK_ZOOM_IN: ToolbarZoomInClick(this); break;
case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
- case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype, -1); break;
+ case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype); break;
case MTHK_BUILD_ROAD: ShowBuildRoadToolbar(_last_built_roadtype); break;
case MTHK_BUILD_DOCKS: ShowBuildDocksToolbar(); break;
case MTHK_BUILD_AIRPORT: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) ShowBuildAirToolbar(); break;