mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-06-20 20:19:35 +01:00
Fix 6e10584b91
: Keep custom news from game scripts in encoded form. (#13741)
This allows the news message to translated as appropriate.
This commit is contained in:
parent
b979f0414c
commit
51fd2853cb
@ -750,9 +750,9 @@ Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestio
|
||||
* @param suggestion Suggested bounding box.
|
||||
* @return Bounding box for the multi-line string, may be bigger than \a suggestion.
|
||||
*/
|
||||
Dimension GetStringMultiLineBoundingBox(std::string_view str, const Dimension &suggestion)
|
||||
Dimension GetStringMultiLineBoundingBox(std::string_view str, const Dimension &suggestion, FontSize fontsize)
|
||||
{
|
||||
Dimension box = {suggestion.width, (uint)GetStringHeight(str, suggestion.width)};
|
||||
Dimension box = {suggestion.width, (uint)GetStringHeight(str, suggestion.width, fontsize)};
|
||||
return box;
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ int GetStringHeight(std::string_view str, int maxw, FontSize fontsize = FS_NORMA
|
||||
int GetStringHeight(StringID str, int maxw);
|
||||
int GetStringLineCount(std::string_view str, int maxw);
|
||||
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion);
|
||||
Dimension GetStringMultiLineBoundingBox(std::string_view str, const Dimension &suggestion);
|
||||
Dimension GetStringMultiLineBoundingBox(std::string_view str, const Dimension &suggestion, FontSize fontsize = FS_NORMAL);
|
||||
void LoadStringWidthTable(bool monospace = false);
|
||||
|
||||
void DrawDirtyBlocks();
|
||||
|
@ -2170,20 +2170,12 @@ CommandCost CmdIndustrySetProduction(DoCommandFlags flags, IndustryID ind_id, ui
|
||||
if (ind == nullptr) return CMD_ERROR;
|
||||
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
StringID str = STR_NULL;
|
||||
if (prod_level > ind->prod_level) {
|
||||
str = GetIndustrySpec(ind->type)->production_up_text;
|
||||
} else if (prod_level < ind->prod_level) {
|
||||
str = GetIndustrySpec(ind->type)->production_down_text;
|
||||
}
|
||||
if (prod_level != ind->prod_level && !custom_news.empty()) str = STR_NEWS_CUSTOM_ITEM;
|
||||
|
||||
ind->ctlflags.Set(IndustryControlFlag::ExternalProdLevel);
|
||||
ind->prod_level = prod_level;
|
||||
ind->RecomputeProductionMultipliers();
|
||||
|
||||
/* Show news message if requested. */
|
||||
if (show_news && str != STR_NULL) {
|
||||
if (show_news && prod_level != ind->prod_level) {
|
||||
NewsType nt;
|
||||
switch (WhoCanServiceIndustry(ind)) {
|
||||
case 0: nt = NewsType::IndustryNobody; break;
|
||||
@ -2194,13 +2186,19 @@ CommandCost CmdIndustrySetProduction(DoCommandFlags flags, IndustryID ind_id, ui
|
||||
|
||||
/* Set parameters of news string */
|
||||
EncodedString headline;
|
||||
if (str == STR_NEWS_CUSTOM_ITEM) {
|
||||
headline = GetEncodedString(str, custom_news.GetDecodedString());
|
||||
} else if (str > STR_LAST_STRINGID) {
|
||||
if (!custom_news.empty()) {
|
||||
headline = custom_news;
|
||||
} else {
|
||||
StringID str = (prod_level > ind->prod_level)
|
||||
? GetIndustrySpec(ind->type)->production_up_text
|
||||
: GetIndustrySpec(ind->type)->production_down_text;
|
||||
|
||||
if (str > STR_LAST_STRINGID) {
|
||||
headline = GetEncodedString(str, STR_TOWN_NAME, ind->town->index, GetIndustrySpec(ind->type)->name);
|
||||
} else {
|
||||
headline = GetEncodedString(str, ind->index);
|
||||
}
|
||||
}
|
||||
|
||||
AddIndustryNewsItem(std::move(headline), nt, ind->index);
|
||||
}
|
||||
|
@ -841,7 +841,6 @@ STR_MESSAGE_HISTORY_TOOLTIP :{BLACK}A list o
|
||||
STR_MESSAGE_NEWS_FORMAT :{STRING} - {RAW_STRING}
|
||||
|
||||
STR_NEWS_MESSAGE_CAPTION :{WHITE}Message
|
||||
STR_NEWS_CUSTOM_ITEM :{BIG_FONT}{BLACK}{RAW_STRING}
|
||||
|
||||
STR_NEWS_FIRST_TRAIN_ARRIVAL :{BIG_FONT}{BLACK}Citizens celebrate . . .{}First train arrives at {STATION}!
|
||||
STR_NEWS_FIRST_BUS_ARRIVAL :{BIG_FONT}{BLACK}Citizens celebrate . . .{}First bus arrives at {STATION}!
|
||||
|
@ -424,6 +424,7 @@ struct NewsWindow : Window {
|
||||
|
||||
void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
|
||||
{
|
||||
FontSize fontsize = FS_NORMAL;
|
||||
std::string str;
|
||||
switch (widget) {
|
||||
case WID_N_CAPTION: {
|
||||
@ -441,6 +442,7 @@ struct NewsWindow : Window {
|
||||
|
||||
case WID_N_MESSAGE:
|
||||
case WID_N_COMPANY_MSG:
|
||||
fontsize = FS_LARGE;
|
||||
str = this->ni->headline.GetDecodedString();
|
||||
break;
|
||||
|
||||
@ -481,7 +483,7 @@ struct NewsWindow : Window {
|
||||
Dimension d = size;
|
||||
d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
|
||||
d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
|
||||
d = GetStringMultiLineBoundingBox(str, d);
|
||||
d = GetStringMultiLineBoundingBox(str, d, fontsize);
|
||||
d.width += padding.width;
|
||||
d.height += padding.height;
|
||||
size = maxdim(size, d);
|
||||
@ -513,7 +515,7 @@ struct NewsWindow : Window {
|
||||
|
||||
case WID_N_MESSAGE:
|
||||
case WID_N_COMPANY_MSG:
|
||||
DrawStringMultiLine(r, this->ni->headline.GetDecodedString(), TC_FROMSTRING, SA_CENTER);
|
||||
DrawStringMultiLine(r, this->ni->headline.GetDecodedString(), TC_BLACK, SA_CENTER, false, FS_LARGE);
|
||||
break;
|
||||
|
||||
case WID_N_MGR_FACE: {
|
||||
@ -957,7 +959,7 @@ CommandCost CmdCustomNewsItem(DoCommandFlags flags, NewsType type, CompanyID com
|
||||
if (company != INVALID_OWNER && company != _local_company) return CommandCost();
|
||||
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
AddNewsItem(GetEncodedString(STR_NEWS_CUSTOM_ITEM, text.GetDecodedString()), type, NewsStyle::Normal, {}, reference, {});
|
||||
AddNewsItem(EncodedString{text}, type, NewsStyle::Normal, {}, reference, {});
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
|
Loading…
Reference in New Issue
Block a user