diff --git a/src/news_func.h b/src/news_func.h index 02552af88f..76a3f178e1 100644 --- a/src/news_func.h +++ b/src/news_func.h @@ -15,7 +15,7 @@ #include "station_type.h" #include "industry_type.h" -void AddNewsItem(StringID string, NewsType type, NewsStyle style, NewsFlag flags, NewsReferenceType reftype1 = NR_NONE, uint32_t ref1 = UINT32_MAX, NewsReferenceType reftype2 = NR_NONE, uint32_t ref2 = UINT32_MAX, std::unique_ptr &&data = nullptr, AdviceType advice_type = AdviceType::Invalid); +void AddNewsItem(StringID string, NewsType type, NewsStyle style, NewsFlags flags, NewsReferenceType reftype1 = NR_NONE, uint32_t ref1 = UINT32_MAX, NewsReferenceType reftype2 = NR_NONE, uint32_t ref2 = UINT32_MAX, std::unique_ptr &&data = nullptr, AdviceType advice_type = AdviceType::Invalid); inline void AddCompanyNewsItem(StringID string, std::unique_ptr cni) { @@ -29,7 +29,7 @@ inline void AddCompanyNewsItem(StringID string, std::unique_ptr &&data = nullptr, StationID station = INVALID_STATION) { - AddNewsItem(string, type, NewsStyle::Thin, NF_NO_TRANSPARENT | NF_SHADE, NR_TILE, tile.base(), station == INVALID_STATION ? NR_NONE : NR_STATION, station, std::move(data)); + AddNewsItem(string, type, NewsStyle::Thin, {NewsFlag::NoTransparency, NewsFlag::Shaded}, NR_TILE, tile.base(), station == INVALID_STATION ? NR_NONE : NR_STATION, station, std::move(data)); } inline void AddIndustryNewsItem(StringID string, NewsType type, IndustryID industry, std::unique_ptr &&data = nullptr) { - AddNewsItem(string, type, NewsStyle::Thin, NF_NO_TRANSPARENT | NF_SHADE, NR_INDUSTRY, industry, NR_NONE, UINT32_MAX, std::move(data)); + AddNewsItem(string, type, NewsStyle::Thin, {NewsFlag::NoTransparency, NewsFlag::Shaded}, NR_INDUSTRY, industry, NR_NONE, UINT32_MAX, std::move(data)); } void NewsLoop(); diff --git a/src/news_gui.cpp b/src/news_gui.cpp index ccad1f8c28..3b880e3857 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -396,10 +396,10 @@ struct NewsWindow : Window { } else { nvp->InitializeViewport(this, GetReferenceTile(ni->reftype1, ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS)); } - if (this->ni->flags & NF_NO_TRANSPARENT) nvp->disp_flags.Set(NWidgetDisplayFlag::NoTransparency); - if ((this->ni->flags & NF_INCOLOUR) == 0) { + if (this->ni->flags.Test(NewsFlag::NoTransparency)) nvp->disp_flags.Set(NWidgetDisplayFlag::NoTransparency); + if (!this->ni->flags.Test(NewsFlag::InColour)) { nvp->disp_flags.Set(NWidgetDisplayFlag::ShadeGrey); - } else if (this->ni->flags & NF_SHADE) { + } else if (this->ni->flags.Test(NewsFlag::Shaded)) { nvp->disp_flags.Set(NWidgetDisplayFlag::ShadeDimmed); } } @@ -874,11 +874,11 @@ static std::list::iterator DeleteNewsItem(std::list::iterato * * @see NewsSubtype */ -NewsItem::NewsItem(StringID string_id, NewsType type, NewsStyle style, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, std::unique_ptr &&data, AdviceType advice_type) : +NewsItem::NewsItem(StringID string_id, NewsType type, NewsStyle style, NewsFlags flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, std::unique_ptr &&data, AdviceType advice_type) : string_id(string_id), date(TimerGameCalendar::date), economy_date(TimerGameEconomy::date), type(type), advice_type(advice_type), style(style), flags(flags), reftype1(reftype1), reftype2(reftype2), ref1(ref1), ref2(ref2), data(std::move(data)) { /* show this news message in colour? */ - if (TimerGameCalendar::year >= _settings_client.gui.coloured_news_year) this->flags |= NF_INCOLOUR; + if (TimerGameCalendar::year >= _settings_client.gui.coloured_news_year) this->flags.Set(NewsFlag::InColour); CopyOutDParam(this->params, 10); } @@ -896,7 +896,7 @@ NewsItem::NewsItem(StringID string_id, NewsType type, NewsStyle style, NewsFlag * * @see NewsSubtype */ -void AddNewsItem(StringID string, NewsType type, NewsStyle style, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, std::unique_ptr &&data, AdviceType advice_type) +void AddNewsItem(StringID string, NewsType type, NewsStyle style, NewsFlags flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, std::unique_ptr &&data, AdviceType advice_type) { if (_game_mode == GM_MENU) return; @@ -1056,7 +1056,7 @@ void ChangeVehicleNews(VehicleID from_index, VehicleID to_index) for (auto &ni : _news) { if (ni.reftype1 == NR_VEHICLE && ni.ref1 == from_index) ni.ref1 = to_index; if (ni.reftype2 == NR_VEHICLE && ni.ref2 == from_index) ni.ref2 = to_index; - if (ni.flags & NF_VEHICLE_PARAM0 && std::get(ni.params[0]) == from_index) ni.params[0] = to_index; + if (ni.flags.Test(NewsFlag::VehicleParam0) && std::get(ni.params[0]) == from_index) ni.params[0] = to_index; } } diff --git a/src/news_type.h b/src/news_type.h index 15a194bc48..898aa91f6c 100644 --- a/src/news_type.h +++ b/src/news_type.h @@ -85,21 +85,15 @@ enum class NewsStyle : uint8_t { /** * Various OR-able news-item flags. - * @note #NF_INCOLOUR is set automatically if needed. + * @note #NewsFlag::InColour is set automatically if needed. */ -enum NewsFlag : uint8_t { - NFB_INCOLOUR = 0, ///< News item is shown in colour (otherwise it is shown in black & white). - NFB_NO_TRANSPARENT = 1, ///< News item disables transparency in the viewport. - NFB_SHADE = 2, ///< News item uses shaded colours. - NFB_VEHICLE_PARAM0 = 6, ///< String param 0 contains a vehicle ID. (special autoreplace behaviour) - - NF_INCOLOUR = 1 << NFB_INCOLOUR, ///< Bit value for coloured news. - NF_NO_TRANSPARENT = 1 << NFB_NO_TRANSPARENT, ///< Bit value for disabling transparency. - NF_SHADE = 1 << NFB_SHADE, ///< Bit value for enabling shading. - NF_VEHICLE_PARAM0 = 1 << NFB_VEHICLE_PARAM0, ///< Bit value for specifying that string param 0 contains a vehicle ID. (special autoreplace behaviour) +enum class NewsFlag : uint8_t { + InColour, ///< News item is shown in colour (otherwise it is shown in black & white). + NoTransparency, ///< News item disables transparency in the viewport. + Shaded, ///< News item uses shaded colours. + VehicleParam0, ///< String param 0 contains a vehicle ID. (special autoreplace behaviour) }; -DECLARE_ENUM_AS_BIT_SET(NewsFlag) - +using NewsFlags = EnumBitSet; /** * News display options @@ -148,7 +142,7 @@ struct NewsItem { NewsType type; ///< Type of the news AdviceType advice_type; ///< The type of advice, to be able to remove specific advices later on. NewsStyle style; /// Window style for the news. - NewsFlag flags; ///< NewsFlags bits @see NewsFlag + NewsFlags flags; ///< NewsFlags bits @see NewsFlag NewsReferenceType reftype1; ///< Type of ref1 NewsReferenceType reftype2; ///< Type of ref2 @@ -159,7 +153,7 @@ struct NewsItem { std::vector params; ///< Parameters for string resolving. - NewsItem(StringID string_id, NewsType type, NewsStyle style, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, std::unique_ptr &&data, AdviceType advice_type); + NewsItem(StringID string_id, NewsType type, NewsStyle style, NewsFlags flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, std::unique_ptr &&data, AdviceType advice_type); }; /** diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 088a397a2c..6a477c13a0 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -532,7 +532,7 @@ static void ShowRejectOrAcceptNews(const Station *st, CargoTypes cargoes, bool r SetDParam(0, st->index); SetDParam(1, cargoes); StringID msg = reject ? STR_NEWS_STATION_NO_LONGER_ACCEPTS_CARGO_LIST : STR_NEWS_STATION_NOW_ACCEPTS_CARGO_LIST; - AddNewsItem(msg, NT_ACCEPTANCE, NewsStyle::Small, NF_INCOLOUR, NR_STATION, st->index); + AddNewsItem(msg, NT_ACCEPTANCE, NewsStyle::Small, NewsFlag::InColour, NR_STATION, st->index); } /**