1
0
Fork 0

Codechange: Use parameterised GetString() for news window.

pull/13696/head
Peter Nelson 2025-03-01 23:41:51 +00:00 committed by Peter Nelson
parent 937fb12d9a
commit 5f073670d7
1 changed files with 8 additions and 14 deletions

View File

@ -449,7 +449,7 @@ struct NewsWindow : Window {
case WID_N_VEH_NAME: case WID_N_VEH_NAME:
case WID_N_VEH_TITLE: case WID_N_VEH_TITLE:
str = GetString(this->GetNewVehicleMessageString(widget)); str = this->GetNewVehicleMessageString(widget);
break; break;
case WID_N_VEH_INFO: { case WID_N_VEH_INFO: {
@ -524,8 +524,7 @@ struct NewsWindow : Window {
} }
case WID_N_MGR_NAME: { case WID_N_MGR_NAME: {
const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get()); const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
SetDParamStr(0, cni->president_name); DrawStringMultiLine(r, GetString(STR_JUST_RAW_STRING, cni->president_name), TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
break; break;
} }
@ -612,8 +611,7 @@ struct NewsWindow : Window {
NWidgetResizeBase *wid = this->GetWidget<NWidgetResizeBase>(WID_N_MGR_NAME); NWidgetResizeBase *wid = this->GetWidget<NWidgetResizeBase>(WID_N_MGR_NAME);
if (wid != nullptr) { if (wid != nullptr) {
SetDParamStr(0, static_cast<const CompanyNewsInformation *>(this->ni->data.get())->president_name); int y = GetStringHeight(GetString(STR_JUST_RAW_STRING, static_cast<const CompanyNewsInformation *>(this->ni->data.get())->president_name), wid->current_x);
int y = GetStringHeight(STR_JUST_RAW_STRING, wid->current_x);
if (wid->UpdateVerticalSize(y)) this->ReInit(0, 0); if (wid->UpdateVerticalSize(y)) this->ReInit(0, 0);
} }
} }
@ -666,19 +664,17 @@ private:
AddDirtyBlock(this->left, mintop, this->left + this->width, maxtop + this->height); AddDirtyBlock(this->left, mintop, this->left + this->width, maxtop + this->height);
} }
StringID GetNewVehicleMessageString(WidgetID widget) const std::string GetNewVehicleMessageString(WidgetID widget) const
{ {
assert(std::holds_alternative<EngineID>(ni->ref1)); assert(std::holds_alternative<EngineID>(ni->ref1));
EngineID engine = std::get<EngineID>(this->ni->ref1); EngineID engine = std::get<EngineID>(this->ni->ref1);
switch (widget) { switch (widget) {
case WID_N_VEH_TITLE: case WID_N_VEH_TITLE:
SetDParam(0, GetEngineCategoryName(engine)); return GetString(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE, GetEngineCategoryName(engine));
return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
case WID_N_VEH_NAME: case WID_N_VEH_NAME:
SetDParam(0, PackEngineNameDParam(engine, EngineNameContext::PreviewNews)); return GetString(STR_NEWS_NEW_VEHICLE_TYPE, PackEngineNameDParam(engine, EngineNameContext::PreviewNews));
return STR_NEWS_NEW_VEHICLE_TYPE;
default: default:
NOT_REACHED(); NOT_REACHED();
@ -1212,8 +1208,7 @@ struct MessageHistoryWindow : Window {
/* Months are off-by-one, so it's actually 8. Not using /* Months are off-by-one, so it's actually 8. Not using
* month 12 because the 1 is usually less wide. */ * month 12 because the 1 is usually less wide. */
SetDParam(0, TimerGameCalendar::ConvertYMDToDate(CalendarTime::ORIGINAL_MAX_YEAR, 7, 30)); this->date_width = GetStringBoundingBox(GetString(STR_JUST_DATE_TINY, TimerGameCalendar::ConvertYMDToDate(CalendarTime::ORIGINAL_MAX_YEAR, 7, 30))).width + WidgetDimensions::scaled.hsep_wide;
this->date_width = GetStringBoundingBox(STR_JUST_DATE_TINY).width + WidgetDimensions::scaled.hsep_wide;
size.height = 4 * resize.height + WidgetDimensions::scaled.framerect.Vertical(); // At least 4 lines are visible. size.height = 4 * resize.height + WidgetDimensions::scaled.framerect.Vertical(); // At least 4 lines are visible.
size.width = std::max(200u, size.width); // At least 200 pixels wide. size.width = std::max(200u, size.width); // At least 200 pixels wide.
@ -1232,8 +1227,7 @@ struct MessageHistoryWindow : Window {
auto [first, last] = this->vscroll->GetVisibleRangeIterators(_news); auto [first, last] = this->vscroll->GetVisibleRangeIterators(_news);
for (auto ni = first; ni != last; ++ni) { for (auto ni = first; ni != last; ++ni) {
SetDParam(0, ni->date); DrawString(date.left, date.right, y, GetString(STR_JUST_DATE_TINY, ni->date), TC_WHITE);
DrawString(date.left, date.right, y, STR_JUST_DATE_TINY, TC_WHITE);
DrawNewsString(news.left, news.right, y, TC_WHITE, &*ni); DrawNewsString(news.left, news.right, y, TC_WHITE, &*ni);
y += this->line_height; y += this->line_height;