diff --git a/src/newgrf_class.h b/src/newgrf_class.h index 4bac546d35..e0efeb4ae4 100644 --- a/src/newgrf_class.h +++ b/src/newgrf_class.h @@ -57,6 +57,7 @@ public: static void Assign(Tspec *spec); static uint GetClassCount(); static uint GetUIClassCount(); + static bool HasUIClass(); static Tid GetUIClass(uint index); static NewGRFClass *Get(Tid cls_id); diff --git a/src/newgrf_class_func.h b/src/newgrf_class_func.h index 4d854153b5..33c6a15894 100644 --- a/src/newgrf_class_func.h +++ b/src/newgrf_class_func.h @@ -131,6 +131,18 @@ DEFINE_NEWGRF_CLASS_METHOD(uint)::GetUIClassCount() return cnt; } +/** + * Get whether at least one class is available to the user. + * @return Whether at least one class is available to the user. + */ +DEFINE_NEWGRF_CLASS_METHOD(bool)::HasUIClass() +{ + for (uint i = 0; i < Tmax && classes[i].global_id != 0; i++) { + if (classes[i].GetUISpecCount() > 0) return true; + } + return false; +} + /** * Get the nth-class with user available specs. * @param index UI index of a class. @@ -223,6 +235,7 @@ DEFINE_NEWGRF_CLASS_METHOD(const Tspec *)::GetByGrf(uint32 grfid, byte local_id, template NewGRFClass *name::Get(Tid cls_id); \ template uint name::GetClassCount(); \ template uint name::GetUIClassCount(); \ + template bool name::HasUIClass(); \ template Tid name::GetUIClass(uint index); \ template const Tspec *name::GetSpec(uint index) const; \ template int name::GetUIFromIndex(int index) const; \ diff --git a/src/object_gui.cpp b/src/object_gui.cpp index 98ba5f51a9..c76184add1 100644 --- a/src/object_gui.cpp +++ b/src/object_gui.cpp @@ -755,7 +755,7 @@ static WindowDesc _build_object_desc( Window *ShowBuildObjectPicker() { /* Don't show the place object button when there are no objects to place. */ - if (ObjectClass::GetUIClassCount() > 0) { + if (ObjectClass::HasUIClass()) { return AllocateWindowDescFront(&_build_object_desc, 0); } return nullptr; diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index 241d4f87c0..be4337e895 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -221,7 +221,7 @@ struct TerraformToolbarWindow : Window { { /* Don't show the place object button when there are no objects to place. */ NWidgetStacked *show_object = this->GetWidget(WID_TT_SHOW_PLACE_OBJECT); - show_object->SetDisplayedPlane(ObjectClass::GetUIClassCount() != 0 ? 0 : SZSP_NONE); + show_object->SetDisplayedPlane(ObjectClass::HasUIClass() ? 0 : SZSP_NONE); SetWidgetDisabledState(WID_TT_BUY_LAND, _settings_game.construction.purchase_land_permitted == 0); }