/** Close the in-game console. */ void IConsoleClose() { if (_iconsole_mode == ICONSOLE_OPENED) IConsoleSwitch(); }
virtual EventState OnHotkey(int hotkey) { if (hotkey == 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 (HasModalProgress()) return ES_NOT_HANDLED; switch (hotkey) { case GHK_ABANDON: /* No point returning from the main menu to itself */ if (_game_mode == GM_MENU) return ES_HANDLED; if (_settings_client.gui.autosave_on_exit) { DoExitSave(); _switch_mode = SM_MENU; } else { AskExitToGameMenu(); } return ES_HANDLED; case GHK_CONSOLE: IConsoleSwitch(); return ES_HANDLED; case GHK_BOUNDING_BOXES: ToggleBoundingBoxes(); return ES_HANDLED; case GHK_DIRTY_BLOCKS: ToggleDirtyBlocks(); return ES_HANDLED; } if (_game_mode == GM_MENU) return ES_NOT_HANDLED; switch (hotkey) { case GHK_CENTER: case GHK_CENTER_ZOOM: { Point pt = GetTileBelowCursor(); if (pt.x != -1) { bool instant = (hotkey == GHK_CENTER_ZOOM && this->viewport->zoom != _settings_client.gui.zoom_min); if (hotkey == GHK_CENTER_ZOOM) MaxZoomInOut(ZOOM_IN, this); ScrollMainWindowTo(pt.x, pt.y, -1, instant); } break; } case GHK_RESET_OBJECT_TO_PLACE: ResetObjectToPlace(); ToolbarSelectLastTool(); break; case GHK_DELETE_WINDOWS: DeleteNonVitalWindows(); break; case GHK_DELETE_NONVITAL_WINDOWS: DeleteAllNonVitalWindows(); break; case GHK_REFRESH_SCREEN: MarkWholeScreenDirty(); break; case GHK_CRASH: // Crash the game *(volatile byte *)0 = 0; break; case GHK_MONEY: // Gimme money /* You can only cheat for money in single player. */ if (!_networking) DoCommandP(0, 10000000, 0, CMD_MONEY_CHEAT); break; case GHK_UPDATE_COORDS: // Update the coordinates of all station signs UpdateAllVirtCoords(); break; 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)(hotkey - GHK_TOGGLE_TRANSPARENCY)); MarkWholeScreenDirty(); break; 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)(hotkey - GHK_TOGGLE_INVISIBILITY)); MarkWholeScreenDirty(); break; case GHK_TRANSPARENCY_TOOLBAR: ShowTransparencyToolbar(); break; case GHK_TRANSPARANCY: ResetRestoreAllTransparency(); break; #ifdef ENABLE_NETWORK case GHK_CHAT: // smart chat; send to team if any, otherwise to all if (_networking) { const NetworkClientInfo *cio = NetworkClientInfo::GetByClientID(_network_own_client_id); if (cio == NULL) break; ShowNetworkChatQueryWindow(NetworkClientPreferTeamChat(cio) ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas); } break; case GHK_CHAT_ALL: // send text message to all clients if (_networking) ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0); break; case GHK_CHAT_COMPANY: // send text to all team mates if (_networking) { const NetworkClientInfo *cio = NetworkClientInfo::GetByClientID(_network_own_client_id); if (cio == NULL) break; ShowNetworkChatQueryWindow(DESTTYPE_TEAM, cio->client_playas); } break; case GHK_CHAT_SERVER: // send text to the server if (_networking && !_network_server) { ShowNetworkChatQueryWindow(DESTTYPE_CLIENT, CLIENT_ID_SERVER); } break; #endif default: return ES_NOT_HANDLED; } return ES_HANDLED; }
virtual EventState OnKeyPress(uint16 key, uint16 keycode) { if (_focused_window != this) return ES_NOT_HANDLED; const int scroll_height = (this->height / this->line_height) - 1; switch (keycode) { case WKC_UP: IConsoleHistoryNavigate(1); this->SetDirty(); break; case WKC_DOWN: IConsoleHistoryNavigate(-1); this->SetDirty(); break; case WKC_SHIFT | WKC_PAGEDOWN: this->Scroll(-scroll_height); break; case WKC_SHIFT | WKC_PAGEUP: this->Scroll(scroll_height); break; case WKC_SHIFT | WKC_DOWN: this->Scroll(-1); break; case WKC_SHIFT | WKC_UP: this->Scroll(1); break; case WKC_BACKQUOTE: IConsoleSwitch(); break; case WKC_RETURN: case WKC_NUM_ENTER: { /* We always want the ] at the left side; we always force these strings to be left * aligned anyway. So enforce this in all cases by addding a left-to-right marker, * otherwise it will be drawn at the wrong side with right-to-left texts. */ IConsolePrintF(CC_COMMAND, LRM "] %s", _iconsole_cmdline.buf); const char *cmd = IConsoleHistoryAdd(_iconsole_cmdline.buf); IConsoleClearCommand(); if (cmd != NULL) IConsoleCmdExec(cmd); break; } case WKC_CTRL | WKC_RETURN: _iconsole_mode = (_iconsole_mode == ICONSOLE_FULL) ? ICONSOLE_OPENED : ICONSOLE_FULL; IConsoleResize(this); MarkWholeScreenDirty(); break; #ifdef WITH_COCOA case (WKC_META | 'V'): #endif case (WKC_CTRL | 'V'): if (InsertTextBufferClipboard(&_iconsole_cmdline)) { IConsoleResetHistoryPos(); this->SetDirty(); } break; case (WKC_CTRL | 'L'): IConsoleCmdExec("clear"); break; #ifdef WITH_COCOA case (WKC_META | 'U'): #endif case (WKC_CTRL | 'U'): DeleteTextBufferAll(&_iconsole_cmdline); this->SetDirty(); break; case WKC_BACKSPACE: case WKC_DELETE: if (DeleteTextBufferChar(&_iconsole_cmdline, keycode)) { IConsoleResetHistoryPos(); this->SetDirty(); } break; case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME: if (MoveTextBufferPos(&_iconsole_cmdline, keycode)) { IConsoleResetHistoryPos(); this->SetDirty(); } break; default: if (IsValidChar(key, CS_ALPHANUMERAL)) { IConsoleWindow::scroll = 0; InsertTextBufferChar(&_iconsole_cmdline, key); IConsoleResetHistoryPos(); this->SetDirty(); } else { return ES_NOT_HANDLED; } break; } return ES_HANDLED; }
virtual EventState OnKeyPress(WChar key, uint16 keycode) { if (_focused_window != this) return ES_NOT_HANDLED; const int scroll_height = (this->height / this->line_height) - 1; switch (keycode) { case WKC_UP: IConsoleHistoryNavigate(1); this->SetDirty(); break; case WKC_DOWN: IConsoleHistoryNavigate(-1); this->SetDirty(); break; case WKC_SHIFT | WKC_PAGEDOWN: this->Scroll(-scroll_height); break; case WKC_SHIFT | WKC_PAGEUP: this->Scroll(scroll_height); break; case WKC_SHIFT | WKC_DOWN: this->Scroll(-1); break; case WKC_SHIFT | WKC_UP: this->Scroll(1); break; case WKC_BACKQUOTE: IConsoleSwitch(); break; case WKC_RETURN: case WKC_NUM_ENTER: { /* We always want the ] at the left side; we always force these strings to be left * aligned anyway. So enforce this in all cases by addding a left-to-right marker, * otherwise it will be drawn at the wrong side with right-to-left texts. */ IConsolePrintF(CC_COMMAND, LRM "] %s", _iconsole_cmdline.buf); const char *cmd = IConsoleHistoryAdd(_iconsole_cmdline.buf); IConsoleClearCommand(); if (cmd != NULL) IConsoleCmdExec(cmd); break; } case WKC_CTRL | WKC_RETURN: _iconsole_mode = (_iconsole_mode == ICONSOLE_FULL) ? ICONSOLE_OPENED : ICONSOLE_FULL; IConsoleResize(this); MarkWholeScreenDirty(); break; case (WKC_CTRL | 'L'): IConsoleCmdExec("clear"); break; default: if (_iconsole_cmdline.HandleKeyPress(key, keycode) != HKPR_NOT_HANDLED) { IConsoleWindow::scroll = 0; IConsoleResetHistoryPos(); this->SetDirty(); } else { return ES_NOT_HANDLED; } break; } return ES_HANDLED; }