1
0
Fork 0

Codechange: Handle dropdown clicks in wrapper functions that go beep

pull/14470/head
Tyler Trahan 2025-07-20 21:44:40 -04:00
parent ce6bc21641
commit 621d7cc44d
25 changed files with 100 additions and 63 deletions

View File

@ -493,7 +493,7 @@ public:
{
switch (widget) {
case WID_AP_CLASS_DROPDOWN:
ShowDropDownList(this, BuildAirportClassDropDown(), _selected_airport_class, WID_AP_CLASS_DROPDOWN);
this->HandleDropdownListButtonClick(BuildAirportClassDropDown(), _selected_airport_class, WID_AP_CLASS_DROPDOWN);
break;
case WID_AP_AIRPORT_LIST: {

View File

@ -534,16 +534,16 @@ public:
DropDownList list;
list.push_back(MakeDropDownListStringItem(STR_REPLACE_ENGINES, 1));
list.push_back(MakeDropDownListStringItem(STR_REPLACE_WAGONS, 0));
ShowDropDownList(this, std::move(list), this->replace_engines ? 1 : 0, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN);
this->HandleDropdownListButtonClick(std::move(list), this->replace_engines ? 1 : 0, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN);
break;
}
case WID_RV_RAIL_TYPE_DROPDOWN: // Railtype selection dropdown menu
ShowDropDownList(this, GetRailTypeDropDownList(true, true), this->sel_railtype, widget);
this->HandleDropdownListButtonClick(GetRailTypeDropDownList(true, true), this->sel_railtype, widget);
break;
case WID_RV_ROAD_TYPE_DROPDOWN: // Roadtype selection dropdown menu
ShowDropDownList(this, GetRoadTypeDropDownList(RTTB_ROAD | RTTB_TRAM, true, true), this->sel_roadtype, widget);
this->HandleDropdownListButtonClick(GetRoadTypeDropDownList(RTTB_ROAD | RTTB_TRAM, true, true), this->sel_roadtype, widget);
break;
case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
@ -563,7 +563,7 @@ public:
ReplaceClick_StartReplace(false);
} else {
bool replacment_when_old = EngineHasReplacementWhenOldForCompany(Company::Get(_local_company), this->sel_engine[0], this->sel_group);
ShowDropDownMenu(this, _start_replace_dropdown, replacment_when_old ? 1 : 0, WID_RV_START_REPLACE, !this->replace_engines ? 1 << 1 : 0, 0);
this->HandleDropdownMenuButtonClick(_start_replace_dropdown, replacment_when_old ? 1 : 0, WID_RV_START_REPLACE, !this->replace_engines ? 1 << 1 : 0, 0);
}
break;
}

View File

@ -278,7 +278,7 @@ public:
break;
case WID_BBS_DROPDOWN_CRITERIA:
ShowDropDownMenu(this, BuildBridgeWindow::sorter_names, this->bridges.SortType(), WID_BBS_DROPDOWN_CRITERIA, 0, 0);
this->HandleDropdownMenuButtonClick(BuildBridgeWindow::sorter_names, this->bridges.SortType(), WID_BBS_DROPDOWN_CRITERIA, 0, 0);
break;
}
}

View File

@ -1675,12 +1675,12 @@ struct BuildVehicleWindow : Window {
break;
case WID_BV_CARGO_FILTER_DROPDOWN: // Select cargo filtering criteria dropdown menu
ShowDropDownList(this, this->BuildCargoDropDownList(), this->cargo_filter_criteria, widget);
this->HandleDropdownListButtonClick(this->BuildCargoDropDownList(), this->cargo_filter_criteria, widget);
break;
case WID_BV_CONFIGURE_BADGES:
if (this->badge_classes.GetClasses().empty()) break;
ShowDropDownList(this, this->BuildBadgeConfigurationList(), -1, widget, 0, false, true);
this->HandleDropdownListButtonClick(this->BuildBadgeConfigurationList(), -1, widget, 0, false, true);
break;
case WID_BV_SHOW_HIDE: {
@ -1706,7 +1706,7 @@ struct BuildVehicleWindow : Window {
default:
if (IsInsideMM(widget, this->badge_filters.first, this->badge_filters.second)) {
ShowDropDownList(this, this->GetWidget<NWidgetBadgeFilter>(widget)->GetDropDownList(), -1, widget, 0, false);
this->HandleDropdownListButtonClick(this->GetWidget<NWidgetBadgeFilter>(widget)->GetDropDownList(), -1, widget, 0, false);
}
break;
}

View File

@ -660,7 +660,7 @@ private:
} else {
sel = default_col;
}
ShowDropDownList(this, std::move(list), sel, widget);
this->HandleDropdownListButtonClick(std::move(list), sel, widget);
}
void BuildGroupList(CompanyID owner)

View File

@ -96,7 +96,7 @@ struct SetDateWindow : Window {
break;
}
ShowDropDownList(this, std::move(list), selected, widget);
this->HandleDropdownListButtonClick(std::move(list), selected, widget);
}
void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override

View File

@ -14,7 +14,6 @@
#include "gfx_func.h"
#include "gfx_type.h"
#include "palette_func.h"
#include "window_gui.h"
/**
* Base list item class from which others are derived.

View File

@ -657,23 +657,23 @@ struct GenerateLandscapeWindow : public Window {
break;
case WID_GL_MAPSIZE_X_PULLDOWN: // Mapsize X
ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, WID_GL_MAPSIZE_X_PULLDOWN);
this->HandleDropdownListButtonClick(BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, WID_GL_MAPSIZE_X_PULLDOWN);
break;
case WID_GL_MAPSIZE_Y_PULLDOWN: // Mapsize Y
ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, WID_GL_MAPSIZE_Y_PULLDOWN);
this->HandleDropdownListButtonClick(BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, WID_GL_MAPSIZE_Y_PULLDOWN);
break;
case WID_GL_TOWN_PULLDOWN: // Number of towns
ShowDropDownMenu(this, _num_towns, _settings_newgame.difficulty.number_towns, WID_GL_TOWN_PULLDOWN, 0, 0);
this->HandleDropdownMenuButtonClick(_num_towns, _settings_newgame.difficulty.number_towns, WID_GL_TOWN_PULLDOWN, 0, 0);
break;
case WID_GL_TOWNNAME_DROPDOWN: // Townname generator
ShowDropDownList(this, BuildTownNameDropDown(), _settings_newgame.game_creation.town_name, WID_GL_TOWNNAME_DROPDOWN);
this->HandleDropdownListButtonClick(BuildTownNameDropDown(), _settings_newgame.game_creation.town_name, WID_GL_TOWNNAME_DROPDOWN);
break;
case WID_GL_INDUSTRY_PULLDOWN: // Number of industries
ShowDropDownMenu(this, _num_inds, _settings_newgame.difficulty.industry_density, WID_GL_INDUSTRY_PULLDOWN, 0, 0);
this->HandleDropdownMenuButtonClick(_num_inds, _settings_newgame.difficulty.industry_density, WID_GL_INDUSTRY_PULLDOWN, 0, 0);
break;
case WID_GL_GENERATE_BUTTON: { // Generate
@ -773,12 +773,12 @@ struct GenerateLandscapeWindow : public Window {
break;
case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: // Heightmap rotation
ShowDropDownMenu(this, _rotation, _settings_newgame.game_creation.heightmap_rotation, WID_GL_HEIGHTMAP_ROTATION_PULLDOWN, 0, 0);
this->HandleDropdownMenuButtonClick(_rotation, _settings_newgame.game_creation.heightmap_rotation, WID_GL_HEIGHTMAP_ROTATION_PULLDOWN, 0, 0);
break;
case WID_GL_TERRAIN_PULLDOWN: // Terrain type
/* For the original map generation only the first four are valid. */
ShowDropDownMenu(this, _elevations, _settings_newgame.difficulty.terrain_type, WID_GL_TERRAIN_PULLDOWN, 0, _settings_newgame.game_creation.land_generator == LG_ORIGINAL ? ~0xF : 0);
this->HandleDropdownMenuButtonClick(_elevations, _settings_newgame.difficulty.terrain_type, WID_GL_TERRAIN_PULLDOWN, 0, _settings_newgame.game_creation.land_generator == LG_ORIGINAL ? ~0xF : 0);
break;
case WID_GL_WATER_PULLDOWN: { // Water quantity
@ -787,20 +787,20 @@ struct GenerateLandscapeWindow : public Window {
if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL) {
SetBit(hidden_mask, CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY);
}
ShowDropDownMenu(this, _sea_lakes, _settings_newgame.difficulty.quantity_sea_lakes, WID_GL_WATER_PULLDOWN, 0, hidden_mask);
this->HandleDropdownMenuButtonClick(_sea_lakes, _settings_newgame.difficulty.quantity_sea_lakes, WID_GL_WATER_PULLDOWN, 0, hidden_mask);
break;
}
case WID_GL_RIVER_PULLDOWN: // Amount of rivers
ShowDropDownMenu(this, _rivers, _settings_newgame.game_creation.amount_of_rivers, WID_GL_RIVER_PULLDOWN, 0, 0);
this->HandleDropdownMenuButtonClick(_rivers, _settings_newgame.game_creation.amount_of_rivers, WID_GL_RIVER_PULLDOWN, 0, 0);
break;
case WID_GL_SMOOTHNESS_PULLDOWN: // Map smoothness
ShowDropDownMenu(this, _smoothness, _settings_newgame.game_creation.tgen_smoothness, WID_GL_SMOOTHNESS_PULLDOWN, 0, 0);
this->HandleDropdownMenuButtonClick(_smoothness, _settings_newgame.game_creation.tgen_smoothness, WID_GL_SMOOTHNESS_PULLDOWN, 0, 0);
break;
case WID_GL_VARIETY_PULLDOWN: // Map variety
ShowDropDownMenu(this, _variety, _settings_newgame.game_creation.variety, WID_GL_VARIETY_PULLDOWN, 0, 0);
this->HandleDropdownMenuButtonClick(_variety, _settings_newgame.game_creation.variety, WID_GL_VARIETY_PULLDOWN, 0, 0);
break;
/* Freetype map borders */
@ -1134,11 +1134,11 @@ struct CreateScenarioWindow : public Window
break;
case WID_CS_MAPSIZE_X_PULLDOWN: // Mapsize X
ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, WID_CS_MAPSIZE_X_PULLDOWN);
this->HandleDropdownListButtonClick(BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, WID_CS_MAPSIZE_X_PULLDOWN);
break;
case WID_CS_MAPSIZE_Y_PULLDOWN: // Mapsize Y
ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, WID_CS_MAPSIZE_Y_PULLDOWN);
this->HandleDropdownListButtonClick(BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, WID_CS_MAPSIZE_Y_PULLDOWN);
break;
case WID_CS_EMPTY_WORLD: // Empty world / flat world

View File

@ -700,15 +700,15 @@ public:
break;
case WID_GL_GROUP_BY_DROPDOWN: // Select grouping option dropdown menu
ShowDropDownMenu(this, this->vehicle_group_by_names, this->grouping, WID_GL_GROUP_BY_DROPDOWN, 0, 0);
this->HandleDropdownMenuButtonClick(this->vehicle_group_by_names, this->grouping, WID_GL_GROUP_BY_DROPDOWN, 0, 0);
return;
case WID_GL_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu
ShowDropDownMenu(this, this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_GL_SORT_BY_DROPDOWN, 0, (this->vli.vtype == VEH_TRAIN || this->vli.vtype == VEH_ROAD) ? 0 : (1 << 10));
this->HandleDropdownMenuButtonClick(this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_GL_SORT_BY_DROPDOWN, 0, (this->vli.vtype == VEH_TRAIN || this->vli.vtype == VEH_ROAD) ? 0 : (1 << 10));
return;
case WID_GL_FILTER_BY_CARGO: // Select filtering criteria dropdown menu
ShowDropDownList(this, this->BuildCargoDropDownList(false), this->cargo_filter_criteria, widget);
this->HandleDropdownListButtonClick(this->BuildCargoDropDownList(false), this->cargo_filter_criteria, widget);
break;
case WID_GL_ALL_VEHICLES: // All vehicles button
@ -849,7 +849,7 @@ public:
break;
case WID_GL_MANAGE_VEHICLES_DROPDOWN: {
ShowDropDownList(this, this->BuildActionDropdownList(true, Group::IsValidID(this->vli.ToGroupID()), IsDefaultGroupID(this->vli.ToGroupID())), -1, WID_GL_MANAGE_VEHICLES_DROPDOWN);
this->HandleDropdownListButtonClick(this->BuildActionDropdownList(true, Group::IsValidID(this->vli.ToGroupID()), IsDefaultGroupID(this->vli.ToGroupID())), -1, WID_GL_MANAGE_VEHICLES_DROPDOWN);
break;
}

View File

@ -1798,15 +1798,15 @@ public:
break;
case WID_ID_DROPDOWN_CRITERIA:
ShowDropDownMenu(this, IndustryDirectoryWindow::sorter_names, this->industries.SortType(), WID_ID_DROPDOWN_CRITERIA, 0, 0);
this->HandleDropdownMenuButtonClick(IndustryDirectoryWindow::sorter_names, this->industries.SortType(), WID_ID_DROPDOWN_CRITERIA, 0, 0);
break;
case WID_ID_FILTER_BY_ACC_CARGO: // Cargo filter dropdown
ShowDropDownList(this, this->BuildCargoDropDownList(), this->accepted_cargo_filter_criteria, widget);
this->HandleDropdownListButtonClick(this->BuildCargoDropDownList(), this->accepted_cargo_filter_criteria, widget);
break;
case WID_ID_FILTER_BY_PROD_CARGO: // Cargo filter dropdown
ShowDropDownList(this, this->BuildCargoDropDownList(), this->produced_cargo_filter_criteria, widget);
this->HandleDropdownListButtonClick(this->BuildCargoDropDownList(), this->produced_cargo_filter_criteria, widget);
break;
case WID_ID_INDUSTRY_LIST: {
@ -3092,7 +3092,7 @@ struct IndustryCargoesWindow : public Window {
}
if (!lst.empty()) {
int selected = (this->ind_cargo >= NUM_INDUSTRYTYPES) ? (int)(this->ind_cargo - NUM_INDUSTRYTYPES) : -1;
ShowDropDownList(this, std::move(lst), selected, WID_IC_CARGO_DROPDOWN);
this->HandleDropdownListButtonClick(std::move(lst), selected, WID_IC_CARGO_DROPDOWN);
}
break;
}
@ -3106,7 +3106,7 @@ struct IndustryCargoesWindow : public Window {
}
if (!lst.empty()) {
int selected = (this->ind_cargo < NUM_INDUSTRYTYPES) ? (int)this->ind_cargo : -1;
ShowDropDownList(this, std::move(lst), selected, WID_IC_IND_DROPDOWN);
this->HandleDropdownListButtonClick(std::move(lst), selected, WID_IC_IND_DROPDOWN);
}
break;
}

View File

@ -595,7 +595,7 @@ struct MusicTrackSelectionWindow : public Window {
case WID_MTS_MUSICSET: {
int selected = 0;
ShowDropDownList(this, BuildSetDropDownList<BaseMusic>(&selected), selected, widget);
this->HandleDropdownListButtonClick(BuildSetDropDownList<BaseMusic>(&selected), selected, widget);
break;
}

View File

@ -1019,7 +1019,7 @@ struct NetworkStartServerWindow : public Window {
break;
case WID_NSS_CONNTYPE_BTN: // Connection type
ShowDropDownList(this, BuildVisibilityDropDownList(), _settings_client.network.server_game_type, WID_NSS_CONNTYPE_BTN);
this->HandleDropdownListButtonClick(BuildVisibilityDropDownList(), _settings_client.network.server_game_type, WID_NSS_CONNTYPE_BTN);
break;
case WID_NSS_CLIENTS_BTND: case WID_NSS_CLIENTS_BTNU: // Click on up/down button for number of clients
@ -1714,7 +1714,7 @@ public:
case WID_CL_SERVER_VISIBILITY:
if (!_network_server) break;
ShowDropDownList(this, BuildVisibilityDropDownList(), _settings_client.network.server_game_type, WID_CL_SERVER_VISIBILITY);
this->HandleDropdownListButtonClick(BuildVisibilityDropDownList(), _settings_client.network.server_game_type, WID_CL_SERVER_VISIBILITY);
break;
case WID_CL_MATRIX: {

View File

@ -15,6 +15,7 @@
#include "newgrf_badge.h"
#include "newgrf_badge_type.h"
#include "timer/timer_game_calendar.h"
#include "widget_type.h"
class GUIBadgeClasses : public UsedBadgeClasses {
public:

View File

@ -941,7 +941,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
}
this->CloseChildWindows(WC_QUERY_STRING); // Remove the parameter query window
ShowDropDownList(this, std::move(list), this->preset, WID_NS_PRESET_LIST);
this->HandleDropdownListButtonClick(std::move(list), this->preset, WID_NS_PRESET_LIST);
break;
}

View File

@ -1254,7 +1254,7 @@ public:
} else {
const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
assert(o != nullptr);
ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
this->HandleDropdownMenuButtonClick(_order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
}
break;
@ -1275,7 +1275,7 @@ public:
case OPOS_SHARE: sel = 3; break;
default: NOT_REACHED();
}
ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0);
this->HandleDropdownMenuButtonClick(this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0);
}
break;
@ -1283,7 +1283,7 @@ public:
if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
this->OrderClick_FullLoad(OLF_FULL_LOAD_ANY, true);
} else {
ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
this->HandleDropdownMenuButtonClick(_order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
}
break;
@ -1291,7 +1291,7 @@ public:
if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
this->OrderClick_Unload(OUFB_UNLOAD, true);
} else {
ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
this->HandleDropdownMenuButtonClick(_order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
}
break;
@ -1300,14 +1300,14 @@ public:
break;
case WID_O_DEPOT_ACTION:
ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_DEPOT_ACTION, 0, 0);
this->HandleDropdownMenuButtonClick(_order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_DEPOT_ACTION, 0, 0);
break;
case WID_O_REFIT_DROPDOWN:
if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
this->OrderClick_Refit(0, true);
} else {
ShowDropDownMenu(this, _order_refit_action_dropdown, 0, WID_O_REFIT_DROPDOWN, 0, 0);
this->HandleDropdownMenuButtonClick(_order_refit_action_dropdown, 0, WID_O_REFIT_DROPDOWN, 0, 0);
}
break;
@ -1320,14 +1320,14 @@ public:
for (const auto &ocv : _order_conditional_variable) {
list.push_back(MakeDropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv, ocv));
}
ShowDropDownList(this, std::move(list), this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE);
this->HandleDropdownListButtonClick(std::move(list), this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE);
break;
}
case WID_O_COND_COMPARATOR: {
const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
assert(o != nullptr);
ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
this->HandleDropdownMenuButtonClick(_order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
break;
}

View File

@ -441,12 +441,12 @@ void PickerWindow::OnClick(Point pt, WidgetID widget, int)
case WID_PW_CONFIGURE_BADGES:
if (this->badge_classes.GetClasses().empty()) break;
ShowDropDownList(this, BuildBadgeClassConfigurationList(this->badge_classes, 1, {}), -1, widget, 0, false, true);
this->HandleDropdownListButtonClick(BuildBadgeClassConfigurationList(this->badge_classes, 1, {}), -1, widget, 0, false, true);
break;
default:
if (IsInsideMM(widget, this->badge_filters.first, this->badge_filters.second)) {
ShowDropDownList(this, this->GetWidget<NWidgetBadgeFilter>(widget)->GetDropDownList(), -1, widget, 0, false);
this->HandleDropdownListButtonClick(this->GetWidget<NWidgetBadgeFilter>(widget)->GetDropDownList(), -1, widget, 0, false);
}
break;
}

View File

@ -20,6 +20,7 @@
#include "table/strings.h"
#include "safeguards.h"
#include "window_gui.h"
/* == BaseSettingEntry methods == */

View File

@ -1148,7 +1148,7 @@ struct GameOptionsWindow : Window {
int selected;
DropDownList list = this->BuildDropDownList(widget, &selected);
if (!list.empty()) {
ShowDropDownList(this, std::move(list), selected, widget);
this->HandleDropdownListButtonClick(std::move(list), selected, widget);
} else {
if (widget == WID_GO_RESOLUTION_DROPDOWN) ShowErrorMessage(GetEncodedString(STR_ERROR_RESOLUTION_LIST_FAILED), {}, WL_ERROR);
}
@ -1180,7 +1180,7 @@ struct GameOptionsWindow : Window {
int selected;
DropDownList list = this->BuildDropDownList(widget, &selected);
if (!list.empty()) {
ShowDropDownList(this, std::move(list), this->filter.mode, widget);
this->HandleDropdownListButtonClick(std::move(list), this->filter.mode, widget);
}
break;
}
@ -1189,7 +1189,7 @@ struct GameOptionsWindow : Window {
int selected;
DropDownList list = this->BuildDropDownList(widget, &selected);
if (!list.empty()) {
ShowDropDownList(this, std::move(list), this->filter.type, widget);
this->HandleDropdownListButtonClick(std::move(list), this->filter.type, widget);
}
break;
}

View File

@ -658,12 +658,12 @@ public:
break;
case WID_STL_SORTDROPBTN: // select sorting criteria dropdown menu
ShowDropDownMenu(this, CompanyStationsWindow::sorter_names, this->stations.SortType(), WID_STL_SORTDROPBTN, 0, 0);
this->HandleDropdownMenuButtonClick(CompanyStationsWindow::sorter_names, this->stations.SortType(), WID_STL_SORTDROPBTN, 0, 0);
break;
case WID_STL_CARGODROPDOWN:
this->filter_expanded = false;
ShowDropDownList(this, this->BuildCargoDropDownList(this->filter_expanded), -1, widget, 0, false, true);
this->HandleDropdownListButtonClick(this->BuildCargoDropDownList(this->filter_expanded), -1, widget, 0, false, true);
break;
}
}
@ -2005,14 +2005,14 @@ struct StationViewWindow : public Window {
* sorting criteria for columns 1, 2, and 3. Column 0 is always
* sorted by cargo type. The others can theoretically be sorted
* by different things but there is no UI for that. */
ShowDropDownMenu(this, StationViewWindow::sort_names,
this->HandleDropdownMenuButtonClick(StationViewWindow::sort_names,
this->current_mode * 2 + (this->sortings[1] == CargoSortType::Count ? 1 : 0),
WID_SV_SORT_BY, 0, 0);
break;
}
case WID_SV_GROUP_BY: {
ShowDropDownMenu(this, StationViewWindow::group_names, this->grouping_index, WID_SV_GROUP_BY, 0, 0);
this->HandleDropdownMenuButtonClick(StationViewWindow::group_names, this->grouping_index, WID_SV_GROUP_BY, 0, 0);
break;
}

View File

@ -805,7 +805,7 @@ public:
selected++;
}
ShowDropDownList(this, std::move(list), selected, widget);
this->HandleDropdownListButtonClick(std::move(list), selected, widget);
}
break;
}

View File

@ -514,7 +514,7 @@ void TextfileWindow::AfterLoadMarkdown()
for (size_t line : this->jumplist) {
list.push_back(MakeDropDownListStringItem(GetString(STR_TEXTFILE_JUMPLIST_ITEM, this->lines[line].text), (int)line));
}
ShowDropDownList(this, std::move(list), -1, widget);
this->HandleDropdownListButtonClick(std::move(list), -1, widget);
break;
}

View File

@ -937,7 +937,7 @@ public:
break;
case WID_TD_SORT_CRITERIA: // Click on sort criteria dropdown
ShowDropDownMenu(this, TownDirectoryWindow::sorter_names, this->towns.SortType(), WID_TD_SORT_CRITERIA, 0, 0);
this->HandleDropdownMenuButtonClick(TownDirectoryWindow::sorter_names, this->towns.SortType(), WID_TD_SORT_CRITERIA, 0, 0);
break;
case WID_TD_LIST: { // Click on Town Matrix

View File

@ -2101,16 +2101,16 @@ public:
break;
case WID_VL_GROUP_BY_PULLDOWN: // Select sorting criteria dropdown menu
ShowDropDownMenu(this, this->vehicle_group_by_names, this->grouping, WID_VL_GROUP_BY_PULLDOWN, 0, 0);
this->HandleDropdownMenuButtonClick(this->vehicle_group_by_names, this->grouping, WID_VL_GROUP_BY_PULLDOWN, 0, 0);
return;
case WID_VL_SORT_BY_PULLDOWN: // Select sorting criteria dropdown menu
ShowDropDownMenu(this, this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_VL_SORT_BY_PULLDOWN, 0,
this->HandleDropdownMenuButtonClick(this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_VL_SORT_BY_PULLDOWN, 0,
(this->vli.vtype == VEH_TRAIN || this->vli.vtype == VEH_ROAD) ? 0 : (1 << 10));
return;
case WID_VL_FILTER_BY_CARGO: // Cargo filter dropdown
ShowDropDownList(this, this->BuildCargoDropDownList(false), this->cargo_filter_criteria, widget);
this->HandleDropdownListButtonClick(this->BuildCargoDropDownList(false), this->cargo_filter_criteria, widget);
break;
case WID_VL_LIST: { // Matrix to show vehicles
@ -2159,7 +2159,7 @@ public:
break;
case WID_VL_MANAGE_VEHICLES_DROPDOWN: {
ShowDropDownList(this, this->BuildActionDropdownList(this->vli.type == VL_STANDARD, false, true), 0, WID_VL_MANAGE_VEHICLES_DROPDOWN);
this->HandleDropdownListButtonClick(this->BuildActionDropdownList(this->vli.type == VL_STANDARD, false, true), 0, WID_VL_MANAGE_VEHICLES_DROPDOWN);
break;
}
@ -2727,7 +2727,7 @@ struct VehicleDetailsWindow : Window {
case WID_VD_SERVICE_INTERVAL_DROPDOWN: {
const Vehicle *v = Vehicle::Get(this->window_number);
ShowDropDownMenu(this,
this->HandleDropdownMenuButtonClick(
TimerGameEconomy::UsingWallclockUnits() ? _service_interval_dropdown_wallclock : _service_interval_dropdown_calendar,
v->ServiceIntervalIsCustom() ? (v->ServiceIntervalIsPercent() ? 2 : 1) : 0, widget, 0, 0);
break;

View File

@ -30,6 +30,7 @@
#include "hotkeys.h"
#include "toolbar_gui.h"
#include "statusbar_gui.h"
#include "dropdown_func.h"
#include "error.h"
#include "game/game.hpp"
#include "video/video_driver.hpp"
@ -587,6 +588,38 @@ EventState Window::OnHotkey(int hotkey)
return ES_HANDLED;
}
/**
* Handle the player clicking on a dropdown list.
* @param list Prepopulated DropDownList.
* @param selected The initially selected list item.
* @param button The widget within the parent window that is used to determine
* the list's location.
* @param width Override the minimum width determined by the selected widget and list contents.
* @param instant_close Set to true if releasing mouse button should close the
* list regardless of where the cursor is.
* @param persist Set if this dropdown should stay open after an option is selected.
*/
void Window::HandleDropdownListButtonClick(DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
{
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
ShowDropDownList(this, std::forward<DropDownList>(list), selected, button, width, instant_close, persist);
}
/**
* Handle the player clicking on a dropdown menu.
* @param strings Menu list.
* @param selected Index of initial selected item.
* @param button Button widget number of the parent window \a w that wants the dropdown menu.
* @param disabled_mask Bitmask for disabled items (items with their bit set are displayed, but not selectable in the dropdown list).
* @param hidden_mask Bitmask for hidden items (items with their bit set are not copied to the dropdown list).
* @param width Minimum width of the dropdown menu.
*/
void Window::HandleDropdownMenuButtonClick(std::span<const StringID> strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
{
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
ShowDropDownMenu(this, strings, selected, button, disabled_mask, hidden_mask, width);
}
/**
* Do all things to make a button look clicked and mark it to be
* unclicked in a few ticks.

View File

@ -13,6 +13,7 @@
#include "vehiclelist.h"
#include "vehicle_type.h"
#include "viewport_type.h"
#include "dropdown_type.h"
#include "company_type.h"
#include "tile_type.h"
#include "widget_type.h"
@ -499,6 +500,8 @@ public:
EventState HandleEditBoxKey(WidgetID wid, char32_t key, uint16_t keycode);
virtual void InsertTextString(WidgetID wid, std::string_view str, bool marked, std::optional<size_t> caret, std::optional<size_t> insert_location, std::optional<size_t> replacement_end);
void HandleDropdownListButtonClick(DropDownList &&list, int selected, WidgetID button, uint width = 0, bool instant_close = false, bool persist = false);
void HandleDropdownMenuButtonClick(std::span<const StringID> strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width = 0);
void HandleButtonClick(WidgetID widget);
int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height = -1) const;