diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 74c99c9f16..7a3dbd22ae 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -893,6 +893,7 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList * int sprite_width = sprite_left + sprite_right; int sprite_x = rtl ? r - sprite_right - 1 : l + sprite_left + 1; + int sprite_y_offset = sprite_y_offsets[type] + step_size / 2; Dimension replace_icon = {0, 0}; int count_width = 0; @@ -908,6 +909,10 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList * int count_left = l; int count_right = rtl ? text_left : r - WD_FRAMERECT_RIGHT - replace_icon.width - 8; + int normal_text_y_offset = (step_size - FONT_HEIGHT_NORMAL) / 2; + int small_text_y_offset = step_size - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 1; + int replace_icon_y_offset = (step_size - replace_icon.height) / 2 - 1; + for (; min < max; min++, y += step_size) { const EngineID engine = (*eng_list)[min]; /* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_company here. */ @@ -923,8 +928,8 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList * DrawVehicleEngine(l, r, sprite_x, y + sprite_y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_company), EIT_PURCHASE); if (show_count) { SetDParam(0, num_engines); - DrawString(count_left, count_right, Center(y, step_size, FONT_HEIGHT_SMALL), STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT | SA_FORCE); - if (EngineHasReplacementForCompany(Company::Get(_local_company), engine, selected_group)) DrawSprite(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ? PALETTE_CRASH : PAL_NONE, replace_icon_left, Center(y, step_size, replace_icon.height)); + DrawString(count_left, count_right, y + small_text_y_offset, STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT | SA_FORCE); + if (EngineHasReplacementForCompany(Company::Get(_local_company), engine, selected_group)) DrawSprite(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ? PALETTE_CRASH : PAL_NONE, replace_icon_left, y + replace_icon_y_offset); } } } diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 1af2d14e41..ca7f98fb4d 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -641,7 +641,7 @@ public: case WID_SL_LOAD_NETWORK_BUTTON: { char savePath[PATH_MAX]; - FiosMakeSavegameName(savePath, NETWORK_SAVE_FILENAME, sizeof(savePath)); + FiosMakeSavegameName(savePath, NETWORK_SAVE_FILENAME, lastof(savePath)); #ifdef __ANDROID__ if (!SDL_ANDROID_CloudLoad(savePath, NULL, "OpenTTD")) { break; diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 1d38995056..cd6745b2c1 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -658,8 +658,7 @@ public: case ContentInfo::DOES_NOT_EXIST: sprite = SPR_BLOT; pal = PALETTE_TO_RED; break; default: NOT_REACHED(); } - - DrawSprite(sprite, pal, Center(nwi_checkbox->pos_x + (pal == PAL_NONE ? 2 : 3), nwi_checkbox->current_x, sprite_dim.width), Center(y, this->resize.step_height, sprite_dim.height + (pal == PAL_NONE ? 0 : -2))); + DrawSprite(sprite, pal, nwi_checkbox->pos_x + (pal == PAL_NONE ? 2 : 3), y + sprite_y_offset + (pal == PAL_NONE ? 1 : 0)); StringID str = STR_CONTENT_TYPE_BASE_GRAPHICS + ci->type - CONTENT_TYPE_BASE_GRAPHICS; DrawString(nwi_type->pos_x, nwi_type->pos_x + nwi_type->current_x - 1, y + text_y_offset, str, TC_BLACK, SA_HOR_CENTER); diff --git a/src/openttd.cpp b/src/openttd.cpp index 816488530d..55d3ade155 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1176,7 +1176,7 @@ void SwitchToMode(SwitchMode new_mode) lastPart++; } MakeScreenshot(SC_VIEWPORT, NETWORK_SAVE_SCREENSHOT_FILE); - FioFindFullPath(screenshotFile, sizeof(screenshotFile), SCREENSHOT_DIR, NETWORK_SAVE_SCREENSHOT_FILE_PNG); + FioFindFullPath(screenshotFile, lastof(screenshotFile), SCREENSHOT_DIR, NETWORK_SAVE_SCREENSHOT_FILE_PNG); uint64_t playedTime = abs(_date - DAYS_TILL(_settings_newgame.game_creation.starting_year)) * 1000; int ret = SDL_ANDROID_CloudSave(_file_to_saveload.name, lastPart, "OpenTTD", lastPart, screenshotFile, playedTime); if (_settings_client.gui.save_to_network == 2) { diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 03da6c072a..4b7d0ccafc 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -807,17 +807,13 @@ static const NWidgetPart _nested_station_view_widgets[] = { * @param y y coordinate * @param width the width of the view */ -static void DrawCargoIcons(CargoID i, uint waiting, int left, int right, int top, int bottom) +static void DrawCargoIcons(CargoID i, uint waiting, int left, int right, int top, int y) { int width = ScaleGUITrad(10); uint num = min((waiting + (width / 2)) / width, (right - left) / width); // maximum is width / 10 icons so it won't overflow if (num == 0) return; SpriteID sprite = CargoSpec::Get(i)->GetCargoIcon(); - Dimension d = GetSpriteSize(sprite); - - uint num = min((waiting + 5) / d.width, (right - left) / d.width); // maximum is width / 10 icons so it won't overflow - if (num == 0) return; int x = _current_text_dir == TD_RTL ? left : right - num * width; do { diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index ac688600b5..dab8466d2d 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -1417,9 +1417,11 @@ public: } } if (type == NWID_HORIZONTAL) { - w->window_desc->default_width = nbuttons * this->smallest_x; + //w->window_desc->default_width_trad = nbuttons * this->smallest_x; + w->window_desc->pref_width = nbuttons * this->smallest_x; } else { - w->window_desc->default_height = nbuttons * this->smallest_y; + //w->window_desc->default_height_trad = nbuttons * this->smallest_y; + w->window_desc->pref_height = nbuttons * this->smallest_y; } _toolbar_width = nbuttons * this->smallest_x; } diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 4963ba29f2..5198c4d2c3 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -362,14 +362,6 @@ void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int b /* Longest item in the list, if auto_width is enabled */ uint max_item_width = 0; - if (auto_width) { - /* Find the longest item in the list */ - for (const DropDownListItem * const *it = list->Begin(); it != list->End(); ++it) { - const DropDownListItem *item = *it; - max_item_width = max(max_item_width, item->Width() + 5); - } - } - /* Total length of list */ int height = 0; @@ -383,14 +375,11 @@ void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int b int screen_bottom = GetMainViewBottom(); bool scroll = false; - enum { DISPLAY_BORDER = 20, TOP_BORDER = 4 }; - - /* Check if the dropdown will fully fit below the widget. */ - if (top + height + DISPLAY_BORDER >= screen_bottom) { - /* If not, check if it will fit above the widget. */ - int screen_top = GetMainViewTop(); - if (w->top + wi_rect.top - TOP_BORDER > screen_top + height) { - top = w->top + wi_rect.top - height - TOP_BORDER; + /* Check if the dropdown will fully fit below the widget */ + if (top + height + 4 >= screen_bottom) { + /* If not, check if it will fit above the widget */ + if (w->top + wi_rect.top - height > GetMainViewTop()) { + top = w->top + wi_rect.top - height - 4; } else { /* ... and lastly if it won't, enable the scroll bar and fit the * list in below the widget */ @@ -398,30 +387,9 @@ void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int b int rows = (screen_bottom - 4 - top) / avg_height; height = rows * avg_height; scroll = true; - - /* ... and choose whether to put the list above or below the widget. */ - bool put_above = false; - int available_height = screen_bottom - w->top - wi_rect.bottom; - if (w->top + wi_rect.top - screen_top > available_height) { - // Put it above. - available_height = w->top + wi_rect.top - screen_top - DISPLAY_BORDER - TOP_BORDER; - put_above = true; - } - - /* Check at least there is space for one item. */ - assert(available_height >= avg_height); - - /* And lastly, fit the list,... */ - int rows = available_height / avg_height; - height = rows * avg_height; - - /* ... add space for the scrollbar,... */ + /* Add space for the scroll bar if we automatically determined + * the width of the list. */ max_item_width += NWidgetScrollbar::GetVerticalDimension().width; - - /* ... and set the top position if needed. */ - if (put_above) { - top = w->top + wi_rect.top - height - TOP_BORDER; - } } } diff --git a/src/window.cpp b/src/window.cpp index 1b219d6af6..9e4a42785d 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -3590,7 +3590,7 @@ void RelocateAllWindows(int neww, int newh) break; case WC_MAIN_TOOLBAR_RIGHT: - ResizeWindow(w, min(neww, w->window_desc->default_width) - w->width, 0, false); + ResizeWindow(w, min(neww, _toolbar_width) - w->width, 0, false); top = w->top; left = neww - w->width;