diff --git a/src/openrct2-ui/windows/GameBottomToolbar.cpp b/src/openrct2-ui/windows/GameBottomToolbar.cpp index 7d2fd1393a..756f396c4a 100644 --- a/src/openrct2-ui/windows/GameBottomToolbar.cpp +++ b/src/openrct2-ui/windows/GameBottomToolbar.cpp @@ -337,7 +337,7 @@ static void window_game_bottom_toolbar_invalidate(rct_window* w) if (subjectLoc == std::nullopt) w->disabled_widgets |= (1 << WIDX_NEWS_LOCATE); - if (!(news_type_properties[static_cast(newsItem->Type)] & NEWS_TYPE_HAS_SUBJECT)) + if (!(newsItem->TypeHasSubject())) { w->disabled_widgets |= (1 << WIDX_NEWS_SUBJECT); window_game_bottom_toolbar_widgets[WIDX_NEWS_SUBJECT].type = WWT_EMPTY; diff --git a/src/openrct2-ui/windows/News.cpp b/src/openrct2-ui/windows/News.cpp index cd14646aca..5c4a3bd6a6 100644 --- a/src/openrct2-ui/windows/News.cpp +++ b/src/openrct2-ui/windows/News.cpp @@ -198,16 +198,12 @@ static void window_news_scrollmousedown(rct_window* w, int32_t scrollIndex, cons buttonIndex = 0; break; } - else if ( - mutableScreenCoords.x < 351 - && news_type_properties[static_cast(newsItem.Type)] & NEWS_TYPE_HAS_SUBJECT) + else if (mutableScreenCoords.x < 351 && newsItem.TypeHasSubject()) { buttonIndex = 1; break; } - else if ( - mutableScreenCoords.x < 376 - && news_type_properties[static_cast(newsItem.Type)] & NEWS_TYPE_HAS_LOCATION) + else if (mutableScreenCoords.x < 376 && newsItem.TypeHasLocation()) { buttonIndex = 2; break; @@ -273,8 +269,7 @@ static void window_news_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32 gfx_draw_string_left_wrapped(dpi, &text, { 2, y + lineHeight }, 325, STR_BOTTOM_TOOLBAR_NEWS_TEXT, COLOUR_BRIGHT_GREEN); // Subject button - if ((news_type_properties[static_cast(newsItem.Type)] & NEWS_TYPE_HAS_SUBJECT) - && !(newsItem.Flags & NEWS_FLAG_HAS_BUTTON)) + if ((newsItem.TypeHasSubject()) && !(newsItem.Flags & NEWS_FLAG_HAS_BUTTON)) { auto screenCoords = ScreenCoordsXY{ 328, y + lineHeight + 4 }; @@ -350,8 +345,7 @@ static void window_news_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32 } // Location button - if ((news_type_properties[static_cast(newsItem.Type)] & NEWS_TYPE_HAS_LOCATION) - && !(newsItem.Flags & NEWS_FLAG_HAS_BUTTON)) + if ((newsItem.TypeHasLocation()) && !(newsItem.Flags & NEWS_FLAG_HAS_BUTTON)) { auto screenCoords = ScreenCoordsXY{ 352, y + lineHeight + 4 }; diff --git a/src/openrct2/management/NewsItem.cpp b/src/openrct2/management/NewsItem.cpp index 35cb3e9410..44612befb8 100644 --- a/src/openrct2/management/NewsItem.cpp +++ b/src/openrct2/management/NewsItem.cpp @@ -26,20 +26,6 @@ NewsItemQueues gNewsItems; -/** rct2: 0x0097BE7C */ -const uint8_t news_type_properties[] = { - 0, // News::ItemType::Null - NEWS_TYPE_HAS_LOCATION | NEWS_TYPE_HAS_SUBJECT, // News::ItemType::Ride - NEWS_TYPE_HAS_LOCATION | NEWS_TYPE_HAS_SUBJECT, // News::ItemType::PeepOnRide - NEWS_TYPE_HAS_LOCATION | NEWS_TYPE_HAS_SUBJECT, // News::ItemType::Peep - NEWS_TYPE_HAS_SUBJECT, // News::ItemType::Money - NEWS_TYPE_HAS_LOCATION, // News::ItemType::Blank - NEWS_TYPE_HAS_SUBJECT, // News::ItemType::Research - NEWS_TYPE_HAS_SUBJECT, // News::ItemType::Peeps - NEWS_TYPE_HAS_SUBJECT, // News::ItemType::Award - NEWS_TYPE_HAS_SUBJECT, // News::ItemType::Graph -}; - NewsItem& NewsItemQueues::Current() { return Recent.front(); diff --git a/src/openrct2/management/NewsItem.h b/src/openrct2/management/NewsItem.h index 2d2d2fd56a..cfa5ee7d68 100644 --- a/src/openrct2/management/NewsItem.h +++ b/src/openrct2/management/NewsItem.h @@ -36,13 +36,13 @@ namespace News }; constexpr size_t ItemTypeCount = static_cast(News::ItemType::Count); -} // namespace News -enum -{ - NEWS_TYPE_HAS_LOCATION = 1, - NEWS_TYPE_HAS_SUBJECT = 2, -}; + enum ItemTypeProperty : uint8_t + { + HasLocation = 1, + HasSubject = 2, + }; +} // namespace News enum { @@ -66,14 +66,45 @@ struct NewsItem { return Type == News::ItemType::Null; } + + constexpr uint8_t GetTypeProperties() const + { + switch (Type) + { + case News::ItemType::Blank: + return News::ItemTypeProperty::HasLocation; + case News::ItemType::Money: + case News::ItemType::Research: + case News::ItemType::Peeps: + case News::ItemType::Award: + case News::ItemType::Graph: + return News::ItemTypeProperty::HasSubject; + case News::ItemType::Ride: + case News::ItemType::PeepOnRide: + case News::ItemType::Peep: + return News::ItemTypeProperty::HasLocation | News::ItemTypeProperty::HasSubject; + case News::ItemType::Null: + case News::ItemType::Count: + default: + return 0; + } + } + + constexpr bool TypeHasSubject() const + { + return this->GetTypeProperties() & News::ItemTypeProperty::HasSubject; + } + + constexpr bool TypeHasLocation() const + { + return this->GetTypeProperties() & News::ItemTypeProperty::HasLocation; + } }; constexpr int32_t NEWS_ITEM_HISTORY_START = 11; constexpr int32_t MAX_NEWS_ITEMS_ARCHIVE = 50; constexpr int32_t MAX_NEWS_ITEMS = NEWS_ITEM_HISTORY_START + MAX_NEWS_ITEMS_ARCHIVE; -extern const uint8_t news_type_properties[10]; - template class NewsItemQueue { public: diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index e508b441cf..c4dd17c6ce 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -427,7 +427,7 @@ public: { const rct12_news_item* src = &_s6.news_items[i]; NewsItem* dst = &gNewsItems[i]; - if (src->Type < std::size(news_type_properties)) + if (src->Type < News::ItemTypeCount) { dst->Type = static_cast(src->Type); dst->Flags = src->Flags;