mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-19 18:32:35 +01:00
Codechange: Make ContentType::State an enum class. (#14279)
This commit is contained in:
@@ -357,7 +357,7 @@ class NetworkContentListWindow : public Window, ContentCallback {
|
||||
|
||||
bool first = true;
|
||||
for (const ContentInfo *ci : this->content) {
|
||||
if (ci->state != ContentInfo::DOES_NOT_EXIST) continue;
|
||||
if (ci->state != ContentInfo::State::DoesNotExist) continue;
|
||||
|
||||
if (!first) url.push_back(',');
|
||||
first = false;
|
||||
@@ -409,7 +409,7 @@ class NetworkContentListWindow : public Window, ContentCallback {
|
||||
bool all_available = true;
|
||||
|
||||
for (const ContentInfo &ci : _network_content_client.Info()) {
|
||||
if (ci.state == ContentInfo::DOES_NOT_EXIST) all_available = false;
|
||||
if (ci.state == ContentInfo::State::DoesNotExist) all_available = false;
|
||||
this->content.push_back(&ci);
|
||||
}
|
||||
|
||||
@@ -443,7 +443,7 @@ class NetworkContentListWindow : public Window, ContentCallback {
|
||||
/** Sort content by state. */
|
||||
static bool StateSorter(const ContentInfo * const &a, const ContentInfo * const &b)
|
||||
{
|
||||
int r = a->state - b->state;
|
||||
int r = to_underlying(a->state) - to_underlying(b->state);
|
||||
if (r == 0) return TypeSorter(a, b);
|
||||
return r < 0;
|
||||
}
|
||||
@@ -460,7 +460,7 @@ class NetworkContentListWindow : public Window, ContentCallback {
|
||||
/** Filter content by tags/name */
|
||||
static bool TagNameFilter(const ContentInfo * const *a, ContentListFilterData &filter)
|
||||
{
|
||||
if ((*a)->state == ContentInfo::SELECTED || (*a)->state == ContentInfo::AUTOSELECTED) return true;
|
||||
if ((*a)->state == ContentInfo::State::Selected || (*a)->state == ContentInfo::State::Autoselected) return true;
|
||||
|
||||
filter.string_filter.ResetState();
|
||||
for (auto &tag : (*a)->tags) filter.string_filter.AddLine(tag);
|
||||
@@ -474,7 +474,7 @@ class NetworkContentListWindow : public Window, ContentCallback {
|
||||
{
|
||||
if (filter.types.None()) return true;
|
||||
if (filter.types.Test((*a)->type)) return true;
|
||||
return ((*a)->state == ContentInfo::SELECTED || (*a)->state == ContentInfo::AUTOSELECTED);
|
||||
return ((*a)->state == ContentInfo::State::Selected || (*a)->state == ContentInfo::State::Autoselected);
|
||||
}
|
||||
|
||||
/** Filter the content list */
|
||||
@@ -655,11 +655,11 @@ public:
|
||||
SpriteID sprite;
|
||||
SpriteID pal = PAL_NONE;
|
||||
switch (ci->state) {
|
||||
case ContentInfo::UNSELECTED: sprite = SPR_BOX_EMPTY; break;
|
||||
case ContentInfo::SELECTED: sprite = SPR_BOX_CHECKED; break;
|
||||
case ContentInfo::AUTOSELECTED: sprite = SPR_BOX_CHECKED; break;
|
||||
case ContentInfo::ALREADY_HERE: sprite = SPR_BLOT; pal = PALETTE_TO_GREEN; break;
|
||||
case ContentInfo::DOES_NOT_EXIST: sprite = SPR_BLOT; pal = PALETTE_TO_RED; break;
|
||||
case ContentInfo::State::Unselected: sprite = SPR_BOX_EMPTY; break;
|
||||
case ContentInfo::State::Selected: sprite = SPR_BOX_CHECKED; break;
|
||||
case ContentInfo::State::Autoselected: sprite = SPR_BOX_CHECKED; break;
|
||||
case ContentInfo::State::AlreadyHere: sprite = SPR_BLOT; pal = PALETTE_TO_GREEN; break;
|
||||
case ContentInfo::State::DoesNotExist: sprite = SPR_BLOT; pal = PALETTE_TO_RED; break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
DrawSpriteIgnorePadding(sprite, pal, {checkbox.left, mr.top, checkbox.right, mr.bottom}, SA_CENTER);
|
||||
@@ -695,7 +695,7 @@ public:
|
||||
if (this->selected == nullptr) return;
|
||||
|
||||
/* And fill the rest of the details when there's information to place there */
|
||||
DrawStringMultiLine(hr.left, hr.right, hr.top + GetCharacterHeight(FS_NORMAL), hr.bottom, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + this->selected->state, TC_FROMSTRING, SA_CENTER);
|
||||
DrawStringMultiLine(hr.left, hr.right, hr.top + GetCharacterHeight(FS_NORMAL), hr.bottom, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + to_underlying(this->selected->state), TC_FROMSTRING, SA_CENTER);
|
||||
|
||||
/* Also show the total download size, so keep some space from the bottom */
|
||||
tr.bottom -= GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
|
||||
@@ -758,7 +758,7 @@ public:
|
||||
|
||||
std::string buf;
|
||||
for (const ContentInfo *ci : tree) {
|
||||
if (ci == this->selected || ci->state != ContentInfo::SELECTED) continue;
|
||||
if (ci == this->selected || ci->state != ContentInfo::State::Selected) continue;
|
||||
|
||||
if (!buf.empty()) buf += list_separator;
|
||||
buf += ci->name;
|
||||
@@ -772,7 +772,7 @@ public:
|
||||
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
|
||||
{
|
||||
if (widget >= WID_NCL_TEXTFILE && widget < WID_NCL_TEXTFILE + TFT_CONTENT_END) {
|
||||
if (this->selected == nullptr || this->selected->state != ContentInfo::ALREADY_HERE) return;
|
||||
if (this->selected == nullptr || this->selected->state != ContentInfo::State::AlreadyHere) return;
|
||||
|
||||
ShowContentTextfileWindow(this, (TextfileType)(widget - WID_NCL_TEXTFILE), this->selected);
|
||||
return;
|
||||
@@ -957,12 +957,12 @@ public:
|
||||
bool show_select_upgrade = false;
|
||||
for (const ContentInfo *ci : this->content) {
|
||||
switch (ci->state) {
|
||||
case ContentInfo::SELECTED:
|
||||
case ContentInfo::AUTOSELECTED:
|
||||
case ContentInfo::State::Selected:
|
||||
case ContentInfo::State::Autoselected:
|
||||
this->filesize_sum += ci->filesize;
|
||||
break;
|
||||
|
||||
case ContentInfo::UNSELECTED:
|
||||
case ContentInfo::State::Unselected:
|
||||
show_select_all = true;
|
||||
show_select_upgrade |= ci->upgrade;
|
||||
break;
|
||||
@@ -979,7 +979,7 @@ public:
|
||||
this->SetWidgetDisabledState(WID_NCL_SELECT_UPDATE, !show_select_upgrade || !this->filter_data.string_filter.IsEmpty());
|
||||
this->SetWidgetDisabledState(WID_NCL_OPEN_URL, this->selected == nullptr || this->selected->url.empty());
|
||||
for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
|
||||
this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == nullptr || this->selected->state != ContentInfo::ALREADY_HERE || !this->selected->GetTextfile(tft).has_value());
|
||||
this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == nullptr || this->selected->state != ContentInfo::State::AlreadyHere || !this->selected->GetTextfile(tft).has_value());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user