mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use enum class for NewsReferenceType.
parent
ca75a8ce19
commit
9a6fc4eb76
|
@ -433,7 +433,7 @@ set_name:;
|
||||||
SetDParam(1, STR_NEWS_COMPANY_LAUNCH_DESCRIPTION);
|
SetDParam(1, STR_NEWS_COMPANY_LAUNCH_DESCRIPTION);
|
||||||
SetDParamStr(2, cni->company_name);
|
SetDParamStr(2, cni->company_name);
|
||||||
SetDParam(3, t->index);
|
SetDParam(3, t->index);
|
||||||
AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NewsType::CompanyInfo, NewsStyle::Company, {}, NR_TILE, c->last_build_coordinate.base(), NR_NONE, UINT32_MAX, std::move(cni));
|
AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NewsType::CompanyInfo, NewsStyle::Company, {}, NewsReferenceType::Tile, c->last_build_coordinate.base(), NewsReferenceType::None, UINT32_MAX, std::move(cni));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1131,7 +1131,7 @@ static void NewVehicleAvailable(Engine *e)
|
||||||
if (!IsVehicleTypeDisabled(e->type, false) && !e->info.extra_flags.Test(ExtraEngineFlag::NoNews)) {
|
if (!IsVehicleTypeDisabled(e->type, false) && !e->info.extra_flags.Test(ExtraEngineFlag::NoNews)) {
|
||||||
SetDParam(0, GetEngineCategoryName(index));
|
SetDParam(0, GetEngineCategoryName(index));
|
||||||
SetDParam(1, PackEngineNameDParam(index, EngineNameContext::PreviewNews));
|
SetDParam(1, PackEngineNameDParam(index, EngineNameContext::PreviewNews));
|
||||||
AddNewsItem(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NewsType::NewVehicles, NewsStyle::Vehicle, {}, NR_ENGINE, index);
|
AddNewsItem(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NewsType::NewVehicles, NewsStyle::Vehicle, {}, NewsReferenceType::Engine, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update the toolbar. */
|
/* Update the toolbar. */
|
||||||
|
|
|
@ -15,11 +15,11 @@
|
||||||
#include "station_type.h"
|
#include "station_type.h"
|
||||||
#include "industry_type.h"
|
#include "industry_type.h"
|
||||||
|
|
||||||
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<NewsAllocatedData> &&data = nullptr, AdviceType advice_type = AdviceType::Invalid);
|
void AddNewsItem(StringID string, NewsType type, NewsStyle style, NewsFlags flags, NewsReferenceType reftype1 = NewsReferenceType::None, uint32_t ref1 = UINT32_MAX, NewsReferenceType reftype2 = NewsReferenceType::None, uint32_t ref2 = UINT32_MAX, std::unique_ptr<NewsAllocatedData> &&data = nullptr, AdviceType advice_type = AdviceType::Invalid);
|
||||||
|
|
||||||
inline void AddCompanyNewsItem(StringID string, std::unique_ptr<CompanyNewsInformation> cni)
|
inline void AddCompanyNewsItem(StringID string, std::unique_ptr<CompanyNewsInformation> cni)
|
||||||
{
|
{
|
||||||
AddNewsItem(string, NewsType::CompanyInfo, NewsStyle::Company, {}, NR_NONE, UINT32_MAX, NR_NONE, UINT32_MAX, std::move(cni));
|
AddNewsItem(string, NewsType::CompanyInfo, NewsStyle::Company, {}, NewsReferenceType::None, UINT32_MAX, NewsReferenceType::None, UINT32_MAX, std::move(cni));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,7 +29,7 @@ inline void AddCompanyNewsItem(StringID string, std::unique_ptr<CompanyNewsInfor
|
||||||
*/
|
*/
|
||||||
inline void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle, StationID station = INVALID_STATION)
|
inline void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle, StationID station = INVALID_STATION)
|
||||||
{
|
{
|
||||||
AddNewsItem(string, type, NewsStyle::Thin, {NewsFlag::NoTransparency, NewsFlag::Shaded}, NR_VEHICLE, vehicle, station == INVALID_STATION ? NR_NONE : NR_STATION, station);
|
AddNewsItem(string, type, NewsStyle::Thin, {NewsFlag::NoTransparency, NewsFlag::Shaded}, NewsReferenceType::Vehicle, vehicle, station == INVALID_STATION ? NewsReferenceType::None : NewsReferenceType::Station, station);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,17 +39,17 @@ inline void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle
|
||||||
*/
|
*/
|
||||||
inline void AddVehicleAdviceNewsItem(AdviceType advice_type, StringID string, VehicleID vehicle)
|
inline void AddVehicleAdviceNewsItem(AdviceType advice_type, StringID string, VehicleID vehicle)
|
||||||
{
|
{
|
||||||
AddNewsItem(string, NewsType::Advice, NewsStyle::Small, {NewsFlag::InColour, NewsFlag::VehicleParam0}, NR_VEHICLE, vehicle, NR_NONE, {}, nullptr, advice_type);
|
AddNewsItem(string, NewsType::Advice, NewsStyle::Small, {NewsFlag::InColour, NewsFlag::VehicleParam0}, NewsReferenceType::Vehicle, vehicle, NewsReferenceType::None, {}, nullptr, advice_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void AddTileNewsItem(StringID string, NewsType type, TileIndex tile, std::unique_ptr<NewsAllocatedData> &&data = nullptr, StationID station = INVALID_STATION)
|
inline void AddTileNewsItem(StringID string, NewsType type, TileIndex tile, std::unique_ptr<NewsAllocatedData> &&data = nullptr, StationID station = INVALID_STATION)
|
||||||
{
|
{
|
||||||
AddNewsItem(string, type, NewsStyle::Thin, {NewsFlag::NoTransparency, NewsFlag::Shaded}, NR_TILE, tile.base(), station == INVALID_STATION ? NR_NONE : NR_STATION, station, std::move(data));
|
AddNewsItem(string, type, NewsStyle::Thin, {NewsFlag::NoTransparency, NewsFlag::Shaded}, NewsReferenceType::Tile, tile.base(), station == INVALID_STATION ? NewsReferenceType::None : NewsReferenceType::Station, station, std::move(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void AddIndustryNewsItem(StringID string, NewsType type, IndustryID industry, std::unique_ptr<NewsAllocatedData> &&data = nullptr)
|
inline void AddIndustryNewsItem(StringID string, NewsType type, IndustryID industry, std::unique_ptr<NewsAllocatedData> &&data = nullptr)
|
||||||
{
|
{
|
||||||
AddNewsItem(string, type, NewsStyle::Thin, {NewsFlag::NoTransparency, NewsFlag::Shaded}, NR_INDUSTRY, industry, NR_NONE, UINT32_MAX, std::move(data));
|
AddNewsItem(string, type, NewsStyle::Thin, {NewsFlag::NoTransparency, NewsFlag::Shaded}, NewsReferenceType::Industry, industry, NewsReferenceType::None, UINT32_MAX, std::move(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewsLoop();
|
void NewsLoop();
|
||||||
|
|
|
@ -90,10 +90,10 @@ const NewsContainer &GetNews()
|
||||||
static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32_t ref)
|
static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32_t ref)
|
||||||
{
|
{
|
||||||
switch (reftype) {
|
switch (reftype) {
|
||||||
case NR_TILE: return (TileIndex)ref;
|
case NewsReferenceType::Tile: return (TileIndex)ref;
|
||||||
case NR_STATION: return Station::Get((StationID)ref)->xy;
|
case NewsReferenceType::Station: return Station::Get((StationID)ref)->xy;
|
||||||
case NR_INDUSTRY: return Industry::Get((IndustryID)ref)->location.tile + TileDiffXY(1, 1);
|
case NewsReferenceType::Industry: return Industry::Get((IndustryID)ref)->location.tile + TileDiffXY(1, 1);
|
||||||
case NR_TOWN: return Town::Get((TownID)ref)->xy;
|
case NewsReferenceType::Town: return Town::Get((TownID)ref)->xy;
|
||||||
default: return INVALID_TILE;
|
default: return INVALID_TILE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -366,7 +366,7 @@ struct NewsWindow : Window {
|
||||||
if (&desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->SetString(static_cast<StringID>(std::get<uint64_t>(this->ni->params[0])));
|
if (&desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->SetString(static_cast<StringID>(std::get<uint64_t>(this->ni->params[0])));
|
||||||
|
|
||||||
NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP);
|
NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP);
|
||||||
if (ni->reftype1 == NR_VEHICLE && nwid != nullptr) {
|
if (ni->reftype1 == NewsReferenceType::Vehicle && nwid != nullptr) {
|
||||||
const Vehicle *v = Vehicle::Get(ni->ref1);
|
const Vehicle *v = Vehicle::Get(ni->ref1);
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
|
@ -391,7 +391,7 @@ struct NewsWindow : Window {
|
||||||
/* Initialize viewport if it exists. */
|
/* Initialize viewport if it exists. */
|
||||||
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
|
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
|
||||||
if (nvp != nullptr) {
|
if (nvp != nullptr) {
|
||||||
if (ni->reftype1 == NR_VEHICLE) {
|
if (ni->reftype1 == NewsReferenceType::Vehicle) {
|
||||||
nvp->InitializeViewport(this, static_cast<VehicleID>(ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
|
nvp->InitializeViewport(this, static_cast<VehicleID>(ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
|
||||||
} else {
|
} else {
|
||||||
nvp->InitializeViewport(this, GetReferenceTile(ni->reftype1, ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
|
nvp->InitializeViewport(this, GetReferenceTile(ni->reftype1, ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
|
||||||
|
@ -457,14 +457,14 @@ struct NewsWindow : Window {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_N_VEH_INFO: {
|
case WID_N_VEH_INFO: {
|
||||||
assert(this->ni->reftype1 == NR_ENGINE);
|
assert(this->ni->reftype1 == NewsReferenceType::Engine);
|
||||||
EngineID engine = this->ni->ref1;
|
EngineID engine = this->ni->ref1;
|
||||||
str = GetEngineInfoString(engine);
|
str = GetEngineInfoString(engine);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WID_N_SHOW_GROUP:
|
case WID_N_SHOW_GROUP:
|
||||||
if (this->ni->reftype1 == NR_VEHICLE) {
|
if (this->ni->reftype1 == NewsReferenceType::Vehicle) {
|
||||||
Dimension d2 = GetStringBoundingBox(this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP)->GetString());
|
Dimension d2 = GetStringBoundingBox(this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP)->GetString());
|
||||||
d2.height += WidgetDimensions::scaled.captiontext.Vertical();
|
d2.height += WidgetDimensions::scaled.captiontext.Vertical();
|
||||||
d2.width += WidgetDimensions::scaled.captiontext.Horizontal();
|
d2.width += WidgetDimensions::scaled.captiontext.Horizontal();
|
||||||
|
@ -541,14 +541,14 @@ struct NewsWindow : Window {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_N_VEH_SPR: {
|
case WID_N_VEH_SPR: {
|
||||||
assert(this->ni->reftype1 == NR_ENGINE);
|
assert(this->ni->reftype1 == NewsReferenceType::Engine);
|
||||||
EngineID engine = this->ni->ref1;
|
EngineID engine = this->ni->ref1;
|
||||||
DrawVehicleEngine(r.left, r.right, CenterBounds(r.left, r.right, 0), CenterBounds(r.top, r.bottom, 0), engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
|
DrawVehicleEngine(r.left, r.right, CenterBounds(r.left, r.right, 0), CenterBounds(r.top, r.bottom, 0), engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
|
||||||
GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
|
GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WID_N_VEH_INFO: {
|
case WID_N_VEH_INFO: {
|
||||||
assert(this->ni->reftype1 == NR_ENGINE);
|
assert(this->ni->reftype1 == NewsReferenceType::Engine);
|
||||||
EngineID engine = this->ni->ref1;
|
EngineID engine = this->ni->ref1;
|
||||||
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
|
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
|
||||||
break;
|
break;
|
||||||
|
@ -566,7 +566,7 @@ struct NewsWindow : Window {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_N_CAPTION:
|
case WID_N_CAPTION:
|
||||||
if (this->ni->reftype1 == NR_VEHICLE) {
|
if (this->ni->reftype1 == NewsReferenceType::Vehicle) {
|
||||||
const Vehicle *v = Vehicle::Get(this->ni->ref1);
|
const Vehicle *v = Vehicle::Get(this->ni->ref1);
|
||||||
ShowVehicleViewWindow(v);
|
ShowVehicleViewWindow(v);
|
||||||
}
|
}
|
||||||
|
@ -576,13 +576,13 @@ struct NewsWindow : Window {
|
||||||
break; // Ignore clicks
|
break; // Ignore clicks
|
||||||
|
|
||||||
case WID_N_SHOW_GROUP:
|
case WID_N_SHOW_GROUP:
|
||||||
if (this->ni->reftype1 == NR_VEHICLE) {
|
if (this->ni->reftype1 == NewsReferenceType::Vehicle) {
|
||||||
const Vehicle *v = Vehicle::Get(this->ni->ref1);
|
const Vehicle *v = Vehicle::Get(this->ni->ref1);
|
||||||
ShowCompanyGroupForVehicle(v);
|
ShowCompanyGroupForVehicle(v);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (this->ni->reftype1 == NR_VEHICLE) {
|
if (this->ni->reftype1 == NewsReferenceType::Vehicle) {
|
||||||
const Vehicle *v = Vehicle::Get(this->ni->ref1);
|
const Vehicle *v = Vehicle::Get(this->ni->ref1);
|
||||||
ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
|
ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
|
||||||
} else {
|
} else {
|
||||||
|
@ -607,7 +607,7 @@ struct NewsWindow : Window {
|
||||||
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
|
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
|
||||||
nvp->UpdateViewportCoordinates(this);
|
nvp->UpdateViewportCoordinates(this);
|
||||||
|
|
||||||
if (ni->reftype1 != NR_VEHICLE) {
|
if (ni->reftype1 != NewsReferenceType::Vehicle) {
|
||||||
ScrollWindowToTile(GetReferenceTile(ni->reftype1, ni->ref1), this, true); // Re-center viewport.
|
ScrollWindowToTile(GetReferenceTile(ni->reftype1, ni->ref1), this, true); // Re-center viewport.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -677,7 +677,7 @@ private:
|
||||||
|
|
||||||
StringID GetNewVehicleMessageString(WidgetID widget) const
|
StringID GetNewVehicleMessageString(WidgetID widget) const
|
||||||
{
|
{
|
||||||
assert(this->ni->reftype1 == NR_ENGINE);
|
assert(this->ni->reftype1 == NewsReferenceType::Engine);
|
||||||
EngineID engine = this->ni->ref1;
|
EngineID engine = this->ni->ref1;
|
||||||
|
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
|
@ -930,28 +930,28 @@ CommandCost CmdCustomNewsItem(DoCommandFlag flags, NewsType type, NewsReferenceT
|
||||||
if (text.empty()) return CMD_ERROR;
|
if (text.empty()) return CMD_ERROR;
|
||||||
|
|
||||||
switch (reftype1) {
|
switch (reftype1) {
|
||||||
case NR_NONE: break;
|
case NewsReferenceType::None: break;
|
||||||
case NR_TILE:
|
case NewsReferenceType::Tile:
|
||||||
if (!IsValidTile(reference)) return CMD_ERROR;
|
if (!IsValidTile(reference)) return CMD_ERROR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NR_VEHICLE:
|
case NewsReferenceType::Vehicle:
|
||||||
if (!Vehicle::IsValidID(reference)) return CMD_ERROR;
|
if (!Vehicle::IsValidID(reference)) return CMD_ERROR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NR_STATION:
|
case NewsReferenceType::Station:
|
||||||
if (!Station::IsValidID(reference)) return CMD_ERROR;
|
if (!Station::IsValidID(reference)) return CMD_ERROR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NR_INDUSTRY:
|
case NewsReferenceType::Industry:
|
||||||
if (!Industry::IsValidID(reference)) return CMD_ERROR;
|
if (!Industry::IsValidID(reference)) return CMD_ERROR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NR_TOWN:
|
case NewsReferenceType::Town:
|
||||||
if (!Town::IsValidID(reference)) return CMD_ERROR;
|
if (!Town::IsValidID(reference)) return CMD_ERROR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NR_ENGINE:
|
case NewsReferenceType::Engine:
|
||||||
if (!Engine::IsValidID(reference)) return CMD_ERROR;
|
if (!Engine::IsValidID(reference)) return CMD_ERROR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -962,7 +962,7 @@ CommandCost CmdCustomNewsItem(DoCommandFlag flags, NewsType type, NewsReferenceT
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
SetDParamStr(0, text);
|
SetDParamStr(0, text);
|
||||||
AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NewsStyle::Normal, {}, reftype1, reference, NR_NONE, UINT32_MAX);
|
AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NewsStyle::Normal, {}, reftype1, reference, NewsReferenceType::None, UINT32_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CommandCost();
|
return CommandCost();
|
||||||
|
@ -1000,7 +1000,7 @@ void DeleteNews(Tpredicate predicate)
|
||||||
void DeleteVehicleNews(VehicleID vid, AdviceType advice_type)
|
void DeleteVehicleNews(VehicleID vid, AdviceType advice_type)
|
||||||
{
|
{
|
||||||
DeleteNews([&](const auto &ni) {
|
DeleteNews([&](const auto &ni) {
|
||||||
return ((ni.reftype1 == NR_VEHICLE && ni.ref1 == vid) || (ni.reftype2 == NR_VEHICLE && ni.ref2 == vid)) && (advice_type == AdviceType::Invalid || ni.advice_type == advice_type);
|
return ((ni.reftype1 == NewsReferenceType::Vehicle && ni.ref1 == vid) || (ni.reftype2 == NewsReferenceType::Vehicle && ni.ref2 == vid)) && (advice_type == AdviceType::Invalid || ni.advice_type == advice_type);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1012,7 +1012,7 @@ void DeleteVehicleNews(VehicleID vid, AdviceType advice_type)
|
||||||
void DeleteStationNews(StationID sid)
|
void DeleteStationNews(StationID sid)
|
||||||
{
|
{
|
||||||
DeleteNews([&](const auto &ni) {
|
DeleteNews([&](const auto &ni) {
|
||||||
return (ni.reftype1 == NR_STATION && ni.ref1 == sid) || (ni.reftype2 == NR_STATION && ni.ref2 == sid);
|
return (ni.reftype1 == NewsReferenceType::Station && ni.ref1 == sid) || (ni.reftype2 == NewsReferenceType::Station && ni.ref2 == sid);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1023,7 +1023,7 @@ void DeleteStationNews(StationID sid)
|
||||||
void DeleteIndustryNews(IndustryID iid)
|
void DeleteIndustryNews(IndustryID iid)
|
||||||
{
|
{
|
||||||
DeleteNews([&](const auto &ni) {
|
DeleteNews([&](const auto &ni) {
|
||||||
return (ni.reftype1 == NR_INDUSTRY && ni.ref1 == iid) || (ni.reftype2 == NR_INDUSTRY && ni.ref2 == iid);
|
return (ni.reftype1 == NewsReferenceType::Industry && ni.ref1 == iid) || (ni.reftype2 == NewsReferenceType::Industry && ni.ref2 == iid);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1033,8 +1033,8 @@ void DeleteIndustryNews(IndustryID iid)
|
||||||
void DeleteInvalidEngineNews()
|
void DeleteInvalidEngineNews()
|
||||||
{
|
{
|
||||||
DeleteNews([](const auto &ni) {
|
DeleteNews([](const auto &ni) {
|
||||||
return (ni.reftype1 == NR_ENGINE && (!Engine::IsValidID(ni.ref1) || !Engine::Get(ni.ref1)->IsEnabled())) ||
|
return (ni.reftype1 == NewsReferenceType::Engine && (!Engine::IsValidID(ni.ref1) || !Engine::Get(ni.ref1)->IsEnabled())) ||
|
||||||
(ni.reftype2 == NR_ENGINE && (!Engine::IsValidID(ni.ref2) || !Engine::Get(ni.ref2)->IsEnabled()));
|
(ni.reftype2 == NewsReferenceType::Engine && (!Engine::IsValidID(ni.ref2) || !Engine::Get(ni.ref2)->IsEnabled()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1054,8 +1054,8 @@ static void RemoveOldNewsItems()
|
||||||
void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
|
void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
|
||||||
{
|
{
|
||||||
for (auto &ni : _news) {
|
for (auto &ni : _news) {
|
||||||
if (ni.reftype1 == NR_VEHICLE && ni.ref1 == from_index) ni.ref1 = to_index;
|
if (ni.reftype1 == NewsReferenceType::Vehicle && ni.ref1 == from_index) ni.ref1 = to_index;
|
||||||
if (ni.reftype2 == NR_VEHICLE && ni.ref2 == from_index) ni.ref2 = to_index;
|
if (ni.reftype2 == NewsReferenceType::Vehicle && ni.ref2 == from_index) ni.ref2 = to_index;
|
||||||
if (ni.flags.Test(NewsFlag::VehicleParam0) && std::get<uint64_t>(ni.params[0]) == from_index) ni.params[0] = to_index;
|
if (ni.flags.Test(NewsFlag::VehicleParam0) && std::get<uint64_t>(ni.params[0]) == from_index) ni.params[0] = to_index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,14 +65,14 @@ enum class AdviceType : uint8_t {
|
||||||
* You have to make sure, #ChangeVehicleNews catches the DParams of your message.
|
* You have to make sure, #ChangeVehicleNews catches the DParams of your message.
|
||||||
* This is NOT ensured by the references.
|
* This is NOT ensured by the references.
|
||||||
*/
|
*/
|
||||||
enum NewsReferenceType : uint8_t {
|
enum class NewsReferenceType : uint8_t {
|
||||||
NR_NONE, ///< Empty reference
|
None, ///< Empty reference
|
||||||
NR_TILE, ///< Reference tile. Scroll to tile when clicking on the news.
|
Tile, ///< Reference tile. Scroll to tile when clicking on the news.
|
||||||
NR_VEHICLE, ///< Reference vehicle. Scroll to vehicle when clicking on the news. Delete news when vehicle is deleted.
|
Vehicle, ///< Reference vehicle. Scroll to vehicle when clicking on the news. Delete news when vehicle is deleted.
|
||||||
NR_STATION, ///< Reference station. Scroll to station when clicking on the news. Delete news when station is deleted.
|
Station, ///< Reference station. Scroll to station when clicking on the news. Delete news when station is deleted.
|
||||||
NR_INDUSTRY, ///< Reference industry. Scroll to industry when clicking on the news. Delete news when industry is deleted.
|
Industry, ///< Reference industry. Scroll to industry when clicking on the news. Delete news when industry is deleted.
|
||||||
NR_TOWN, ///< Reference town. Scroll to town when clicking on the news.
|
Town, ///< Reference town. Scroll to town when clicking on the news.
|
||||||
NR_ENGINE, ///< Reference engine.
|
Engine, ///< Reference engine.
|
||||||
};
|
};
|
||||||
|
|
||||||
/** News Window Styles. */
|
/** News Window Styles. */
|
||||||
|
|
|
@ -38,11 +38,11 @@ public:
|
||||||
*/
|
*/
|
||||||
enum NewsReferenceType {
|
enum NewsReferenceType {
|
||||||
/* Selection of useful game elements to refer to. */
|
/* Selection of useful game elements to refer to. */
|
||||||
NR_NONE = ::NR_NONE, ///< No reference supplied.
|
NR_NONE = to_underlying(::NewsReferenceType::None), ///< No reference supplied.
|
||||||
NR_TILE = ::NR_TILE, ///< Reference location, scroll to the location when clicking on the news.
|
NR_TILE = to_underlying(::NewsReferenceType::Tile), ///< Reference location, scroll to the location when clicking on the news.
|
||||||
NR_STATION = ::NR_STATION, ///< Reference station, scroll to the station when clicking on the news. Delete news when the station is deleted.
|
NR_STATION = to_underlying(::NewsReferenceType::Station), ///< Reference station, scroll to the station when clicking on the news. Delete news when the station is deleted.
|
||||||
NR_INDUSTRY = ::NR_INDUSTRY, ///< Reference industry, scrolls to the industry when clicking on the news. Delete news when the industry is deleted.
|
NR_INDUSTRY = to_underlying(::NewsReferenceType::Industry), ///< Reference industry, scrolls to the industry when clicking on the news. Delete news when the industry is deleted.
|
||||||
NR_TOWN = ::NR_TOWN, ///< Reference town, scroll to the town when clicking on the news.
|
NR_TOWN = to_underlying(::NewsReferenceType::Town), ///< Reference town, scroll to the town when clicking on the news.
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -532,7 +532,7 @@ static void ShowRejectOrAcceptNews(const Station *st, CargoTypes cargoes, bool r
|
||||||
SetDParam(0, st->index);
|
SetDParam(0, st->index);
|
||||||
SetDParam(1, cargoes);
|
SetDParam(1, cargoes);
|
||||||
StringID msg = reject ? STR_NEWS_STATION_NO_LONGER_ACCEPTS_CARGO_LIST : STR_NEWS_STATION_NOW_ACCEPTS_CARGO_LIST;
|
StringID msg = reject ? STR_NEWS_STATION_NO_LONGER_ACCEPTS_CARGO_LIST : STR_NEWS_STATION_NOW_ACCEPTS_CARGO_LIST;
|
||||||
AddNewsItem(msg, NewsType::Acceptance, NewsStyle::Small, NewsFlag::InColour, NR_STATION, st->index);
|
AddNewsItem(msg, NewsType::Acceptance, NewsStyle::Small, NewsFlag::InColour, NewsReferenceType::Station, st->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -74,8 +74,8 @@ void Subsidy::AwardTo(CompanyID company)
|
||||||
*/
|
*/
|
||||||
std::pair<NewsReferenceType, NewsReferenceType> SetupSubsidyDecodeParam(const Subsidy *s, SubsidyDecodeParamType mode, uint parameter_offset)
|
std::pair<NewsReferenceType, NewsReferenceType> SetupSubsidyDecodeParam(const Subsidy *s, SubsidyDecodeParamType mode, uint parameter_offset)
|
||||||
{
|
{
|
||||||
NewsReferenceType reftype1 = NR_NONE;
|
NewsReferenceType reftype1 = NewsReferenceType::None;
|
||||||
NewsReferenceType reftype2 = NR_NONE;
|
NewsReferenceType reftype2 = NewsReferenceType::None;
|
||||||
|
|
||||||
/* Always use the plural form of the cargo name - trying to decide between plural or singular causes issues for translations */
|
/* Always use the plural form of the cargo name - trying to decide between plural or singular causes issues for translations */
|
||||||
const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
|
const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
|
||||||
|
@ -83,11 +83,11 @@ std::pair<NewsReferenceType, NewsReferenceType> SetupSubsidyDecodeParam(const Su
|
||||||
|
|
||||||
switch (s->src_type) {
|
switch (s->src_type) {
|
||||||
case SourceType::Industry:
|
case SourceType::Industry:
|
||||||
reftype1 = NR_INDUSTRY;
|
reftype1 = NewsReferenceType::Industry;
|
||||||
SetDParam(parameter_offset + 1, STR_INDUSTRY_NAME);
|
SetDParam(parameter_offset + 1, STR_INDUSTRY_NAME);
|
||||||
break;
|
break;
|
||||||
case SourceType::Town:
|
case SourceType::Town:
|
||||||
reftype1 = NR_TOWN;
|
reftype1 = NewsReferenceType::Town;
|
||||||
SetDParam(parameter_offset + 1, STR_TOWN_NAME);
|
SetDParam(parameter_offset + 1, STR_TOWN_NAME);
|
||||||
break;
|
break;
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
|
@ -96,11 +96,11 @@ std::pair<NewsReferenceType, NewsReferenceType> SetupSubsidyDecodeParam(const Su
|
||||||
|
|
||||||
switch (s->dst_type) {
|
switch (s->dst_type) {
|
||||||
case SourceType::Industry:
|
case SourceType::Industry:
|
||||||
reftype2 = NR_INDUSTRY;
|
reftype2 = NewsReferenceType::Industry;
|
||||||
SetDParam(parameter_offset + 4, STR_INDUSTRY_NAME);
|
SetDParam(parameter_offset + 4, STR_INDUSTRY_NAME);
|
||||||
break;
|
break;
|
||||||
case SourceType::Town:
|
case SourceType::Town:
|
||||||
reftype2 = NR_TOWN;
|
reftype2 = NewsReferenceType::Town;
|
||||||
SetDParam(parameter_offset + 4, STR_TOWN_NAME);
|
SetDParam(parameter_offset + 4, STR_TOWN_NAME);
|
||||||
break;
|
break;
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
|
|
|
@ -3388,7 +3388,7 @@ static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlag flags)
|
||||||
|
|
||||||
AddNewsItem(
|
AddNewsItem(
|
||||||
TimerGameEconomy::UsingWallclockUnits() ? STR_NEWS_ROAD_REBUILDING_MINUTES : STR_NEWS_ROAD_REBUILDING_MONTHS,
|
TimerGameEconomy::UsingWallclockUnits() ? STR_NEWS_ROAD_REBUILDING_MINUTES : STR_NEWS_ROAD_REBUILDING_MONTHS,
|
||||||
NewsType::General, NewsStyle::Normal, {}, NR_TOWN, t->index, NR_NONE, UINT32_MAX);
|
NewsType::General, NewsStyle::Normal, {}, NewsReferenceType::Town, t->index, NewsReferenceType::None, UINT32_MAX);
|
||||||
AI::BroadcastNewEvent(new ScriptEventRoadReconstruction((ScriptCompany::CompanyID)(Owner)_current_company, t->index));
|
AI::BroadcastNewEvent(new ScriptEventRoadReconstruction((ScriptCompany::CompanyID)(Owner)_current_company, t->index));
|
||||||
Game::NewEvent(new ScriptEventRoadReconstruction((ScriptCompany::CompanyID)(Owner)_current_company, t->index));
|
Game::NewEvent(new ScriptEventRoadReconstruction((ScriptCompany::CompanyID)(Owner)_current_company, t->index));
|
||||||
}
|
}
|
||||||
|
@ -3543,7 +3543,7 @@ static CommandCost TownActionBuyRights(Town *t, DoCommandFlag flags)
|
||||||
SetDParam(1, TimerGameEconomy::UsingWallclockUnits() ? STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION_MINUTES : STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION_MONTHS);
|
SetDParam(1, TimerGameEconomy::UsingWallclockUnits() ? STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION_MINUTES : STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION_MONTHS);
|
||||||
SetDParam(2, t->index);
|
SetDParam(2, t->index);
|
||||||
SetDParamStr(3, cni->company_name);
|
SetDParamStr(3, cni->company_name);
|
||||||
AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NewsType::General, NewsStyle::Company, {}, NR_TOWN, t->index, NR_NONE, UINT32_MAX, std::move(cni));
|
AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NewsType::General, NewsStyle::Company, {}, NewsReferenceType::Town, t->index, NewsReferenceType::None, UINT32_MAX, std::move(cni));
|
||||||
AI::BroadcastNewEvent(new ScriptEventExclusiveTransportRights((ScriptCompany::CompanyID)(Owner)_current_company, t->index));
|
AI::BroadcastNewEvent(new ScriptEventExclusiveTransportRights((ScriptCompany::CompanyID)(Owner)_current_company, t->index));
|
||||||
Game::NewEvent(new ScriptEventExclusiveTransportRights((ScriptCompany::CompanyID)(Owner)_current_company, t->index));
|
Game::NewEvent(new ScriptEventExclusiveTransportRights((ScriptCompany::CompanyID)(Owner)_current_company, t->index));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue