(svn r25414) -Codechange: Move handling of global hotkeys to HotkeyList.

This commit is contained in:
frosch
2013-06-15 15:31:22 +00:00
parent ee4e68bd5e
commit fef30983e6
11 changed files with 145 additions and 142 deletions

View File

@@ -138,12 +138,25 @@ struct BuildAirToolbarWindow : Window {
static HotkeyList hotkeys;
};
/**
* Handler for global hotkeys of the BuildAirToolbarWindow.
* @param hotkey Hotkey
* @return ES_HANDLED if hotkey was accepted.
*/
static EventState AirportToolbarGlobalHotkeys(int hotkey)
{
if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) return ES_NOT_HANDLED;
Window *w = ShowBuildAirToolbar();
if (w == NULL) return ES_NOT_HANDLED;
return w->OnHotkey(hotkey);
}
static Hotkey airtoolbar_hotkeys[] = {
Hotkey('1', "airport", WID_AT_AIRPORT),
Hotkey('2', "demolish", WID_AT_DEMOLISH),
HOTKEY_LIST_END
};
HotkeyList BuildAirToolbarWindow::hotkeys("airtoolbar", airtoolbar_hotkeys);
HotkeyList BuildAirToolbarWindow::hotkeys("airtoolbar", airtoolbar_hotkeys, AirportToolbarGlobalHotkeys);
static const NWidgetPart _nested_air_toolbar_widgets[] = {
NWidget(NWID_HORIZONTAL),
@@ -181,16 +194,6 @@ Window *ShowBuildAirToolbar()
return AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
}
EventState AirportToolbarGlobalHotkeys(uint16 key, uint16 keycode)
{
if (!CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) return ES_NOT_HANDLED;
int num = BuildAirToolbarWindow::hotkeys.CheckMatch(keycode, true);
if (num == -1) return ES_NOT_HANDLED;
Window *w = ShowBuildAirToolbar();
if (w == NULL) return ES_NOT_HANDLED;
return w->OnHotkey(num);
}
class BuildAirportWindow : public PickerWindowBase {
SpriteID preview_sprite; ///< Cached airport preview sprite.
int line_height;