diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 9d783fa868..26c66013fc 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -523,14 +523,12 @@ static void UpdatePlayerMenuHeight(Window *w) if (_networking && WP(w, menu_d).main_button == 9) num++; if (WP(w, menu_d).item_count != num) { - Point pos; WP(w, menu_d).item_count = num; SetWindowDirty(w); num = num * 10 + 2; w->height = num; w->widget[0].bottom = w->widget[0].top + num - 1; - pos = GetToolbarDropdownPos(0, w->width, w->height); - w->top = pos.y; + w->top = GetToolbarDropdownPos(0, w->width, w->height).y; SetWindowDirty(w); } } @@ -686,10 +684,6 @@ static int GetStringListMaxWidth(StringID base_string, byte count) * @return Return a pointer to the newly created dropdown window */ Window *PopupMainToolbMenu(Window *w, uint16 parent_button, StringID base_string, byte item_count, byte disabled_mask) { - int width; - int height; - Point pos; - assert(disabled_mask == 0 || item_count <= 8); w->LowerWidget(parent_button); w->InvalidateWidget(parent_button); @@ -697,10 +691,10 @@ static int GetStringListMaxWidth(StringID base_string, byte count) DeleteWindowById(WC_TOOLBAR_MENU, 0); // Extend the dropdown toolbar to the longest string in the list - width = max(GetStringListMaxWidth(base_string, item_count) + 6, 140); - height = item_count * 10 + 2; + int width = max(GetStringListMaxWidth(base_string, item_count) + 6, 140); + int height = item_count * 10 + 2; - pos = GetToolbarDropdownPos(parent_button, width, height); + Point pos = GetToolbarDropdownPos(parent_button, width, height); w = AllocateWindow(pos.x, pos.y, width, height, MenuWndProc, WC_TOOLBAR_MENU, _menu_widgets); w->widget[0].bottom = item_count * 10 + 1; @@ -722,13 +716,11 @@ static int GetStringListMaxWidth(StringID base_string, byte count) Window *PopupMainPlayerToolbMenu(Window *w, int main_button, int gray) { - Point pos;; - w->LowerWidget(main_button); w->InvalidateWidget(main_button); DeleteWindowById(WC_TOOLBAR_MENU, 0); - pos = GetToolbarDropdownPos(main_button, 241, 82); + Point pos = GetToolbarDropdownPos(main_button, 241, 82); w = AllocateWindow(pos.x, pos.y, 241, 82, PlayerMenuWndProc, WC_TOOLBAR_MENU, _player_menu_widgets); w->flags4 &= ~WF_WHITE_BORDER_MASK; WP(w, menu_d).item_count = 0; diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 0b89d1e54e..309120e2f6 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -45,12 +45,11 @@ extern RoadType _last_built_roadtype; * the default position is aligned with the left side of the clicked button */ Point GetToolbarDropdownPos(uint16 parent_button, int width, int height) { - Window *w = FindWindowById(WC_MAIN_TOOLBAR,0); + const Window *w = FindWindowById(WC_MAIN_TOOLBAR,0); Point pos; - pos.x = w->widget[GB(parent_button, 0, 8)].left; - pos.y = -height; + pos.x = w->widget[GB(parent_button, 0, 8)].left; pos.x = w->left + Clamp(pos.x, 0, w->width - width); - pos.y = w->top + pos.y; + pos.y = w->height; return pos; }