1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Close #12398: Refactor NEWS_TYPE_* to use strong enum

This commit is contained in:
pizza2004
2020-07-26 04:57:58 -06:00
parent cee7f8d34c
commit c2b11a9582
5 changed files with 45 additions and 34 deletions

View File

@@ -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<uint8_t>(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;

View File

@@ -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<uint8_t>(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<uint8_t>(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<uint8_t>(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<uint8_t>(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 };

View File

@@ -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();

View File

@@ -36,13 +36,13 @@ namespace News
};
constexpr size_t ItemTypeCount = static_cast<size_t>(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<std::size_t N> class NewsItemQueue
{
public:

View File

@@ -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<News::ItemType>(src->Type);
dst->Flags = src->Flags;