virtual void OnClick(Point pt, int widget, int click_count) { if (widget >= WID_TT_BEGIN && widget < WID_TT_END) { if (_ctrl_pressed) { /* toggle the bit of the transparencies lock variable */ ToggleTransparencyLock((TransparencyOption)(widget - WID_TT_BEGIN)); this->SetDirty(); } else { /* toggle the bit of the transparencies variable and play a sound */ ToggleTransparency((TransparencyOption)(widget - WID_TT_BEGIN)); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); MarkWholeScreenDirty(); } } else if (widget == WID_TT_BUTTONS) { uint i; for (i = WID_TT_BEGIN; i < WID_TT_END; i++) { const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(i); if (IsInsideBS(pt.x, nwid->pos_x, nwid->current_x)) { break; } } if (i == WID_TT_LOADING || i == WID_TT_END) return; ToggleInvisibility((TransparencyOption)(i - WID_TT_BEGIN)); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); /* Redraw whole screen only if transparency is set */ if (IsTransparencySet((TransparencyOption)(i - WID_TT_BEGIN))) { MarkWholeScreenDirty(); } else { this->SetWidgetDirty(WID_TT_BUTTONS); } } }
/** * Change the name of the president. * @param tile unused * @param flags operation to perform * @param p1 unused * @param p2 unused * @param text the new name or an empty string when resetting to the default * @return the cost of this operation or an error */ CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { bool reset = StrEmpty(text); if (!reset) { if (Utf8StringLength(text) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) return CMD_ERROR; if (!IsUniquePresidentName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); } if (flags & DC_EXEC) { Company *c = Company::Get(_current_company); free(c->president_name); if (reset) { c->president_name = NULL; } else { c->president_name = strdup(text); if (c->name_1 == STR_SV_UNNAMED && c->name == NULL) { char buf[80]; snprintf(buf, lengthof(buf), "%s Transport", text); DoCommand(0, 0, 0, DC_EXEC, CMD_RENAME_COMPANY, buf); } } MarkWholeScreenDirty(); CompanyAdminUpdate(c); } return CommandCost(); }
virtual void OnClick(Point pt, int widget, int click_count) { switch (widget) { case WID_BT_TYPE_11: case WID_BT_TYPE_12: case WID_BT_TYPE_13: case WID_BT_TYPE_14: case WID_BT_TYPE_21: case WID_BT_TYPE_22: case WID_BT_TYPE_23: case WID_BT_TYPE_24: case WID_BT_TYPE_31: case WID_BT_TYPE_32: case WID_BT_TYPE_33: case WID_BT_TYPE_34: if (widget - WID_BT_TYPE_11 >= this->count) break; if (HandlePlacePushButton(this, widget, SPR_CURSOR_TREE, HT_RECT)) { this->tree_to_plant = (TreeType)(this->base + widget - WID_BT_TYPE_11); } break; case WID_BT_TYPE_RANDOM: // tree of random type. if (HandlePlacePushButton(this, WID_BT_TYPE_RANDOM, SPR_CURSOR_TREE, HT_RECT)) { this->tree_to_plant = TREE_INVALID; } break; case WID_BT_MANY_RANDOM: // place trees randomly over the landscape if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP); PlaceTreesRandomly(); MarkWholeScreenDirty(); break; } }
static void MakeNewGameDone() { SettingsDisableElrail(_settings_game.vehicle.disable_elrails); /* In a dedicated server, the server does not play */ if (_network_dedicated || BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 0) { SetLocalCompany(COMPANY_SPECTATOR); IConsoleCmdExec("exec scripts/game_start.scr 0"); return; } /* Create a single company */ DoStartupNewCompany(false); Company *c = Company::Get(COMPANY_FIRST); c->settings = _settings_client.company; IConsoleCmdExec("exec scripts/game_start.scr 0"); SetLocalCompany(COMPANY_FIRST); InitializeRailGUI(); #ifdef ENABLE_NETWORK /* We are the server, we start a new company (not dedicated), * so set the default password *if* needed. */ if (_network_server && !StrEmpty(_settings_client.network.default_company_pass)) { NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass); } #endif /* ENABLE_NETWORK */ if (_settings_client.gui.pause_on_newgame) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE); MarkWholeScreenDirty(); }
EndGameWindow(const WindowDesc *desc) : EndGameHighScoreBaseWindow(desc) { /* Pause in single-player to have a look at the highscore at your own leisure */ if (!_networking) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE); this->background_img = SPR_TYCOON_IMG1_BEGIN; if (_local_company != COMPANY_SPECTATOR) { const Company *c = Company::Get(_local_company); if (c->old_economy[0].performance_history == SCORE_MAX) { this->background_img = SPR_TYCOON_IMG2_BEGIN; } } /* In a network game show the endscores of the custom difficulty 'network' which is the last one * as well as generate a TOP5 of that game, and not an all-time top5. */ if (_networking) { this->window_number = lengthof(_highscore_table) - 1; this->rank = SaveHighScoreValueNetwork(); } else { /* in single player _local company is always valid */ const Company *c = Company::Get(_local_company); this->window_number = _settings_game.difficulty.diff_level; this->rank = SaveHighScoreValue(c); } MarkWholeScreenDirty(); }
const char *VideoDriver_Allegro::Start(const char * const *parm) { if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) { DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error); return "Failed to set up Allegro"; } _allegro_instance_count++; install_timer(); install_mouse(); install_keyboard(); #if defined _DEBUG /* Allegro replaces SEGV/ABRT signals meaning that the debugger will never * be triggered, so rereplace the signals and make the debugger useful. */ signal(SIGABRT, NULL); signal(SIGSEGV, NULL); #endif #if defined(DOS) /* Force DOS builds to ALWAYS use full screen as * it can't do windowed. */ _fullscreen = true; #endif GetVideoModes(); if (!CreateMainSurface(_cur_resolution.width, _cur_resolution.height)) { return "Failed to set up Allegro video"; } MarkWholeScreenDirty(); set_close_button_callback(HandleExitGameRequest); return NULL; }
/** * Size of the application screen changed. * Adapt the game screen-size, re-allocate the open windows, and repaint everything */ void GameSizeChanged() { _cur_resolution.width = _screen.width; _cur_resolution.height = _screen.height; ScreenSizeChanged(); RelocateAllWindows(_screen.width, _screen.height); MarkWholeScreenDirty(); }
/** * Change the company manager's face. * @param tile unused * @param flags operation to perform * @param p1 unused * @param p2 face bitmasked * @param text unused * @return the cost of this operation or an error */ CommandCost CmdSetCompanyManagerFace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { CompanyManagerFace cmf = (CompanyManagerFace)p2; if (!IsValidCompanyManagerFace(cmf)) return CMD_ERROR; if (flags & DC_EXEC) { Company::Get(_current_company)->face = cmf; MarkWholeScreenDirty(); } return CommandCost(); }
void FlatEmptyWorld(byte tile_height) { int edge_distance = _settings_game.construction.freeform_edges ? 0 : 2; for (uint row = edge_distance; row < MapSizeY() - edge_distance; row++) { for (uint col = edge_distance; col < MapSizeX() - edge_distance; col++) { SetTileHeight(TileXY(col, row), tile_height); } } FixSlopes(); MarkWholeScreenDirty(); }
/** * Really perform the scan for all NewGRFs. * @param callback The callback to call after the scanning is complete. */ void DoScanNewGRFFiles(void *callback) { _modal_progress_work_mutex->BeginCritical(); ClearGRFConfigList(&_all_grfs); TarScanner::DoScan(TarScanner::NEWGRF); DEBUG(grf, 1, "Scanning for NewGRFs"); uint num = GRFFileScanner::DoScan(); DEBUG(grf, 1, "Scan complete, found %d files", num); if (num != 0 && _all_grfs != NULL) { /* Sort the linked list using quicksort. * For that we first have to make an array, then sort and * then remake the linked list. */ GRFConfig **to_sort = MallocT<GRFConfig*>(num); uint i = 0; for (GRFConfig *p = _all_grfs; p != NULL; p = p->next, i++) { to_sort[i] = p; } /* Number of files is not necessarily right */ num = i; QSortT(to_sort, num, &GRFSorter); for (i = 1; i < num; i++) { to_sort[i - 1]->next = to_sort[i]; } to_sort[num - 1]->next = NULL; _all_grfs = to_sort[0]; free(to_sort); #ifdef ENABLE_NETWORK NetworkAfterNewGRFScan(); #endif } _modal_progress_work_mutex->EndCritical(); _modal_progress_paint_mutex->BeginCritical(); /* Yes... these are the NewGRF windows */ InvalidateWindowClassesData(WC_SAVELOAD, 0, true); InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE, GOID_NEWGRF_RESCANNED, true); if (callback != NULL) ((NewGRFScanCallback*)callback)->OnNewGRFsScanned(); DeleteWindowByClass(WC_MODAL_PROGRESS); SetModalProgress(false); MarkWholeScreenDirty(); _modal_progress_paint_mutex->EndCritical(); }
HighScoreWindow(const WindowDesc *desc, int difficulty, int8 ranking) : EndGameHighScoreBaseWindow(desc) { /* pause game to show the chart */ if (!_networking) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE); /* Close all always on-top windows to get a clean screen */ if (_game_mode != GM_MENU) HideVitalWindows(); MarkWholeScreenDirty(); this->window_number = difficulty; // show highscore chart for difficulty... this->background_img = SPR_HIGHSCORE_CHART_BEGIN; // which background to show this->rank = ranking; }
/** Toggle in-game console between opened and closed. */ void IConsoleSwitch() { switch (_iconsole_mode) { case ICONSOLE_CLOSED: new IConsoleWindow(); break; case ICONSOLE_OPENED: case ICONSOLE_FULL: DeleteWindowById(WC_CONSOLE, 0); break; } MarkWholeScreenDirty(); }
static void GenerateCompanyName(Company *c) { TileIndex tile; Town *t; StringID str; Company *cc; uint32 strp; /* Reserve space for extra unicode character. We need to do this to be able * to detect too long company name. */ char buffer[MAX_LENGTH_COMPANY_NAME_BYTES + MAX_CHAR_LENGTH]; if (c->name_1 != STR_SV_UNNAMED) return; tile = c->last_build_coordinate; if (tile == 0) return; t = ClosestTownFromTile(tile, UINT_MAX); if (t->name == NULL && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) { str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_PLAYERNAME_START; strp = t->townnameparts; verify_name:; /* No companies must have this name already */ FOR_ALL_COMPANIES(cc) { if (cc->name_1 == str && cc->name_2 == strp) goto bad_town_name; } GetString(buffer, str, lastof(buffer)); if (strlen(buffer) >= MAX_LENGTH_COMPANY_NAME_BYTES) goto bad_town_name; set_name:; c->name_1 = str; c->name_2 = strp; MarkWholeScreenDirty(); if (c->is_ai) { CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1); cni->FillData(c); SetDParam(0, STR_NEWS_COMPANY_LAUNCH_TITLE); SetDParam(1, STR_NEWS_COMPANY_LAUNCH_DESCRIPTION); SetDParamStr(2, cni->company_name); SetDParam(3, t->index); AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_NEW, NR_TILE, c->last_build_coordinate, NR_NONE, UINT32_MAX, cni); } AI::BroadcastNewEvent(new AIEventCompanyNew(c->index), c->index); return; }
/** * Clean up the 'mess' of generation. That is, show windows again, reset * thread variables, and delete the progress window. */ static void CleanupGeneration() { _generating_world = false; if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE); /* Show all vital windows again, because we have hidden them */ if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows(); _gw.active = false; _gw.proc = NULL; _gw.abortp = NULL; _gw.threaded = false; DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0); MarkWholeScreenDirty(); }
/** * Load a heightmap from file and change the map in his current dimensions * to a landscape representing the heightmap. * It converts pixels to height. The brighter, the higher. * @param dft Type of image file. * @param filename of the heightmap file to be imported */ void LoadHeightmap(DetailedFileType dft, const char *filename) { uint x, y; byte *map = nullptr; if (!ReadHeightMap(dft, filename, &x, &y, &map)) { free(map); return; } GrayscaleToMapHeights(x, y, map); free(map); FixSlopes(); MarkWholeScreenDirty(); }
void LoadHeightmap(char *filename) { uint x, y; byte *map = NULL; if (!ReadHeightMap(filename, &x, &y, &map)) { free(map); return; } GrayscaleToMapHeights(x, y, map); free(map); FixSlopes(); MarkWholeScreenDirty(); }
/** * Clean up the 'mess' of generation. That is, show windows again, reset * thread variables, and delete the progress window. */ static void CleanupGeneration() { _generating_world = false; SetMouseCursorBusy(false); /* Show all vital windows again, because we have hidden them */ if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows(); SetModalProgress(false); _gw.proc = NULL; _gw.abortp = NULL; _gw.threaded = false; DeleteWindowByClass(WC_MODAL_PROGRESS); ShowFirstError(); MarkWholeScreenDirty(); }
/** Change the size of the in-game console window after the screen size changed, or the window state changed. */ void IConsoleResize(Window *w) { switch (_iconsole_mode) { case ICONSOLE_OPENED: w->height = _screen.height / 3; w->width = _screen.width; break; case ICONSOLE_FULL: w->height = _screen.height - ICON_BOTTOM_BORDERWIDTH; w->width = _screen.width; break; default: return; } MarkWholeScreenDirty(); }
/** * Scan for all NewGRFs. * @param callback The callback to call after the scanning is complete. */ void ScanNewGRFFiles(NewGRFScanCallback *callback) { /* First set the modal progress. This ensures that it will eventually let go of the paint mutex. */ SetModalProgress(true); /* Only then can we really start, especially by marking the whole screen dirty. Get those other windows hidden!. */ MarkWholeScreenDirty(); if (!VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL, "ottd:newgrf-scan")) { _modal_progress_work_mutex->EndCritical(); _modal_progress_paint_mutex->EndCritical(); DoScanNewGRFFiles(callback); _modal_progress_paint_mutex->BeginCritical(); _modal_progress_work_mutex->BeginCritical(); } else { UpdateNewGRFScanStatus(0, NULL); } }
void ResetViewportAfterLoadGame() { Window *w = FindWindowById(WC_MAIN_WINDOW, 0); w->viewport->scrollpos_x = _saved_scrollpos_x; w->viewport->scrollpos_y = _saved_scrollpos_y; w->viewport->dest_scrollpos_x = _saved_scrollpos_x; w->viewport->dest_scrollpos_y = _saved_scrollpos_y; ViewPort *vp = w->viewport; vp->zoom = (ZoomLevel)min(_saved_scrollpos_zoom, ZOOM_LVL_MAX); vp->virtual_width = ScaleByZoom(vp->width, vp->zoom); vp->virtual_height = ScaleByZoom(vp->height, vp->zoom); DoZoomInOutWindow(ZOOM_NONE, w); // update button status MarkWholeScreenDirty(); }
/** Change the name of the company. * @param tile unused * @param flags operation to perform * @param p1 unused * @param p2 unused * @param text the new name or an empty string when resetting to the default * @return the cost of this operation or an error */ CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { bool reset = StrEmpty(text); if (!reset) { if (strlen(text) >= MAX_LENGTH_COMPANY_NAME_BYTES) return CMD_ERROR; if (!IsUniqueCompanyName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); } if (flags & DC_EXEC) { Company *c = Company::Get(_current_company); free(c->name); c->name = reset ? NULL : strdup(text); MarkWholeScreenDirty(); } return CommandCost(); }
/** * Sets the local company and updates the settings that are set on a * per-company basis to reflect the core's state in the GUI. * @param new_company the new company * @pre Company::IsValidID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE */ void SetLocalCompany(CompanyID new_company) { /* company could also be COMPANY_SPECTATOR or OWNER_NONE */ assert(Company::IsValidID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE); #ifdef ENABLE_NETWORK /* Delete the chat window, if you were team chatting. */ InvalidateWindowData(WC_SEND_NETWORK_MSG, DESTTYPE_TEAM, _local_company); #endif assert(IsLocalCompany()); _current_company = _local_company = new_company; /* Delete any construction windows... */ DeleteConstructionWindows(); /* ... and redraw the whole screen. */ MarkWholeScreenDirty(); }
/** Give a custom name to your vehicle * @param tile unused * @param flags type of operation * @param p1 vehicle ID to name * @param p2 unused * @param text the new name or an empty string when resetting to the default * @return the cost of this operation or an error */ CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { Vehicle *v = Vehicle::GetIfValid(p1); if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR; bool reset = StrEmpty(text); if (!reset) { if (strlen(text) >= MAX_LENGTH_VEHICLE_NAME_BYTES) return CMD_ERROR; if (!(flags & DC_AUTOREPLACE) && !IsUniqueVehicleName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); } if (flags & DC_EXEC) { free(v->name); v->name = reset ? NULL : strdup(text); InvalidateWindowClassesData(WC_TRAINS_LIST, 1); MarkWholeScreenDirty(); } return CommandCost(); }
const char *VideoDriver_SDL::Start(const char * const *parm) { char buf[30]; _use_hwpalette = GetDriverParamInt(parm, "hw_palette", 2); const char *s = SdlOpen(SDL_INIT_VIDEO); if (s != NULL) return s; GetVideoModes(); if (!CreateMainSurface(_cur_resolution.width, _cur_resolution.height)) { return SDL_CALL SDL_GetError(); } SDL_CALL SDL_VideoDriverName(buf, sizeof buf); DEBUG(driver, 1, "SDL: using driver '%s'", buf); MarkWholeScreenDirty(); SetupKeyboard(); _draw_threaded = GetDriverParam(parm, "no_threads") == NULL && GetDriverParam(parm, "no_thread") == NULL; return NULL; }
virtual void OnClick(Point pt, int widget, int click_count) { switch (widget) { case BTW_TYPE_11: case BTW_TYPE_12: case BTW_TYPE_13: case BTW_TYPE_14: case BTW_TYPE_21: case BTW_TYPE_22: case BTW_TYPE_23: case BTW_TYPE_24: case BTW_TYPE_31: case BTW_TYPE_32: case BTW_TYPE_33: case BTW_TYPE_34: if (widget - BTW_TYPE_11 >= this->count) break; if (HandlePlacePushButton(this, widget, SPR_CURSOR_TREE, HT_RECT)) { this->tree_to_plant = (TreeType)(this->base + widget - BTW_TYPE_11); } break; case BTW_TYPE_RANDOM: // tree of random type. if (HandlePlacePushButton(this, BTW_TYPE_RANDOM, SPR_CURSOR_TREE, HT_RECT)) { this->tree_to_plant = TREE_INVALID; } break; case BTW_MANY_RANDOM: // place trees randomly over the landscape this->LowerWidget(BTW_MANY_RANDOM); this->flags4 |= WF_TIMEOUT_BEGIN; SndPlayFx(SND_15_BEEP); PlaceTreesRandomly(); MarkWholeScreenDirty(); break; } }
void ResetViewportAfterLoadGame() { Window *w = FindWindowById(WC_MAIN_WINDOW, 0); w->viewport->scrollpos_x = _saved_scrollpos_x; w->viewport->scrollpos_y = _saved_scrollpos_y; w->viewport->dest_scrollpos_x = _saved_scrollpos_x; w->viewport->dest_scrollpos_y = _saved_scrollpos_y; ViewPort *vp = w->viewport; vp->zoom = (ZoomLevel)min(_saved_scrollpos_zoom, ZOOM_LVL_MAX); vp->virtual_width = ScaleByZoom(vp->width, vp->zoom); vp->virtual_height = ScaleByZoom(vp->height, vp->zoom); /* If zoom_max is ZOOM_LVL_MIN then the setting has not been loaded yet, therefore all levels are allowed. */ if (_settings_client.gui.zoom_max != ZOOM_LVL_MIN) { /* Ensure zoom level is allowed */ while (vp->zoom < _settings_client.gui.zoom_min) DoZoomInOutWindow(ZOOM_OUT, w); while (vp->zoom > _settings_client.gui.zoom_max) DoZoomInOutWindow(ZOOM_IN, w); } DoZoomInOutWindow(ZOOM_NONE, w); // update button status MarkWholeScreenDirty(); }
/** * Give a custom name to your vehicle * @param tile unused * @param flags type of operation * @param p1 vehicle ID to name * @param p2 unused * @param text the new name or an empty string when resetting to the default * @return the cost of this operation or an error */ CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { Vehicle *v = Vehicle::GetIfValid(p1); if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR; CommandCost ret = CheckOwnership(v->owner); if (ret.Failed()) return ret; bool reset = StrEmpty(text); if (!reset) { if (Utf8StringLength(text) >= MAX_LENGTH_VEHICLE_NAME_CHARS) return CMD_ERROR; if (!(flags & DC_AUTOREPLACE) && !IsUniqueVehicleName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); } if (flags & DC_EXEC) { free(v->name); v->name = reset ? NULL : strdup(text); InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 1); MarkWholeScreenDirty(); } return CommandCost(); }
const char *VideoDriver_SDL::Start(const char * const *parm) { char buf[30]; const char *s = SdlOpen(SDL_INIT_VIDEO); if (s != NULL) return s; GetVideoModes(); if (!CreateMainSurface(_cur_resolution.width, _cur_resolution.height)) { return SDL_CALL SDL_GetError(); } SDL_CALL SDL_VideoDriverName(buf, sizeof buf); DEBUG(driver, 1, "SDL: using driver '%s'", buf); MarkWholeScreenDirty(); SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_CALL SDL_EnableUNICODE(1); _draw_threaded = GetDriverParam(parm, "no_threads") == NULL && GetDriverParam(parm, "no_thread") == NULL; return NULL; }
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; }