Merge branch 'master' into jgrpp

# Conflicts:
#	src/articulated_vehicles.cpp
#	src/articulated_vehicles.h
#	src/autoreplace_cmd.cpp
#	src/build_vehicle_gui.cpp
#	src/company_gui.cpp
#	src/core/format.hpp
#	src/genworld_gui.cpp
#	src/gfx.cpp
#	src/group_gui.cpp
#	src/linkgraph/linkgraph_gui.cpp
#	src/misc/endian_buffer.hpp
#	src/music/music_driver.hpp
#	src/newgrf_gui.cpp
#	src/rail_cmd.cpp
#	src/road_gui.cpp
#	src/settings_type.h
#	src/strgen/strgen.cpp
#	src/strings.cpp
#	src/timetable_cmd.cpp
#	src/town.h
#	src/vehicle.cpp
#	src/vehicle_gui.cpp
#	src/vehicle_gui_base.h
#	src/widget.cpp
#	src/widgets/dropdown.cpp
#	src/widgets/road_widget.h
This commit is contained in:
Jonathan G Rennison
2023-12-16 23:54:58 +00:00
130 changed files with 1765 additions and 1676 deletions

View File

@@ -28,7 +28,6 @@ enum AirportPickerWidgets {
WID_AP_LAYOUT_INCREASE, ///< Increase the layout number.
WID_AP_AIRPORT_SPRITE, ///< A visual display of the airport currently selected.
WID_AP_EXTRA_TEXT, ///< Additional text about the airport.
WID_AP_BOTTOMPANEL, ///< Panel at the bottom.
WID_AP_COVERAGE_LABEL, ///< Label if you want to see the coverage.
WID_AP_BTN_DONTHILIGHT, ///< Don't show the coverage button.
WID_AP_BTN_DOHILIGHT, ///< Show the coverage button.

View File

@@ -32,12 +32,13 @@ enum ReplaceVehicleWidgets {
WID_RV_INFO_TAB, ///< Info tab.
WID_RV_STOP_REPLACE, ///< Stop Replacing button.
/* Train/road only widgets */
WID_RV_RAIL_ROAD_TYPE_DROPDOWN, ///< Dropdown menu about the rail/roadtype.
/* Train only widgets. */
WID_RV_RAIL_TYPE_DROPDOWN, ///< Dropdown to select railtype.
WID_RV_TRAIN_ENGINEWAGON_DROPDOWN, ///< Dropdown to select engines and/or wagons.
WID_RV_TRAIN_WAGONREMOVE_TOGGLE, ///< Button to toggle removing wagons.
/* Road only widgets. */
WID_RV_ROAD_TYPE_DROPDOWN, ///< Dropdown to select roadtype.
};
#endif /* WIDGETS_AUTOREPLACE_WIDGET_H */

View File

@@ -47,10 +47,14 @@ uint DropDownListStringItem::Width() const
return GetStringBoundingBox(this->String()).width + WidgetDimensions::scaled.dropdowntext.Horizontal();
}
void DropDownListStringItem::Draw(const Rect &r, bool sel, Colours) const
void DropDownListStringItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
{
Rect ir = r.Shrink(WidgetDimensions::scaled.dropdowntext);
DrawString(ir.left, ir.right, r.top, this->String(), (sel ? TC_WHITE : TC_BLACK) | this->colour_flags);
if (this->String().empty()) {
this->DropDownListItem::Draw(r, sel, bg_colour);
} else {
Rect ir = r.Shrink(WidgetDimensions::scaled.dropdowntext);
DrawString(ir.left, ir.right, r.top, this->String(), (sel ? TC_WHITE : TC_BLACK) | this->colour_flags);
}
}
/**
@@ -360,6 +364,21 @@ struct DropdownWindow : Window {
}
};
/**
* Determine width and height required to fully display a DropDownList
* @param list The list.
* @return Dimension required to display the list.
*/
Dimension GetDropDownListDimension(const DropDownList &list)
{
Dimension dim{};
for (const auto &item : list) {
dim.height += item->Height();
dim.width = std::max(dim.width, item->Width());
}
return dim;
}
/**
* Show a drop down list.
* @param w Parent window for the list.
@@ -381,18 +400,9 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button
/* The preferred width equals the calling widget */
uint width = wi_rect.Width();
/* Longest item in the list */
uint max_item_width = 0;
/* Total height of list */
uint height = 0;
for (const auto &item : list) {
height += item->Height();
max_item_width = std::max(max_item_width, item->Width());
}
max_item_width += WidgetDimensions::scaled.fullbevel.Horizontal();
/* Get the height and width required for the list. */
Dimension dim = GetDropDownListDimension(list);
dim.width += WidgetDimensions::scaled.fullbevel.Horizontal();
/* Scrollbar needed? */
bool scroll = false;
@@ -404,7 +414,7 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button
uint available_height = std::max(GetMainViewBottom() - top - (int)WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0);
/* If the dropdown doesn't fully fit below the widget... */
if (height > available_height) {
if (dim.height > available_height) {
uint available_height_above = std::max(w->top + wi_rect.top - GetMainViewTop() - (int)WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0);
@@ -415,29 +425,28 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button
}
/* If the dropdown doesn't fully fit, we need a dropdown. */
if (height > available_height) {
if (dim.height > available_height) {
scroll = true;
uint avg_height = height / (uint)list.size();
uint avg_height = dim.height / (uint)list.size();
/* Fit the list; create at least one row, even if there is no height available. */
uint rows = std::max<uint>(available_height / avg_height, 1);
height = rows * avg_height;
dim.height = rows * avg_height;
/* Add space for the scrollbar. */
max_item_width += NWidgetScrollbar::GetVerticalDimension().width;
dim.width += NWidgetScrollbar::GetVerticalDimension().width;
}
/* Set the top position if needed. */
if (above) {
top = w->top + wi_rect.top - height - WidgetDimensions::scaled.fullbevel.Vertical() * 2;
top = w->top + wi_rect.top - dim.height - WidgetDimensions::scaled.fullbevel.Vertical() * 2;
}
}
width = std::max(width, max_item_width);
dim.width = std::max(width, dim.width);
Point dw_pos = { w->left + (_current_text_dir == TD_RTL ? wi_rect.right + 1 - (int)width : wi_rect.left), top};
Dimension dw_size = {width, height};
DropdownWindow *dropdown = new DropdownWindow(w, std::move(list), selected, button, instant_close, dw_pos, dw_size, wi_colour, scroll, sync_parent_focus);
DropdownWindow *dropdown = new DropdownWindow(w, std::move(list), selected, button, instant_close, dw_pos, dim, wi_colour, scroll, sync_parent_focus);
/* The dropdown starts scrolling downwards when opening it towards
* the top and holding down the mouse button. It can be fooled by

View File

@@ -51,7 +51,7 @@ public:
DropDownListStringItem(StringID string, int result, bool masked);
DropDownListStringItem(const std::string &string, int result, bool masked);
bool Selectable() const override { return true; }
bool Selectable() const override { return !this->String().empty(); }
uint Width() const override;
void Draw(const Rect &r, bool sel, Colours bg_colour) const override;
const std::string &String() const { return this->string; }
@@ -86,4 +86,6 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width = 0, bool instant_close = false, DropDownSyncFocus sync_parent_focus = DDSF_NONE);
Dimension GetDropDownListDimension(const DropDownList &list);
#endif /* WIDGETS_DROPDOWN_TYPE_H */

View File

@@ -44,33 +44,30 @@ enum BuildRoadDepotWidgets {
/** Widgets of the #BuildRoadStationWindow class. */
enum BuildRoadStationWidgets {
/* Name starts with BRO instead of BR, because of collision with BuildRailStationWidgets */
WID_BROS_CAPTION, ///< Caption of the window.
WID_BROS_BACKGROUND, ///< Background of the window.
WID_BROS_STATION_NE, ///< Terminal station with NE entry.
WID_BROS_STATION_SE, ///< Terminal station with SE entry.
WID_BROS_STATION_SW, ///< Terminal station with SW entry.
WID_BROS_STATION_NW, ///< Terminal station with NW entry.
WID_BROS_STATION_X, ///< Drive-through station in x-direction.
WID_BROS_STATION_Y, ///< Drive-through station in y-direction.
WID_BROS_LT_OFF, ///< Turn off area highlight.
WID_BROS_LT_ON, ///< Turn on area highlight.
WID_BROS_INFO, ///< Station acceptance info.
WID_BROS_MATRIX, ///< Matrix widget displaying all available road stops.
WID_BROS_IMAGE, ///< Panel used for each image of the matrix.
WID_BROS_MATRIX_SCROLL, ///< Scrollbar of the #WID_BROS_SHOW_NEWST_ADDITIONS.
WID_BROS_FILTER_CONTAINER, ///< Container for the filter text box for the road stop class list.
WID_BROS_FILTER_EDITBOX, ///< Filter text box for the road stop class list.
WID_BROS_SHOW_NEWST_DEFSIZE, ///< Selection for default-size button for new road stops.
WID_BROS_SHOW_NEWST_ADDITIONS, ///< Selection for new class selection list.
WID_BROS_SHOW_NEWST_MATRIX, ///< Selection for new stop image matrix.
WID_BROS_SHOW_NEWST_RESIZE, ///< Selection for panel and resize at bottom right for new stops.
WID_BROS_SHOW_NEWST_ORIENTATION, ///< Selection for the orientation string for new stops.
WID_BROS_SHOW_NEWST_TYPE_SEL, ///< Selection for the type name.
WID_BROS_SHOW_NEWST_TYPE, ///< Display of selected stop type.
WID_BROS_NEWST_LIST, ///< List with new road stops.
WID_BROS_NEWST_SCROLL, ///< Scrollbar of the #WID_BROS_NEWST_LIST.
WID_BROS_CAPTION, ///< Caption of the window.
WID_BROS_STATION_NE, ///< Terminal station with NE entry.
WID_BROS_STATION_SE, ///< Terminal station with SE entry.
WID_BROS_STATION_SW, ///< Terminal station with SW entry.
WID_BROS_STATION_NW, ///< Terminal station with NW entry.
WID_BROS_STATION_X, ///< Drive-through station in x-direction.
WID_BROS_STATION_Y, ///< Drive-through station in y-direction.
WID_BROS_LT_OFF, ///< Turn off area highlight.
WID_BROS_LT_ON, ///< Turn on area highlight.
WID_BROS_ACCEPTANCE, ///< Station acceptance info.
WID_BROS_MATRIX, ///< Matrix widget displaying all available road stops.
WID_BROS_IMAGE, ///< Panel used for each image of the matrix.
WID_BROS_MATRIX_SCROLL, ///< Scrollbar of the #WID_BROS_SHOW_NEWST_ADDITIONS.
WID_BROS_FILTER_CONTAINER, ///< Container for the filter text box for the road stop class list.
WID_BROS_FILTER_EDITBOX, ///< Filter text box for the road stop class list.
WID_BROS_SHOW_NEWST_DEFSIZE, ///< Selection for default-size button for new road stops.
WID_BROS_SHOW_NEWST_ADDITIONS, ///< Selection for new class selection list.
WID_BROS_SHOW_NEWST_MATRIX, ///< Selection for new stop image matrix.
WID_BROS_SHOW_NEWST_RESIZE, ///< Selection for panel and resize at bottom right for new stops.
WID_BROS_SHOW_NEWST_ORIENTATION, ///< Selection for the orientation string for new stops.
WID_BROS_SHOW_NEWST_TYPE_SEL, ///< Selection for the type name.
WID_BROS_SHOW_NEWST_TYPE, ///< Display of selected stop type.
WID_BROS_NEWST_LIST, ///< List with new road stops.
WID_BROS_NEWST_SCROLL, ///< Scrollbar of the #WID_BROS_NEWST_LIST.
};
/** Widgets of the #BuildRoadWaypointWindow class. */

View File

@@ -28,7 +28,6 @@ enum GameOptionsWidgets {
WID_GO_GUI_SCALE_MAIN_TOOLBAR, ///< Toggle for bigger main toolbar.
WID_GO_BASE_GRF_DROPDOWN, ///< Use to select a base GRF.
WID_GO_BASE_GRF_PARAMETERS, ///< Base GRF parameters.
WID_GO_BASE_GRF_STATUS, ///< Info about missing files etc.
WID_GO_BASE_GRF_TEXTFILE, ///< Open base GRF readme, changelog (+1) or license (+2).
WID_GO_BASE_GRF_DESCRIPTION = WID_GO_BASE_GRF_TEXTFILE + TFT_CONTENT_END, ///< Description of selected base GRF.
WID_GO_BASE_SFX_DROPDOWN, ///< Use to select a base SFX.
@@ -40,7 +39,6 @@ enum GameOptionsWidgets {
WID_GO_TEXT_MUSIC_VOLUME, ///< Music volume label.
WID_GO_BASE_MUSIC_VOLUME, ///< Change music volume.
WID_GO_BASE_MUSIC_JUKEBOX, ///< Open the jukebox.
WID_GO_BASE_MUSIC_STATUS, ///< Info about corrupted files etc.
WID_GO_BASE_MUSIC_TEXTFILE, ///< Open base music readme, changelog (+1) or license (+2).
WID_GO_BASE_MUSIC_DESCRIPTION = WID_GO_BASE_MUSIC_TEXTFILE + TFT_CONTENT_END, ///< Description of selected base music set.
WID_GO_VIDEO_ACCEL_BUTTON, ///< Toggle for video acceleration.