Changeset - r13419:9590b77424f8
[Not reviewed]
master
0 4 0
smatz - 15 years ago 2009-11-01 18:15:35
smatz@openttd.org
(svn r17938) -Feature: non-automatic screenshot name can be entered in console
4 files changed with 39 insertions and 23 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -1215,27 +1215,42 @@ DEF_CONSOLE_CMD(ConAlias)
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConScreenShot)
 
{
 
	if (argc == 0) {
 
		IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [big | no_con]'");
 
		IConsoleHelp("'big' makes a screenshot of the whole map, 'no_con' hides the console to create the screenshot");
 
		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. Screenshots of whole map are always drawn without console");
 
		return true;
 
	}
 

	
 
	if (argc > 3) return false;
 

	
 
	SetScreenshotType(SC_VIEWPORT);
 
	ScreenshotType type = SC_VIEWPORT;
 
	const char *name = NULL;
 

	
 
	if (argc > 1) {
 
		if (strcmp(argv[1], "big") == 0 || (argc == 3 && strcmp(argv[2], "big") == 0))
 
			SetScreenshotType(SC_WORLD);
 
		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();
 
			if (argc > 2) name = argv[2];
 
		} else if (argc == 2) {
 
			/* screenshot filename */
 
			name = argv[1];
 
		} else {
 
			/* screenshot argv[1] argv[2] - invalid*/
 
			return false;
 
		}
 
	}
 

	
 
		if (strcmp(argv[1], "no_con") == 0 || (argc == 3 && strcmp(argv[2], "no_con") == 0))
 
			IConsoleClose();
 
	}
 
	RequestScreenshot(type, name);
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConInfoVar)
 
{
src/screenshot.cpp
Show inline comments
 
@@ -536,43 +536,44 @@ static void LargeWorldCallback(void *use
 
	_screen = old_screen;
 
	_screen_disable_anim = old_disable_anim;
 
}
 

	
 
static char *MakeScreenshotName(const char *ext)
 
{
 
	static char filename[MAX_PATH];
 
	int serial;
 
	size_t len;
 

	
 
	if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
 
		strecpy(_screenshot_name, "screenshot", lastof(_screenshot_name));
 
	} else {
 
		GenerateDefaultSaveName(_screenshot_name, lastof(_screenshot_name));
 
	if (_screenshot_name[0] == '\0') {
 
		if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
 
			strecpy(_screenshot_name, "screenshot", lastof(_screenshot_name));
 
		} else {
 
			GenerateDefaultSaveName(_screenshot_name, lastof(_screenshot_name));
 
		}
 
	}
 

	
 
	/* 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);
 

	
 
	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)) {
 
			/* We need more characters than MAX_PATH -> end with error */
 
			filename[0] = '\0';
 
			break;
 
		}
 
		if (!FileExists(filename)) break;
 
		/* 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;
 
}
 

	
 
void SetScreenshotType(ScreenshotType t)
 
void RequestScreenshot(ScreenshotType t, const char *name)
 
{
 
	_screenshot_type = t;
 
	_screenshot_name[0] = '\0';
 
	if (name != NULL) strecpy(_screenshot_name, name, lastof(_screenshot_name));
 
}
 

	
 
bool IsScreenshotRequested()
 
{
 
	return (_screenshot_type != SC_NONE);
 
}
src/screenshot.h
Show inline comments
 
@@ -21,13 +21,13 @@ enum ScreenshotType {
 
	SC_NONE,
 
	SC_VIEWPORT,
 
	SC_WORLD
 
};
 

	
 
bool MakeScreenshot();
 
void SetScreenshotType(ScreenshotType t);
 
void RequestScreenshot(ScreenshotType t, const char *name);
 
bool IsScreenshotRequested();
 

	
 
extern char _screenshot_format_name[8];
 
extern uint _num_screenshot_formats;
 
extern uint _cur_screenshot_format;
 
extern char _screenshot_name[];
src/toolbar_gui.cpp
Show inline comments
 
@@ -745,18 +745,18 @@ static void ToolbarHelpClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, TBN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, 7);
 
}
 

	
 
static void MenuClickSmallScreenshot()
 
{
 
	SetScreenshotType(SC_VIEWPORT);
 
	RequestScreenshot(SC_VIEWPORT, NULL);
 
}
 

	
 
static void MenuClickWorldScreenshot()
 
{
 
	SetScreenshotType(SC_WORLD);
 
	RequestScreenshot(SC_WORLD, NULL);
 
}
 

	
 
static void MenuClickHelp(int index)
 
{
 
	switch (index) {
 
		case 0: PlaceLandBlockInfo();       break;
0 comments (0 inline, 0 general)