Changeset - r15406:54ee8730c306
[Not reviewed]
master
0 3 0
yexo - 14 years ago 2010-07-03 13:42:27
yexo@openttd.org
(svn r20059) -Feature: customizable hotkeys for the main window (the global hotkeys)
3 files changed with 117 insertions and 45 deletions:
0 comments (0 inline, 0 general)
src/hotkeys.cpp
Show inline comments
 
@@ -224,12 +224,13 @@ void SaveLoadHotkeyGroup(IniGroup *group
 
		SaveHotkeyGroup(group, hotkey_list);
 
	} else {
 
		LoadHotkeyGroup(group, hotkey_list);
 
	}
 
}
 

	
 
struct MainWindow;
 
struct TerraformToolbarWindow;
 
struct ScenarioEditorLandscapeGenerationWindow;
 
struct OrdersWindow;
 

	
 
static void SaveLoadHotkeys(bool save)
 
{
 
@@ -240,12 +241,13 @@ static void SaveLoadHotkeys(bool save)
 

	
 
#define SL_HOTKEYS(name, window_name) \
 
	extern Hotkey<window_name> *_##name##_hotkeys;\
 
	group = ini->GetGroup(#name);\
 
	SaveLoadHotkeyGroup(group, _##name##_hotkeys, save);
 

	
 
	SL_HOTKEYS(global, MainWindow);
 
	SL_HOTKEYS(terraform, TerraformToolbarWindow);
 
	SL_HOTKEYS(terraform_editor, ScenarioEditorLandscapeGenerationWindow);
 
	SL_HOTKEYS(order, OrdersWindow);
 

	
 

	
 
#undef SL_HOTKEYS
src/hotkeys.h
Show inline comments
 
@@ -71,13 +71,13 @@ struct Hotkey {
 
		} else {
 
			this->callback = new CallbackWrapper(callback);
 
		}
 

	
 
		const uint16 *keycode = default_keycodes;
 
		while (*keycode != 0) {
 
			this->keycodes.Include(keycode);
 
			this->keycodes.Include(*keycode);
 
			keycode++;
 
		}
 
	}
 

	
 
	~Hotkey()
 
	{
src/main_gui.cpp
Show inline comments
 
@@ -27,12 +27,13 @@
 
#include "zoom_func.h"
 
#include "company_base.h"
 
#include "company_func.h"
 
#include "toolbar_gui.h"
 
#include "statusbar_gui.h"
 
#include "tilehighlight_func.h"
 
#include "hotkeys.h"
 

	
 
#include "network/network.h"
 
#include "network/network_func.h"
 
#include "network/network_gui.h"
 
#include "network/network_base.h"
 

	
 
@@ -204,12 +205,34 @@ static const WindowDesc _main_window_des
 
	WDP_MANUAL, 0, 0,
 
	WC_MAIN_WINDOW, WC_NONE,
 
	0,
 
	_nested_main_window_widgets, lengthof(_nested_main_window_widgets)
 
);
 

	
 
enum {
 
	GHK_QUIT,
 
	GHK_CONSOLE,
 
	GHK_BOUNDING_BOXES,
 
	GHK_CENTER,
 
	GHK_CENTER_ZOOM,
 
	GHK_RESET_OBJECT_TO_PLACE,
 
	GHK_DELETE_WINDOWS,
 
	GHK_DELETE_NONVITAL_WINDOWS,
 
	GHK_REFRESH_SCREEN,
 
	GHK_CRASH,
 
	GHK_MONEY,
 
	GHK_UPDATE_COORDS,
 
	GHK_TOGGLE_TRANSPARENCY,
 
	GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
 
	GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
 
	GHK_TRANSPARANCY,
 
	GHK_CHAT,
 
	GHK_CHAT_ALL,
 
	GHK_CHAT_COMPANY,
 
};
 

	
 
struct MainWindow : Window
 
{
 
	MainWindow() : Window()
 
	{
 
		this->InitNested(&_main_window_desc, 0);
 
		ResizeWindow(this, _screen.width, _screen.height);
 
@@ -234,123 +257,120 @@ struct MainWindow : Window
 
			DrawSprite(SPR_OTTD_D, PAL_NONE, off_x +  96, 50);
 
		}
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		switch (keycode) {
 
			case 'Q' | WKC_CTRL:
 
			case 'Q' | WKC_META:
 
				HandleExitGameRequest();
 
				return ES_HANDLED;
 
		int num = CheckHotkeyMatch(global_hotkeys, keycode, this);
 
		if (num == GHK_QUIT) {
 
			HandleExitGameRequest();
 
			return ES_HANDLED;
 
		}
 

	
 
		/* Disable all key shortcuts, except quit shortcuts when
 
		 * generating the world, otherwise they create threading
 
		 * problem during the generating, resulting in random
 
		 * assertions that are hard to trigger and debug */
 
		if (IsGeneratingWorld()) return ES_NOT_HANDLED;
 

	
 
		if (keycode == WKC_BACKQUOTE) {
 
		if (num == GHK_CONSOLE) {
 
			IConsoleSwitch();
 
			return ES_HANDLED;
 
		}
 

	
 
		if (keycode == ('B' | WKC_CTRL)) {
 
		if (num == GHK_BOUNDING_BOXES) {
 
			extern bool _draw_bounding_boxes;
 
			_draw_bounding_boxes = !_draw_bounding_boxes;
 
			MarkWholeScreenDirty();
 
			return ES_HANDLED;
 
		}
 

	
 
		if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
 

	
 
		switch (keycode) {
 
			case 'C':
 
			case 'Z': {
 
		switch (num) {
 
			case GHK_CENTER:
 
			case GHK_CENTER_ZOOM: {
 
				Point pt = GetTileBelowCursor();
 
				if (pt.x != -1) {
 
					if (keycode == 'Z') MaxZoomInOut(ZOOM_IN, this);
 
					if (num == GHK_CENTER_ZOOM) MaxZoomInOut(ZOOM_IN, this);
 
					ScrollMainWindowTo(pt.x, pt.y);
 
				}
 
				break;
 
			}
 

	
 
			case WKC_ESC: ResetObjectToPlace(); break;
 
			case WKC_DELETE: DeleteNonVitalWindows(); break;
 
			case WKC_DELETE | WKC_SHIFT: DeleteAllNonVitalWindows(); break;
 
			case 'R' | WKC_CTRL: MarkWholeScreenDirty(); break;
 
			case GHK_RESET_OBJECT_TO_PLACE: ResetObjectToPlace(); break;
 
			case GHK_DELETE_WINDOWS: DeleteNonVitalWindows(); break;
 
			case GHK_DELETE_NONVITAL_WINDOWS: DeleteAllNonVitalWindows(); break;
 
			case GHK_REFRESH_SCREEN: MarkWholeScreenDirty(); break;
 

	
 
#if defined(_DEBUG)
 
			case '0' | WKC_ALT: // Crash the game
 
			case GHK_CRASH: // Crash the game
 
				*(byte*)0 = 0;
 
				break;
 

	
 
			case '1' | WKC_ALT: // Gimme money
 
			case GHK_MONEY: // Gimme money
 
				/* Server can not cheat in advertise mode either! */
 
#ifdef ENABLE_NETWORK
 
				if (!_networking || !_network_server || !_settings_client.network.server_advertise)
 
#endif /* ENABLE_NETWORK */
 
					DoCommandP(0, 10000000, 0, CMD_MONEY_CHEAT);
 
				break;
 

	
 
			case '2' | WKC_ALT: // Update the coordinates of all station signs
 
			case GHK_UPDATE_COORDS: // Update the coordinates of all station signs
 
				UpdateAllVirtCoords();
 
				break;
 
#endif
 

	
 
			case '1' | WKC_CTRL:
 
			case '2' | WKC_CTRL:
 
			case '3' | WKC_CTRL:
 
			case '4' | WKC_CTRL:
 
			case '5' | WKC_CTRL:
 
			case '6' | WKC_CTRL:
 
			case '7' | WKC_CTRL:
 
			case '8' | WKC_CTRL:
 
			case '9' | WKC_CTRL:
 
			case GHK_TOGGLE_TRANSPARENCY:
 
			case GHK_TOGGLE_TRANSPARENCY + 1:
 
			case GHK_TOGGLE_TRANSPARENCY + 2:
 
			case GHK_TOGGLE_TRANSPARENCY + 3:
 
			case GHK_TOGGLE_TRANSPARENCY + 4:
 
			case GHK_TOGGLE_TRANSPARENCY + 5:
 
			case GHK_TOGGLE_TRANSPARENCY + 6:
 
			case GHK_TOGGLE_TRANSPARENCY + 7:
 
			case GHK_TOGGLE_TRANSPARENCY + 8:
 
				/* Transparency toggle hot keys */
 
				ToggleTransparency((TransparencyOption)(keycode - ('1' | WKC_CTRL)));
 
				ToggleTransparency((TransparencyOption)(num - GHK_TOGGLE_TRANSPARENCY));
 
				MarkWholeScreenDirty();
 
				break;
 

	
 
			case '1' | WKC_CTRL | WKC_SHIFT:
 
			case '2' | WKC_CTRL | WKC_SHIFT:
 
			case '3' | WKC_CTRL | WKC_SHIFT:
 
			case '4' | WKC_CTRL | WKC_SHIFT:
 
			case '5' | WKC_CTRL | WKC_SHIFT:
 
			case '6' | WKC_CTRL | WKC_SHIFT:
 
			case '7' | WKC_CTRL | WKC_SHIFT:
 
			case '8' | WKC_CTRL | WKC_SHIFT:
 
			case GHK_TOGGLE_INVISIBILITY:
 
			case GHK_TOGGLE_INVISIBILITY + 1:
 
			case GHK_TOGGLE_INVISIBILITY + 2:
 
			case GHK_TOGGLE_INVISIBILITY + 3:
 
			case GHK_TOGGLE_INVISIBILITY + 4:
 
			case GHK_TOGGLE_INVISIBILITY + 5:
 
			case GHK_TOGGLE_INVISIBILITY + 6:
 
			case GHK_TOGGLE_INVISIBILITY + 7:
 
				/* Invisibility toggle hot keys */
 
				ToggleInvisibilityWithTransparency((TransparencyOption)(keycode - ('1' | WKC_CTRL | WKC_SHIFT)));
 
				ToggleInvisibilityWithTransparency((TransparencyOption)(num - GHK_TOGGLE_INVISIBILITY));
 
				MarkWholeScreenDirty();
 
				break;
 

	
 
			case 'X' | WKC_CTRL:
 
			case GHK_TRANSPARENCY_TOOLBAR:
 
				ShowTransparencyToolbar();
 
				break;
 

	
 
			case 'X':
 
			case GHK_TRANSPARANCY:
 
				ResetRestoreAllTransparency();
 
				break;
 

	
 
#ifdef ENABLE_NETWORK
 
			case WKC_RETURN: case 'T': // smart chat; send to team if any, otherwise to all
 
			case GHK_CHAT: // smart chat; send to team if any, otherwise to all
 
				if (_networking) {
 
					const NetworkClientInfo *cio = NetworkFindClientInfoFromClientID(_network_own_client_id);
 
					if (cio == NULL) break;
 

	
 
					ShowNetworkChatQueryWindow(NetworkClientPreferTeamChat(cio) ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas);
 
				}
 
				break;
 

	
 
			case WKC_SHIFT | WKC_RETURN: case WKC_SHIFT | 'T': // send text message to all clients
 
			case GHK_CHAT_ALL: // send text message to all clients
 
				if (_networking) ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0);
 
				break;
 

	
 
			case WKC_CTRL | WKC_RETURN: case WKC_CTRL | 'T': // send text to all team mates
 
			case GHK_CHAT_COMPANY: // send text to all team mates
 
				if (_networking) {
 
					const NetworkClientInfo *cio = NetworkFindClientInfoFromClientID(_network_own_client_id);
 
					if (cio == NULL) break;
 

	
 
					ShowNetworkChatQueryWindow(DESTTYPE_TEAM, cio->client_playas);
 
				}
 
@@ -392,14 +412,64 @@ struct MainWindow : Window
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		/* Forward the message to the appropiate toolbar (ingame or scenario editor) */
 
		InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data);
 
	}
 

	
 
	static Hotkey<MainWindow> global_hotkeys[];
 
};
 

	
 
const uint16 _ghk_quit_keys[] = {'Q' | WKC_CTRL, 'Q' | WKC_META, 0};
 
const uint16 _ghk_chat_keys[] = {WKC_RETURN, 'T', 0};
 
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};
 

	
 
Hotkey<MainWindow> MainWindow::global_hotkeys[] = {
 
	Hotkey<MainWindow>(_ghk_quit_keys, "quit", GHK_QUIT),
 
	Hotkey<MainWindow>(WKC_BACKQUOTE, "console", GHK_CONSOLE),
 
	Hotkey<MainWindow>('B' | WKC_CTRL, "bounding_boxes", GHK_BOUNDING_BOXES),
 
	Hotkey<MainWindow>('C', "center", GHK_CENTER),
 
	Hotkey<MainWindow>('Z', "center_zoom", GHK_CENTER_ZOOM),
 
	Hotkey<MainWindow>(WKC_ESC, "reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
 
	Hotkey<MainWindow>(WKC_DELETE, "delete_windows", GHK_DELETE_WINDOWS),
 
	Hotkey<MainWindow>(WKC_DELETE | WKC_SHIFT, "delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
 
	Hotkey<MainWindow>('R' | WKC_CTRL, "refresh_screen", GHK_REFRESH_SCREEN),
 
#if defined(_DEBUG)
 
	Hotkey<MainWindow>('0' | WKC_ALT, "crash_game", GHK_CRASH),
 
	Hotkey<MainWindow>('1' | WKC_ALT, "money", GHK_MONEY),
 
	Hotkey<MainWindow>('2' | WKC_ALT, "update_coordinates", GHK_UPDATE_COORDS),
 
#endif
 
	Hotkey<MainWindow>('1' | WKC_CTRL, "transparency_signs", GHK_TOGGLE_TRANSPARENCY),
 
	Hotkey<MainWindow>('2' | WKC_CTRL, "transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
 
	Hotkey<MainWindow>('3' | WKC_CTRL, "transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
 
	Hotkey<MainWindow>('4' | WKC_CTRL, "transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
 
	Hotkey<MainWindow>('5' | WKC_CTRL, "transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
 
	Hotkey<MainWindow>('6' | WKC_CTRL, "transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
 
	Hotkey<MainWindow>('7' | WKC_CTRL, "transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
 
	Hotkey<MainWindow>('8' | WKC_CTRL, "transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
 
	Hotkey<MainWindow>('9' | WKC_CTRL, "transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
 
	Hotkey<MainWindow>('1' | WKC_CTRL | WKC_SHIFT, "invisibility_signs", GHK_TOGGLE_INVISIBILITY),
 
	Hotkey<MainWindow>('2' | WKC_CTRL | WKC_SHIFT, "invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
 
	Hotkey<MainWindow>('3' | WKC_CTRL | WKC_SHIFT, "invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
 
	Hotkey<MainWindow>('4' | WKC_CTRL | WKC_SHIFT, "invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
 
	Hotkey<MainWindow>('5' | WKC_CTRL | WKC_SHIFT, "invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
 
	Hotkey<MainWindow>('6' | WKC_CTRL | WKC_SHIFT, "invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
 
	Hotkey<MainWindow>('7' | WKC_CTRL | WKC_SHIFT, "invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
 
	Hotkey<MainWindow>('8' | WKC_CTRL | WKC_SHIFT, "invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
 
	Hotkey<MainWindow>('X' | WKC_CTRL, "transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
 
	Hotkey<MainWindow>('X', "toggle_transparency", GHK_TRANSPARANCY),
 
#ifdef ENABLE_NETWORK
 
	Hotkey<MainWindow>(_ghk_chat_keys, "chat", GHK_CHAT),
 
	Hotkey<MainWindow>(_ghk_chat_all_keys, "chat_all", GHK_CHAT_ALL),
 
	Hotkey<MainWindow>(_ghk_chat_company_keys, "chat_company", GHK_CHAT_COMPANY),
 
#endif
 
	HOTKEY_LIST_END(MainWindow)
 
};
 
Hotkey<MainWindow> *_global_hotkeys = MainWindow::global_hotkeys;
 

	
 

	
 
void ShowSelectGameWindow();
 

	
 
void SetupColoursAndInitialWindow()
 
{
 
	for (uint i = 0; i != 16; i++) {
0 comments (0 inline, 0 general)