mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Pass GRFConfig by reference where feasible. (#13388)
In places where a GRFConfig is passed by pointer and not checked for nullptr, use a reference instead.pull/13390/head
parent
e894a5880c
commit
9b947a37b8
|
@ -186,7 +186,7 @@ static void LoadSpriteTables()
|
||||||
static const char *master_filename = "OPENTTD.GRF";
|
static const char *master_filename = "OPENTTD.GRF";
|
||||||
GRFConfig *master = new GRFConfig(master_filename);
|
GRFConfig *master = new GRFConfig(master_filename);
|
||||||
master->palette |= GRFP_GRF_DOS;
|
master->palette |= GRFP_GRF_DOS;
|
||||||
FillGRFDetails(master, false, BASESET_DIR);
|
FillGRFDetails(*master, false, BASESET_DIR);
|
||||||
ClrBit(master->flags, GCF_INIT_ONLY);
|
ClrBit(master->flags, GCF_INIT_ONLY);
|
||||||
|
|
||||||
/* Baseset extra graphics */
|
/* Baseset extra graphics */
|
||||||
|
@ -381,7 +381,7 @@ GRFConfig &GraphicsSet::GetOrCreateExtraConfig() const
|
||||||
case PAL_WINDOWS: this->extra_cfg->palette |= GRFP_GRF_WINDOWS; break;
|
case PAL_WINDOWS: this->extra_cfg->palette |= GRFP_GRF_WINDOWS; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
FillGRFDetails(this->extra_cfg.get(), false, BASESET_DIR);
|
FillGRFDetails(*this->extra_cfg, false, BASESET_DIR);
|
||||||
}
|
}
|
||||||
return *this->extra_cfg;
|
return *this->extra_cfg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,20 +180,20 @@ const NetworkServerGameInfo &GetCurrentNetworkServerGameInfo()
|
||||||
* @param config The GRF to handle.
|
* @param config The GRF to handle.
|
||||||
* @param name The name of the NewGRF, empty when unknown.
|
* @param name The name of the NewGRF, empty when unknown.
|
||||||
*/
|
*/
|
||||||
static void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config, std::string_view name)
|
static void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig &config, std::string_view name)
|
||||||
{
|
{
|
||||||
/* Find the matching GRF file */
|
/* Find the matching GRF file */
|
||||||
const GRFConfig *f = FindGRFConfig(config->ident.grfid, FGCM_EXACT, &config->ident.md5sum);
|
const GRFConfig *f = FindGRFConfig(config.ident.grfid, FGCM_EXACT, &config.ident.md5sum);
|
||||||
if (f == nullptr) {
|
if (f == nullptr) {
|
||||||
AddGRFTextToList(config->name, name.empty() ? GetString(STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN) : name);
|
AddGRFTextToList(config.name, name.empty() ? GetString(STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN) : name);
|
||||||
config->status = GCS_NOT_FOUND;
|
config.status = GCS_NOT_FOUND;
|
||||||
} else {
|
} else {
|
||||||
config->filename = f->filename;
|
config.filename = f->filename;
|
||||||
config->name = f->name;
|
config.name = f->name;
|
||||||
config->info = f->info;
|
config.info = f->info;
|
||||||
config->url = f->url;
|
config.url = f->url;
|
||||||
}
|
}
|
||||||
SetBit(config->flags, GCF_COPY);
|
SetBit(config.flags, GCF_COPY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -337,7 +337,7 @@ void DeserializeNetworkGameInfo(Packet &p, NetworkGameInfo &info, const GameInfo
|
||||||
|
|
||||||
GRFConfig *c = new GRFConfig();
|
GRFConfig *c = new GRFConfig();
|
||||||
c->ident = grf.ident;
|
c->ident = grf.ident;
|
||||||
HandleIncomingNetworkGameInfoGRFConfig(c, grf.name);
|
HandleIncomingNetworkGameInfoGRFConfig(*c, grf.name);
|
||||||
|
|
||||||
/* Append GRFConfig to the list */
|
/* Append GRFConfig to the list */
|
||||||
*dst = c;
|
*dst = c;
|
||||||
|
|
|
@ -6862,9 +6862,9 @@ static void CfgApply(ByteReader &buf)
|
||||||
* best result as no NewGRF author can complain about that.
|
* best result as no NewGRF author can complain about that.
|
||||||
* @param c The NewGRF to disable.
|
* @param c The NewGRF to disable.
|
||||||
*/
|
*/
|
||||||
static void DisableStaticNewGRFInfluencingNonStaticNewGRFs(GRFConfig *c)
|
static void DisableStaticNewGRFInfluencingNonStaticNewGRFs(GRFConfig &c)
|
||||||
{
|
{
|
||||||
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC, c);
|
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC, &c);
|
||||||
error->data = _cur.grfconfig->GetName();
|
error->data = _cur.grfconfig->GetName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6949,7 +6949,7 @@ static void SkipIf(ByteReader &buf)
|
||||||
GRFConfig *c = GetGRFConfig(cond_val, mask);
|
GRFConfig *c = GetGRFConfig(cond_val, mask);
|
||||||
|
|
||||||
if (c != nullptr && HasBit(c->flags, GCF_STATIC) && !HasBit(_cur.grfconfig->flags, GCF_STATIC) && _networking) {
|
if (c != nullptr && HasBit(c->flags, GCF_STATIC) && !HasBit(_cur.grfconfig->flags, GCF_STATIC) && _networking) {
|
||||||
DisableStaticNewGRFInfluencingNonStaticNewGRFs(c);
|
DisableStaticNewGRFInfluencingNonStaticNewGRFs(*c);
|
||||||
c = nullptr;
|
c = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7591,7 +7591,7 @@ static void ParamSet(ByteReader &buf)
|
||||||
GRFConfig *c = GetGRFConfig(data);
|
GRFConfig *c = GetGRFConfig(data);
|
||||||
if (c != nullptr && HasBit(c->flags, GCF_STATIC) && !HasBit(_cur.grfconfig->flags, GCF_STATIC) && _networking) {
|
if (c != nullptr && HasBit(c->flags, GCF_STATIC) && !HasBit(_cur.grfconfig->flags, GCF_STATIC) && _networking) {
|
||||||
/* Disable the read GRF if it is a static NewGRF. */
|
/* Disable the read GRF if it is a static NewGRF. */
|
||||||
DisableStaticNewGRFInfluencingNonStaticNewGRFs(c);
|
DisableStaticNewGRFInfluencingNonStaticNewGRFs(*c);
|
||||||
src1 = 0;
|
src1 = 0;
|
||||||
} else if (file == nullptr || c == nullptr || c->status == GCS_DISABLED) {
|
} else if (file == nullptr || c == nullptr || c->status == GCS_DISABLED) {
|
||||||
src1 = 0;
|
src1 = 0;
|
||||||
|
@ -8905,9 +8905,9 @@ static void BuildCargoTranslationMap()
|
||||||
* Prepare loading a NewGRF file with its config
|
* Prepare loading a NewGRF file with its config
|
||||||
* @param config The NewGRF configuration struct with name, id, parameters and alike.
|
* @param config The NewGRF configuration struct with name, id, parameters and alike.
|
||||||
*/
|
*/
|
||||||
static void InitNewGRFFile(const GRFConfig *config)
|
static void InitNewGRFFile(const GRFConfig &config)
|
||||||
{
|
{
|
||||||
GRFFile *newfile = GetFileByFilename(config->filename);
|
GRFFile *newfile = GetFileByFilename(config.filename);
|
||||||
if (newfile != nullptr) {
|
if (newfile != nullptr) {
|
||||||
/* We already loaded it once. */
|
/* We already loaded it once. */
|
||||||
_cur.grffile = newfile;
|
_cur.grffile = newfile;
|
||||||
|
@ -8922,10 +8922,10 @@ static void InitNewGRFFile(const GRFConfig *config)
|
||||||
* Constructor for GRFFile
|
* Constructor for GRFFile
|
||||||
* @param config GRFConfig to copy name, grfid and parameters from.
|
* @param config GRFConfig to copy name, grfid and parameters from.
|
||||||
*/
|
*/
|
||||||
GRFFile::GRFFile(const GRFConfig *config)
|
GRFFile::GRFFile(const GRFConfig &config)
|
||||||
{
|
{
|
||||||
this->filename = config->filename;
|
this->filename = config.filename;
|
||||||
this->grfid = config->ident.grfid;
|
this->grfid = config.ident.grfid;
|
||||||
|
|
||||||
/* Initialise local settings to defaults */
|
/* Initialise local settings to defaults */
|
||||||
this->traininfo_vehicle_pitch = 0;
|
this->traininfo_vehicle_pitch = 0;
|
||||||
|
@ -8952,7 +8952,7 @@ GRFFile::GRFFile(const GRFConfig *config)
|
||||||
this->tramtype_map[0] = ROADTYPE_TRAM;
|
this->tramtype_map[0] = ROADTYPE_TRAM;
|
||||||
|
|
||||||
/* Copy the initial parameter list */
|
/* Copy the initial parameter list */
|
||||||
this->param = config->param;
|
this->param = config.param;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9620,12 +9620,12 @@ static void DecodeSpecialSprite(uint8_t *buf, uint num, GrfLoadingStage stage)
|
||||||
* @param stage The loading stage of the NewGRF.
|
* @param stage The loading stage of the NewGRF.
|
||||||
* @param file The file to load the GRF data from.
|
* @param file The file to load the GRF data from.
|
||||||
*/
|
*/
|
||||||
static void LoadNewGRFFileFromFile(GRFConfig *config, GrfLoadingStage stage, SpriteFile &file)
|
static void LoadNewGRFFileFromFile(GRFConfig &config, GrfLoadingStage stage, SpriteFile &file)
|
||||||
{
|
{
|
||||||
_cur.file = &file;
|
_cur.file = &file;
|
||||||
_cur.grfconfig = config;
|
_cur.grfconfig = &config;
|
||||||
|
|
||||||
Debug(grf, 2, "LoadNewGRFFile: Reading NewGRF-file '{}'", config->filename);
|
Debug(grf, 2, "LoadNewGRFFile: Reading NewGRF-file '{}'", config.filename);
|
||||||
|
|
||||||
uint8_t grf_container_version = file.GetContainerVersion();
|
uint8_t grf_container_version = file.GetContainerVersion();
|
||||||
if (grf_container_version == 0) {
|
if (grf_container_version == 0) {
|
||||||
|
@ -9709,9 +9709,9 @@ static void LoadNewGRFFileFromFile(GRFConfig *config, GrfLoadingStage stage, Spr
|
||||||
* @param temporary The NewGRF/sprite file is to be loaded temporarily and should be closed immediately,
|
* @param temporary The NewGRF/sprite file is to be loaded temporarily and should be closed immediately,
|
||||||
* contrary to loading the SpriteFile and having it cached by the SpriteCache.
|
* contrary to loading the SpriteFile and having it cached by the SpriteCache.
|
||||||
*/
|
*/
|
||||||
void LoadNewGRFFile(GRFConfig *config, GrfLoadingStage stage, Subdirectory subdir, bool temporary)
|
void LoadNewGRFFile(GRFConfig &config, GrfLoadingStage stage, Subdirectory subdir, bool temporary)
|
||||||
{
|
{
|
||||||
const std::string &filename = config->filename;
|
const std::string &filename = config.filename;
|
||||||
|
|
||||||
/* A .grf file is activated only if it was active when the game was
|
/* A .grf file is activated only if it was active when the game was
|
||||||
* started. If a game is loaded, only its active .grfs will be
|
* started. If a game is loaded, only its active .grfs will be
|
||||||
|
@ -9725,11 +9725,11 @@ void LoadNewGRFFile(GRFConfig *config, GrfLoadingStage stage, Subdirectory subdi
|
||||||
if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
|
if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
|
||||||
_cur.grffile = GetFileByFilename(filename);
|
_cur.grffile = GetFileByFilename(filename);
|
||||||
if (_cur.grffile == nullptr) UserError("File '{}' lost in cache.\n", filename);
|
if (_cur.grffile == nullptr) UserError("File '{}' lost in cache.\n", filename);
|
||||||
if (stage == GLS_RESERVE && config->status != GCS_INITIALISED) return;
|
if (stage == GLS_RESERVE && config.status != GCS_INITIALISED) return;
|
||||||
if (stage == GLS_ACTIVATION && !HasBit(config->flags, GCF_RESERVED)) return;
|
if (stage == GLS_ACTIVATION && !HasBit(config.flags, GCF_RESERVED)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool needs_palette_remap = config->palette & GRFP_USE_MASK;
|
bool needs_palette_remap = config.palette & GRFP_USE_MASK;
|
||||||
if (temporary) {
|
if (temporary) {
|
||||||
SpriteFile temporarySpriteFile(filename, subdir, needs_palette_remap);
|
SpriteFile temporarySpriteFile(filename, subdir, needs_palette_remap);
|
||||||
LoadNewGRFFileFromFile(config, stage, temporarySpriteFile);
|
LoadNewGRFFileFromFile(config, stage, temporarySpriteFile);
|
||||||
|
@ -10119,7 +10119,7 @@ void LoadNewGRF(SpriteID load_index, uint num_baseset)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stage == GLS_LABELSCAN) InitNewGRFFile(c);
|
if (stage == GLS_LABELSCAN) InitNewGRFFile(*c);
|
||||||
|
|
||||||
if (!HasBit(c->flags, GCF_STATIC) && !HasBit(c->flags, GCF_SYSTEM)) {
|
if (!HasBit(c->flags, GCF_STATIC) && !HasBit(c->flags, GCF_SYSTEM)) {
|
||||||
if (num_non_static == NETWORK_MAX_GRF_COUNT) {
|
if (num_non_static == NETWORK_MAX_GRF_COUNT) {
|
||||||
|
@ -10133,7 +10133,7 @@ void LoadNewGRF(SpriteID load_index, uint num_baseset)
|
||||||
|
|
||||||
num_grfs++;
|
num_grfs++;
|
||||||
|
|
||||||
LoadNewGRFFile(c, stage, subdir, false);
|
LoadNewGRFFile(*c, stage, subdir, false);
|
||||||
if (stage == GLS_RESERVE) {
|
if (stage == GLS_RESERVE) {
|
||||||
SetBit(c->flags, GCF_RESERVED);
|
SetBit(c->flags, GCF_RESERVED);
|
||||||
} else if (stage == GLS_ACTIVATION) {
|
} else if (stage == GLS_ACTIVATION) {
|
||||||
|
|
|
@ -148,7 +148,7 @@ struct GRFFile : ZeroedMemoryAllocator {
|
||||||
uint32_t grf_features; ///< Bitset of GrfSpecFeature the grf uses
|
uint32_t grf_features; ///< Bitset of GrfSpecFeature the grf uses
|
||||||
PriceMultipliers price_base_multipliers; ///< Price base multipliers as set by the grf.
|
PriceMultipliers price_base_multipliers; ///< Price base multipliers as set by the grf.
|
||||||
|
|
||||||
GRFFile(const struct GRFConfig *config);
|
GRFFile(const struct GRFConfig &config);
|
||||||
|
|
||||||
/** Get GRF Parameter with range checking */
|
/** Get GRF Parameter with range checking */
|
||||||
uint32_t GetParam(uint number) const
|
uint32_t GetParam(uint number) const
|
||||||
|
@ -193,7 +193,7 @@ inline bool HasGrfMiscBit(GrfMiscBit bit)
|
||||||
/* Indicates which are the newgrf features currently loaded ingame */
|
/* Indicates which are the newgrf features currently loaded ingame */
|
||||||
extern GRFLoadedFeatures _loaded_newgrf_features;
|
extern GRFLoadedFeatures _loaded_newgrf_features;
|
||||||
|
|
||||||
void LoadNewGRFFile(struct GRFConfig *config, GrfLoadingStage stage, Subdirectory subdir, bool temporary);
|
void LoadNewGRFFile(struct GRFConfig &config, GrfLoadingStage stage, Subdirectory subdir, bool temporary);
|
||||||
void LoadNewGRF(SpriteID load_index, uint num_baseset);
|
void LoadNewGRF(SpriteID load_index, uint num_baseset);
|
||||||
void ReloadNewGRFData(); // in saveload/afterload.cpp
|
void ReloadNewGRFData(); // in saveload/afterload.cpp
|
||||||
void ResetNewGRFData();
|
void ResetNewGRFData();
|
||||||
|
|
|
@ -258,14 +258,14 @@ size_t GRFGetSizeOfDataSection(FileHandle &f)
|
||||||
* @param subdir The subdirectory to look in.
|
* @param subdir The subdirectory to look in.
|
||||||
* @return MD5 sum was successfully computed
|
* @return MD5 sum was successfully computed
|
||||||
*/
|
*/
|
||||||
static bool CalcGRFMD5Sum(GRFConfig *config, Subdirectory subdir)
|
static bool CalcGRFMD5Sum(GRFConfig &config, Subdirectory subdir)
|
||||||
{
|
{
|
||||||
Md5 checksum;
|
Md5 checksum;
|
||||||
uint8_t buffer[1024];
|
uint8_t buffer[1024];
|
||||||
size_t len, size;
|
size_t len, size;
|
||||||
|
|
||||||
/* open the file */
|
/* open the file */
|
||||||
auto f = FioFOpenFile(config->filename, "rb", subdir, &size);
|
auto f = FioFOpenFile(config.filename, "rb", subdir, &size);
|
||||||
if (!f.has_value()) return false;
|
if (!f.has_value()) return false;
|
||||||
|
|
||||||
long start = ftell(*f);
|
long start = ftell(*f);
|
||||||
|
@ -280,7 +280,7 @@ static bool CalcGRFMD5Sum(GRFConfig *config, Subdirectory subdir)
|
||||||
size -= len;
|
size -= len;
|
||||||
checksum.Append(buffer, len);
|
checksum.Append(buffer, len);
|
||||||
}
|
}
|
||||||
checksum.Finish(config->ident.md5sum);
|
checksum.Finish(config.ident.md5sum);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -293,27 +293,27 @@ static bool CalcGRFMD5Sum(GRFConfig *config, Subdirectory subdir)
|
||||||
* @param subdir the subdirectory to search in.
|
* @param subdir the subdirectory to search in.
|
||||||
* @return Operation was successfully completed.
|
* @return Operation was successfully completed.
|
||||||
*/
|
*/
|
||||||
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir)
|
bool FillGRFDetails(GRFConfig &config, bool is_static, Subdirectory subdir)
|
||||||
{
|
{
|
||||||
if (!FioCheckFileExists(config->filename, subdir)) {
|
if (!FioCheckFileExists(config.filename, subdir)) {
|
||||||
config->status = GCS_NOT_FOUND;
|
config.status = GCS_NOT_FOUND;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find and load the Action 8 information */
|
/* Find and load the Action 8 information */
|
||||||
LoadNewGRFFile(config, GLS_FILESCAN, subdir, true);
|
LoadNewGRFFile(config, GLS_FILESCAN, subdir, true);
|
||||||
config->SetSuitablePalette();
|
config.SetSuitablePalette();
|
||||||
config->FinalizeParameterInfo();
|
config.FinalizeParameterInfo();
|
||||||
|
|
||||||
/* Skip if the grfid is 0 (not read) or if it is an internal GRF */
|
/* Skip if the grfid is 0 (not read) or if it is an internal GRF */
|
||||||
if (config->ident.grfid == 0 || HasBit(config->flags, GCF_SYSTEM)) return false;
|
if (config.ident.grfid == 0 || HasBit(config.flags, GCF_SYSTEM)) return false;
|
||||||
|
|
||||||
if (is_static) {
|
if (is_static) {
|
||||||
/* Perform a 'safety scan' for static GRFs */
|
/* Perform a 'safety scan' for static GRFs */
|
||||||
LoadNewGRFFile(config, GLS_SAFETYSCAN, subdir, true);
|
LoadNewGRFFile(config, GLS_SAFETYSCAN, subdir, true);
|
||||||
|
|
||||||
/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */
|
/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */
|
||||||
if (HasBit(config->flags, GCF_UNSAFE)) return false;
|
if (HasBit(config.flags, GCF_UNSAFE)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CalcGRFMD5Sum(config, subdir);
|
return CalcGRFMD5Sum(config, subdir);
|
||||||
|
@ -540,7 +540,7 @@ bool GRFFileScanner::AddFile(const std::string &filename, size_t basepath_length
|
||||||
GRFConfig *c = new GRFConfig(filename.c_str() + basepath_length);
|
GRFConfig *c = new GRFConfig(filename.c_str() + basepath_length);
|
||||||
|
|
||||||
bool added = true;
|
bool added = true;
|
||||||
if (FillGRFDetails(c, false)) {
|
if (FillGRFDetails(*c, false)) {
|
||||||
if (_all_grfs == nullptr) {
|
if (_all_grfs == nullptr) {
|
||||||
_all_grfs = c;
|
_all_grfs = c;
|
||||||
} else {
|
} else {
|
||||||
|
@ -704,10 +704,10 @@ GRFConfig *GetGRFConfig(uint32_t grfid, uint32_t mask)
|
||||||
|
|
||||||
|
|
||||||
/** Build a string containing space separated parameter values, and terminate */
|
/** Build a string containing space separated parameter values, and terminate */
|
||||||
std::string GRFBuildParamList(const GRFConfig *c)
|
std::string GRFBuildParamList(const GRFConfig &c)
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
for (const uint32_t &value : c->param) {
|
for (const uint32_t &value : c.param) {
|
||||||
if (!result.empty()) result += ' ';
|
if (!result.empty()) result += ' ';
|
||||||
result += std::to_string(value);
|
result += std::to_string(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,12 +235,12 @@ void AppendToGRFConfigList(GRFConfigList &dst, GRFConfig *el);
|
||||||
void ClearGRFConfigList(GRFConfigList &config);
|
void ClearGRFConfigList(GRFConfigList &config);
|
||||||
void ResetGRFConfig(bool defaults);
|
void ResetGRFConfig(bool defaults);
|
||||||
GRFListCompatibility IsGoodGRFConfigList(GRFConfigList &grfconfig);
|
GRFListCompatibility IsGoodGRFConfigList(GRFConfigList &grfconfig);
|
||||||
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
|
bool FillGRFDetails(GRFConfig &config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
|
||||||
std::string GRFBuildParamList(const GRFConfig *c);
|
std::string GRFBuildParamList(const GRFConfig &c);
|
||||||
|
|
||||||
/* In newgrf_gui.cpp */
|
/* In newgrf_gui.cpp */
|
||||||
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfigList &config);
|
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfigList &config);
|
||||||
void OpenGRFParameterWindow(bool is_baseset, GRFConfig *c, bool editable);
|
void OpenGRFParameterWindow(bool is_baseset, GRFConfig &c, bool editable);
|
||||||
|
|
||||||
void UpdateNewGRFScanStatus(uint num, const char *name);
|
void UpdateNewGRFScanStatus(uint num, const char *name);
|
||||||
void UpdateNewGRFConfigPalette(int32_t new_value = 0);
|
void UpdateNewGRFConfigPalette(int32_t new_value = 0);
|
||||||
|
|
|
@ -68,47 +68,47 @@ void ShowNewGRFError()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ShowNewGRFInfo(const GRFConfig *c, const Rect &r, bool show_params)
|
static void ShowNewGRFInfo(const GRFConfig &c, const Rect &r, bool show_params)
|
||||||
{
|
{
|
||||||
Rect tr = r.Shrink(WidgetDimensions::scaled.frametext);
|
Rect tr = r.Shrink(WidgetDimensions::scaled.frametext);
|
||||||
if (c->error.has_value()) {
|
if (c.error.has_value()) {
|
||||||
SetDParamStr(0, c->error->custom_message); // is skipped by built-in messages
|
SetDParamStr(0, c.error->custom_message); // is skipped by built-in messages
|
||||||
SetDParamStr(1, c->filename);
|
SetDParamStr(1, c.filename);
|
||||||
SetDParamStr(2, c->error->data);
|
SetDParamStr(2, c.error->data);
|
||||||
for (uint i = 0; i < c->error->param_value.size(); i++) {
|
for (uint i = 0; i < c.error->param_value.size(); i++) {
|
||||||
SetDParam(3 + i, c->error->param_value[i]);
|
SetDParam(3 + i, c.error->param_value[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDParamStr(0, GetString(c->error->message != STR_NULL ? c->error->message : STR_JUST_RAW_STRING));
|
SetDParamStr(0, GetString(c.error->message != STR_NULL ? c.error->message : STR_JUST_RAW_STRING));
|
||||||
tr.top = DrawStringMultiLine(tr, c->error->severity);
|
tr.top = DrawStringMultiLine(tr, c.error->severity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw filename or not if it is not known (GRF sent over internet) */
|
/* Draw filename or not if it is not known (GRF sent over internet) */
|
||||||
if (!c->filename.empty()) {
|
if (!c.filename.empty()) {
|
||||||
SetDParamStr(0, c->filename);
|
SetDParamStr(0, c.filename);
|
||||||
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_FILENAME);
|
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_FILENAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare and draw GRF ID */
|
/* Prepare and draw GRF ID */
|
||||||
SetDParamStr(0, fmt::format("{:08X}", BSWAP32(c->ident.grfid)));
|
SetDParamStr(0, fmt::format("{:08X}", BSWAP32(c.ident.grfid)));
|
||||||
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_GRF_ID);
|
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_GRF_ID);
|
||||||
|
|
||||||
if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c->version != 0) {
|
if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c.version != 0) {
|
||||||
SetDParam(0, c->version);
|
SetDParam(0, c.version);
|
||||||
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_VERSION);
|
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_VERSION);
|
||||||
}
|
}
|
||||||
if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c->min_loadable_version != 0) {
|
if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c.min_loadable_version != 0) {
|
||||||
SetDParam(0, c->min_loadable_version);
|
SetDParam(0, c.min_loadable_version);
|
||||||
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_MIN_VERSION);
|
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_MIN_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare and draw MD5 sum */
|
/* Prepare and draw MD5 sum */
|
||||||
SetDParamStr(0, FormatArrayAsHex(c->ident.md5sum));
|
SetDParamStr(0, FormatArrayAsHex(c.ident.md5sum));
|
||||||
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_MD5SUM);
|
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_MD5SUM);
|
||||||
|
|
||||||
/* Show GRF parameter list */
|
/* Show GRF parameter list */
|
||||||
if (show_params) {
|
if (show_params) {
|
||||||
if (!c->param.empty()) {
|
if (!c.param.empty()) {
|
||||||
SetDParam(0, STR_JUST_RAW_STRING);
|
SetDParam(0, STR_JUST_RAW_STRING);
|
||||||
SetDParamStr(1, GRFBuildParamList(c));
|
SetDParamStr(1, GRFBuildParamList(c));
|
||||||
} else {
|
} else {
|
||||||
|
@ -117,23 +117,23 @@ static void ShowNewGRFInfo(const GRFConfig *c, const Rect &r, bool show_params)
|
||||||
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_PARAMETER);
|
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_PARAMETER);
|
||||||
|
|
||||||
/* Draw the palette of the NewGRF */
|
/* Draw the palette of the NewGRF */
|
||||||
if (c->palette & GRFP_BLT_32BPP) {
|
if (c.palette & GRFP_BLT_32BPP) {
|
||||||
SetDParam(0, (c->palette & GRFP_USE_WINDOWS) ? STR_NEWGRF_SETTINGS_PALETTE_LEGACY_32BPP : STR_NEWGRF_SETTINGS_PALETTE_DEFAULT_32BPP);
|
SetDParam(0, (c.palette & GRFP_USE_WINDOWS) ? STR_NEWGRF_SETTINGS_PALETTE_LEGACY_32BPP : STR_NEWGRF_SETTINGS_PALETTE_DEFAULT_32BPP);
|
||||||
} else {
|
} else {
|
||||||
SetDParam(0, (c->palette & GRFP_USE_WINDOWS) ? STR_NEWGRF_SETTINGS_PALETTE_LEGACY : STR_NEWGRF_SETTINGS_PALETTE_DEFAULT);
|
SetDParam(0, (c.palette & GRFP_USE_WINDOWS) ? STR_NEWGRF_SETTINGS_PALETTE_LEGACY : STR_NEWGRF_SETTINGS_PALETTE_DEFAULT);
|
||||||
}
|
}
|
||||||
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_PALETTE);
|
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_PALETTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show flags */
|
/* Show flags */
|
||||||
if (c->status == GCS_NOT_FOUND) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_NOT_FOUND);
|
if (c.status == GCS_NOT_FOUND) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_NOT_FOUND);
|
||||||
if (c->status == GCS_DISABLED) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_DISABLED);
|
if (c.status == GCS_DISABLED) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_DISABLED);
|
||||||
if (HasBit(c->flags, GCF_INVALID)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_INCOMPATIBLE);
|
if (HasBit(c.flags, GCF_INVALID)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_INCOMPATIBLE);
|
||||||
if (HasBit(c->flags, GCF_COMPATIBLE)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_COMPATIBLE_LOADED);
|
if (HasBit(c.flags, GCF_COMPATIBLE)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_COMPATIBLE_LOADED);
|
||||||
|
|
||||||
/* Draw GRF info if it exists */
|
/* Draw GRF info if it exists */
|
||||||
if (!StrEmpty(c->GetDescription())) {
|
if (!StrEmpty(c.GetDescription())) {
|
||||||
SetDParamStr(0, c->GetDescription());
|
SetDParamStr(0, c.GetDescription());
|
||||||
tr.top = DrawStringMultiLine(tr, STR_JUST_RAW_STRING, TC_BLACK);
|
tr.top = DrawStringMultiLine(tr, STR_JUST_RAW_STRING, TC_BLACK);
|
||||||
} else {
|
} else {
|
||||||
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_NO_INFO);
|
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_NO_INFO);
|
||||||
|
@ -145,7 +145,7 @@ static void ShowNewGRFInfo(const GRFConfig *c, const Rect &r, bool show_params)
|
||||||
*/
|
*/
|
||||||
struct NewGRFParametersWindow : public Window {
|
struct NewGRFParametersWindow : public Window {
|
||||||
static GRFParameterInfo dummy_parameter_info; ///< Dummy info in case a newgrf didn't provide info about some parameter.
|
static GRFParameterInfo dummy_parameter_info; ///< Dummy info in case a newgrf didn't provide info about some parameter.
|
||||||
GRFConfig *grf_config; ///< Set the parameters of this GRFConfig.
|
GRFConfig &grf_config; ///< Set the parameters of this GRFConfig.
|
||||||
int32_t clicked_button; ///< The row in which a button was clicked or INT_MAX when none is selected.
|
int32_t clicked_button; ///< The row in which a button was clicked or INT_MAX when none is selected.
|
||||||
bool clicked_increase; ///< True if the increase button was clicked, false for the decrease button.
|
bool clicked_increase; ///< True if the increase button was clicked, false for the decrease button.
|
||||||
bool clicked_dropdown; ///< Whether the dropdown is open.
|
bool clicked_dropdown; ///< Whether the dropdown is open.
|
||||||
|
@ -156,7 +156,7 @@ struct NewGRFParametersWindow : public Window {
|
||||||
bool action14present; ///< True if action14 information is present.
|
bool action14present; ///< True if action14 information is present.
|
||||||
bool editable; ///< Allow editing parameters.
|
bool editable; ///< Allow editing parameters.
|
||||||
|
|
||||||
NewGRFParametersWindow(WindowDesc &desc, bool is_baseset, GRFConfig *c, bool editable) : Window(desc),
|
NewGRFParametersWindow(WindowDesc &desc, bool is_baseset, GRFConfig &c, bool editable) : Window(desc),
|
||||||
grf_config(c),
|
grf_config(c),
|
||||||
clicked_button(INT32_MAX),
|
clicked_button(INT32_MAX),
|
||||||
clicked_dropdown(false),
|
clicked_dropdown(false),
|
||||||
|
@ -164,7 +164,7 @@ struct NewGRFParametersWindow : public Window {
|
||||||
clicked_row(INT32_MAX),
|
clicked_row(INT32_MAX),
|
||||||
editable(editable)
|
editable(editable)
|
||||||
{
|
{
|
||||||
this->action14present = (c->num_valid_params != c->param.size() || !c->param_info.empty());
|
this->action14present = (this->grf_config.num_valid_params != this->grf_config.param.size() || !this->grf_config.param_info.empty());
|
||||||
|
|
||||||
this->CreateNestedTree();
|
this->CreateNestedTree();
|
||||||
this->GetWidget<NWidgetCore>(WID_NP_CAPTION)->SetStringTip(is_baseset ? STR_BASEGRF_PARAMETERS_CAPTION : STR_NEWGRF_PARAMETERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
|
this->GetWidget<NWidgetCore>(WID_NP_CAPTION)->SetStringTip(is_baseset ? STR_BASEGRF_PARAMETERS_CAPTION : STR_NEWGRF_PARAMETERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
|
||||||
|
@ -196,7 +196,7 @@ struct NewGRFParametersWindow : public Window {
|
||||||
*/
|
*/
|
||||||
bool HasParameterInfo(uint nr) const
|
bool HasParameterInfo(uint nr) const
|
||||||
{
|
{
|
||||||
return nr < this->grf_config->param_info.size() && this->grf_config->param_info[nr].has_value();
|
return nr < this->grf_config.param_info.size() && this->grf_config.param_info[nr].has_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -207,7 +207,7 @@ struct NewGRFParametersWindow : public Window {
|
||||||
*/
|
*/
|
||||||
GRFParameterInfo &GetParameterInfo(uint nr) const
|
GRFParameterInfo &GetParameterInfo(uint nr) const
|
||||||
{
|
{
|
||||||
return this->HasParameterInfo(nr) ? this->grf_config->param_info[nr].value() : GetDummyParameterInfo(nr);
|
return this->HasParameterInfo(nr) ? this->grf_config.param_info[nr].value() : GetDummyParameterInfo(nr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
|
void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
|
||||||
|
@ -240,7 +240,7 @@ struct NewGRFParametersWindow : public Window {
|
||||||
case WID_NP_DESCRIPTION:
|
case WID_NP_DESCRIPTION:
|
||||||
/* Minimum size of 4 lines. The 500 is the default size of the window. */
|
/* Minimum size of 4 lines. The 500 is the default size of the window. */
|
||||||
Dimension suggestion = {500U - WidgetDimensions::scaled.frametext.Horizontal(), (uint)GetCharacterHeight(FS_NORMAL) * 4 + WidgetDimensions::scaled.frametext.Vertical()};
|
Dimension suggestion = {500U - WidgetDimensions::scaled.frametext.Horizontal(), (uint)GetCharacterHeight(FS_NORMAL) * 4 + WidgetDimensions::scaled.frametext.Vertical()};
|
||||||
for (const auto &par_info : this->grf_config->param_info) {
|
for (const auto &par_info : this->grf_config.param_info) {
|
||||||
if (!par_info.has_value()) continue;
|
if (!par_info.has_value()) continue;
|
||||||
const char *desc = GetGRFStringFromGRFText(par_info->desc);
|
const char *desc = GetGRFStringFromGRFText(par_info->desc);
|
||||||
if (desc == nullptr) continue;
|
if (desc == nullptr) continue;
|
||||||
|
@ -284,12 +284,12 @@ struct NewGRFParametersWindow : public Window {
|
||||||
int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2;
|
int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2;
|
||||||
for (int32_t i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
|
for (int32_t i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
|
||||||
GRFParameterInfo &par_info = this->GetParameterInfo(i);
|
GRFParameterInfo &par_info = this->GetParameterInfo(i);
|
||||||
uint32_t current_value = this->grf_config->GetValue(par_info);
|
uint32_t current_value = this->grf_config.GetValue(par_info);
|
||||||
bool selected = (i == this->clicked_row);
|
bool selected = (i == this->clicked_row);
|
||||||
|
|
||||||
if (par_info.type == PTYPE_BOOL) {
|
if (par_info.type == PTYPE_BOOL) {
|
||||||
DrawBoolButton(buttons_left, ir.top + button_y_offset, current_value != 0, this->editable);
|
DrawBoolButton(buttons_left, ir.top + button_y_offset, current_value != 0, this->editable);
|
||||||
SetDParam(2, this->grf_config->GetValue(par_info) == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
|
SetDParam(2, this->grf_config.GetValue(par_info) == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
|
||||||
} else if (par_info.type == PTYPE_UINT_ENUM) {
|
} else if (par_info.type == PTYPE_UINT_ENUM) {
|
||||||
if (par_info.complete_labels) {
|
if (par_info.complete_labels) {
|
||||||
DrawDropDownButton(buttons_left, ir.top + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && this->clicked_dropdown, this->editable);
|
DrawDropDownButton(buttons_left, ir.top + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && this->clicked_dropdown, this->editable);
|
||||||
|
@ -335,22 +335,20 @@ struct NewGRFParametersWindow : public Window {
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_NP_NUMPAR_DEC:
|
case WID_NP_NUMPAR_DEC:
|
||||||
if (this->editable && !this->action14present && !this->grf_config->param.empty()) {
|
if (this->editable && !this->action14present && !this->grf_config.param.empty()) {
|
||||||
this->grf_config->param.pop_back();
|
this->grf_config.param.pop_back();
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
|
SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_NP_NUMPAR_INC: {
|
case WID_NP_NUMPAR_INC:
|
||||||
GRFConfig *c = this->grf_config;
|
if (this->editable && !this->action14present && this->grf_config.param.size() < this->grf_config.num_valid_params) {
|
||||||
if (this->editable && !this->action14present && c->param.size() < c->num_valid_params) {
|
this->grf_config.param.emplace_back(0);
|
||||||
this->grf_config->param.emplace_back(0);
|
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
|
SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case WID_NP_BACKGROUND: {
|
case WID_NP_BACKGROUND: {
|
||||||
if (!this->editable) break;
|
if (!this->editable) break;
|
||||||
|
@ -371,7 +369,7 @@ struct NewGRFParametersWindow : public Window {
|
||||||
GRFParameterInfo &par_info = this->GetParameterInfo(num);
|
GRFParameterInfo &par_info = this->GetParameterInfo(num);
|
||||||
|
|
||||||
/* One of the arrows is clicked */
|
/* One of the arrows is clicked */
|
||||||
uint32_t old_val = this->grf_config->GetValue(par_info);
|
uint32_t old_val = this->grf_config.GetValue(par_info);
|
||||||
if (par_info.type != PTYPE_BOOL && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && par_info.complete_labels) {
|
if (par_info.type != PTYPE_BOOL && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && par_info.complete_labels) {
|
||||||
if (this->clicked_dropdown) {
|
if (this->clicked_dropdown) {
|
||||||
/* unclick the dropdown */
|
/* unclick the dropdown */
|
||||||
|
@ -416,7 +414,7 @@ struct NewGRFParametersWindow : public Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (val != old_val) {
|
if (val != old_val) {
|
||||||
this->grf_config->SetValue(par_info, val);
|
this->grf_config.SetValue(par_info, val);
|
||||||
|
|
||||||
this->clicked_button = num;
|
this->clicked_button = num;
|
||||||
this->unclick_timeout.Reset();
|
this->unclick_timeout.Reset();
|
||||||
|
@ -432,7 +430,7 @@ struct NewGRFParametersWindow : public Window {
|
||||||
|
|
||||||
case WID_NP_RESET:
|
case WID_NP_RESET:
|
||||||
if (!this->editable) break;
|
if (!this->editable) break;
|
||||||
this->grf_config->SetParameterDefaults();
|
this->grf_config.SetParameterDefaults();
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
|
SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
|
||||||
break;
|
break;
|
||||||
|
@ -448,7 +446,7 @@ struct NewGRFParametersWindow : public Window {
|
||||||
if (!str.has_value() || str->empty()) return;
|
if (!str.has_value() || str->empty()) return;
|
||||||
int32_t value = atoi(str->c_str());
|
int32_t value = atoi(str->c_str());
|
||||||
GRFParameterInfo &par_info = this->GetParameterInfo(this->clicked_row);
|
GRFParameterInfo &par_info = this->GetParameterInfo(this->clicked_row);
|
||||||
this->grf_config->SetValue(par_info, value);
|
this->grf_config.SetValue(par_info, value);
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,7 +455,7 @@ struct NewGRFParametersWindow : public Window {
|
||||||
if (widget != WID_NP_SETTING_DROPDOWN) return;
|
if (widget != WID_NP_SETTING_DROPDOWN) return;
|
||||||
assert(this->clicked_dropdown);
|
assert(this->clicked_dropdown);
|
||||||
GRFParameterInfo &par_info = this->GetParameterInfo(this->clicked_row);
|
GRFParameterInfo &par_info = this->GetParameterInfo(this->clicked_row);
|
||||||
this->grf_config->SetValue(par_info, index);
|
this->grf_config.SetValue(par_info, index);
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,11 +485,11 @@ struct NewGRFParametersWindow : public Window {
|
||||||
{
|
{
|
||||||
if (!gui_scope) return;
|
if (!gui_scope) return;
|
||||||
if (!this->action14present) {
|
if (!this->action14present) {
|
||||||
this->SetWidgetDisabledState(WID_NP_NUMPAR_DEC, !this->editable || this->grf_config->param.empty());
|
this->SetWidgetDisabledState(WID_NP_NUMPAR_DEC, !this->editable || this->grf_config.param.empty());
|
||||||
this->SetWidgetDisabledState(WID_NP_NUMPAR_INC, !this->editable || std::size(this->grf_config->param) >= this->grf_config->num_valid_params);
|
this->SetWidgetDisabledState(WID_NP_NUMPAR_INC, !this->editable || std::size(this->grf_config.param) >= this->grf_config.num_valid_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->vscroll->SetCount(this->action14present ? this->grf_config->num_valid_params : GRFConfig::MAX_NUM_PARAMS);
|
this->vscroll->SetCount(this->action14present ? this->grf_config.num_valid_params : GRFConfig::MAX_NUM_PARAMS);
|
||||||
if (this->clicked_row != INT32_MAX && this->clicked_row >= this->vscroll->GetCount()) {
|
if (this->clicked_row != INT32_MAX && this->clicked_row >= this->vscroll->GetCount()) {
|
||||||
this->clicked_row = INT32_MAX;
|
this->clicked_row = INT32_MAX;
|
||||||
this->CloseChildWindows(WC_QUERY_STRING);
|
this->CloseChildWindows(WC_QUERY_STRING);
|
||||||
|
@ -547,7 +545,7 @@ static WindowDesc _newgrf_parameters_desc(
|
||||||
_nested_newgrf_parameter_widgets
|
_nested_newgrf_parameter_widgets
|
||||||
);
|
);
|
||||||
|
|
||||||
void OpenGRFParameterWindow(bool is_baseset, GRFConfig *c, bool editable)
|
void OpenGRFParameterWindow(bool is_baseset, GRFConfig &c, bool editable)
|
||||||
{
|
{
|
||||||
CloseWindowByClass(WC_GRF_PARAMETERS);
|
CloseWindowByClass(WC_GRF_PARAMETERS);
|
||||||
new NewGRFParametersWindow(_newgrf_parameters_desc, is_baseset, c, editable);
|
new NewGRFParametersWindow(_newgrf_parameters_desc, is_baseset, c, editable);
|
||||||
|
@ -818,12 +816,12 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
* @param c grf to display.
|
* @param c grf to display.
|
||||||
* @return Palette for the sprite.
|
* @return Palette for the sprite.
|
||||||
*/
|
*/
|
||||||
inline PaletteID GetPalette(const GRFConfig *c) const
|
inline PaletteID GetPalette(const GRFConfig &c) const
|
||||||
{
|
{
|
||||||
PaletteID pal;
|
PaletteID pal;
|
||||||
|
|
||||||
/* Pick a colour */
|
/* Pick a colour */
|
||||||
switch (c->status) {
|
switch (c.status) {
|
||||||
case GCS_NOT_FOUND:
|
case GCS_NOT_FOUND:
|
||||||
case GCS_DISABLED:
|
case GCS_DISABLED:
|
||||||
pal = PALETTE_TO_RED;
|
pal = PALETTE_TO_RED;
|
||||||
|
@ -838,9 +836,9 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
|
|
||||||
/* Do not show a "not-failure" colour when it actually failed to load */
|
/* Do not show a "not-failure" colour when it actually failed to load */
|
||||||
if (pal != PALETTE_TO_RED) {
|
if (pal != PALETTE_TO_RED) {
|
||||||
if (HasBit(c->flags, GCF_STATIC)) {
|
if (HasBit(c.flags, GCF_STATIC)) {
|
||||||
pal = PALETTE_TO_GREY;
|
pal = PALETTE_TO_GREY;
|
||||||
} else if (HasBit(c->flags, GCF_COMPATIBLE)) {
|
} else if (HasBit(c.flags, GCF_COMPATIBLE)) {
|
||||||
pal = PALETTE_TO_ORANGE;
|
pal = PALETTE_TO_ORANGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -874,7 +872,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
if (this->vscroll->IsVisible(i)) {
|
if (this->vscroll->IsVisible(i)) {
|
||||||
const char *text = c->GetName();
|
const char *text = c->GetName();
|
||||||
bool h = (this->active_sel == c);
|
bool h = (this->active_sel == c);
|
||||||
PaletteID pal = this->GetPalette(c);
|
PaletteID pal = this->GetPalette(*c);
|
||||||
|
|
||||||
if (h) {
|
if (h) {
|
||||||
GfxFillRect(br.left, tr.top, br.right, tr.top + step_height - 1, PC_DARK_BLUE);
|
GfxFillRect(br.left, tr.top, br.right, tr.top + step_height - 1, PC_DARK_BLUE);
|
||||||
|
@ -932,7 +930,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
const GRFConfig *selected = this->active_sel;
|
const GRFConfig *selected = this->active_sel;
|
||||||
if (selected == nullptr) selected = this->avail_sel;
|
if (selected == nullptr) selected = this->avail_sel;
|
||||||
if (selected != nullptr) {
|
if (selected != nullptr) {
|
||||||
ShowNewGRFInfo(selected, r, this->show_params);
|
ShowNewGRFInfo(*selected, r, this->show_params);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1134,7 +1132,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
case WID_NS_SET_PARAMETERS: { // Edit parameters
|
case WID_NS_SET_PARAMETERS: { // Edit parameters
|
||||||
if (this->active_sel == nullptr || !this->show_params || this->active_sel->num_valid_params == 0) break;
|
if (this->active_sel == nullptr || !this->show_params || this->active_sel->num_valid_params == 0) break;
|
||||||
|
|
||||||
OpenGRFParameterWindow(false, this->active_sel, this->editable);
|
OpenGRFParameterWindow(false, *this->active_sel, this->editable);
|
||||||
this->InvalidateData(GOID_NEWGRF_CHANGES_MADE);
|
this->InvalidateData(GOID_NEWGRF_CHANGES_MADE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1108,7 +1108,7 @@ static GRFConfig *GRFLoadConfig(const IniFile &ini, const char *grpname, bool is
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if item is valid */
|
/* Check if item is valid */
|
||||||
if (!FillGRFDetails(c, is_static) || HasBit(c->flags, GCF_INVALID)) {
|
if (!FillGRFDetails(*c, is_static) || HasBit(c->flags, GCF_INVALID)) {
|
||||||
if (c->status == GCS_NOT_FOUND) {
|
if (c->status == GCS_NOT_FOUND) {
|
||||||
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
|
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
|
||||||
} else if (HasBit(c->flags, GCF_UNSAFE)) {
|
} else if (HasBit(c->flags, GCF_UNSAFE)) {
|
||||||
|
@ -1242,7 +1242,7 @@ static void GraphicsSetSaveConfig(IniFile &ini)
|
||||||
const GRFConfig *extra_cfg = used_set->GetExtraConfig();
|
const GRFConfig *extra_cfg = used_set->GetExtraConfig();
|
||||||
if (extra_cfg != nullptr && !extra_cfg->param.empty()) {
|
if (extra_cfg != nullptr && !extra_cfg->param.empty()) {
|
||||||
group.GetOrCreateItem("extra_version").SetValue(fmt::format("{}", extra_cfg->version));
|
group.GetOrCreateItem("extra_version").SetValue(fmt::format("{}", extra_cfg->version));
|
||||||
group.GetOrCreateItem("extra_params").SetValue(GRFBuildParamList(extra_cfg));
|
group.GetOrCreateItem("extra_params").SetValue(GRFBuildParamList(*extra_cfg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1256,7 +1256,7 @@ static void GRFSaveConfig(IniFile &ini, const char *grpname, const GRFConfig *li
|
||||||
for (c = list; c != nullptr; c = c->next) {
|
for (c = list; c != nullptr; c = c->next) {
|
||||||
std::string key = fmt::format("{:08X}|{}|{}", BSWAP32(c->ident.grfid),
|
std::string key = fmt::format("{:08X}|{}|{}", BSWAP32(c->ident.grfid),
|
||||||
FormatArrayAsHex(c->ident.md5sum), c->filename);
|
FormatArrayAsHex(c->ident.md5sum), c->filename);
|
||||||
group.GetOrCreateItem(key).SetValue(GRFBuildParamList(c));
|
group.GetOrCreateItem(key).SetValue(GRFBuildParamList(*c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -815,7 +815,7 @@ struct GameOptionsWindow : Window {
|
||||||
if (used_set == nullptr || !used_set->IsConfigurable()) break;
|
if (used_set == nullptr || !used_set->IsConfigurable()) break;
|
||||||
GRFConfig &extra_cfg = used_set->GetOrCreateExtraConfig();
|
GRFConfig &extra_cfg = used_set->GetOrCreateExtraConfig();
|
||||||
if (extra_cfg.param.empty()) extra_cfg.SetParameterDefaults();
|
if (extra_cfg.param.empty()) extra_cfg.SetParameterDefaults();
|
||||||
OpenGRFParameterWindow(true, &extra_cfg, _game_mode == GM_MENU);
|
OpenGRFParameterWindow(true, extra_cfg, _game_mode == GM_MENU);
|
||||||
if (_game_mode == GM_MENU) this->reload = true;
|
if (_game_mode == GM_MENU) this->reload = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue