1
0
Fork 0

(svn r17938) -Feature: non-automatic screenshot name can be entered in console

release/1.0
smatz 2009-11-01 18:15:35 +00:00
parent be446d6f54
commit 090c762921
4 changed files with 38 additions and 22 deletions

View File

@ -1218,22 +1218,37 @@ DEF_CONSOLE_CMD(ConAlias)
DEF_CONSOLE_CMD(ConScreenShot) DEF_CONSOLE_CMD(ConScreenShot)
{ {
if (argc == 0) { if (argc == 0) {
IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [big | no_con]'"); IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [big | no_con] [file name]'");
IConsoleHelp("'big' makes a screenshot of the whole map, 'no_con' hides the console to create the screenshot"); IConsoleHelp("'big' makes a screenshot of the whole map, 'no_con' hides the console to create"
"the screenshot. Screenshots of whole map are always drawn without console");
return true; return true;
} }
if (argc > 3) return false; if (argc > 3) return false;
SetScreenshotType(SC_VIEWPORT); ScreenshotType type = SC_VIEWPORT;
if (argc > 1) { const char *name = NULL;
if (strcmp(argv[1], "big") == 0 || (argc == 3 && strcmp(argv[2], "big") == 0))
SetScreenshotType(SC_WORLD);
if (strcmp(argv[1], "no_con") == 0 || (argc == 3 && strcmp(argv[2], "no_con") == 0)) if (argc > 1) {
if (strcmp(argv[1], "big") == 0) {
/* screenshot big [filename] */
type = SC_WORLD;
if (argc > 2) name = argv[2];
} else if (strcmp(argv[1], "no_con") == 0) {
/* screenshot no_con [filename] */
IConsoleClose(); 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;
}
} }
RequestScreenshot(type, name);
return true; return true;
} }

View File

@ -539,21 +539,20 @@ static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, ui
static char *MakeScreenshotName(const char *ext) static char *MakeScreenshotName(const char *ext)
{ {
static char filename[MAX_PATH]; if (_screenshot_name[0] == '\0') {
int serial; if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
size_t len; strecpy(_screenshot_name, "screenshot", lastof(_screenshot_name));
} else {
if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) { GenerateDefaultSaveName(_screenshot_name, lastof(_screenshot_name));
strecpy(_screenshot_name, "screenshot", lastof(_screenshot_name)); }
} else {
GenerateDefaultSaveName(_screenshot_name, lastof(_screenshot_name));
} }
/* Add extension to screenshot file */ /* Add extension to screenshot file */
len = strlen(_screenshot_name); size_t len = strlen(_screenshot_name);
snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext); snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext);
for (serial = 1;; serial++) { static char filename[20 + 1]; // 1 character more to detect overflow
for (uint serial = 1;; serial++) {
if (snprintf(filename, lengthof(filename), "%s%s", _personal_dir, _screenshot_name) >= (int)lengthof(filename)) { if (snprintf(filename, lengthof(filename), "%s%s", _personal_dir, _screenshot_name) >= (int)lengthof(filename)) {
/* We need more characters than MAX_PATH -> end with error */ /* We need more characters than MAX_PATH -> end with error */
filename[0] = '\0'; filename[0] = '\0';
@ -561,15 +560,17 @@ static char *MakeScreenshotName(const char *ext)
} }
if (!FileExists(filename)) break; if (!FileExists(filename)) break;
/* If file exists try another one with same name, but just with a higher index */ /* If file exists try another one with same name, but just with a higher index */
snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, "#%d.%s", serial, ext); snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, "#%u.%s", serial, ext);
} }
return filename; return filename;
} }
void SetScreenshotType(ScreenshotType t) void RequestScreenshot(ScreenshotType t, const char *name)
{ {
_screenshot_type = t; _screenshot_type = t;
_screenshot_name[0] = '\0';
if (name != NULL) strecpy(_screenshot_name, name, lastof(_screenshot_name));
} }
bool IsScreenshotRequested() bool IsScreenshotRequested()

View File

@ -24,7 +24,7 @@ enum ScreenshotType {
}; };
bool MakeScreenshot(); bool MakeScreenshot();
void SetScreenshotType(ScreenshotType t); void RequestScreenshot(ScreenshotType t, const char *name);
bool IsScreenshotRequested(); bool IsScreenshotRequested();
extern char _screenshot_format_name[8]; extern char _screenshot_format_name[8];

View File

@ -748,12 +748,12 @@ static void ToolbarHelpClick(Window *w)
static void MenuClickSmallScreenshot() static void MenuClickSmallScreenshot()
{ {
SetScreenshotType(SC_VIEWPORT); RequestScreenshot(SC_VIEWPORT, NULL);
} }
static void MenuClickWorldScreenshot() static void MenuClickWorldScreenshot()
{ {
SetScreenshotType(SC_WORLD); RequestScreenshot(SC_WORLD, NULL);
} }
static void MenuClickHelp(int index) static void MenuClickHelp(int index)