Add NewGRFClass helper method for whether any UI classes available
This commit is contained in:
@@ -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);
|
||||
|
||||
|
@@ -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<Tspec, Tid, Tmax> *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; \
|
||||
|
@@ -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<BuildObjectWindow>(&_build_object_desc, 0);
|
||||
}
|
||||
return nullptr;
|
||||
|
@@ -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<NWidgetStacked>(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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user