Changeset - r20401:9fccb7c94c07
[Not reviewed]
master
0 11 0
frosch - 11 years ago 2013-06-15 15:31:22
frosch@openttd.org
(svn r25414) -Codechange: Move handling of global hotkeys to HotkeyList.
11 files changed with 145 insertions and 142 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_gui.cpp
Show inline comments
 
@@ -1399,12 +1399,25 @@ StringFilter AIDebugWindow::break_string
 
/** Make a number of rows with buttons for each company for the AI debug window. */
 
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);
 
}
 

	
 
/**
 
 * Handler for global hotkeys of the AIDebugWindow.
 
 * @param hotkey Hotkey
 
 * @return ES_HANDLED if hotkey was accepted.
 
 */
 
static EventState AIDebugGlobalHotkeys(int hotkey)
 
{
 
	if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
 
	Window *w = ShowAIDebugWindow(INVALID_COMPANY);
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	return w->OnHotkey(hotkey);
 
}
 

	
 
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),
 
	Hotkey('4', "company_4", WID_AID_COMPANY_BUTTON_START + 3),
 
	Hotkey('5', "company_5", WID_AID_COMPANY_BUTTON_START + 4),
 
@@ -1424,13 +1437,13 @@ static Hotkey aidebug_hotkeys[] = {
 
	Hotkey('B', "break_toggle", WID_AID_BREAK_STR_ON_OFF_BTN),
 
	Hotkey('F', "break_string", WID_AID_BREAK_STR_EDIT_BOX),
 
	Hotkey('C', "match_case", WID_AID_MATCH_CASE_BTN),
 
	Hotkey(WKC_RETURN, "continue", WID_AID_CONTINUE_BTN),
 
	HOTKEY_LIST_END
 
};
 
HotkeyList AIDebugWindow::hotkeys("aidebug", aidebug_hotkeys);
 
HotkeyList AIDebugWindow::hotkeys("aidebug", aidebug_hotkeys, AIDebugGlobalHotkeys);
 

	
 
/** Widgets for the AI debug window. */
 
static const NWidgetPart _nested_ai_debug_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_AI_DEBUG, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
@@ -1499,24 +1512,12 @@ Window *ShowAIDebugWindow(CompanyID show
 
	}
 

	
 
	return NULL;
 
}
 

	
 
/**
 
 * Handler for global AI debug window hotkeys.
 
 */
 
EventState AIDebugGlobalHotkeys(uint16 key, uint16 keycode)
 
{
 
	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;
 
	return w->OnHotkey(num);
 
}
 

	
 
/**
 
 * Reset the AI windows to their initial state.
 
 */
 
void InitializeAIGui()
 
{
 
	AIDebugWindow::ai_debug_company = INVALID_COMPANY;
 
}
src/airport_gui.cpp
Show inline comments
 
@@ -135,18 +135,31 @@ struct BuildAirToolbarWindow : Window {
 
		DeleteWindowById(WC_SELECT_STATION, 0);
 
	}
 

	
 
	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),
 
		NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
 
		NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_TOOLBAR_AIRCRAFT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
 
@@ -178,22 +191,12 @@ Window *ShowBuildAirToolbar()
 
	if (!Company::IsValidID(_local_company)) return NULL;
 

	
 
	DeleteWindowByClass(WC_BUILD_TOOLBAR);
 
	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;
 
	Scrollbar *vscroll;
 

	
 
	/** Build a dropdown list of available airport classes */
src/dock_gui.cpp
Show inline comments
 
@@ -266,12 +266,25 @@ struct BuildDocksToolbarWindow : Window 
 
		VpSetPresizeRange(tile_from, tile_to);
 
	}
 

	
 
	static HotkeyList hotkeys;
 
};
 

	
 
/**
 
 * Handler for global hotkeys of the BuildDocksToolbarWindow.
 
 * @param hotkey Hotkey
 
 * @return ES_HANDLED if hotkey was accepted.
 
 */
 
static EventState DockToolbarGlobalHotkeys(int hotkey)
 
{
 
	if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
 
	Window *w = ShowBuildDocksToolbar();
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	return w->OnHotkey(hotkey);
 
}
 

	
 
const uint16 _dockstoolbar_aqueduct_keys[] = {'B', '8', 0};
 

	
 
static Hotkey dockstoolbar_hotkeys[] = {
 
	Hotkey('1', "canal", WID_DT_CANAL),
 
	Hotkey('2', "lock", WID_DT_LOCK),
 
	Hotkey('3', "demolish", WID_DT_DEMOLISH),
 
@@ -279,13 +292,13 @@ static Hotkey dockstoolbar_hotkeys[] = {
 
	Hotkey('5', "dock", WID_DT_STATION),
 
	Hotkey('6', "buoy", WID_DT_BUOY),
 
	Hotkey('7', "river", WID_DT_RIVER),
 
	Hotkey(_dockstoolbar_aqueduct_keys, "aqueduct", WID_DT_BUILD_AQUEDUCT),
 
	HOTKEY_LIST_END
 
};
 
HotkeyList BuildDocksToolbarWindow::hotkeys("dockstoolbar", dockstoolbar_hotkeys);
 
HotkeyList BuildDocksToolbarWindow::hotkeys("dockstoolbar", dockstoolbar_hotkeys, DockToolbarGlobalHotkeys);
 

	
 
/**
 
 * Nested widget parts of docks toolbar, game version.
 
 * Position of #WID_DT_RIVER widget has changed.
 
 */
 
static const NWidgetPart _nested_build_docks_toolbar_widgets[] = {
 
@@ -326,21 +339,12 @@ Window *ShowBuildDocksToolbar()
 
	if (!Company::IsValidID(_local_company)) return NULL;
 

	
 
	DeleteWindowByClass(WC_BUILD_TOOLBAR);
 
	return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
 
}
 

	
 
EventState DockToolbarGlobalHotkeys(uint16 key, uint16 keycode)
 
{
 
	int num = BuildDocksToolbarWindow::hotkeys.CheckMatch(keycode, true);
 
	if (num == -1) return ES_NOT_HANDLED;
 
	Window *w = ShowBuildDocksToolbar();
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	return w->OnHotkey(num);
 
}
 

	
 
/**
 
 * Nested widget parts of docks toolbar, scenario editor version.
 
 * Positions of #WID_DT_DEPOT, #WID_DT_STATION, and #WID_DT_BUOY widgets have changed.
 
 */
 
static const NWidgetPart _nested_build_docks_scen_toolbar_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
src/hotkeys.cpp
Show inline comments
 
@@ -246,14 +246,14 @@ Hotkey::Hotkey(const uint16 *default_key
 
 */
 
void Hotkey::AddKeycode(uint16 keycode)
 
{
 
	this->keycodes.Include(keycode);
 
}
 

	
 
HotkeyList::HotkeyList(const char *ini_group, Hotkey *items) :
 
	ini_group(ini_group), items(items)
 
HotkeyList::HotkeyList(const char *ini_group, Hotkey *items, GlobalHotkeyHandlerFunc global_hotkey_handler) :
 
	global_hotkey_handler(global_hotkey_handler), ini_group(ini_group), items(items)
 
{
 
	if (_hotkey_lists == NULL) _hotkey_lists = new SmallVector<HotkeyList*, 16>();
 
	*_hotkey_lists->Append() = this;
 
}
 

	
 
HotkeyList::~HotkeyList()
 
@@ -334,48 +334,16 @@ void LoadHotkeysFromConfig()
 
/** Save the hotkeys to the config file */
 
void SaveHotkeysToConfig()
 
{
 
	SaveLoadHotkeys(true);
 
}
 

	
 
typedef EventState GlobalHotkeyHandler(uint16, uint16);
 

	
 
GlobalHotkeyHandler RailToolbarGlobalHotkeys;
 
GlobalHotkeyHandler DockToolbarGlobalHotkeys;
 
GlobalHotkeyHandler AirportToolbarGlobalHotkeys;
 
GlobalHotkeyHandler TerraformToolbarGlobalHotkeys;
 
GlobalHotkeyHandler TerraformToolbarEditorGlobalHotkeys;
 
GlobalHotkeyHandler RoadToolbarGlobalHotkeys;
 
GlobalHotkeyHandler RoadToolbarEditorGlobalHotkeys;
 
GlobalHotkeyHandler SignListGlobalHotkeys;
 
GlobalHotkeyHandler AIDebugGlobalHotkeys;
 

	
 

	
 
GlobalHotkeyHandler *_global_hotkey_handlers[] = {
 
	RailToolbarGlobalHotkeys,
 
	DockToolbarGlobalHotkeys,
 
	AirportToolbarGlobalHotkeys,
 
	TerraformToolbarGlobalHotkeys,
 
	RoadToolbarGlobalHotkeys,
 
	SignListGlobalHotkeys,
 
	AIDebugGlobalHotkeys,
 
};
 

	
 
GlobalHotkeyHandler *_global_hotkey_handlers_editor[] = {
 
	TerraformToolbarEditorGlobalHotkeys,
 
	RoadToolbarEditorGlobalHotkeys,
 
};
 

	
 

	
 
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;
 
		}
 
	for (HotkeyList **list = _hotkey_lists->Begin(); list != _hotkey_lists->End(); ++list) {
 
		if ((*list)->global_hotkey_handler == NULL) continue;
 

	
 
		int hotkey = (*list)->CheckMatch(keycode, true);
 
		if (hotkey >= 0 && ((*list)->global_hotkey_handler(hotkey) == ES_HANDLED)) return;
 
	}
 
}
 

	
src/hotkeys.h
Show inline comments
 
@@ -11,12 +11,13 @@
 

	
 
#ifndef HOTKEYS_H
 
#define HOTKEYS_H
 

	
 
#include "core/smallvec_type.hpp"
 
#include "gfx_type.h"
 
#include "window_type.h"
 

	
 
/**
 
 * All data for a single hotkey. The name (for saving/loading a configfile),
 
 * a list of keycodes and a number to help identifying this hotkey.
 
 */
 
struct Hotkey {
 
@@ -35,20 +36,23 @@ struct Hotkey {
 
struct IniFile;
 

	
 
/**
 
 * List of hotkeys for a window.
 
 */
 
struct HotkeyList {
 
	HotkeyList(const char *ini_group, Hotkey *items);
 
	typedef EventState (*GlobalHotkeyHandlerFunc)(int hotkey);
 

	
 
	HotkeyList(const char *ini_group, Hotkey *items, GlobalHotkeyHandlerFunc global_hotkey_handler = NULL);
 
	~HotkeyList();
 

	
 
	void Load(IniFile *ini);
 
	void Save(IniFile *ini) const;
 

	
 
	int CheckMatch(uint16 keycode, bool global_only = false) const;
 

	
 
	GlobalHotkeyHandlerFunc global_hotkey_handler;
 
private:
 
	const char *ini_group;
 
	Hotkey *items;
 

	
 
	/**
 
	 * Dummy private copy constructor to prevent compilers from
src/rail_gui.cpp
Show inline comments
 
@@ -752,12 +752,26 @@ struct BuildRailToolbarWindow : Window {
 
		return ES_NOT_HANDLED;
 
	}
 

	
 
	static HotkeyList hotkeys;
 
};
 

	
 
/**
 
 * Handler for global hotkeys of the BuildRailToolbarWindow.
 
 * @param hotkey Hotkey
 
 * @return ES_HANDLED if hotkey was accepted.
 
 */
 
static EventState RailToolbarGlobalHotkeys(int hotkey)
 
{
 
	if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_TRAIN)) return ES_NOT_HANDLED;
 
	extern RailType _last_built_railtype;
 
	Window *w = ShowBuildRailToolbar(_last_built_railtype);
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	return w->OnHotkey(hotkey);
 
}
 

	
 
const uint16 _railtoolbar_autorail_keys[] = {'5', 'A' | WKC_GLOBAL_HOTKEY, 0};
 

	
 
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),
 
@@ -771,13 +785,13 @@ static Hotkey railtoolbar_hotkeys[] = {
 
	Hotkey('B', "bridge", WID_RAT_BUILD_BRIDGE),
 
	Hotkey('T', "tunnel", WID_RAT_BUILD_TUNNEL),
 
	Hotkey('R', "remove", WID_RAT_REMOVE),
 
	Hotkey('C', "convert", WID_RAT_CONVERT_RAIL),
 
	HOTKEY_LIST_END
 
};
 
HotkeyList BuildRailToolbarWindow::hotkeys("railtoolbar", railtoolbar_hotkeys);
 
HotkeyList BuildRailToolbarWindow::hotkeys("railtoolbar", railtoolbar_hotkeys, RailToolbarGlobalHotkeys);
 

	
 
static const NWidgetPart _nested_build_rail_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
 
		NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_RAT_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
 
@@ -842,23 +856,12 @@ Window *ShowBuildRailToolbar(RailType ra
 
	DeleteWindowByClass(WC_BUILD_TOOLBAR);
 
	_cur_railtype = railtype;
 
	_remove_button_clicked = false;
 
	return new BuildRailToolbarWindow(&_build_rail_desc, railtype);
 
}
 

	
 
EventState RailToolbarGlobalHotkeys(uint16 key, uint16 keycode)
 
{
 
	if (!CanBuildVehicleInfrastructure(VEH_TRAIN)) return ES_NOT_HANDLED;
 
	extern RailType _last_built_railtype;
 
	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;
 
	return w->OnHotkey(num);
 
}
 

	
 
/* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
 
 * --pasky */
 

	
 
static void HandleStationPlacement(TileIndex start, TileIndex end)
 
{
 
	TileArea ta(start, end);
src/road_gui.cpp
Show inline comments
 
@@ -657,12 +657,39 @@ struct BuildRoadToolbarWindow : Window {
 
		return ES_NOT_HANDLED;
 
	}
 

	
 
	static HotkeyList hotkeys;
 
};
 

	
 
/**
 
 * Handler for global hotkeys of the BuildRoadToolbarWindow.
 
 * @param hotkey Hotkey
 
 * @return ES_HANDLED if hotkey was accepted.
 
 */
 
static EventState RoadToolbarGlobalHotkeys(int hotkey)
 
{
 
	Window *w = NULL;
 
	switch (_game_mode) {
 
		case GM_NORMAL: {
 
			extern RoadType _last_built_roadtype;
 
			w = ShowBuildRoadToolbar(_last_built_roadtype);
 
			break;
 
		}
 

	
 
		case GM_EDITOR:
 
			w = ShowBuildRoadScenToolbar();
 
			break;
 

	
 
		default:
 
			break;
 
	}
 

	
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	return w->OnHotkey(hotkey);
 
}
 

	
 
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),
 
	Hotkey('4', "demolish", WID_ROT_DEMOLISH),
 
	Hotkey('5', "depot", WID_ROT_DEPOT),
 
@@ -671,13 +698,13 @@ static Hotkey roadtoolbar_hotkeys[] = {
 
	Hotkey('8', "oneway", WID_ROT_ONE_WAY),
 
	Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
 
	Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
 
	Hotkey('R', "remove", WID_ROT_REMOVE),
 
	HOTKEY_LIST_END
 
};
 
HotkeyList BuildRoadToolbarWindow::hotkeys("roadtoolbar", roadtoolbar_hotkeys);
 
HotkeyList BuildRoadToolbarWindow::hotkeys("roadtoolbar", roadtoolbar_hotkeys, RoadToolbarGlobalHotkeys);
 

	
 

	
 
static const NWidgetPart _nested_build_road_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
 
		NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_ROAD_TOOLBAR_ROAD_CONSTRUCTION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
@@ -771,22 +798,12 @@ Window *ShowBuildRoadToolbar(RoadType ro
 
	_cur_roadtype = roadtype;
 

	
 
	DeleteWindowByClass(WC_BUILD_TOOLBAR);
 
	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 = 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;
 
	return w->OnHotkey(num);
 
}
 

	
 
static const NWidgetPart _nested_build_road_scen_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
 
		NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_ROAD_TOOLBAR_ROAD_CONSTRUCTION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
 
	EndContainer(),
 
@@ -826,21 +843,12 @@ static WindowDesc _build_road_scen_desc(
 
Window *ShowBuildRoadScenToolbar()
 
{
 
	_cur_roadtype = ROADTYPE_ROAD;
 
	return AllocateWindowDescFront<BuildRoadToolbarWindow>(&_build_road_scen_desc, TRANSPORT_ROAD);
 
}
 

	
 
EventState RoadToolbarEditorGlobalHotkeys(uint16 key, uint16 keycode)
 
{
 
	int num = BuildRoadToolbarWindow::hotkeys.CheckMatch(keycode, true);
 
	if (num == -1) return ES_NOT_HANDLED;
 
	Window *w = ShowBuildRoadScenToolbar();
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	return w->OnHotkey(num);
 
}
 

	
 
struct BuildRoadDepotWindow : public PickerWindowBase {
 
	BuildRoadDepotWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
 
	{
 
		this->CreateNestedTree();
 

	
 
		this->LowerWidget(_road_depot_orientation + WID_BROD_DEPOT_NE);
src/signs_gui.cpp
Show inline comments
 
@@ -335,17 +335,30 @@ struct SignListWindow : Window, SignList
 
		}
 
	}
 

	
 
	static HotkeyList hotkeys;
 
};
 

	
 
/**
 
 * Handler for global hotkeys of the SignListWindow.
 
 * @param hotkey Hotkey
 
 * @return ES_HANDLED if hotkey was accepted.
 
 */
 
static EventState SignListGlobalHotkeys(int hotkey)
 
{
 
	if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
 
	Window *w = ShowSignList();
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	return w->OnHotkey(hotkey);
 
}
 

	
 
static Hotkey signlist_hotkeys[] = {
 
	Hotkey('F', "focus_filter_box", SLHK_FOCUS_FILTER_BOX),
 
	HOTKEY_LIST_END
 
};
 
HotkeyList SignListWindow::hotkeys("signlist", signlist_hotkeys);
 
HotkeyList SignListWindow::hotkeys("signlist", signlist_hotkeys, SignListGlobalHotkeys);
 

	
 
static const NWidgetPart _nested_sign_list_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY, WID_SIL_CAPTION), SetDataTip(STR_SIGN_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
@@ -388,21 +401,12 @@ static WindowDesc _sign_list_desc(
 
 */
 
Window *ShowSignList()
 
{
 
	return AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
 
}
 

	
 
EventState SignListGlobalHotkeys(uint16 key, uint16 keycode)
 
{
 
	int num = SignListWindow::hotkeys.CheckMatch(keycode, true);
 
	if (num == -1) return ES_NOT_HANDLED;
 
	Window *w = ShowSignList();
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	return w->OnHotkey(num);
 
}
 

	
 
/**
 
 * Actually rename the sign.
 
 * @param index the sign to rename.
 
 * @param text  the new name.
 
 * @return true if the window will already be removed after returning.
 
 */
src/terraform_gui.cpp
Show inline comments
 
@@ -287,24 +287,37 @@ struct TerraformToolbarWindow : Window {
 
		this->RaiseButtons();
 
	}
 

	
 
	static HotkeyList hotkeys;
 
};
 

	
 
/**
 
 * Handler for global hotkeys of the TerraformToolbarWindow.
 
 * @param hotkey Hotkey
 
 * @return ES_HANDLED if hotkey was accepted.
 
 */
 
static EventState TerraformToolbarGlobalHotkeys(int hotkey)
 
{
 
	if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
 
	Window *w = ShowTerraformToolbar(NULL);
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	return w->OnHotkey(hotkey);
 
}
 

	
 
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),
 
	Hotkey('D' | WKC_GLOBAL_HOTKEY, "dynamite", WID_TT_DEMOLISH),
 
	Hotkey('U', "buyland", WID_TT_BUY_LAND),
 
	Hotkey('I', "trees", WID_TT_PLANT_TREES),
 
	Hotkey('O', "placesign", WID_TT_PLACE_SIGN),
 
	Hotkey('P', "placeobject", WID_TT_PLACE_OBJECT),
 
	HOTKEY_LIST_END
 
};
 
HotkeyList TerraformToolbarWindow::hotkeys("terraform", terraform_hotkeys);
 
HotkeyList TerraformToolbarWindow::hotkeys("terraform", terraform_hotkeys, TerraformToolbarGlobalHotkeys);
 

	
 
static const NWidgetPart _nested_terraform_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
 
		NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_LANDSCAPING_TOOLBAR, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
 
@@ -368,21 +381,12 @@ Window *ShowTerraformToolbar(Window *lin
 
	link->top  = w->top;
 
	link->SetDirty();
 

	
 
	return w;
 
}
 

	
 
EventState TerraformToolbarGlobalHotkeys(uint16 key, uint16 keycode)
 
{
 
	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;
 
	return w->OnHotkey(num);
 
}
 

	
 
static byte _terraform_size = 1;
 

	
 
/**
 
 * Raise/Lower a bigger chunk of land at the same time in the editor. When
 
 * raising get the lowest point, when lowering the highest point, and set all
 
 * tiles in the selection to that height.
 
@@ -709,24 +713,37 @@ struct ScenarioEditorLandscapeGeneration
 
		DeleteWindowById(WC_BUILD_OBJECT, 0);
 
	}
 

	
 
	static HotkeyList hotkeys;
 
};
 

	
 
/**
 
 * Handler for global hotkeys of the ScenarioEditorLandscapeGenerationWindow.
 
 * @param hotkey Hotkey
 
 * @return ES_HANDLED if hotkey was accepted.
 
 */
 
static EventState TerraformToolbarEditorGlobalHotkeys(int hotkey)
 
{
 
	if (_game_mode != GM_EDITOR) return ES_NOT_HANDLED;
 
	Window *w = ShowEditorTerraformToolbar();
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	return w->OnHotkey(hotkey);
 
}
 

	
 
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),
 
	Hotkey('E' | WKC_GLOBAL_HOTKEY, "level", WID_ETT_LEVEL_LAND),
 
	Hotkey('R', "rocky", WID_ETT_PLACE_ROCKS),
 
	Hotkey('T', "desert", WID_ETT_PLACE_DESERT),
 
	Hotkey('O', "object", WID_ETT_PLACE_OBJECT),
 
	HOTKEY_LIST_END
 
};
 

	
 
HotkeyList ScenarioEditorLandscapeGenerationWindow::hotkeys("terraform_editor", terraform_editor_hotkeys);
 
HotkeyList ScenarioEditorLandscapeGenerationWindow::hotkeys("terraform_editor", terraform_editor_hotkeys, TerraformToolbarEditorGlobalHotkeys);
 

	
 
static WindowDesc _scen_edit_land_gen_desc(
 
	WDP_AUTO, "toolbar_landscape_scen", 0, 0,
 
	WC_SCEN_LAND_GEN, WC_NONE,
 
	WDF_CONSTRUCTION,
 
	_nested_scen_edit_land_gen_widgets, lengthof(_nested_scen_edit_land_gen_widgets),
 
@@ -738,15 +755,6 @@ static WindowDesc _scen_edit_land_gen_de
 
 * @return The allocated toolbar.
 
 */
 
Window *ShowEditorTerraformToolbar()
 
{
 
	return AllocateWindowDescFront<ScenarioEditorLandscapeGenerationWindow>(&_scen_edit_land_gen_desc, 0);
 
}
 

	
 
EventState TerraformToolbarEditorGlobalHotkeys(uint16 key, uint16 keycode)
 
{
 
	int num = ScenarioEditorLandscapeGenerationWindow::hotkeys.CheckMatch(keycode, true);
 
	if (num == -1) return ES_NOT_HANDLED;
 
	Window *w = ShowEditorTerraformToolbar();
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	return w->OnHotkey(num);
 
}
src/window_gui.h
Show inline comments
 
@@ -17,18 +17,12 @@
 
#include "company_type.h"
 
#include "tile_type.h"
 
#include "widget_type.h"
 
#include "core/smallvec_type.hpp"
 
#include "core/smallmap_type.hpp"
 

	
 
/** State of handling an event. */
 
enum EventState {
 
	ES_HANDLED,     ///< The passed event is handled.
 
	ES_NOT_HANDLED, ///< The passed event is not handled.
 
};
 

	
 
/**
 
 * Flags to describe the look of the frame
 
 */
 
enum FrameFlags {
 
	FR_NONE         =  0,
 
	FR_TRANSPARENT  =  1 << 0,  ///< Makes the background transparent if set
src/window_type.h
Show inline comments
 
@@ -688,7 +688,13 @@ enum GameOptionsInvalidationData {
 

	
 
struct Window;
 

	
 
/** Number to differentiate different windows of the same class */
 
typedef int32 WindowNumber;
 

	
 
/** State of handling an event. */
 
enum EventState {
 
	ES_HANDLED,     ///< The passed event is handled.
 
	ES_NOT_HANDLED, ///< The passed event is not handled.
 
};
 

	
 
#endif /* WINDOW_TYPE_H */
0 comments (0 inline, 0 general)