diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index d7322da9ca..0be10062b6 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -161,10 +161,10 @@ public: virtual const void *GetSpec(uint index) const = 0; /** - * Set the string parameters to write the right data for a STRINGn. - * @param index the index to get the string parameters for. + * Get the name of this item. + * @param index the index to get the name for. */ - virtual void SetStringParameters(uint index) const = 0; + virtual std::string GetName(uint index) const = 0; /** * Get the GRFID of the file that includes this item. @@ -209,38 +209,6 @@ public: { return {}; } - -protected: - /** - * Helper to make setting the strings easier. - * @param string the string to actually draw. - * @param index the (instance) index for the string. - */ - void SetSimpleStringParameters(StringID string, uint32_t index) const - { - SetDParam(0, string); - SetDParam(1, index); - } - - - /** - * Helper to make setting the strings easier for objects at a specific tile. - * @param string the string to draw the object's name - * @param index the (instance) index for the string. - * @param tile the tile the object is at - */ - void SetObjectAtStringParameters(StringID string, uint32_t index, TileIndex tile) const - { - SetDParam(0, STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT); - SetDParam(1, string); - SetDParam(2, index); - SetDParam(3, tile); - } - - void SetObjectAtStringParameters(StringID string, ConvertibleThroughBase auto index, TileIndex tile) const - { - this->SetObjectAtStringParameters(string, index.base(), tile); - } }; @@ -374,11 +342,11 @@ struct NewGRFInspectWindow : Window { this->OnInvalidateData(0, true); } - void SetStringParameters(WidgetID widget) const override + std::string GetWidgetString(WidgetID widget, StringID stringid) const override { - if (widget != WID_NGRFI_CAPTION) return; + if (widget != WID_NGRFI_CAPTION) return this->Window::GetWidgetString(widget, stringid); - GetFeatureHelper(this->window_number).SetStringParameters(this->GetFeatureIndex()); + return GetFeatureHelper(this->window_number).GetName(this->GetFeatureIndex()); } void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override @@ -877,33 +845,33 @@ struct SpriteAlignerWindow : Window { this->InvalidateData(0, true); } - void SetStringParameters(WidgetID widget) const override + std::string GetWidgetString(WidgetID widget, StringID stringid) const override { const Sprite *spr = GetSprite(this->current_sprite, SpriteType::Normal); switch (widget) { case WID_SA_CAPTION: if (this->act5_type != nullptr) { - SetDParam(0, STR_SPRITE_ALIGNER_CAPTION_ACTION5); - SetDParam(1, this->act5_type - GetAction5Types().data()); - SetDParam(2, this->current_sprite - this->act5_type->sprite_base); - SetDParamStr(3, GetOriginFile(this->current_sprite)->GetSimplifiedFilename()); - SetDParam(4, GetSpriteLocalID(this->current_sprite)); - } else if (this->current_sprite < SPR_OPENTTD_BASE) { - SetDParam(0, STR_SPRITE_ALIGNER_CAPTION_ACTIONA); - SetDParam(1, this->current_sprite); - SetDParamStr(2, GetOriginFile(this->current_sprite)->GetSimplifiedFilename()); - SetDParam(3, GetSpriteLocalID(this->current_sprite)); - } else { - SetDParam(0, STR_SPRITE_ALIGNER_CAPTION_NO_ACTION); - SetDParamStr(1, GetOriginFile(this->current_sprite)->GetSimplifiedFilename()); - SetDParam(2, GetSpriteLocalID(this->current_sprite)); + return GetString(stringid, + STR_SPRITE_ALIGNER_CAPTION_ACTION5, + this->act5_type - GetAction5Types().data(), + this->current_sprite - this->act5_type->sprite_base, + GetOriginFile(this->current_sprite)->GetSimplifiedFilename(), + GetSpriteLocalID(this->current_sprite)); } - break; + if (this->current_sprite < SPR_OPENTTD_BASE) { + return GetString(stringid, + STR_SPRITE_ALIGNER_CAPTION_ACTIONA, + this->current_sprite, + GetOriginFile(this->current_sprite)->GetSimplifiedFilename(), + GetSpriteLocalID(this->current_sprite)); + } + return GetString(stringid, + STR_SPRITE_ALIGNER_CAPTION_NO_ACTION, + GetOriginFile(this->current_sprite)->GetSimplifiedFilename(), + GetSpriteLocalID(this->current_sprite)); case WID_SA_OFFSETS_ABS: - SetDParam(0, UnScaleByZoom(spr->x_offs, SpriteAlignerWindow::zoom)); - SetDParam(1, UnScaleByZoom(spr->y_offs, SpriteAlignerWindow::zoom)); - break; + return GetString(stringid, UnScaleByZoom(spr->x_offs, SpriteAlignerWindow::zoom), UnScaleByZoom(spr->y_offs, SpriteAlignerWindow::zoom)); case WID_SA_OFFSETS_REL: { /* Relative offset is new absolute offset - starting absolute offset. @@ -911,17 +879,16 @@ struct SpriteAlignerWindow : Window { */ const auto key_offs_pair = this->offs_start_map.find(this->current_sprite); if (key_offs_pair != this->offs_start_map.end()) { - SetDParam(0, UnScaleByZoom(spr->x_offs - key_offs_pair->second.first, SpriteAlignerWindow::zoom)); - SetDParam(1, UnScaleByZoom(spr->y_offs - key_offs_pair->second.second, SpriteAlignerWindow::zoom)); - } else { - SetDParam(0, 0); - SetDParam(1, 0); + return GetString(stringid, + UnScaleByZoom(spr->x_offs - key_offs_pair->second.first, SpriteAlignerWindow::zoom), + UnScaleByZoom(spr->y_offs - key_offs_pair->second.second, SpriteAlignerWindow::zoom)); } - break; + + return GetString(stringid, 0, 0); } default: - break; + return this->Window::GetWidgetString(widget, stringid); } } diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index df09ac84fe..b083758506 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -70,7 +70,7 @@ class NIHVehicle : public NIHelper { uint GetParent(uint index) const override { const Vehicle *first = Vehicle::Get(index)->First(); return GetInspectWindowNumber(GetGrfSpecFeature(first->type), first->index); } const void *GetInstance(uint index)const override { return Vehicle::Get(index); } const void *GetSpec(uint index) const override { return Vehicle::Get(index)->GetEngine(); } - void SetStringParameters(uint index) const override { this->SetSimpleStringParameters(STR_VEHICLE_NAME, index); } + std::string GetName(uint index) const override { return GetString(STR_VEHICLE_NAME, index); } uint32_t GetGRFID(uint index) const override { return Vehicle::Get(index)->GetGRFID(); } std::span GetBadges(uint index) const override { return Vehicle::Get(index)->GetEngine()->badges; } @@ -134,7 +134,7 @@ class NIHStation : public NIHelper { uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Station::GetByTile(TileIndex{index})->town->index); } const void *GetInstance(uint ) const override { return nullptr; } const void *GetSpec(uint index) const override { return GetStationSpec(TileIndex{index}); } - void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), TileIndex{index}); } + std::string GetName(uint index) const override { return GetString(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT, STR_STATION_NAME, GetStationIndex(index), index); } uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetStationSpec(TileIndex{index})->grf_prop.grfid : 0; } std::span GetBadges(uint index) const override { return this->IsInspectable(index) ? GetStationSpec(TileIndex{index})->badges : std::span{}; } @@ -199,7 +199,7 @@ class NIHHouse : public NIHelper { uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, GetTownIndex(index)); } const void *GetInstance(uint)const override { return nullptr; } const void *GetSpec(uint index) const override { return HouseSpec::Get(GetHouseType(index)); } - void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_TOWN_NAME, GetTownIndex(index), TileIndex{index}); } + std::string GetName(uint index) const override { return GetString(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT, STR_TOWN_NAME, GetTownIndex(index), index); } uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? HouseSpec::Get(GetHouseType(index))->grf_prop.grfid : 0; } std::span GetBadges(uint index) const override { return HouseSpec::Get(GetHouseType(index))->badges; } @@ -249,7 +249,7 @@ class NIHIndustryTile : public NIHelper { uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_INDUSTRIES, GetIndustryIndex(index)); } const void *GetInstance(uint)const override { return nullptr; } const void *GetSpec(uint index) const override { return GetIndustryTileSpec(GetIndustryGfx(index)); } - void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_INDUSTRY_NAME, GetIndustryIndex(index), TileIndex{index}); } + std::string GetName(uint index) const override { return GetString(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT, STR_INDUSTRY_NAME, GetIndustryIndex(index), index); } uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetIndustryTileSpec(GetIndustryGfx(index))->grf_prop.grfid : 0; } std::span GetBadges(uint index) const override { return GetIndustryTileSpec(GetIndustryGfx(index))->badges; } @@ -361,7 +361,7 @@ class NIHIndustry : public NIHelper { uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Industry::Get(index)->town->index); } const void *GetInstance(uint index)const override { return Industry::Get(index); } const void *GetSpec(uint index) const override { return GetIndustrySpec(Industry::Get(index)->type); } - void SetStringParameters(uint index) const override { this->SetSimpleStringParameters(STR_INDUSTRY_NAME, index); } + std::string GetName(uint index) const override { return GetString(STR_INDUSTRY_NAME, index); } uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetIndustrySpec(Industry::Get(index)->type)->grf_prop.grfid : 0; } std::span GetBadges(uint index) const override { return GetIndustrySpec(Industry::Get(index)->type)->badges; } @@ -423,7 +423,7 @@ class NIHObject : public NIHelper { uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Object::GetByTile(TileIndex{index})->town->index); } const void *GetInstance(uint index)const override { return Object::GetByTile(TileIndex{index}); } const void *GetSpec(uint index) const override { return ObjectSpec::GetByTile(TileIndex{index}); } - void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_OBJECT, INVALID_STRING_ID, TileIndex{index}); } + std::string GetName(uint index) const override { return GetString(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT, STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_OBJECT, INVALID_STRING_ID, index); } uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? ObjectSpec::GetByTile(TileIndex{index})->grf_prop.grfid : 0; } std::span GetBadges(uint index) const override { return ObjectSpec::GetByTile(TileIndex{index})->badges; } @@ -458,7 +458,7 @@ class NIHRailType : public NIHelper { uint GetParent(uint) const override { return UINT32_MAX; } const void *GetInstance(uint) const override { return nullptr; } const void *GetSpec(uint) const override { return nullptr; } - void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_RAIL_TYPE, INVALID_STRING_ID, TileIndex{index}); } + std::string GetName(uint index) const override { return GetString(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT, STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_RAIL_TYPE, INVALID_STRING_ID, index); } uint32_t GetGRFID(uint) const override { return 0; } std::span GetBadges(uint index) const override { return GetRailTypeInfo(GetRailType(TileIndex{index}))->badges; } @@ -494,7 +494,7 @@ class NIHAirportTile : public NIHelper { uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_AIRPORTS, GetStationIndex(index)); } const void *GetInstance(uint)const override { return nullptr; } const void *GetSpec(uint index) const override { return AirportTileSpec::Get(GetAirportGfx(index)); } - void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), TileIndex{index}); } + std::string GetName(uint index) const override { return GetString(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT, STR_STATION_NAME, GetStationIndex(index), index); } uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? AirportTileSpec::Get(GetAirportGfx(index))->grf_prop.grfid : 0; } std::span GetBadges(uint index) const override { return AirportTileSpec::Get(GetAirportGfx(index))->badges; } @@ -536,7 +536,7 @@ class NIHAirport : public NIHelper { uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Station::Get(index)->town->index); } const void *GetInstance(uint index)const override { return Station::Get(index); } const void *GetSpec(uint index) const override { return AirportSpec::Get(Station::Get(index)->airport.type); } - void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, index, Station::Get(index)->airport.tile); } + std::string GetName(uint index) const override { return GetString(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT, STR_STATION_NAME, index, Station::Get(index)->airport.tile); } uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? AirportSpec::Get(Station::Get(index)->airport.type)->grf_prop.grfid : 0; } std::span GetBadges(uint index) const override { return AirportSpec::Get(Station::Get(index)->airport.type)->badges; } @@ -582,7 +582,7 @@ class NIHTown : public NIHelper { uint GetParent(uint) const override { return UINT32_MAX; } const void *GetInstance(uint index)const override { return Town::Get(index); } const void *GetSpec(uint) const override { return nullptr; } - void SetStringParameters(uint index) const override { this->SetSimpleStringParameters(STR_TOWN_NAME, index); } + std::string GetName(uint index) const override { return GetString(STR_TOWN_NAME, index); } uint32_t GetGRFID(uint) const override { return 0; } bool PSAWithParameter() const override { return true; } std::span GetBadges(uint) const override { return {}; } @@ -628,7 +628,7 @@ class NIHRoadType : public NIHelper { uint GetParent(uint) const override { return UINT32_MAX; } const void *GetInstance(uint) const override { return nullptr; } const void *GetSpec(uint) const override { return nullptr; } - void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_ROAD_TYPE, INVALID_STRING_ID, TileIndex{index}); } + std::string GetName(uint index) const override { return GetString(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT, STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_ROAD_TYPE, INVALID_STRING_ID, index); } uint32_t GetGRFID(uint) const override { return 0; } std::span GetBadges(uint index) const override { @@ -698,7 +698,7 @@ class NIHRoadStop : public NIHelper { uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, BaseStation::GetByTile(TileIndex{index})->town->index); } const void *GetInstance(uint)const override { return nullptr; } const void *GetSpec(uint index) const override { return GetRoadStopSpec(TileIndex{index}); } - void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), TileIndex{index}); } + std::string GetName(uint index) const override { return GetString(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT, STR_STATION_NAME, GetStationIndex(index), index); } uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetRoadStopSpec(TileIndex{index})->grf_prop.grfid : 0; } std::span GetBadges(uint index) const override { return this->IsInspectable(index) ? GetRoadStopSpec(TileIndex{index})->badges : std::span{}; }