Update to 14.0-beta1

This commit is contained in:
dP
2024-02-04 02:18:17 +05:30
parent 79037e2c65
commit 33ef333b57
1325 changed files with 138461 additions and 70983 deletions
+86 -109
View File
@@ -12,7 +12,6 @@
#include "viewport_func.h"
#include "strings_func.h"
#include "window_func.h"
#include "date_func.h"
#include "vehicle_base.h"
#include "vehicle_func.h"
#include "vehicle_gui.h"
@@ -32,10 +31,12 @@
#include "command_func.h"
#include "company_base.h"
#include "settings_internal.h"
#include "guitimer_func.h"
#include "group_gui.h"
#include "zoom_func.h"
#include "news_cmd.h"
#include "timer/timer.h"
#include "timer/timer_window.h"
#include "timer/timer_game_calendar.h"
#include "widgets/news_widget.h"
@@ -69,7 +70,7 @@ static const NewsItem *_current_news = nullptr;
* @param ref The reference.
* @return A tile for the referenced object, or INVALID_TILE if none.
*/
static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32 ref)
static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32_t ref)
{
switch (reftype) {
case NR_TILE: return (TileIndex)ref;
@@ -81,13 +82,13 @@ static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32 ref)
}
/* Normal news items. */
static const NWidgetPart _nested_normal_news_widgets[] = {
static constexpr NWidgetPart _nested_normal_news_widgets[] = {
NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
NWidget(NWID_SPACER), SetFill(1, 0),
NWidget(NWID_VERTICAL),
NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_JUST_DATE_LONG, STR_NULL), SetTextStyle(TC_BLACK, FS_SMALL),
NWidget(NWID_SPACER), SetFill(0, 1),
EndContainer(),
EndContainer(),
@@ -95,15 +96,15 @@ static const NWidgetPart _nested_normal_news_widgets[] = {
EndContainer(),
};
static WindowDesc _normal_news_desc(
static WindowDesc _normal_news_desc(__FILE__, __LINE__,
WDP_MANUAL, nullptr, 0, 0,
WC_NEWS_WINDOW, WC_NONE,
0,
_nested_normal_news_widgets, lengthof(_nested_normal_news_widgets)
std::begin(_nested_normal_news_widgets), std::end(_nested_normal_news_widgets)
);
/* New vehicles news items. */
static const NWidgetPart _nested_vehicle_news_widgets[] = {
static constexpr NWidgetPart _nested_vehicle_news_widgets[] = {
NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
NWidget(NWID_VERTICAL),
@@ -122,15 +123,15 @@ static const NWidgetPart _nested_vehicle_news_widgets[] = {
EndContainer(),
};
static WindowDesc _vehicle_news_desc(
static WindowDesc _vehicle_news_desc(__FILE__, __LINE__,
WDP_MANUAL, nullptr, 0, 0,
WC_NEWS_WINDOW, WC_NONE,
0,
_nested_vehicle_news_widgets, lengthof(_nested_vehicle_news_widgets)
std::begin(_nested_vehicle_news_widgets), std::end(_nested_vehicle_news_widgets)
);
/* Company news items. */
static const NWidgetPart _nested_company_news_widgets[] = {
static constexpr NWidgetPart _nested_company_news_widgets[] = {
NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
NWidget(NWID_VERTICAL),
@@ -150,21 +151,21 @@ static const NWidgetPart _nested_company_news_widgets[] = {
EndContainer(),
};
static WindowDesc _company_news_desc(
static WindowDesc _company_news_desc(__FILE__, __LINE__,
WDP_MANUAL, nullptr, 0, 0,
WC_NEWS_WINDOW, WC_NONE,
0,
_nested_company_news_widgets, lengthof(_nested_company_news_widgets)
std::begin(_nested_company_news_widgets), std::end(_nested_company_news_widgets)
);
/* Thin news items. */
static const NWidgetPart _nested_thin_news_widgets[] = {
static constexpr NWidgetPart _nested_thin_news_widgets[] = {
NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
NWidget(NWID_SPACER), SetFill(1, 0),
NWidget(NWID_VERTICAL),
NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_JUST_DATE_LONG, STR_NULL), SetTextStyle(TC_BLACK, FS_SMALL),
NWidget(NWID_SPACER), SetFill(0, 1),
EndContainer(),
EndContainer(),
@@ -173,15 +174,15 @@ static const NWidgetPart _nested_thin_news_widgets[] = {
EndContainer(),
};
static WindowDesc _thin_news_desc(
static WindowDesc _thin_news_desc(__FILE__, __LINE__,
WDP_MANUAL, nullptr, 0, 0,
WC_NEWS_WINDOW, WC_NONE,
0,
_nested_thin_news_widgets, lengthof(_nested_thin_news_widgets)
std::begin(_nested_thin_news_widgets), std::end(_nested_thin_news_widgets)
);
/* Small news items. */
static const NWidgetPart _nested_small_news_widgets[] = {
static constexpr NWidgetPart _nested_small_news_widgets[] = {
/* Caption + close box. The caption is no WWT_CAPTION as the window shall not be moveable and so on. */
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
@@ -199,17 +200,17 @@ static const NWidgetPart _nested_small_news_widgets[] = {
EndContainer(),
};
static WindowDesc _small_news_desc(
static WindowDesc _small_news_desc(__FILE__, __LINE__,
WDP_MANUAL, nullptr, 0, 0,
WC_NEWS_WINDOW, WC_NONE,
0,
_nested_small_news_widgets, lengthof(_nested_small_news_widgets)
std::begin(_nested_small_news_widgets), std::end(_nested_small_news_widgets)
);
/**
* Window layouts for news items.
*/
static WindowDesc* _news_window_layout[] = {
static WindowDesc *_news_window_layout[] = {
&_thin_news_desc, ///< NF_THIN
&_small_news_desc, ///< NF_SMALL
&_normal_news_desc, ///< NF_NORMAL
@@ -217,7 +218,7 @@ static WindowDesc* _news_window_layout[] = {
&_company_news_desc, ///< NF_COMPANY
};
WindowDesc* GetNewsWindowLayout(NewsFlag flags)
WindowDesc *GetNewsWindowLayout(NewsFlag flags)
{
uint layout = GB(flags, NFB_WINDOW_LAYOUT, NFB_WINDOW_LAYOUT_COUNT);
assert(layout < lengthof(_news_window_layout));
@@ -262,14 +263,11 @@ NewsDisplay NewsTypeData::GetDisplay() const
/** Window class displaying a news item. */
struct NewsWindow : Window {
uint16 chat_height; ///< Height of the chat window.
uint16 status_height; ///< Height of the status bar window
uint16_t chat_height; ///< Height of the chat window.
uint16_t status_height; ///< Height of the status bar window
const NewsItem *ni; ///< News item to display.
static int duration; ///< Remaining time for showing the current news message (may only be access while a news item is displayed).
static const uint TIMER_INTERVAL = 210; ///< Scrolling interval, scaled by line text line height. This value chosen to maintain the 15ms at normal zoom.
GUITimer timer;
NewsWindow(WindowDesc *desc, const NewsItem *ni) : Window(desc), ni(ni)
{
NewsWindow::duration = 16650;
@@ -282,7 +280,7 @@ struct NewsWindow : Window {
this->CreateNestedTree();
/* For company news with a face we have a separate headline in param[0] */
if (desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->widget_data = this->ni->params[0];
if (desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->widget_data = this->ni->params[0].data;
NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP);
if (ni->reftype1 == NR_VEHICLE && nwid != nullptr) {
@@ -310,7 +308,11 @@ struct NewsWindow : Window {
/* Initialize viewport if it exists. */
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
if (nvp != nullptr) {
nvp->InitializeViewport(this, ni->reftype1 == NR_VEHICLE ? 0x80000000 | ni->ref1 : (uint32)GetReferenceTile(ni->reftype1, ni->ref1),ScaleZoomGUI(ZOOM_LVL_NEWS));
if (ni->reftype1 == NR_VEHICLE) {
nvp->InitializeViewport(this, static_cast<VehicleID>(ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
} else {
nvp->InitializeViewport(this, GetReferenceTile(ni->reftype1, ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
}
if (this->ni->flags & NF_NO_TRANSPARENT) nvp->disp_flags |= ND_NO_TRANSPARENCY;
if ((this->ni->flags & NF_INCOLOUR) == 0) {
nvp->disp_flags |= ND_SHADE_GREY;
@@ -322,11 +324,6 @@ struct NewsWindow : Window {
PositionNewsMessage(this);
}
void OnInit() override
{
this->timer.SetInterval(TIMER_INTERVAL / FONT_HEIGHT_NORMAL);
}
void DrawNewsBorder(const Rect &r) const
{
Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
@@ -339,13 +336,13 @@ struct NewsWindow : Window {
GfxFillRect( r.left, ir.bottom, r.right, r.bottom, PC_BLACK);
}
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
{
Point pt = { 0, _screen.height };
return pt;
}
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
{
StringID str = STR_NULL;
switch (widget) {
@@ -359,7 +356,7 @@ struct NewsWindow : Window {
}
case WID_N_MGR_FACE:
*size = maxdim(*size, GetSpriteSize(SPR_GRADIENT));
*size = maxdim(*size, GetScaledSpriteSize(SPR_GRADIENT));
break;
case WID_N_MGR_NAME:
@@ -368,7 +365,7 @@ struct NewsWindow : Window {
break;
case WID_N_MESSAGE:
CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
CopyInDParam(this->ni->params);
str = this->ni->string_id;
break;
@@ -419,16 +416,16 @@ struct NewsWindow : Window {
*size = maxdim(*size, d);
}
void SetStringParameters(int widget) const override
void SetStringParameters(WidgetID widget) const override
{
if (widget == WID_N_DATE) SetDParam(0, this->ni->date);
}
void DrawWidget(const Rect &r, int widget) const override
void DrawWidget(const Rect &r, WidgetID widget) const override
{
switch (widget) {
case WID_N_CAPTION:
DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, TC_FROMSTRING, STR_NEWS_MESSAGE_CAPTION, SA_CENTER);
DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, TC_FROMSTRING, STR_NEWS_MESSAGE_CAPTION, SA_CENTER, FS_NORMAL);
break;
case WID_N_PANEL:
@@ -436,13 +433,13 @@ struct NewsWindow : Window {
break;
case WID_N_MESSAGE:
CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
CopyInDParam(this->ni->params);
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->ni->string_id, TC_FROMSTRING, SA_CENTER);
break;
case WID_N_MGR_FACE: {
const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
DrawCompanyManagerFace(cni->face, cni->colour, r.left, r.top);
DrawCompanyManagerFace(cni->face, cni->colour, r);
GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
break;
}
@@ -481,7 +478,7 @@ struct NewsWindow : Window {
}
}
void OnClick(Point pt, int widget, int click_count) override
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
{
switch (widget) {
case WID_N_CLOSEBOX:
@@ -543,7 +540,7 @@ struct NewsWindow : Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
void OnInvalidateData(int data = 0, bool gui_scope = true) override
void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
{
if (!gui_scope) return;
/* The chatbar has notified us that is was either created or closed */
@@ -552,20 +549,23 @@ struct NewsWindow : Window {
this->SetWindowTop(newtop);
}
void OnRealtimeTick(uint delta_ms) override
void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
{
int count = this->timer.CountElapsed(delta_ms);
if (count > 0) {
/* Scroll up newsmessages from the bottom */
int newtop = std::max(this->top - 2 * count, _screen.height - this->height - this->status_height - this->chat_height);
this->SetWindowTop(newtop);
}
/* Decrement the news timer. We don't need to action an elapsed event here,
* so no need to use TimerElapsed(). */
if (NewsWindow::duration > 0) NewsWindow::duration -= delta_ms;
}
/**
* Scroll the news message slowly up from the bottom.
*
* The interval of 210ms is chosen to maintain 15ms at normal zoom: 210 / GetCharacterHeight(FS_NORMAL) = 15ms.
*/
IntervalTimer<TimerWindow> scroll_interval = {std::chrono::milliseconds(210) / GetCharacterHeight(FS_NORMAL), [this](uint count) {
int newtop = std::max(this->top - 2 * static_cast<int>(count), _screen.height - this->height - this->status_height - this->chat_height);
this->SetWindowTop(newtop);
}};
private:
/**
* Moves the window to a new #top coordinate. Makes screen dirty where needed.
@@ -586,11 +586,11 @@ private:
StringID GetCompanyMessageString() const
{
/* Company news with a face have a separate headline, so the normal message is shifted by two params */
CopyInDParam(0, this->ni->params + 2, lengthof(this->ni->params) - 2);
return this->ni->params[1];
CopyInDParam(std::span(this->ni->params.data() + 2, this->ni->params.size() - 2));
return this->ni->params[1].data;
}
StringID GetNewVehicleMessageString(int widget) const
StringID GetNewVehicleMessageString(WidgetID widget) const
{
assert(this->ni->reftype1 == NR_ENGINE);
EngineID engine = this->ni->ref1;
@@ -690,7 +690,7 @@ static void MoveToNextTickerItem()
const NewsType type = ni->type;
/* check the date, don't show too old items */
if (_date - _news_type_data[type].age > ni->date) continue;
if (TimerGameEconomy::date - _news_type_data[type].age > ni->economy_date) continue;
switch (_news_type_data[type].GetDisplay()) {
default: NOT_REACHED();
@@ -727,7 +727,7 @@ static void MoveToNextNewsItem()
const NewsType type = ni->type;
/* check the date, don't show too old items */
if (_date - _news_type_data[type].age > ni->date) continue;
if (TimerGameEconomy::date - _news_type_data[type].age > ni->economy_date) continue;
switch (_news_type_data[type].GetDisplay()) {
default: NOT_REACHED();
@@ -803,12 +803,12 @@ static void DeleteNewsItem(NewsItem *ni)
*
* @see NewsSubtype
*/
NewsItem::NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, const NewsAllocatedData *data) :
string_id(string_id), date(_date), type(type), flags(flags), reftype1(reftype1), reftype2(reftype2), ref1(ref1), ref2(ref2), data(data)
NewsItem::NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data) :
string_id(string_id), date(TimerGameCalendar::date), economy_date(TimerGameEconomy::date), type(type), flags(flags), reftype1(reftype1), reftype2(reftype2), ref1(ref1), ref2(ref2), data(data)
{
/* show this news message in colour? */
if (_cur_year >= _settings_client.gui.coloured_news_year) this->flags |= NF_INCOLOUR;
CopyOutDParam(this->params, 0, lengthof(this->params));
if (TimerGameCalendar::year >= _settings_client.gui.coloured_news_year) this->flags |= NF_INCOLOUR;
CopyOutDParam(this->params, 10);
}
/**
@@ -824,7 +824,7 @@ NewsItem::NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsRefere
*
* @see NewsSubtype
*/
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, const NewsAllocatedData *data)
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data)
{
if (_game_mode == GM_MENU) return;
@@ -862,7 +862,7 @@ void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceTy
* @param text The text of the news message.
* @return the cost of this operation or an error
*/
CommandCost CmdCustomNewsItem(DoCommandFlag flags, NewsType type, NewsReferenceType reftype1, CompanyID company, uint32 reference, const std::string &text)
CommandCost CmdCustomNewsItem(DoCommandFlag flags, NewsType type, NewsReferenceType reftype1, CompanyID company, uint32_t reference, const std::string &text)
{
if (_current_company != OWNER_DEITY) return CMD_ERROR;
@@ -987,7 +987,7 @@ static void RemoveOldNewsItems()
NewsItem *next;
for (NewsItem *cur = _oldest_news; _total_news > MIN_NEWS_AMOUNT && cur != nullptr; cur = next) {
next = cur->next;
if (_date - _news_type_data[cur->type].age * _settings_client.gui.news_message_timeout > cur->date) DeleteNewsItem(cur);
if (TimerGameEconomy::date - _news_type_data[cur->type].age * _settings_client.gui.news_message_timeout > cur->economy_date) DeleteNewsItem(cur);
}
}
@@ -1002,7 +1002,7 @@ void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
for (NewsItem *ni = _oldest_news; ni != nullptr; ni = ni->next) {
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 && ni->params[0] == from_index) ni->params[0] = to_index;
if (ni->flags & NF_VEHICLE_PARAM0 && ni->params[0].data == from_index) ni->params[0] = to_index;
}
}
@@ -1011,11 +1011,11 @@ void NewsLoop()
/* no news item yet */
if (_total_news == 0) return;
static byte _last_clean_month = 0;
static TimerGameEconomy::Month _last_clean_month = 0;
if (_last_clean_month != _cur_month) {
if (_last_clean_month != TimerGameEconomy::month) {
RemoveOldNewsItems();
_last_clean_month = _cur_month;
_last_clean_month = TimerGameEconomy::month;
}
if (ReadyForNextTickerItem()) MoveToNextTickerItem();
@@ -1043,7 +1043,8 @@ static void ShowNewsMessage(const NewsItem *ni)
* Close active news message window
* @return true if a window was closed.
*/
bool HideActiveNewsMessage() {
bool HideActiveNewsMessage()
{
NewsWindow *w = (NewsWindow*)FindWindowById(WC_NEWS_WINDOW, 0);
if (w == nullptr) return false;
w->Close();
@@ -1103,37 +1104,13 @@ void ShowLastNewsMessage()
*/
static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem *ni)
{
char buffer[512], buffer2[512];
StringID str;
CopyInDParam(ni->params);
CopyInDParam(0, ni->params, lengthof(ni->params));
str = ni->string_id;
/* Get the string, replaces newlines with spaces and remove control codes from the string. */
std::string message = StrMakeValid(GetString(ni->string_id), SVS_REPLACE_TAB_CR_NL_WITH_SPACE);
GetString(buffer, str, lastof(buffer));
/* Copy the just gotten string to another buffer to remove any formatting
* from it such as big fonts, etc. */
const char *ptr = buffer;
char *dest = buffer2;
WChar c_last = '\0';
for (;;) {
WChar c = Utf8Consume(&ptr);
if (c == 0) break;
/* Make a space from a newline, but ignore multiple newlines */
if (c == '\n' && c_last != '\n') {
dest[0] = ' ';
dest++;
} else if (c == '\r') {
dest[0] = dest[1] = dest[2] = dest[3] = ' ';
dest += 4;
} else if (IsPrintable(c)) {
dest += Utf8Encode(dest, c);
}
c_last = c;
}
*dest = '\0';
/* Truncate and show string; postfixed by '...' if necessary */
DrawString(left, right, y, buffer2, colour);
DrawString(left, right, y, message, colour);
}
struct MessageHistoryWindow : Window {
@@ -1150,16 +1127,16 @@ struct MessageHistoryWindow : Window {
this->OnInvalidateData(0);
}
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
{
if (widget == WID_MH_BACKGROUND) {
this->line_height = FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal;
this->line_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
resize->height = this->line_height;
/* Months are off-by-one, so it's actually 8. Not using
* month 12 because the 1 is usually less wide. */
SetDParam(0, ConvertYMDToDate(ORIGINAL_MAX_YEAR, 7, 30));
this->date_width = GetStringBoundingBox(STR_SHORT_DATE).width + WidgetDimensions::scaled.hsep_wide;
SetDParam(0, TimerGameCalendar::ConvertYMDToDate(CalendarTime::ORIGINAL_MAX_YEAR, 7, 30));
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->width = std::max(200u, size->width); // At least 200 pixels wide.
@@ -1172,7 +1149,7 @@ struct MessageHistoryWindow : Window {
this->DrawWidgets();
}
void DrawWidget(const Rect &r, int widget) const override
void DrawWidget(const Rect &r, WidgetID widget) const override
{
if (widget != WID_MH_BACKGROUND || _total_news == 0) return;
@@ -1190,7 +1167,7 @@ struct MessageHistoryWindow : Window {
int y = news.top;
for (int n = this->vscroll->GetCapacity(); n > 0; n--) {
SetDParam(0, ni->date);
DrawString(date.left, date.right, y, STR_SHORT_DATE);
DrawString(date.left, date.right, y, STR_JUST_DATE_TINY, TC_WHITE);
DrawNewsString(news.left, news.right, y, TC_WHITE, ni);
y += this->line_height;
@@ -1205,13 +1182,13 @@ struct MessageHistoryWindow : Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
void OnInvalidateData(int data = 0, bool gui_scope = true) override
void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
{
if (!gui_scope) return;
this->vscroll->SetCount(_total_news);
}
void OnClick(Point pt, int widget, int click_count) override
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
{
if (widget == WID_MH_BACKGROUND) {
NewsItem *ni = _latest_news;
@@ -1232,7 +1209,7 @@ struct MessageHistoryWindow : Window {
}
};
static const NWidgetPart _nested_message_history[] = {
static constexpr NWidgetPart _nested_message_history[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MESSAGE_HISTORY, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
@@ -1251,11 +1228,11 @@ static const NWidgetPart _nested_message_history[] = {
EndContainer(),
};
static WindowDesc _message_history_desc(
static WindowDesc _message_history_desc(__FILE__, __LINE__,
WDP_AUTO, "list_news", 400, 140,
WC_MESSAGE_HISTORY, WC_NONE,
0,
_nested_message_history, lengthof(_nested_message_history)
std::begin(_nested_message_history), std::end(_nested_message_history)
);
/** Display window with news messages history */