MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ConZoomToLevel

Function ConZoomToLevel

src/console_cmds.cpp:313–354  ·  view source on GitHub ↗

* Zoom map to given level. * param level As defined by ZoomLevel and as limited by zoom_min/zoom_max from GUISettings. * @return True when either console help was shown or a proper amount of parameters given. */

Source from the content-addressed store, hash-verified

311 * @return True when either console help was shown or a proper amount of parameters given.
312 */
313static bool ConZoomToLevel(std::span<std::string_view> argv)
314{
315 switch (argv.size()) {
316 case 0:
317 IConsolePrint(CC_HELP, "Set the current zoom level of the main viewport.");
318 IConsolePrint(CC_HELP, "Usage: 'zoomto <level>'.");
319
320 if (ZoomLevel::Min < _settings_client.gui.zoom_min) {
321 IConsolePrint(CC_HELP, "The lowest zoom-in level allowed by current client settings is {}.", std::max(ZoomLevel::Min, _settings_client.gui.zoom_min));
322 } else {
323 IConsolePrint(CC_HELP, "The lowest supported zoom-in level is {}.", std::max(ZoomLevel::Min, _settings_client.gui.zoom_min));
324 }
325
326 if (_settings_client.gui.zoom_max < ZoomLevel::Max) {
327 IConsolePrint(CC_HELP, "The highest zoom-out level allowed by current client settings is {}.", std::min(_settings_client.gui.zoom_max, ZoomLevel::Max));
328 } else {
329 IConsolePrint(CC_HELP, "The highest supported zoom-out level is {}.", std::min(_settings_client.gui.zoom_max, ZoomLevel::Max));
330 }
331 return true;
332
333 case 2: {
334 auto level = ParseInteger<std::underlying_type_t<ZoomLevel>>(argv[1]);
335 if (level.has_value()) {
336 auto zoom_lvl = static_cast<ZoomLevel>(*level);
337 if (!IsInsideMM(zoom_lvl, ZoomLevel::Begin, ZoomLevel::End)) {
338 IConsolePrint(CC_ERROR, "Invalid zoom level. Valid range is {} to {}.", ZoomLevel::Min, ZoomLevel::Max);
339 } else if (!IsInsideMM(zoom_lvl, _settings_client.gui.zoom_min, _settings_client.gui.zoom_max + 1)) {
340 IConsolePrint(CC_ERROR, "Current client settings limit zoom levels to range {} to {}.", _settings_client.gui.zoom_min, _settings_client.gui.zoom_max);
341 } else {
342 Window *w = GetMainWindow();
343 Viewport &vp = *w->viewport;
344 while (vp.zoom > zoom_lvl) DoZoomInOutWindow(ZOOM_IN, w);
345 while (vp.zoom < zoom_lvl) DoZoomInOutWindow(ZOOM_OUT, w);
346 }
347 return true;
348 }
349 break;
350 }
351 }
352
353 return false;
354}
355
356/**
357 * Scroll to a tile on the map.

Callers

nothing calls this directly

Calls 5

IsInsideMMFunction · 0.85
GetMainWindowFunction · 0.85
DoZoomInOutWindowFunction · 0.85
IConsolePrintFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected