Changeset - r25468:f59ee36e2847
[Not reviewed]
master
0 7 0
rubidium42 - 3 years ago 2021-04-28 15:32:33
rubidium@openttd.org
Codechange: move misc settings to std::string
7 files changed with 38 insertions and 46 deletions:
0 comments (0 inline, 0 general)
src/osk_gui.cpp
Show inline comments
 
@@ -24,7 +24,7 @@
 

	
 
#include "safeguards.h"
 

	
 
char _keyboard_opt[2][OSK_KEYBOARD_ENTRIES * 4 + 1];
 
std::string _keyboard_opt[2];
 
static WChar _keyboard[2][OSK_KEYBOARD_ENTRIES];
 

	
 
enum KeyStateBits {
 
@@ -356,16 +356,16 @@ void GetKeyboardLayout()
 
	char errormark[2][OSK_KEYBOARD_ENTRIES + 1]; // used for marking invalid chars
 
	bool has_error = false; // true when an invalid char is detected
 

	
 
	if (StrEmpty(_keyboard_opt[0])) {
 
	if (_keyboard_opt[0].empty()) {
 
		GetString(keyboard[0], STR_OSK_KEYBOARD_LAYOUT, lastof(keyboard[0]));
 
	} else {
 
		strecpy(keyboard[0], _keyboard_opt[0], lastof(keyboard[0]));
 
		strecpy(keyboard[0], _keyboard_opt[0].c_str(), lastof(keyboard[0]));
 
	}
 

	
 
	if (StrEmpty(_keyboard_opt[1])) {
 
	if (_keyboard_opt[1].empty()) {
 
		GetString(keyboard[1], STR_OSK_KEYBOARD_LAYOUT_CAPS, lastof(keyboard[1]));
 
	} else {
 
		strecpy(keyboard[1], _keyboard_opt[1], lastof(keyboard[1]));
 
		strecpy(keyboard[1], _keyboard_opt[1].c_str(), lastof(keyboard[1]));
 
	}
 

	
 
	for (uint j = 0; j < 2; j++) {
src/saveload/saveload.cpp
Show inline comments
 
@@ -61,11 +61,11 @@ extern const SaveLoadVersion SAVEGAME_VE
 
SavegameType _savegame_type; ///< type of savegame we are loading
 
FileToSaveLoad _file_to_saveload; ///< File to save or load in the openttd loop.
 

	
 
uint32 _ttdp_version;        ///< version of TTDP savegame (if applicable)
 
SaveLoadVersion _sl_version; ///< the major savegame version identifier
 
byte   _sl_minor_version;    ///< the minor savegame version, DO NOT USE!
 
char _savegame_format[8];    ///< how to compress savegames
 
bool _do_autosave;           ///< are we doing an autosave at the moment?
 
uint32 _ttdp_version;         ///< version of TTDP savegame (if applicable)
 
SaveLoadVersion _sl_version;  ///< the major savegame version identifier
 
byte   _sl_minor_version;     ///< the minor savegame version, DO NOT USE!
 
std::string _savegame_format; ///< how to compress savegames
 
bool _do_autosave;            ///< are we doing an autosave at the moment?
 

	
 
/** What are we currently doing? */
 
enum SaveLoadAction {
 
@@ -2351,36 +2351,33 @@ static const SaveLoadFormat _saveload_fo
 
/**
 
 * Return the savegameformat of the game. Whether it was created with ZLIB compression
 
 * uncompressed, or another type
 
 * @param s Name of the savegame format. If nullptr it picks the first available one
 
 * @param full_name Name of the savegame format. If empty it picks the first available one
 
 * @param compression_level Output for telling what compression level we want.
 
 * @return Pointer to SaveLoadFormat struct giving all characteristics of this type of savegame
 
 */
 
static const SaveLoadFormat *GetSavegameFormat(char *s, byte *compression_level)
 
static const SaveLoadFormat *GetSavegameFormat(const std::string &full_name, byte *compression_level)
 
{
 
	const SaveLoadFormat *def = lastof(_saveload_formats);
 

	
 
	/* find default savegame format, the highest one with which files can be written */
 
	while (!def->init_write) def--;
 

	
 
	if (!StrEmpty(s)) {
 
	if (!full_name.empty()) {
 
		/* Get the ":..." of the compression level out of the way */
 
		char *complevel = strrchr(s, ':');
 
		if (complevel != nullptr) *complevel = '\0';
 
		size_t separator = full_name.find(':');
 
		bool has_comp_level = separator != std::string::npos;
 
		const std::string name(full_name, 0, has_comp_level ? separator : full_name.size());
 

	
 
		for (const SaveLoadFormat *slf = &_saveload_formats[0]; slf != endof(_saveload_formats); slf++) {
 
			if (slf->init_write != nullptr && strcmp(s, slf->name) == 0) {
 
			if (slf->init_write != nullptr && name.compare(slf->name) == 0) {
 
				*compression_level = slf->default_compression;
 
				if (complevel != nullptr) {
 
					/* There is a compression level in the string.
 
					 * First restore the : we removed to do proper name matching,
 
					 * then move the the begin of the actual version. */
 
					*complevel = ':';
 
					complevel++;
 

	
 
					/* Get the version and determine whether all went fine. */
 
					char *end;
 
					long level = strtol(complevel, &end, 10);
 
					if (end == complevel || level != Clamp(level, slf->min_compression, slf->max_compression)) {
 
				if (has_comp_level) {
 
					const std::string complevel(full_name, separator + 1);
 

	
 
					/* Get the level and determine whether all went fine. */
 
					size_t processed;
 
					long level = std::stol(complevel, &processed, 10);
 
					if (processed == 0 || level != Clamp(level, slf->min_compression, slf->max_compression)) {
 
						SetDParamStr(0, complevel);
 
						ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_LEVEL, WL_CRITICAL);
 
					} else {
 
@@ -2391,12 +2388,9 @@ static const SaveLoadFormat *GetSavegame
 
			}
 
		}
 

	
 
		SetDParamStr(0, s);
 
		SetDParamStr(0, name);
 
		SetDParamStr(1, def->name);
 
		ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_ALGORITHM, WL_CRITICAL);
 

	
 
		/* Restore the string by adding the : back */
 
		if (complevel != nullptr) *complevel = ':';
 
	}
 
	*compression_level = def->default_compression;
 
	return def;
src/saveload/saveload.h
Show inline comments
 
@@ -934,7 +934,7 @@ static inline void SlSkipBytes(size_t le
 
	for (; length != 0; length--) SlReadByte();
 
}
 

	
 
extern char _savegame_format[8];
 
extern std::string _savegame_format;
 
extern bool _do_autosave;
 

	
 
#endif /* SAVELOAD_H */
src/screenshot.cpp
Show inline comments
 
@@ -34,7 +34,7 @@
 
static const char * const SCREENSHOT_NAME = "screenshot"; ///< Default filename of a saved screenshot.
 
static const char * const HEIGHTMAP_NAME  = "heightmap";  ///< Default filename of a saved heightmap.
 

	
 
char _screenshot_format_name[8];      ///< Extension of the current screenshot format (corresponds with #_cur_screenshot_format).
 
std::string _screenshot_format_name;  ///< Extension of the current screenshot format (corresponds with #_cur_screenshot_format).
 
uint _num_screenshot_formats;         ///< Number of available screenshot formats.
 
uint _cur_screenshot_format;          ///< Index of the currently selected screenshot format in #_screenshot_formats.
 
static char _screenshot_name[128];    ///< Filename of the screenshot file.
 
@@ -584,7 +584,7 @@ void InitializeScreenshotFormats()
 
{
 
	uint j = 0;
 
	for (uint i = 0; i < lengthof(_screenshot_formats); i++) {
 
		if (!strcmp(_screenshot_format_name, _screenshot_formats[i].extension)) {
 
		if (_screenshot_format_name.compare(_screenshot_formats[i].extension) != 0) {
 
			j = i;
 
			break;
 
		}
src/screenshot.h
Show inline comments
 
@@ -31,7 +31,7 @@ void MakeScreenshotWithConfirm(Screensho
 
bool MakeScreenshot(ScreenshotType t, std::string name, uint32 width = 0, uint32 height = 0);
 
bool MakeMinimapWorldScreenshot();
 

	
 
extern char _screenshot_format_name[8];
 
extern std::string _screenshot_format_name;
 
extern uint _num_screenshot_formats;
 
extern uint _cur_screenshot_format;
 
extern char _full_screenshot_name[MAX_PATH];
src/table/misc_settings.ini
Show inline comments
 
@@ -23,7 +23,6 @@ static const SettingDescGlobVarList _mis
 
SDTG_LIST  =  SDTG_LIST($name, $type, $length, $flags, $guiflags, $var, $def,                               $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDTG_MMANY = SDTG_MMANY($name, $type,          $flags, $guiflags, $var, $def,                        $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDTG_OMANY = SDTG_OMANY($name, $type,          $flags, $guiflags, $var, $def,       $max,            $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDTG_STR   =   SDTG_STR($name, $type,          $flags, $guiflags, $var, $def,                               $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDTG_SSTR  =  SDTG_SSTR($name, $type,          $flags, $guiflags, $var, $def,                               $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDTG_BOOL  =  SDTG_BOOL($name,                 $flags, $guiflags, $var, $def,                               $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDTG_VAR   =   SDTG_VAR($name, $type,          $flags, $guiflags, $var, $def, $min, $max, $interval,        $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
@@ -156,16 +155,16 @@ var      = _cur_resolution
 
def      = ""0,0""
 
cat      = SC_BASIC
 

	
 
[SDTG_STR]
 
[SDTG_SSTR]
 
name     = ""screenshot_format""
 
type     = SLE_STRB
 
type     = SLE_STR
 
var      = _screenshot_format_name
 
def      = nullptr
 
cat      = SC_EXPERT
 

	
 
[SDTG_STR]
 
[SDTG_SSTR]
 
name     = ""savegame_format""
 
type     = SLE_STRB
 
type     = SLE_STR
 
var      = _savegame_format
 
def      = nullptr
 
cat      = SC_EXPERT
 
@@ -308,16 +307,16 @@ min      = 0
 
max      = 0xFF
 
cat      = SC_BASIC
 

	
 
[SDTG_STR]
 
[SDTG_SSTR]
 
name     = ""keyboard""
 
type     = SLE_STRB
 
type     = SLE_STR
 
var      = _keyboard_opt[0]
 
def      = nullptr
 
cat      = SC_EXPERT
 

	
 
[SDTG_STR]
 
[SDTG_SSTR]
 
name     = ""keyboard_caps""
 
type     = SLE_STRB
 
type     = SLE_STR
 
var      = _keyboard_opt[1]
 
def      = nullptr
 
cat      = SC_EXPERT
src/textbuf_gui.h
Show inline comments
 
@@ -37,8 +37,7 @@ static const uint OSK_KEYBOARD_ENTRIES =
 
/**
 
 * The number of characters has to be OSK_KEYBOARD_ENTRIES. However, these
 
 * have to be UTF-8 encoded, which means up to 4 bytes per character.
 
 * Furthermore the string needs to be '\0'-terminated.
 
 */
 
extern char _keyboard_opt[2][OSK_KEYBOARD_ENTRIES * 4 + 1];
 
extern std::string _keyboard_opt[2];
 

	
 
#endif /* TEXTBUF_GUI_H */
0 comments (0 inline, 0 general)