diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -1409,46 +1409,76 @@ DEF_CONSOLE_CMD(ConAlias) DEF_CONSOLE_CMD(ConScreenShot) { if (argc == 0) { - IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [big | giant | no_con | minimap] [file name]'"); - IConsoleHelp("'big' makes a zoomed-in screenshot of the visible area, 'giant' makes a screenshot of the " - "whole map, 'no_con' hides the console to create the screenshot. 'big' or 'giant' " - "screenshots are always drawn without console. " - "'minimap' makes a top-viewed minimap screenshot of whole world which represents one tile by one pixel."); + IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [viewport | normal | big | giant | minimap] [no_con] [size ] []'"); + IConsoleHelp("'viewport' (default) makes a screenshot of the current viewport (including menus, windows, ..), " + "'normal' makes a screenshot of the visible area, " + "'big' makes a zoomed-in screenshot of the visible area, " + "'giant' makes a screenshot of the whole map, " + "'minimap' makes a top-viewed minimap screenshot of the whole world which represents one tile by one pixel. " + "'no_con' hides the console to create the screenshot (only useful in combination with 'viewport'). " + "'size' sets the width and height of the viewport to make a screenshot of (only useful in combination with 'normal' or 'big')."); return true; } - if (argc > 3) return false; + if (argc > 7) return false; ScreenshotType type = SC_VIEWPORT; + uint32 width = 0; + uint32 height = 0; const char *name = nullptr; + uint32 arg_index = 1; - if (argc > 1) { - if (strcmp(argv[1], "big") == 0) { - /* screenshot big [filename] */ + if (argc > arg_index) { + if (strcmp(argv[arg_index], "viewport") == 0) { + type = SC_VIEWPORT; + arg_index += 1; + } else if (strcmp(argv[arg_index], "normal") == 0) { + type = SC_DEFAULTZOOM; + arg_index += 1; + } else if (strcmp(argv[arg_index], "big") == 0) { type = SC_ZOOMEDIN; - if (argc > 2) name = argv[2]; - } else if (strcmp(argv[1], "giant") == 0) { - /* screenshot giant [filename] */ + arg_index += 1; + } else if (strcmp(argv[arg_index], "giant") == 0) { type = SC_WORLD; - if (argc > 2) name = argv[2]; - } else if (strcmp(argv[1], "minimap") == 0) { - /* screenshot minimap [filename] */ + arg_index += 1; + } else if (strcmp(argv[arg_index], "minimap") == 0) { type = SC_MINIMAP; - if (argc > 2) name = argv[2]; - } else if (strcmp(argv[1], "no_con") == 0) { - /* screenshot no_con [filename] */ - IConsoleClose(); - if (argc > 2) name = argv[2]; - } else if (argc == 2) { - /* screenshot filename */ - name = argv[1]; - } else { - /* screenshot argv[1] argv[2] - invalid */ - return false; + arg_index += 1; } } - MakeScreenshot(type, name); + if (argc > arg_index && strcmp(argv[arg_index], "no_con") == 0) { + if (type != SC_VIEWPORT) { + IConsoleError("'no_con' can only be used in combination with 'viewport'"); + return true; + } + IConsoleClose(); + arg_index += 1; + } + + if (argc > arg_index + 2 && strcmp(argv[arg_index], "size") == 0) { + /* size */ + if (type != SC_DEFAULTZOOM && type != SC_ZOOMEDIN) { + IConsoleError("'size' can only be used in combination with 'normal' or 'big'"); + return true; + } + GetArgumentInteger(&width, argv[arg_index + 1]); + GetArgumentInteger(&height, argv[arg_index + 2]); + arg_index += 3; + } + + if (argc > arg_index) { + /* Last parameter that was not one of the keywords must be the filename. */ + name = argv[arg_index]; + arg_index += 1; + } + + if (argc > arg_index) { + /* We have parameters we did not process; means we misunderstood any of the above. */ + return false; + } + + MakeScreenshot(type, name, width, height); return true; }