mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Return name, description and URL as std::string from GRFConfig. (#13868)
parent
ae2d7947d7
commit
667d013726
|
@ -262,8 +262,8 @@ public:
|
|||
}
|
||||
|
||||
/* NewGRF name */
|
||||
if (td.grf != nullptr) {
|
||||
this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_NEWGRF_NAME, td.grf));
|
||||
if (td.grf.has_value()) {
|
||||
this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_NEWGRF_NAME, std::move(*td.grf)));
|
||||
}
|
||||
|
||||
/* Cargo acceptance is displayed in a extra multiline */
|
||||
|
|
|
@ -82,28 +82,32 @@ void GRFConfig::CopyParams(const GRFConfig &src)
|
|||
* the filename is returned.
|
||||
* @return The name of filename of this grf.
|
||||
*/
|
||||
const char *GRFConfig::GetName() const
|
||||
std::string GRFConfig::GetName() const
|
||||
{
|
||||
const char *name = GetGRFStringFromGRFText(this->name);
|
||||
return StrEmpty(name) ? this->filename.c_str() : name;
|
||||
return StrEmpty(name) ? this->filename : name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the grf info.
|
||||
* @return A string with a description of this grf.
|
||||
*/
|
||||
const char *GRFConfig::GetDescription() const
|
||||
std::optional<std::string> GRFConfig::GetDescription() const
|
||||
{
|
||||
return GetGRFStringFromGRFText(this->info);
|
||||
const char *str = GetGRFStringFromGRFText(this->info);
|
||||
if (StrEmpty(str)) return std::nullopt;
|
||||
return std::string(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the grf url.
|
||||
* @return A string with an url of this grf.
|
||||
*/
|
||||
const char *GRFConfig::GetURL() const
|
||||
std::optional<std::string> GRFConfig::GetURL() const
|
||||
{
|
||||
return GetGRFStringFromGRFText(this->url);
|
||||
const char *str = GetGRFStringFromGRFText(this->url);
|
||||
if (StrEmpty(str)) return std::nullopt;
|
||||
return std::string(str);
|
||||
}
|
||||
|
||||
/** Set the default value for all parameters as specified by action14. */
|
||||
|
|
|
@ -190,9 +190,9 @@ struct GRFConfig {
|
|||
void SetValue(const GRFParameterInfo &info, uint32_t value);
|
||||
|
||||
std::optional<std::string> GetTextfile(TextfileType type) const;
|
||||
const char *GetName() const;
|
||||
const char *GetDescription() const;
|
||||
const char *GetURL() const;
|
||||
std::string GetName() const;
|
||||
std::optional<std::string> GetDescription() const;
|
||||
std::optional<std::string> GetURL() const;
|
||||
|
||||
void SetParameterDefaults();
|
||||
void SetSuitablePalette();
|
||||
|
|
|
@ -128,8 +128,8 @@ static void ShowNewGRFInfo(const GRFConfig &c, const Rect &r, bool show_params)
|
|||
if (c.flags.Test(GRFConfigFlag::Compatible)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_COMPATIBLE_LOADED);
|
||||
|
||||
/* Draw GRF info if it exists */
|
||||
if (!StrEmpty(c.GetDescription())) {
|
||||
tr.top = DrawStringMultiLine(tr, GetString(STR_JUST_RAW_STRING, c.GetDescription()), TC_BLACK);
|
||||
if (auto desc = c.GetDescription(); desc.has_value()) {
|
||||
tr.top = DrawStringMultiLine(tr, GetString(STR_JUST_RAW_STRING, std::move(*desc)), TC_BLACK);
|
||||
} else {
|
||||
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_NO_INFO);
|
||||
}
|
||||
|
@ -854,7 +854,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
|||
int i = 0;
|
||||
for (const auto &c : this->actives) {
|
||||
if (this->vscroll->IsVisible(i)) {
|
||||
const char *text = c->GetName();
|
||||
std::string text = c->GetName();
|
||||
bool h = (this->active_sel == c.get());
|
||||
PaletteID pal = this->GetPalette(*c);
|
||||
|
||||
|
@ -871,7 +871,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
|||
DrawSprite(SPR_SQUARE, pal, square_left, tr.top + square_offset_y);
|
||||
if (c->error.has_value()) DrawSprite(SPR_WARNING_SIGN, 0, warning_left, tr.top + warning_offset_y);
|
||||
uint txtoffset = !c->error.has_value() ? 0 : warning.width;
|
||||
DrawString(text_left + (rtl ? 0 : txtoffset), text_right - (rtl ? txtoffset : 0), tr.top + offset_y, text, h ? TC_WHITE : TC_ORANGE);
|
||||
DrawString(text_left + (rtl ? 0 : txtoffset), text_right - (rtl ? txtoffset : 0), tr.top + offset_y, std::move(text), h ? TC_WHITE : TC_ORANGE);
|
||||
tr.top += step_height;
|
||||
}
|
||||
i++;
|
||||
|
@ -894,10 +894,10 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
|||
for (auto it = first; it != last; ++it) {
|
||||
const GRFConfig *c = *it;
|
||||
bool h = (c == this->avail_sel);
|
||||
const char *text = c->GetName();
|
||||
std::string text = c->GetName();
|
||||
|
||||
if (h) GfxFillRect(br.left, tr.top, br.right, tr.top + step_height - 1, PC_DARK_BLUE);
|
||||
DrawString(tr.left, tr.right, tr.top + offset_y, text, h ? TC_WHITE : TC_SILVER);
|
||||
DrawString(tr.left, tr.right, tr.top + offset_y, std::move(text), h ? TC_WHITE : TC_SILVER);
|
||||
tr.top += step_height;
|
||||
}
|
||||
break;
|
||||
|
@ -948,8 +948,8 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
|||
|
||||
case WID_NS_OPEN_URL: {
|
||||
const GRFConfig *c = (this->avail_sel == nullptr) ? this->active_sel : this->avail_sel;
|
||||
|
||||
OpenBrowser(c->GetURL());
|
||||
auto url = c->GetURL();
|
||||
if (url.has_value()) OpenBrowser(std::move(*url));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1263,7 +1263,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
|||
for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
|
||||
this->SetWidgetDisabledState(WID_NS_NEWGRF_TEXTFILE + tft, selected_config == nullptr || !selected_config->GetTextfile(tft).has_value());
|
||||
}
|
||||
this->SetWidgetDisabledState(WID_NS_OPEN_URL, selected_config == nullptr || StrEmpty(selected_config->GetURL()));
|
||||
this->SetWidgetDisabledState(WID_NS_OPEN_URL, selected_config == nullptr || !selected_config->GetURL().has_value());
|
||||
|
||||
this->SetWidgetDisabledState(WID_NS_SET_PARAMETERS, !this->show_params || this->active_sel == nullptr || this->active_sel->num_valid_params == 0);
|
||||
this->SetWidgetDisabledState(WID_NS_VIEW_PARAMETERS, !this->show_params || this->active_sel == nullptr || this->active_sel->num_valid_params == 0);
|
||||
|
@ -1413,7 +1413,7 @@ private:
|
|||
filter.ResetState();
|
||||
filter.AddLine((*a)->GetName());
|
||||
filter.AddLine((*a)->filename);
|
||||
filter.AddLine((*a)->GetDescription());
|
||||
if (auto desc = (*a)->GetDescription(); desc.has_value()) filter.AddLine(*desc);
|
||||
return filter.GetState();;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ struct TileDesc {
|
|||
StringID airport_class{}; ///< Name of the airport class
|
||||
StringID airport_name{}; ///< Name of the airport
|
||||
StringID airport_tile_name{}; ///< Name of the airport tile
|
||||
const char *grf = nullptr; ///< newGRF used for the tile contents
|
||||
std::optional<std::string> grf = std::nullopt; ///< newGRF used for the tile contents
|
||||
StringID railtype{}; ///< Type of rail on the tile.
|
||||
uint16_t rail_speed = 0; ///< Speed limit of rail (bridges and track)
|
||||
StringID roadtype{}; ///< Type of road on the tile.
|
||||
|
|
Loading…
Reference in New Issue