1
0
Fork 0
pull/11338/merge
Micael Dias 2025-01-30 00:27:27 +00:00 committed by GitHub
commit 3feafcf489
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 67 additions and 55 deletions

View File

@ -74,7 +74,6 @@ struct DropdownWindow : Window {
Rect wi_rect; ///< Rect of the button that opened the dropdown. Rect wi_rect; ///< Rect of the button that opened the dropdown.
DropDownList list; ///< List with dropdown menu items. DropDownList list; ///< List with dropdown menu items.
int selected_result; ///< Result value of the selected item in the list. int selected_result; ///< Result value of the selected item in the list.
uint8_t click_delay = 0; ///< Timer to delay selection.
bool drag_mode = true; bool drag_mode = true;
bool instant_close; ///< Close the window when the mouse button is raised. bool instant_close; ///< Close the window when the mouse button is raised.
bool persist; ///< Persist dropdown menu. bool persist; ///< Persist dropdown menu.
@ -281,12 +280,7 @@ struct DropdownWindow : Window {
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
{ {
if (widget != WID_DM_ITEMS) return; if (widget != WID_DM_ITEMS) return;
int item; this->drag_mode = true;
if (this->GetDropDownItem(item)) {
this->click_delay = 4;
this->selected_result = item;
this->SetDirty();
}
} }
/** Rate limit how fast scrolling happens. */ /** Rate limit how fast scrolling happens. */
@ -300,43 +294,41 @@ struct DropdownWindow : Window {
void OnMouseLoop() override void OnMouseLoop() override
{ {
if (this->click_delay != 0 && --this->click_delay == 0) { /* Scrolling logic */
/* Close the dropdown, so it doesn't affect new window placement.
* Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
if (!this->persist) this->Close();
this->parent->OnDropdownSelect(this->parent_button, this->selected_result);
return;
}
if (this->drag_mode) {
int item;
if (!_left_button_clicked) {
this->drag_mode = false;
if (!this->GetDropDownItem(item)) {
if (this->instant_close) this->Close();
return;
}
this->click_delay = 2;
} else {
if (_cursor.pos.y <= this->top + WidgetDimensions::scaled.dropdownlist.top) { if (_cursor.pos.y <= this->top + WidgetDimensions::scaled.dropdownlist.top) {
/* Cursor is above the list, set scroll up */ /* Cursor is above the list, set scroll up */
this->scrolling = -1; this->scrolling = -1;
return;
} else if (_cursor.pos.y >= this->top + this->height - WidgetDimensions::scaled.dropdownlist.bottom) { } else if (_cursor.pos.y >= this->top + this->height - WidgetDimensions::scaled.dropdownlist.bottom) {
/* Cursor is below list, set scroll down */ /* Cursor is below list, set scroll down */
this->scrolling = 1; this->scrolling = 1;
return;
} }
if (!this->GetDropDownItem(item)) return; /* Hover item under the cursor */
} int item = -1;
const bool item_is_valid = this->GetDropDownItem(item);
if (this->selected_result != item) { if (item_is_valid) {
if (item != this->selected_result) {
this->selected_result = item; this->selected_result = item;
this->SetDirty(); this->SetDirty();
} }
} }
/* Select option logic */
if (!_left_button_clicked) {
bool released_on_item = false;
if (this->drag_mode) {
this->drag_mode = false;
if ((instant_close || item_is_valid) && !this->persist) {
this->Close();
}
if (item_is_valid) {
this->parent->OnDropdownSelect(this->parent_button, this->selected_result);
}
}
}
} }
void ReplaceList(DropDownList &&list) void ReplaceList(DropDownList &&list)

View File

@ -1662,6 +1662,9 @@ STR_CONFIG_SETTING_SCROLLMODE_LMB :Move map with L
STR_CONFIG_SETTING_SMOOTH_SCROLLING :Smooth viewport scrolling: {STRING2} STR_CONFIG_SETTING_SMOOTH_SCROLLING :Smooth viewport scrolling: {STRING2}
STR_CONFIG_SETTING_SMOOTH_SCROLLING_HELPTEXT :Control how the main view scrolls to a specific position when clicking on the smallmap or when issuing a command to scroll to a specific object on the map. If enabled, the viewport scrolls smoothly, if disabled it jumps directly to the targeted spot STR_CONFIG_SETTING_SMOOTH_SCROLLING_HELPTEXT :Control how the main view scrolls to a specific position when clicking on the smallmap or when issuing a command to scroll to a specific object on the map. If enabled, the viewport scrolls smoothly, if disabled it jumps directly to the targeted spot
STR_CONFIG_SETTING_TOOLBAR_DROPDOWNS_INSTANT_CLOSE :Toolbar dropdown menus instant-close: {STRING2}
STR_CONFIG_SETTING_TOOLBAR_DROPDOWNS_INSTANT_CLOSE_HELPTEXT :Controls whether the the main toolbar dropdown menus close instantly on mouse button release
STR_CONFIG_SETTING_MEASURE_TOOLTIP :Show a measurement tooltip when using various build-tools: {STRING2} STR_CONFIG_SETTING_MEASURE_TOOLTIP :Show a measurement tooltip when using various build-tools: {STRING2}
STR_CONFIG_SETTING_MEASURE_TOOLTIP_HELPTEXT :Display tile-distances and height differences when dragging during construction operations STR_CONFIG_SETTING_MEASURE_TOOLTIP_HELPTEXT :Display tile-distances and height differences when dragging during construction operations

View File

@ -2015,6 +2015,7 @@ static SettingsContainer &GetSettingsTree()
general->Add(new SettingEntry("gui.window_snap_radius")); general->Add(new SettingEntry("gui.window_snap_radius"));
general->Add(new SettingEntry("gui.window_soft_limit")); general->Add(new SettingEntry("gui.window_soft_limit"));
general->Add(new SettingEntry("gui.right_click_wnd_close")); general->Add(new SettingEntry("gui.right_click_wnd_close"));
general->Add(new SettingEntry("gui.toolbar_dropdowns_instant_close"));
} }
SettingsPage *viewports = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_VIEWPORTS)); SettingsPage *viewports = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_VIEWPORTS));

View File

@ -178,6 +178,7 @@ struct GUISettings {
uint8_t scrollwheel_multiplier; ///< how much 'wheel' per incoming event from the OS? uint8_t scrollwheel_multiplier; ///< how much 'wheel' per incoming event from the OS?
bool timetable_arrival_departure; ///< show arrivals and departures in vehicle timetables bool timetable_arrival_departure; ///< show arrivals and departures in vehicle timetables
RightClickClose right_click_wnd_close; ///< close window with right click RightClickClose right_click_wnd_close; ///< close window with right click
bool toolbar_dropdowns_instant_close; ///< whether toolbar dropdown menus instant close on mouse release.
bool pause_on_newgame; ///< whether to start new games paused or not bool pause_on_newgame; ///< whether to start new games paused or not
SignalGUISettings signal_gui_mode; ///< select which signal types are shown in the signal GUI SignalGUISettings signal_gui_mode; ///< select which signal types are shown in the signal GUI
SignalCycleSettings cycle_signal_types; ///< Which signal types to cycle with the build signal tool. SignalCycleSettings cycle_signal_types; ///< Which signal types to cycle with the build signal tool.

View File

@ -147,6 +147,14 @@ strhelp = STR_CONFIG_SETTING_RIGHT_MOUSE_WND_CLOSE_HELPTEXT
strval = STR_CONFIG_SETTING_RIGHT_MOUSE_WND_CLOSE_NO strval = STR_CONFIG_SETTING_RIGHT_MOUSE_WND_CLOSE_NO
cat = SC_BASIC cat = SC_BASIC
[SDTC_BOOL]
var = gui.toolbar_dropdowns_instant_close
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def = true
str = STR_CONFIG_SETTING_TOOLBAR_DROPDOWNS_INSTANT_CLOSE
strhelp = STR_CONFIG_SETTING_TOOLBAR_DROPDOWNS_INSTANT_CLOSE_HELPTEXT
cat = SC_BASIC
; We might need to emulate a right mouse button on mac ; We might need to emulate a right mouse button on mac
[SDTC_VAR] [SDTC_VAR]
ifdef = __APPLE__ ifdef = __APPLE__

View File

@ -115,7 +115,7 @@ public:
*/ */
static void PopupMainToolbarMenu(Window *w, WidgetID widget, DropDownList &&list, int def) static void PopupMainToolbarMenu(Window *w, WidgetID widget, DropDownList &&list, int def)
{ {
ShowDropDownList(w, std::move(list), def, widget, 0, true); ShowDropDownList(w, std::move(list), def, widget, 0, _settings_client.gui.toolbar_dropdowns_instant_close);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
} }
@ -291,7 +291,7 @@ static CallBackFunction ToolbarOptionsClick(Window *w)
list.push_back(MakeDropDownListCheckedItem(IsTransparencySet(TO_HOUSES), STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS)); list.push_back(MakeDropDownListCheckedItem(IsTransparencySet(TO_HOUSES), STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS));
list.push_back(MakeDropDownListCheckedItem(IsTransparencySet(TO_SIGNS), STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS)); list.push_back(MakeDropDownListCheckedItem(IsTransparencySet(TO_SIGNS), STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS));
ShowDropDownList(w, std::move(list), 0, WID_TN_SETTINGS, 140, true); ShowDropDownList(w, std::move(list), 0, WID_TN_SETTINGS, 140, _settings_client.gui.toolbar_dropdowns_instant_close);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -687,7 +687,7 @@ static CallBackFunction ToolbarGraphsClick(Window *w)
if (_toolbar_mode != TB_NORMAL) AddDropDownLeagueTableOptions(list); if (_toolbar_mode != TB_NORMAL) AddDropDownLeagueTableOptions(list);
ShowDropDownList(w, std::move(list), GRMN_OPERATING_PROFIT_GRAPH, WID_TN_GRAPHS, 140, true); ShowDropDownList(w, std::move(list), GRMN_OPERATING_PROFIT_GRAPH, WID_TN_GRAPHS, 140, _settings_client.gui.toolbar_dropdowns_instant_close);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
@ -700,7 +700,7 @@ static CallBackFunction ToolbarLeagueClick(Window *w)
AddDropDownLeagueTableOptions(list); AddDropDownLeagueTableOptions(list);
int selected = list[0]->result; int selected = list[0]->result;
ShowDropDownList(w, std::move(list), selected, WID_TN_LEAGUE, 140, true); ShowDropDownList(w, std::move(list), selected, WID_TN_LEAGUE, 140, _settings_client.gui.toolbar_dropdowns_instant_close);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
@ -881,7 +881,7 @@ static CallBackFunction ToolbarZoomOutClick(Window *w)
static CallBackFunction ToolbarBuildRailClick(Window *w) static CallBackFunction ToolbarBuildRailClick(Window *w)
{ {
ShowDropDownList(w, GetRailTypeDropDownList(), _last_built_railtype, WID_TN_RAILS, 140, true); ShowDropDownList(w, GetRailTypeDropDownList(), _last_built_railtype, WID_TN_RAILS, 140, _settings_client.gui.toolbar_dropdowns_instant_close);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -903,7 +903,7 @@ static CallBackFunction MenuClickBuildRail(int index)
static CallBackFunction ToolbarBuildRoadClick(Window *w) static CallBackFunction ToolbarBuildRoadClick(Window *w)
{ {
ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TN_ROADS, 140, true); ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TN_ROADS, 140, _settings_client.gui.toolbar_dropdowns_instant_close);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -925,7 +925,7 @@ static CallBackFunction MenuClickBuildRoad(int index)
static CallBackFunction ToolbarBuildTramClick(Window *w) static CallBackFunction ToolbarBuildTramClick(Window *w)
{ {
ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TN_TRAMS, 140, true); ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TN_TRAMS, 140, _settings_client.gui.toolbar_dropdowns_instant_close);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -949,7 +949,7 @@ static CallBackFunction ToolbarBuildWaterClick(Window *w)
{ {
DropDownList list; DropDownList list;
list.push_back(MakeDropDownListIconItem(SPR_IMG_BUILD_CANAL, PAL_NONE, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 0)); list.push_back(MakeDropDownListIconItem(SPR_IMG_BUILD_CANAL, PAL_NONE, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 0));
ShowDropDownList(w, std::move(list), 0, WID_TN_WATER, 140, true); ShowDropDownList(w, std::move(list), 0, WID_TN_WATER, 140, _settings_client.gui.toolbar_dropdowns_instant_close);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -971,7 +971,7 @@ static CallBackFunction ToolbarBuildAirClick(Window *w)
{ {
DropDownList list; DropDownList list;
list.push_back(MakeDropDownListIconItem(SPR_IMG_AIRPORT, PAL_NONE, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 0)); list.push_back(MakeDropDownListIconItem(SPR_IMG_AIRPORT, PAL_NONE, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 0));
ShowDropDownList(w, std::move(list), 0, WID_TN_AIR, 140, true); ShowDropDownList(w, std::move(list), 0, WID_TN_AIR, 140, _settings_client.gui.toolbar_dropdowns_instant_close);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -995,7 +995,7 @@ static CallBackFunction ToolbarForestClick(Window *w)
list.push_back(MakeDropDownListIconItem(SPR_IMG_LANDSCAPING, PAL_NONE, STR_LANDSCAPING_MENU_LANDSCAPING, 0)); list.push_back(MakeDropDownListIconItem(SPR_IMG_LANDSCAPING, PAL_NONE, STR_LANDSCAPING_MENU_LANDSCAPING, 0));
list.push_back(MakeDropDownListIconItem(SPR_IMG_PLANTTREES, PAL_NONE, STR_LANDSCAPING_MENU_PLANT_TREES, 1)); list.push_back(MakeDropDownListIconItem(SPR_IMG_PLANTTREES, PAL_NONE, STR_LANDSCAPING_MENU_PLANT_TREES, 1));
list.push_back(MakeDropDownListIconItem(SPR_IMG_SIGN, PAL_NONE, STR_LANDSCAPING_MENU_PLACE_SIGN, 2)); list.push_back(MakeDropDownListIconItem(SPR_IMG_SIGN, PAL_NONE, STR_LANDSCAPING_MENU_PLACE_SIGN, 2));
ShowDropDownList(w, std::move(list), 0, WID_TN_LANDSCAPE, 100, true); ShowDropDownList(w, std::move(list), 0, WID_TN_LANDSCAPE, 100, _settings_client.gui.toolbar_dropdowns_instant_close);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -1268,7 +1268,7 @@ static CallBackFunction ToolbarScenGenIndustry(Window *w)
static CallBackFunction ToolbarScenBuildRoadClick(Window *w) static CallBackFunction ToolbarScenBuildRoadClick(Window *w)
{ {
ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TE_ROADS, 140, true); ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TE_ROADS, 140, _settings_client.gui.toolbar_dropdowns_instant_close);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -1288,7 +1288,7 @@ static CallBackFunction ToolbarScenBuildRoad(int index)
static CallBackFunction ToolbarScenBuildTramClick(Window *w) static CallBackFunction ToolbarScenBuildTramClick(Window *w)
{ {
ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TE_TRAMS, 140, true); ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TE_TRAMS, 140, _settings_client.gui.toolbar_dropdowns_instant_close);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }

View File

@ -611,12 +611,19 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
bool focused_widget_changed = false; bool focused_widget_changed = false;
/* If clicked on a window that previously did not have focus */ /* If clicked on a window that previously did not have focus */
if (_focused_window != w && // We already have focus, right? if (_focused_window != w) {
(w->window_desc.flags & WDF_NO_FOCUS) == 0 && // Don't lose focus to toolbars bool allowed_focus_change =
widget_type != WWT_CLOSEBOX) { // Don't change focused window if 'X' (close button) was clicked (w->window_desc.flags & WDF_NO_FOCUS) == 0 && // Don't lose focus to toolbar
widget_type != WWT_CLOSEBOX; // Don't change focused window if 'X' (close button) was clicked
// if we're switching away from a dropdown menu always let it get the lost focus notification
if (_focused_window != nullptr && _focused_window->window_class == WC_DROPDOWN_MENU) {
allowed_focus_change = true;
}
if (allowed_focus_change) {
focused_widget_changed = true; focused_widget_changed = true;
SetFocusedWindow(w); SetFocusedWindow(w);
} }
}
if (nw == nullptr) return; // exit if clicked outside of widgets if (nw == nullptr) return; // exit if clicked outside of widgets