mirror of https://github.com/OpenTTD/OpenTTD
(svn r20073) -Feature: customizable hotkeys for the road toolbar
parent
6c6d1e3792
commit
19f86951d9
|
@ -293,6 +293,8 @@ GlobalHotkeyHandler DockToolbarGlobalHotkeys;
|
||||||
GlobalHotkeyHandler AirportToolbarGlobalHotkeys;
|
GlobalHotkeyHandler AirportToolbarGlobalHotkeys;
|
||||||
GlobalHotkeyHandler TerraformToolbarGlobalHotkeys;
|
GlobalHotkeyHandler TerraformToolbarGlobalHotkeys;
|
||||||
GlobalHotkeyHandler TerraformToolbarEditorGlobalHotkeys;
|
GlobalHotkeyHandler TerraformToolbarEditorGlobalHotkeys;
|
||||||
|
GlobalHotkeyHandler RoadToolbarGlobalHotkeys;
|
||||||
|
GlobalHotkeyHandler RoadToolbarEditorGlobalHotkeys;
|
||||||
|
|
||||||
|
|
||||||
GlobalHotkeyHandler *_global_hotkey_handlers[] = {
|
GlobalHotkeyHandler *_global_hotkey_handlers[] = {
|
||||||
|
@ -300,10 +302,12 @@ GlobalHotkeyHandler *_global_hotkey_handlers[] = {
|
||||||
DockToolbarGlobalHotkeys,
|
DockToolbarGlobalHotkeys,
|
||||||
AirportToolbarGlobalHotkeys,
|
AirportToolbarGlobalHotkeys,
|
||||||
TerraformToolbarGlobalHotkeys,
|
TerraformToolbarGlobalHotkeys,
|
||||||
|
RoadToolbarGlobalHotkeys,
|
||||||
};
|
};
|
||||||
|
|
||||||
GlobalHotkeyHandler *_global_hotkey_handlers_editor[] = {
|
GlobalHotkeyHandler *_global_hotkey_handlers_editor[] = {
|
||||||
TerraformToolbarEditorGlobalHotkeys,
|
TerraformToolbarEditorGlobalHotkeys,
|
||||||
|
RoadToolbarEditorGlobalHotkeys,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "tunnelbridge_map.h"
|
#include "tunnelbridge_map.h"
|
||||||
#include "tilehighlight_func.h"
|
#include "tilehighlight_func.h"
|
||||||
#include "company_base.h"
|
#include "company_base.h"
|
||||||
|
#include "hotkeys.h"
|
||||||
|
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
@ -446,21 +447,6 @@ static OnButtonClick * const _build_road_button_proc[] = {
|
||||||
BuildRoadClick_Remove
|
BuildRoadClick_Remove
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Array with the keycode of the button-clicks for the road-toolbar */
|
|
||||||
static const uint16 _road_keycodes[] = {
|
|
||||||
'1',
|
|
||||||
'2',
|
|
||||||
'3',
|
|
||||||
'4',
|
|
||||||
'5',
|
|
||||||
'6',
|
|
||||||
'7',
|
|
||||||
'8',
|
|
||||||
'B',
|
|
||||||
'T',
|
|
||||||
'R',
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BuildRoadToolbarWindow : Window {
|
struct BuildRoadToolbarWindow : Window {
|
||||||
BuildRoadToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
BuildRoadToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
||||||
{
|
{
|
||||||
|
@ -553,20 +539,11 @@ struct BuildRoadToolbarWindow : Window {
|
||||||
|
|
||||||
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
EventState state = ES_NOT_HANDLED;
|
int num = CheckHotkeyMatch(roadtoolbar_hotkeys, keycode, this);
|
||||||
for (uint i = 0; i != lengthof(_road_keycodes); i++) {
|
if (num == -1 || this->GetWidget<NWidgetBase>(num) == NULL) return ES_NOT_HANDLED;
|
||||||
if (keycode == _road_keycodes[i]) {
|
this->OnClick(Point(), num, 1);
|
||||||
_remove_button_clicked = false;
|
|
||||||
_one_way_button_clicked = false;
|
|
||||||
_build_road_button_proc[i](this);
|
|
||||||
this->UpdateOptionWidgetStatus((RoadToolbarWidgets)(i + RTW_ROAD_X));
|
|
||||||
if (_ctrl_pressed) RoadToolbar_CtrlChanged(this);
|
|
||||||
state = ES_HANDLED;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
|
MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
|
||||||
return state;
|
return ES_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
||||||
|
@ -697,8 +674,27 @@ struct BuildRoadToolbarWindow : Window {
|
||||||
if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED;
|
if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED;
|
||||||
return ES_NOT_HANDLED;
|
return ES_NOT_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Hotkey<BuildRoadToolbarWindow> roadtoolbar_hotkeys[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Hotkey<BuildRoadToolbarWindow> BuildRoadToolbarWindow::roadtoolbar_hotkeys[] = {
|
||||||
|
Hotkey<BuildRoadToolbarWindow>('1', "build_x", RTW_ROAD_X),
|
||||||
|
Hotkey<BuildRoadToolbarWindow>('2', "build_y", RTW_ROAD_Y),
|
||||||
|
Hotkey<BuildRoadToolbarWindow>('3', "autoroad", RTW_AUTOROAD),
|
||||||
|
Hotkey<BuildRoadToolbarWindow>('4', "demolish", RTW_DEMOLISH),
|
||||||
|
Hotkey<BuildRoadToolbarWindow>('5', "depot", RTW_DEPOT),
|
||||||
|
Hotkey<BuildRoadToolbarWindow>('6', "bus_station", RTW_BUS_STATION),
|
||||||
|
Hotkey<BuildRoadToolbarWindow>('7', "truck_station", RTW_TRUCK_STATION),
|
||||||
|
Hotkey<BuildRoadToolbarWindow>('8', "oneway", RTW_ONE_WAY),
|
||||||
|
Hotkey<BuildRoadToolbarWindow>('B', "bridge", RTW_BUILD_BRIDGE),
|
||||||
|
Hotkey<BuildRoadToolbarWindow>('T', "tunnel", RTW_BUILD_TUNNEL),
|
||||||
|
Hotkey<BuildRoadToolbarWindow>('R', "remove", RTW_REMOVE),
|
||||||
|
HOTKEY_LIST_END(BuildRoadToolbarWindow)
|
||||||
|
};
|
||||||
|
Hotkey<BuildRoadToolbarWindow> *_roadtoolbar_hotkeys = BuildRoadToolbarWindow::roadtoolbar_hotkeys;
|
||||||
|
|
||||||
|
|
||||||
static const NWidgetPart _nested_build_road_widgets[] = {
|
static const NWidgetPart _nested_build_road_widgets[] = {
|
||||||
NWidget(NWID_HORIZONTAL),
|
NWidget(NWID_HORIZONTAL),
|
||||||
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
|
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
|
||||||
|
@ -778,13 +774,30 @@ static const WindowDesc _build_tramway_desc(
|
||||||
_nested_build_tramway_widgets, lengthof(_nested_build_tramway_widgets)
|
_nested_build_tramway_widgets, lengthof(_nested_build_tramway_widgets)
|
||||||
);
|
);
|
||||||
|
|
||||||
void ShowBuildRoadToolbar(RoadType roadtype)
|
/**
|
||||||
|
* Open the build road toolbar window
|
||||||
|
*
|
||||||
|
* If the terraform toolbar is linked to the toolbar, that window is also opened.
|
||||||
|
*
|
||||||
|
* @return newly opened road toolbar, or NULL if the toolbar could not be opened.
|
||||||
|
*/
|
||||||
|
Window *ShowBuildRoadToolbar(RoadType roadtype)
|
||||||
{
|
{
|
||||||
if (!Company::IsValidID(_local_company)) return;
|
if (!Company::IsValidID(_local_company)) return NULL;
|
||||||
_cur_roadtype = roadtype;
|
_cur_roadtype = roadtype;
|
||||||
|
|
||||||
DeleteWindowByClass(WC_BUILD_TOOLBAR);
|
DeleteWindowByClass(WC_BUILD_TOOLBAR);
|
||||||
AllocateWindowDescFront<BuildRoadToolbarWindow>(roadtype == ROADTYPE_ROAD ? &_build_road_desc : &_build_tramway_desc, TRANSPORT_ROAD);
|
return AllocateWindowDescFront<BuildRoadToolbarWindow>(roadtype == ROADTYPE_ROAD ? &_build_road_desc : &_build_tramway_desc, TRANSPORT_ROAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
EventState RoadToolbarGlobalHotkeys(uint16 key, uint16 keycode)
|
||||||
|
{
|
||||||
|
extern RoadType _last_built_roadtype;
|
||||||
|
int num = CheckHotkeyMatch<BuildRoadToolbarWindow>(_roadtoolbar_hotkeys, keycode, NULL, true);
|
||||||
|
if (num == -1) return ES_NOT_HANDLED;
|
||||||
|
Window *w = ShowBuildRoadToolbar(_last_built_roadtype);
|
||||||
|
if (w == NULL) return ES_NOT_HANDLED;
|
||||||
|
return w->OnKeyPress(key, keycode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const NWidgetPart _nested_build_road_scen_widgets[] = {
|
static const NWidgetPart _nested_build_road_scen_widgets[] = {
|
||||||
|
@ -821,10 +834,19 @@ static const WindowDesc _build_road_scen_desc(
|
||||||
_nested_build_road_scen_widgets, lengthof(_nested_build_road_scen_widgets)
|
_nested_build_road_scen_widgets, lengthof(_nested_build_road_scen_widgets)
|
||||||
);
|
);
|
||||||
|
|
||||||
void ShowBuildRoadScenToolbar()
|
Window *ShowBuildRoadScenToolbar()
|
||||||
{
|
{
|
||||||
_cur_roadtype = ROADTYPE_ROAD;
|
_cur_roadtype = ROADTYPE_ROAD;
|
||||||
AllocateWindowDescFront<BuildRoadToolbarWindow>(&_build_road_scen_desc, 0);
|
return AllocateWindowDescFront<BuildRoadToolbarWindow>(&_build_road_scen_desc, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
EventState RoadToolbarEditorGlobalHotkeys(uint16 key, uint16 keycode)
|
||||||
|
{
|
||||||
|
int num = CheckHotkeyMatch<BuildRoadToolbarWindow>(_roadtoolbar_hotkeys, keycode, NULL, true);
|
||||||
|
if (num == -1) return ES_NOT_HANDLED;
|
||||||
|
Window *w = ShowBuildRoadScenToolbar();
|
||||||
|
if (w == NULL) return ES_NOT_HANDLED;
|
||||||
|
return w->OnKeyPress(key, keycode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Enum referring to the widgets of the build road depot window */
|
/** Enum referring to the widgets of the build road depot window */
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#include "road_type.h"
|
#include "road_type.h"
|
||||||
|
|
||||||
void ShowBuildRoadToolbar(RoadType roadtype);
|
Window *ShowBuildRoadToolbar(RoadType roadtype);
|
||||||
void ShowBuildRoadScenToolbar();
|
Window *ShowBuildRoadScenToolbar();
|
||||||
|
|
||||||
#endif /* ROAD_GUI_H */
|
#endif /* ROAD_GUI_H */
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
|
|
||||||
RailType _last_built_railtype;
|
RailType _last_built_railtype;
|
||||||
static RoadType _last_built_roadtype;
|
RoadType _last_built_roadtype;
|
||||||
|
|
||||||
enum ToolbarMode {
|
enum ToolbarMode {
|
||||||
TB_NORMAL,
|
TB_NORMAL,
|
||||||
|
|
Loading…
Reference in New Issue