Index: src/fios_gui.cpp =================================================================== --- src/fios_gui.cpp (revision 24820) +++ src/fios_gui.cpp (working copy) @@ -34,6 +34,8 @@ #include "table/sprites.h" #include "table/strings.h" +#include + SaveLoadDialogMode _saveload_mode; LoadCheckData _load_check_data; ///< Data loaded from save during SL_LOAD_CHECK. @@ -78,9 +80,9 @@ NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), NWidget(NWID_VERTICAL), NWidget(NWID_HORIZONTAL), - NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), + NWidget(NWID_HORIZONTAL), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYNAME), SetDataTip(STR_SORT_BY_CAPTION_NAME, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0), - NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYDATE), SetDataTip(STR_SORT_BY_CAPTION_DATE, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0), + NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYDATE), SetDataTip(STR_SORT_BY_CAPTION_DATE, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(0, 0), EndContainer(), NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetMinimalSize(12, 12), SetDataTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON), EndContainer(), @@ -119,9 +121,9 @@ NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_BACKGROUND), SetFill(1, 0), SetResize(1, 0), EndContainer(), NWidget(NWID_VERTICAL), NWidget(NWID_HORIZONTAL), - NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), + NWidget(NWID_HORIZONTAL), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYNAME), SetDataTip(STR_SORT_BY_CAPTION_NAME, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0), - NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYDATE), SetDataTip(STR_SORT_BY_CAPTION_DATE, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0), + NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYDATE), SetDataTip(STR_SORT_BY_CAPTION_DATE, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(0, 0), EndContainer(), NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetMinimalSize(12, 12), SetDataTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON), EndContainer(), @@ -150,9 +152,9 @@ NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), NWidget(NWID_VERTICAL), NWidget(NWID_HORIZONTAL), - NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), + NWidget(NWID_HORIZONTAL), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYNAME), SetDataTip(STR_SORT_BY_CAPTION_NAME, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0), - NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYDATE), SetDataTip(STR_SORT_BY_CAPTION_DATE, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0), + NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYDATE), SetDataTip(STR_SORT_BY_CAPTION_DATE, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(0, 0), EndContainer(), NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetMinimalSize(12, 12), SetDataTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON), EndContainer(), @@ -353,6 +355,9 @@ case WID_SL_DRIVES_DIRECTORIES_LIST: { GfxFillRect(r.left + 1, r.top + 1, r.right, r.bottom, PC_BLACK); + const NWidgetBase *name_column = this->GetWidget(WID_SL_SORT_BYNAME); + const NWidgetBase *date_column = this->GetWidget(WID_SL_SORT_BYDATE); + uint y = r.top + WD_FRAMERECT_TOP; for (uint pos = this->vscroll->GetPosition(); pos < _fios_items.Length(); pos++) { const FiosItem *item = _fios_items.Get(pos); @@ -360,7 +365,14 @@ if (item == this->selected) { GfxFillRect(r.left + 1, y, r.right, y + this->resize.step_height, PC_DARK_BLUE); } - DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, item->title, _fios_colours[item->type]); + + DrawString(name_column->pos_x + WD_FRAMERECT_LEFT, name_column->pos_x + name_column->current_x - 1 - WD_FRAMERECT_RIGHT, y, item->title, _fios_colours[item->type]); + + char timebuf[64]; + if (FileFormatMTime(timebuf, sizeof(timebuf), item->mtime) > 0) { + DrawString(date_column->pos_x + WD_FRAMERECT_LEFT, date_column->pos_x + date_column->current_x - 1 - WD_FRAMERECT_RIGHT, y, timebuf, _fios_colours[item->type], SA_RIGHT); + } + y += this->resize.step_height; if (y >= this->vscroll->GetCapacity() * this->resize.step_height + r.top + WD_FRAMERECT_TOP) break; } @@ -474,9 +486,20 @@ resize->height = FONT_HEIGHT_NORMAL; size->height = resize->height * 10 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; break; + case WID_SL_SORT_BYNAME: case WID_SL_SORT_BYDATE: { - Dimension d = GetStringBoundingBox(this->GetWidget(widget)->widget_data); + /* Give both columns the same minimal size; but only name is resizable */ + char timebuf[64]; + if (FileFormatMTime(timebuf, sizeof(timebuf), 1987887538) > 0) { // TODO what is the max length? + *size = maxdim(*size, GetStringBoundingBox(timebuf)); + size->width += 30; + } + + Dimension d = maxdim( + GetStringBoundingBox(this->GetWidget(WID_SL_SORT_BYNAME)->widget_data), + GetStringBoundingBox(this->GetWidget(WID_SL_SORT_BYDATE)->widget_data) + ); d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the string is centred and it also looks better. d.height += padding.height; *size = maxdim(*size, d); Index: src/fileio_func.h =================================================================== --- src/fileio_func.h (revision 24820) +++ src/fileio_func.h (working copy) @@ -14,6 +14,7 @@ #include "core/enum_type.hpp" #include "fileio_type.h" +#include void FioSeekTo(size_t pos, int mode); void FioSeekToFile(uint8 slot, size_t pos); @@ -66,6 +67,7 @@ const char *FioTarFirstDir(const char *tarname, Subdirectory subdir); void FioTarAddLink(const char *src, const char *dest, Subdirectory subdir); bool ExtractTar(const char *tar_filename, Subdirectory subdir); +size_t FileFormatMTime(char *buf, size_t buflen, uint64 mtime); extern char *_personal_dir; ///< custom directory for personal settings, saves, newgrf, etc. Index: src/fileio.cpp =================================================================== --- src/fileio.cpp (revision 24820) +++ src/fileio.cpp (working copy) @@ -310,6 +310,34 @@ } /** + * Stores a printable version of the given timestamp in the buffer provided. + * In keeping with the FileMTime function, a timestamp of 0 is an error. + * @param buf the output buffer + * @param buflen the length of the output buffer + * @param mtime the timestamp to be formatted + * @return the number of characters written to buf, or 0 in case of error. + */ +size_t FileFormatMTime(char *buf, size_t buflen, uint64 mtime) +{ + if (buf == 0 || mtime == 0) return 0; + + time_t time = (time_t)mtime; + + struct tm *local_mtime = 0; +#if defined(__MINGW32__) + /* MinGW is based on MSVC 6 and does not support localtime_r. + * However, localtime uses thread-local storage and is safe. */ + local_mtime = localtime(&time); + if (local_mtime == 0) return 0; +#else + struct tm temp_storage; + local_mtime = &temp_storage; + if (localtime_r(&time, local_mtime) == 0) return 0; +#endif + return strftime(buf, buflen, "%c", local_mtime); +} + +/** * Test whether the given filename exists. * @param filename the file to test. * @return true if and only if the file exists. Index: src/openttd.cpp =================================================================== --- src/openttd.cpp (revision 24820) +++ src/openttd.cpp (working copy) @@ -10,6 +10,7 @@ /** @file openttd.cpp Functions related to starting OpenTTD. */ #include "stdafx.h" +#include "locale.h" #include "blitter/factory.hpp" #include "sound/sound_driver.hpp" @@ -523,6 +524,7 @@ int ttd_main(int argc, char *argv[]) { + setlocale(LC_ALL, ""); char *musicdriver = NULL; char *sounddriver = NULL; char *videodriver = NULL;