mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-08 23:34:15 +00:00
(svn r24162) -Codechange: Remove NewGRFClass::GetName() and SetName() in favour of using Get() and direct member access (which is needed anyway for GRF string resolving).
This commit is contained in:
parent
73d926c8d4
commit
6f4d2160c2
@ -208,7 +208,7 @@ class BuildAirportWindow : public PickerWindowBase {
|
||||
DropDownList *list = new DropDownList();
|
||||
|
||||
for (uint i = 0; i < AirportClass::GetCount(); i++) {
|
||||
list->push_back(new DropDownListStringItem(AirportClass::GetName((AirportClassID)i), i, false));
|
||||
list->push_back(new DropDownListStringItem(AirportClass::Get((AirportClassID)i)->name, i, false));
|
||||
}
|
||||
|
||||
return list;
|
||||
@ -242,7 +242,7 @@ public:
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_AP_CLASS_DROPDOWN:
|
||||
SetDParam(0, AirportClass::GetName(_selected_airport_class));
|
||||
SetDParam(0, AirportClass::Get(_selected_airport_class)->name);
|
||||
break;
|
||||
|
||||
case WID_AP_LAYOUT_NUM:
|
||||
@ -269,7 +269,7 @@ public:
|
||||
case WID_AP_CLASS_DROPDOWN: {
|
||||
Dimension d = {0, 0};
|
||||
for (uint i = 0; i < AirportClass::GetCount(); i++) {
|
||||
SetDParam(0, AirportClass::GetName((AirportClassID)i));
|
||||
SetDParam(0, AirportClass::Get((AirportClassID)i)->name);
|
||||
d = maxdim(d, GetStringBoundingBox(STR_BLACK_STRING));
|
||||
}
|
||||
d.width += padding.width;
|
||||
|
@ -3809,8 +3809,9 @@ static ChangeInfoResult ObjectChangeInfo(uint id, int numinfo, int prop, ByteRea
|
||||
|
||||
case 0x09: { // Class name
|
||||
StringID class_name = buf->ReadWord();
|
||||
ObjectClass::SetName(spec->cls_id, class_name);
|
||||
_string_to_grf_mapping[&ObjectClass::classes[spec->cls_id].name] = _cur.grffile->grfid;
|
||||
ObjectClass *objclass = ObjectClass::Get(spec->cls_id);
|
||||
objclass->name = class_name;
|
||||
_string_to_grf_mapping[&objclass->name] = _cur.grffile->grfid;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -5351,7 +5352,7 @@ static void FeatureNewName(ByteReader *buf)
|
||||
grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
|
||||
} else {
|
||||
StationClassID cls_id = _cur.grffile->stations[GB(id, 0, 8)]->cls_id;
|
||||
StationClass::SetName(cls_id, AddGRFString(_cur.grffile->grfid, id, lang, new_scheme, false, name, STR_UNDEFINED));
|
||||
StationClass::Get(cls_id)->name = AddGRFString(_cur.grffile->grfid, id, lang, new_scheme, false, name, STR_UNDEFINED);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -25,10 +25,10 @@
|
||||
template <typename Tspec, typename Tid, Tid Tmax>
|
||||
/* static */ void NewGRFClass<Tspec, Tid, Tmax>::InsertDefaults()
|
||||
{
|
||||
AirportClass::SetName(AirportClass::Allocate('SMAL'), STR_AIRPORT_CLASS_SMALL);
|
||||
AirportClass::SetName(AirportClass::Allocate('LARG'), STR_AIRPORT_CLASS_LARGE);
|
||||
AirportClass::SetName(AirportClass::Allocate('HUB_'), STR_AIRPORT_CLASS_HUB);
|
||||
AirportClass::SetName(AirportClass::Allocate('HELI'), STR_AIRPORT_CLASS_HELIPORTS);
|
||||
AirportClass::Get(AirportClass::Allocate('SMAL'))->name = STR_AIRPORT_CLASS_SMALL;
|
||||
AirportClass::Get(AirportClass::Allocate('LARG'))->name = STR_AIRPORT_CLASS_LARGE;
|
||||
AirportClass::Get(AirportClass::Allocate('HUB_'))->name = STR_AIRPORT_CLASS_HUB;
|
||||
AirportClass::Get(AirportClass::Allocate('HELI'))->name = STR_AIRPORT_CLASS_HELIPORTS;
|
||||
}
|
||||
|
||||
INSTANTIATE_NEWGRF_CLASS_METHODS(AirportClass, AirportSpec, AirportClassID, APC_MAX)
|
||||
|
@ -32,11 +32,9 @@ struct NewGRFClass {
|
||||
static void InsertDefaults();
|
||||
|
||||
static Tid Allocate(uint32 global_id);
|
||||
static void SetName(Tid cls_id, StringID name);
|
||||
static void Assign(Tspec *spec);
|
||||
static NewGRFClass *Get(Tid cls_id);
|
||||
|
||||
static StringID GetName(Tid cls_id);
|
||||
static uint GetCount();
|
||||
static uint GetCount(Tid cls_id);
|
||||
static const Tspec *Get(Tid cls_id, uint index);
|
||||
|
@ -64,18 +64,6 @@ DEFINE_NEWGRF_CLASS_METHOD(Tid)::Allocate(uint32 global_id)
|
||||
return (Tid)0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of a particular class.
|
||||
* @param cls_id The id for the class.
|
||||
* @pre index < GetCount(cls_id)
|
||||
* @param name The new name for the class.
|
||||
*/
|
||||
DEFINE_NEWGRF_CLASS_METHOD(void)::SetName(Tid cls_id, StringID name)
|
||||
{
|
||||
assert(cls_id < Tmax);
|
||||
classes[cls_id].name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a spec to one of the classes.
|
||||
* @param spec The spec to assign.
|
||||
@ -104,18 +92,6 @@ NewGRFClass<Tspec, Tid, Tmax> *NewGRFClass<Tspec, Tid, Tmax>::Get(Tid cls_id)
|
||||
return classes + cls_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of a particular class.
|
||||
* @param cls_id The class to get the name of.
|
||||
* @pre index < GetCount(cls_id)
|
||||
* @return The name of said class.
|
||||
*/
|
||||
DEFINE_NEWGRF_CLASS_METHOD(StringID)::GetName(Tid cls_id)
|
||||
{
|
||||
assert(cls_id < Tmax);
|
||||
return classes[cls_id].name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of allocated classes.
|
||||
* @return The number of classes.
|
||||
@ -186,10 +162,8 @@ DEFINE_NEWGRF_CLASS_METHOD(const Tspec *)::GetByGrf(uint32 grfid, byte local_id,
|
||||
#define INSTANTIATE_NEWGRF_CLASS_METHODS(name, Tspec, Tid, Tmax) \
|
||||
template void name::Reset(); \
|
||||
template Tid name::Allocate(uint32 global_id); \
|
||||
template void name::SetName(Tid cls_id, StringID name); \
|
||||
template void name::Assign(Tspec *spec); \
|
||||
template NewGRFClass<Tspec, Tid, Tmax> *name::Get(Tid cls_id); \
|
||||
template StringID name::GetName(Tid cls_id); \
|
||||
template uint name::GetCount(); \
|
||||
template uint name::GetCount(Tid cls_id); \
|
||||
template const Tspec *name::Get(Tid cls_id, uint index); \
|
||||
|
@ -103,12 +103,12 @@ template <typename Tspec, typename Tid, Tid Tmax>
|
||||
if (_game_mode != GM_EDITOR) return;
|
||||
|
||||
ObjectClassID cls = ObjectClass::Allocate('LTHS');
|
||||
ObjectClass::SetName(cls, STR_OBJECT_CLASS_LTHS);
|
||||
ObjectClass::Get(cls)->name = STR_OBJECT_CLASS_LTHS;
|
||||
_object_specs[OBJECT_LIGHTHOUSE].cls_id = cls;
|
||||
ObjectClass::Assign(&_object_specs[OBJECT_LIGHTHOUSE]);
|
||||
|
||||
cls = ObjectClass::Allocate('TRNS');
|
||||
ObjectClass::SetName(cls, STR_OBJECT_CLASS_TRNS);
|
||||
ObjectClass::Get(cls)->name = STR_OBJECT_CLASS_TRNS;
|
||||
_object_specs[OBJECT_TRANSMITTER].cls_id = cls;
|
||||
ObjectClass::Assign(&_object_specs[OBJECT_TRANSMITTER]);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public:
|
||||
switch (widget) {
|
||||
case WID_BO_CLASS_LIST: {
|
||||
for (uint i = 0; i < ObjectClass::GetCount(); i++) {
|
||||
size->width = max(size->width, GetStringBoundingBox(ObjectClass::GetName((ObjectClassID)i)).width);
|
||||
size->width = max(size->width, GetStringBoundingBox(ObjectClass::Get((ObjectClassID)i)->name).width);
|
||||
}
|
||||
size->width += padding.width;
|
||||
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
|
||||
@ -156,7 +156,7 @@ public:
|
||||
case WID_BO_CLASS_LIST: {
|
||||
int y = r.top;
|
||||
for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < ObjectClass::GetCount(); i++) {
|
||||
SetDParam(0, ObjectClass::GetName((ObjectClassID)i));
|
||||
SetDParam(0, ObjectClass::Get((ObjectClassID)i)->name);
|
||||
DrawString(r.left + WD_MATRIX_LEFT, r.right + WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, STR_JUST_STRING,
|
||||
((int)i == _selected_object_class) ? TC_WHITE : TC_BLACK);
|
||||
y += this->line_height;
|
||||
|
@ -1026,7 +1026,7 @@ public:
|
||||
Dimension d = {0, 0};
|
||||
for (uint i = 0; i < StationClass::GetCount(); i++) {
|
||||
if (i == STAT_CLASS_WAYP) continue;
|
||||
SetDParam(0, StationClass::GetName((StationClassID)i));
|
||||
SetDParam(0, StationClass::Get((StationClassID)i)->name);
|
||||
d = maxdim(d, GetStringBoundingBox(STR_BLACK_STRING));
|
||||
}
|
||||
size->width = max(size->width, d.width + padding.width);
|
||||
@ -1104,7 +1104,7 @@ public:
|
||||
for (uint i = 0; i < StationClass::GetCount(); i++) {
|
||||
if (i == STAT_CLASS_WAYP) continue;
|
||||
if (this->vscroll->IsVisible(statclass)) {
|
||||
SetDParam(0, StationClass::GetName((StationClassID)i));
|
||||
SetDParam(0, StationClass::Get((StationClassID)i)->name);
|
||||
DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, row * this->line_height + r.top + WD_MATRIX_TOP, STR_JUST_STRING,
|
||||
(StationClassID)i == _railstation.station_class ? TC_WHITE : TC_BLACK);
|
||||
row++;
|
||||
|
@ -2912,7 +2912,7 @@ static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
|
||||
const StationSpec *spec = GetStationSpec(tile);
|
||||
|
||||
if (spec != NULL) {
|
||||
td->station_class = StationClass::GetName(spec->cls_id);
|
||||
td->station_class = StationClass::Get(spec->cls_id)->name;
|
||||
td->station_name = spec->name;
|
||||
|
||||
if (spec->grf_prop.grffile != NULL) {
|
||||
@ -2927,7 +2927,7 @@ static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
|
||||
|
||||
if (IsAirport(tile)) {
|
||||
const AirportSpec *as = Station::GetByTile(tile)->airport.GetSpec();
|
||||
td->airport_class = AirportClass::GetName(as->cls_id);
|
||||
td->airport_class = AirportClass::Get(as->cls_id)->name;
|
||||
td->airport_name = as->name;
|
||||
|
||||
const AirportTileSpec *ats = AirportTileSpec::GetByTile(tile);
|
||||
|
Loading…
Reference in New Issue
Block a user