Merge branch 'master' into jgrpp

# Conflicts:
#	src/cheat_gui.cpp
#	src/main_gui.cpp
#	src/network/network_gui.cpp
#	src/saveload/saveload.h
#	src/smallmap_gui.cpp
#	src/station_cmd.cpp
#	src/timetable_cmd.cpp
#	src/toolbar_gui.cpp
#	src/widget.cpp
#	src/widget_type.h
#	src/widgets/dropdown_type.h
This commit is contained in:
Jonathan G Rennison
2023-11-25 14:02:04 +00:00
100 changed files with 450 additions and 655 deletions

View File

@@ -90,7 +90,6 @@ static const ServerListPosition SLP_INVALID = -1;
/** Full blown container to make it behave exactly as we want :) */
class NWidgetServerListHeader : public NWidgetContainer {
static const uint MINIMUM_NAME_WIDTH_BEFORE_NEW_HEADER = 150; ///< Minimum width before adding a new header
bool visible[6]; ///< The visible headers
public:
NWidgetServerListHeader() : NWidgetContainer(NWID_HORIZONTAL)
{
@@ -109,17 +108,10 @@ public:
+ GetSpriteSize(SPR_BLOT, nullptr, ZOOM_LVL_OUT_4X).width, 12);
leaf->SetFill(0, 1);
this->Add(leaf);
/* First and last are always visible, the rest is implicitly zeroed */
this->visible[0] = true;
*lastof(this->visible) = true;
}
void SetupSmallestSize(Window *w, bool init_array) override
{
/* Oh yeah, we ought to be findable! */
w->nested_array[WID_NG_HEADER] = this;
this->smallest_y = 0; // Biggest child.
this->fill_x = 1;
this->fill_y = 0;
@@ -151,16 +143,14 @@ public:
this->current_y = given_height;
given_width -= this->tail->smallest_x;
NWidgetBase *child_wid = this->head->next;
/* The first and last widget are always visible, determine which other should be visible */
for (uint i = 1; i < lengthof(this->visible) - 1; i++) {
if (given_width > ScaleGUITrad(MINIMUM_NAME_WIDTH_BEFORE_NEW_HEADER) + child_wid->smallest_x && this->visible[i - 1]) {
this->visible[i] = true;
for (NWidgetBase *child_wid = this->head->next; child_wid->next != nullptr; child_wid = child_wid->next) {
if (given_width > ScaleGUITrad(MINIMUM_NAME_WIDTH_BEFORE_NEW_HEADER) + child_wid->smallest_x && child_wid->prev->current_x != 0) {
given_width -= child_wid->smallest_x;
child_wid->current_x = child_wid->smallest_x; /* Make visible. */
} else {
this->visible[i] = false;
child_wid->current_x = 0; /* Make invisible. */
}
child_wid = child_wid->next;
}
/* All remaining space goes to the first (name) widget */
@@ -168,65 +158,13 @@ public:
/* Now assign the widgets to their rightful place */
uint position = 0; // Place to put next child relative to origin of the container.
uint i = rtl ? lengthof(this->visible) - 1 : 0;
child_wid = rtl ? this->tail : this->head;
while (child_wid != nullptr) {
if (this->visible[i]) {
for (NWidgetBase *child_wid = rtl ? this->tail : this->head; child_wid != nullptr; child_wid = rtl ? child_wid->prev : child_wid->next) {
if (child_wid->current_x != 0) {
child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
position += child_wid->current_x;
}
child_wid = rtl ? child_wid->prev : child_wid->next;
i += rtl ? -1 : 1;
}
}
void Draw(const Window *w) override
{
int i = 0;
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
if (!this->visible[i++]) continue;
child_wid->Draw(w);
}
}
NWidgetCore *GetWidgetFromPos(int x, int y) override
{
if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
int i = 0;
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
if (!this->visible[i++]) continue;
NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
if (nwid != nullptr) return nwid;
}
return nullptr;
}
void FillDirtyWidgets(std::vector<NWidgetBase *> &dirty_widgets) override
{
if (this->base_flags & WBF_DIRTY) {
dirty_widgets.push_back(this);
} else {
int i = 0;
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
if (!this->visible[i++]) continue;
child_wid->FillDirtyWidgets(dirty_widgets);
}
}
}
/**
* Checks whether the given widget is actually visible.
* @param widget the widget to check for visibility
* @return true iff the widget is visible.
*/
bool IsWidgetVisible(NetworkGameWidgets widget) const
{
assert((uint)(widget - WID_NG_NAME) < lengthof(this->visible));
return this->visible[widget - WID_NG_NAME];
}
};
class NetworkGameWindow : public Window {
@@ -428,10 +366,8 @@ protected:
/* only draw details if the server is online */
if (cur_item->status == NGLS_ONLINE) {
const NWidgetServerListHeader *nwi_header = this->GetWidget<NWidgetServerListHeader>(WID_NG_HEADER);
if (nwi_header->IsWidgetVisible(WID_NG_CLIENTS)) {
Rect clients = this->GetWidget<NWidgetBase>(WID_NG_CLIENTS)->GetCurrentRect();
if (const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_NG_CLIENTS); nwid->current_x != 0) {
Rect clients = nwid->GetCurrentRect();
SetDParam(0, cur_item->info.clients_on);
SetDParam(1, cur_item->info.clients_max);
SetDParam(2, cur_item->info.companies_on);
@@ -439,26 +375,26 @@ protected:
DrawString(clients.left, clients.right, y + text_y_offset, STR_NETWORK_SERVER_LIST_GENERAL_ONLINE, TC_FROMSTRING, SA_HOR_CENTER);
}
if (nwi_header->IsWidgetVisible(WID_NG_MAPSIZE)) {
if (const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_NG_MAPSIZE); nwid->current_x != 0) {
/* map size */
Rect mapsize = this->GetWidget<NWidgetBase>(WID_NG_MAPSIZE)->GetCurrentRect();
Rect mapsize = nwid->GetCurrentRect();
SetDParam(0, cur_item->info.map_width);
SetDParam(1, cur_item->info.map_height);
DrawString(mapsize.left, mapsize.right, y + text_y_offset, STR_NETWORK_SERVER_LIST_MAP_SIZE_SHORT, TC_FROMSTRING, SA_HOR_CENTER);
}
if (nwi_header->IsWidgetVisible(WID_NG_DATE)) {
if (const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_NG_DATE); nwid->current_x != 0) {
/* current date */
Rect date = this->GetWidget<NWidgetBase>(WID_NG_DATE)->GetCurrentRect();
Rect date = nwid->GetCurrentRect();
YearMonthDay ymd;
ConvertDateToYMD(cur_item->info.game_date, &ymd);
SetDParam(0, ymd.year);
DrawString(date.left, date.right, y + text_y_offset, STR_JUST_INT, TC_BLACK, SA_HOR_CENTER);
}
if (nwi_header->IsWidgetVisible(WID_NG_YEARS)) {
if (const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_NG_YEARS); nwid->current_x != 0) {
/* number of years the game is running */
Rect years = this->GetWidget<NWidgetBase>(WID_NG_YEARS)->GetCurrentRect();
Rect years = nwid->GetCurrentRect();
YearMonthDay ymd_cur, ymd_start;
ConvertDateToYMD(cur_item->info.game_date, &ymd_cur);
ConvertDateToYMD(cur_item->info.start_date, &ymd_start);
@@ -2446,15 +2382,13 @@ struct NetworkAskRelayWindow : public Window {
{
if (widget == WID_NAR_TEXT) {
*size = GetStringBoundingBox(STR_NETWORK_ASK_RELAY_TEXT);
size->width += WidgetDimensions::scaled.frametext.Horizontal();
size->height += WidgetDimensions::scaled.frametext.Vertical();
}
}
void DrawWidget(const Rect &r, int widget) const override
{
if (widget == WID_NAR_TEXT) {
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_NETWORK_ASK_RELAY_TEXT, TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, STR_NETWORK_ASK_RELAY_TEXT, TC_FROMSTRING, SA_CENTER);
}
}
@@ -2503,12 +2437,14 @@ static const NWidgetPart _nested_network_ask_relay_widgets[] = {
NWidget(WWT_CLOSEBOX, COLOUR_RED),
NWidget(WWT_CAPTION, COLOUR_RED, WID_NAR_CAPTION), SetDataTip(STR_NETWORK_ASK_RELAY_CAPTION, STR_NULL),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_RED), SetPIP(0, 0, 8),
NWidget(WWT_TEXT, COLOUR_RED, WID_NAR_TEXT), SetAlignment(SA_HOR_CENTER), SetFill(1, 1),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 15, 10),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NAR_NO), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_RELAY_NO, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NAR_YES_ONCE), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_RELAY_YES_ONCE, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NAR_YES_ALWAYS), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_RELAY_YES_ALWAYS, STR_NULL),
NWidget(WWT_PANEL, COLOUR_RED),
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup),
NWidget(WWT_TEXT, COLOUR_RED, WID_NAR_TEXT), SetAlignment(SA_HOR_CENTER), SetFill(1, 1),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NAR_NO), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_RELAY_NO, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NAR_YES_ONCE), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_RELAY_YES_ONCE, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NAR_YES_ALWAYS), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_RELAY_YES_ALWAYS, STR_NULL),
EndContainer(),
EndContainer(),
EndContainer(),
};
@@ -2549,15 +2485,13 @@ struct NetworkAskSurveyWindow : public Window {
{
if (widget == WID_NAS_TEXT) {
*size = GetStringBoundingBox(STR_NETWORK_ASK_SURVEY_TEXT);
size->width += WidgetDimensions::scaled.frametext.Horizontal();
size->height += WidgetDimensions::scaled.frametext.Vertical();
}
}
void DrawWidget(const Rect &r, int widget) const override
{
if (widget == WID_NAS_TEXT) {
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_NETWORK_ASK_SURVEY_TEXT, TC_BLACK, SA_CENTER);
DrawStringMultiLine(r, STR_NETWORK_ASK_SURVEY_TEXT, TC_BLACK, SA_CENTER);
}
}
@@ -2598,15 +2532,17 @@ static const NWidgetPart _nested_network_ask_survey_widgets[] = {
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY, WID_NAS_CAPTION), SetDataTip(STR_NETWORK_ASK_SURVEY_CAPTION, STR_NULL),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY), SetPIP(0, 4, 8),
NWidget(WWT_TEXT, COLOUR_GREY, WID_NAS_TEXT), SetAlignment(SA_HOR_CENTER), SetFill(1, 1),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 15, 10),
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NAS_PREVIEW), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_SURVEY_PREVIEW, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NAS_LINK), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_SURVEY_LINK, STR_NULL),
EndContainer(),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 15, 10),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NAS_NO), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_SURVEY_NO, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NAS_YES), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_SURVEY_YES, STR_NULL),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup),
NWidget(WWT_TEXT, COLOUR_GREY, WID_NAS_TEXT), SetAlignment(SA_HOR_CENTER), SetFill(1, 1),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NAS_PREVIEW), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_SURVEY_PREVIEW, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NAS_LINK), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_SURVEY_LINK, STR_NULL),
EndContainer(),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NAS_NO), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_SURVEY_NO, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NAS_YES), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_SURVEY_YES, STR_NULL),
EndContainer(),
EndContainer(),
EndContainer(),
};