mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use window parent association for dropdowns.
This replaces the separate window class and number properties, and allows the window system to close dropdowns automatically.pull/10922/head
parent
2d8d9c49c4
commit
81e5cd23e0
|
@ -437,7 +437,7 @@ struct AISettingsWindow : public Window {
|
|||
|
||||
if (this->clicked_row != num) {
|
||||
this->CloseChildWindows(WC_QUERY_STRING);
|
||||
HideDropDownMenu(this);
|
||||
this->CloseChildWindows(WC_DROPDOWN_MENU);
|
||||
this->clicked_row = num;
|
||||
this->clicked_dropdown = false;
|
||||
}
|
||||
|
@ -452,7 +452,7 @@ struct AISettingsWindow : public Window {
|
|||
if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) {
|
||||
if (this->clicked_dropdown) {
|
||||
/* unclick the dropdown */
|
||||
HideDropDownMenu(this);
|
||||
this->CloseChildWindows(WC_DROPDOWN_MENU);
|
||||
this->clicked_dropdown = false;
|
||||
this->closing_dropdown = false;
|
||||
} else {
|
||||
|
@ -564,7 +564,7 @@ struct AISettingsWindow : public Window {
|
|||
void OnInvalidateData(int data = 0, bool gui_scope = true) override
|
||||
{
|
||||
this->RebuildVisibleSettings();
|
||||
HideDropDownMenu(this);
|
||||
this->CloseChildWindows(WC_DROPDOWN_MENU);
|
||||
this->CloseChildWindows(WC_QUERY_STRING);
|
||||
}
|
||||
|
||||
|
|
|
@ -301,7 +301,7 @@ struct GSConfigWindow : public Window {
|
|||
|
||||
if (this->clicked_row != num) {
|
||||
this->CloseChildWindows(WC_QUERY_STRING);
|
||||
HideDropDownMenu(this);
|
||||
this->CloseChildWindows(WC_DROPDOWN_MENU);
|
||||
this->clicked_row = num;
|
||||
this->clicked_dropdown = false;
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ struct GSConfigWindow : public Window {
|
|||
if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) {
|
||||
if (this->clicked_dropdown) {
|
||||
/* unclick the dropdown */
|
||||
HideDropDownMenu(this);
|
||||
this->CloseChildWindows(WC_DROPDOWN_MENU);
|
||||
this->clicked_dropdown = false;
|
||||
this->closing_dropdown = false;
|
||||
} else {
|
||||
|
@ -434,7 +434,7 @@ struct GSConfigWindow : public Window {
|
|||
this->SetWidgetDisabledState(WID_GSC_TEXTFILE + tft, GameConfig::GetConfig()->GetTextfile(tft, (CompanyID)OWNER_DEITY) == nullptr);
|
||||
}
|
||||
this->RebuildVisibleSettings();
|
||||
HideDropDownMenu(this);
|
||||
this->CloseChildWindows(WC_DROPDOWN_MENU);
|
||||
this->CloseChildWindows(WC_QUERY_STRING);
|
||||
}
|
||||
private:
|
||||
|
|
|
@ -461,7 +461,7 @@ public:
|
|||
|
||||
if (!(IsAllGroupID(this->vli.index) || IsDefaultGroupID(this->vli.index) || Group::IsValidID(this->vli.index))) {
|
||||
this->vli.index = ALL_GROUP;
|
||||
HideDropDownMenu(this);
|
||||
this->CloseChildWindows(WC_DROPDOWN_MENU);
|
||||
}
|
||||
this->SetDirty();
|
||||
}
|
||||
|
@ -512,7 +512,7 @@ public:
|
|||
/* The drop down menu is out, *but* it may not be used, retract it. */
|
||||
if (this->vehicles.size() == 0 && this->IsWidgetLowered(WID_GL_MANAGE_VEHICLES_DROPDOWN)) {
|
||||
this->RaiseWidget(WID_GL_MANAGE_VEHICLES_DROPDOWN);
|
||||
HideDropDownMenu(this);
|
||||
this->CloseChildWindows(WC_DROPDOWN_MENU);
|
||||
}
|
||||
|
||||
/* Disable all lists management button when the list is empty */
|
||||
|
|
|
@ -342,7 +342,7 @@ struct NewGRFParametersWindow : public Window {
|
|||
if (num >= this->vscroll->GetCount()) break;
|
||||
if (this->clicked_row != num) {
|
||||
this->CloseChildWindows(WC_QUERY_STRING);
|
||||
HideDropDownMenu(this);
|
||||
this->CloseChildWindows(WC_DROPDOWN_MENU);
|
||||
this->clicked_row = num;
|
||||
this->clicked_dropdown = false;
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ struct NewGRFParametersWindow : public Window {
|
|||
if (par_info->type != PTYPE_BOOL && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && par_info->complete_labels) {
|
||||
if (this->clicked_dropdown) {
|
||||
/* unclick the dropdown */
|
||||
HideDropDownMenu(this);
|
||||
this->CloseChildWindows(WC_DROPDOWN_MENU);
|
||||
this->clicked_dropdown = false;
|
||||
this->closing_dropdown = false;
|
||||
} else {
|
||||
|
|
|
@ -849,7 +849,6 @@ public:
|
|||
if (this->selected_order == -1) break;
|
||||
|
||||
this->CloseChildWindows();
|
||||
HideDropDownMenu(this);
|
||||
this->selected_order = -1;
|
||||
break;
|
||||
|
||||
|
@ -881,7 +880,6 @@ public:
|
|||
if (to == INVALID_VEH_ORDER_ID) {
|
||||
/* Deleting selected order */
|
||||
this->CloseChildWindows();
|
||||
HideDropDownMenu(this);
|
||||
this->selected_order = -1;
|
||||
break;
|
||||
}
|
||||
|
@ -1181,7 +1179,6 @@ public:
|
|||
|
||||
/* This order won't be selected any more, close all child windows and dropdowns */
|
||||
this->CloseChildWindows();
|
||||
HideDropDownMenu(this);
|
||||
|
||||
if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
|
||||
/* Deselect clicked order */
|
||||
|
|
|
@ -2229,7 +2229,7 @@ struct GameSettingsWindow : Window {
|
|||
|
||||
if (this->valuedropdown_entry == pe) {
|
||||
/* unclick the dropdown */
|
||||
HideDropDownMenu(this);
|
||||
this->CloseChildWindows(WC_DROPDOWN_MENU);
|
||||
this->closing_dropdown = false;
|
||||
this->valuedropdown_entry->SetButtons(0);
|
||||
this->valuedropdown_entry = nullptr;
|
||||
|
|
|
@ -1965,7 +1965,7 @@ public:
|
|||
this->SortVehicleList();
|
||||
|
||||
if (this->vehicles.size() == 0 && this->IsWidgetLowered(WID_VL_MANAGE_VEHICLES_DROPDOWN)) {
|
||||
HideDropDownMenu(this);
|
||||
this->CloseChildWindows(WC_DROPDOWN_MENU);
|
||||
}
|
||||
|
||||
/* Hide the widgets that we will not use in this window
|
||||
|
|
|
@ -119,8 +119,6 @@ static WindowDesc _dropdown_desc(
|
|||
|
||||
/** Drop-down menu window */
|
||||
struct DropdownWindow : Window {
|
||||
WindowClass parent_wnd_class; ///< Parent window class.
|
||||
WindowNumber parent_wnd_num; ///< Parent window number.
|
||||
int parent_button; ///< Parent widget number where the window is dropped from.
|
||||
const DropDownList list; ///< List with dropdown menu items.
|
||||
int selected_index; ///< Index of the selected item in the list.
|
||||
|
@ -178,8 +176,7 @@ struct DropdownWindow : Window {
|
|||
this->vscroll->SetCapacity(size.height * (uint16)this->list.size() / list_height);
|
||||
this->vscroll->SetCount((uint16)this->list.size());
|
||||
|
||||
this->parent_wnd_class = parent->window_class;
|
||||
this->parent_wnd_num = parent->window_number;
|
||||
this->parent = parent;
|
||||
this->parent_button = button;
|
||||
this->selected_index = selected;
|
||||
this->click_delay = 0;
|
||||
|
@ -194,13 +191,10 @@ struct DropdownWindow : Window {
|
|||
* Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
|
||||
this->Window::Close();
|
||||
|
||||
Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
|
||||
if (w2 != nullptr) {
|
||||
Point pt = _cursor.pos;
|
||||
pt.x -= w2->left;
|
||||
pt.y -= w2->top;
|
||||
w2->OnDropdownClose(pt, this->parent_button, this->selected_index, this->instant_close);
|
||||
}
|
||||
Point pt = _cursor.pos;
|
||||
pt.x -= this->parent->left;
|
||||
pt.y -= this->parent->top;
|
||||
this->parent->OnDropdownClose(pt, this->parent_button, this->selected_index, this->instant_close);
|
||||
}
|
||||
|
||||
void OnFocusLost() override
|
||||
|
@ -304,17 +298,11 @@ struct DropdownWindow : Window {
|
|||
|
||||
void OnMouseLoop() override
|
||||
{
|
||||
Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
|
||||
if (w2 == nullptr) {
|
||||
this->Close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->click_delay != 0 && --this->click_delay == 0) {
|
||||
/* 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). */
|
||||
this->Close();
|
||||
w2->OnDropdownSelect(this->parent_button, this->selected_index);
|
||||
this->parent->OnDropdownSelect(this->parent_button, this->selected_index);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -510,16 +498,14 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int butt
|
|||
int HideDropDownMenu(Window *pw)
|
||||
{
|
||||
for (Window *w : Window::Iterate()) {
|
||||
if (w->parent != pw) continue;
|
||||
if (w->window_class != WC_DROPDOWN_MENU) continue;
|
||||
|
||||
DropdownWindow *dw = dynamic_cast<DropdownWindow*>(w);
|
||||
assert(dw != nullptr);
|
||||
if (pw->window_class == dw->parent_wnd_class &&
|
||||
pw->window_number == dw->parent_wnd_num) {
|
||||
int parent_button = dw->parent_button;
|
||||
dw->Close();
|
||||
return parent_button;
|
||||
}
|
||||
int parent_button = dw->parent_button;
|
||||
dw->Close();
|
||||
return parent_button;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
|
Loading…
Reference in New Issue