Skip to content

Commit 8d03138

Browse files
Load/save window: show folder icon next to folders
1 parent 8d645c6 commit 8d03138

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

distribution/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
------------------------------------------------------------------------
33
- Improved: [#23260] Add diagonal (block) brakes to LSM Launched Roller Coaster.
44
- Improved: [#23350] Increased the maximum width of the ride graph window.
5+
- Improved: [#23404] Folders are now paired with an icon in the load/save window.
56
- Fix: [#23286] Currency formatted incorrectly in the in game console.
67

78
0.4.17 (2024-12-08)

resources/g2/icons/folder.png

654 Bytes
Loading

resources/g2/sprites.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@
324324
{
325325
"path": "icons/colour_invisible_pressed.png"
326326
},
327+
{
328+
"path": "icons/folder.png"
329+
},
327330
{
328331
"path": "loader/loader_hybrid_supports.png",
329332
"y": 10

src/openrct2-ui/windows/LoadSave.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626
#include <openrct2/core/Guard.hpp>
2727
#include <openrct2/core/Path.hpp>
2828
#include <openrct2/core/String.hpp>
29+
#include <openrct2/drawing/Drawing.h>
2930
#include <openrct2/localisation/Formatter.h>
3031
#include <openrct2/network/network.h>
3132
#include <openrct2/platform/Platform.h>
3233
#include <openrct2/rct2/T6Exporter.h>
3334
#include <openrct2/ride/TrackDesign.h>
3435
#include <openrct2/scenario/Scenario.h>
3536
#include <openrct2/scenes/title/TitleScene.h>
37+
#include <openrct2/sprites.h>
3638
#include <openrct2/ui/UiContext.h>
3739
#include <openrct2/windows/Intent.h>
3840
#include <openrct2/world/Park.h>
@@ -86,10 +88,10 @@ namespace OpenRCT2::Ui::Windows
8688

8789
static WindowBase* WindowOverwritePromptOpen(const std::string_view name, const std::string_view path);
8890

89-
enum
91+
enum class FileType : uint8_t
9092
{
91-
TYPE_DIRECTORY,
92-
TYPE_FILE,
93+
directory,
94+
file,
9395
};
9496

9597
struct LoadSaveListItem
@@ -99,7 +101,7 @@ namespace OpenRCT2::Ui::Windows
99101
time_t date_modified{ 0 };
100102
std::string date_formatted{};
101103
std::string time_formatted{};
102-
uint8_t type{ 0 };
104+
FileType type{};
103105
bool loaded{ false };
104106
};
105107

@@ -116,7 +118,7 @@ namespace OpenRCT2::Ui::Windows
116118
static bool ListItemSort(LoadSaveListItem& a, LoadSaveListItem& b)
117119
{
118120
if (a.type != b.type)
119-
return a.type - b.type < 0;
121+
return EnumValue(a.type) - EnumValue(b.type) < 0;
120122

121123
switch (Config::Get().general.LoadSaveSort)
122124
{
@@ -525,7 +527,7 @@ namespace OpenRCT2::Ui::Windows
525527
LoadSaveListItem newListItem;
526528
newListItem.path = std::string(1, 'A' + x) + ":" PATH_SEPARATOR;
527529
newListItem.name = newListItem.path;
528-
newListItem.type = TYPE_DIRECTORY;
530+
newListItem.type = FileType::directory;
529531

530532
_listItems.push_back(std::move(newListItem));
531533
}
@@ -577,7 +579,7 @@ namespace OpenRCT2::Ui::Windows
577579
LoadSaveListItem newListItem;
578580
newListItem.path = Path::Combine(absoluteDirectory, subDir);
579581
newListItem.name = std::move(subDir);
580-
newListItem.type = TYPE_DIRECTORY;
582+
newListItem.type = FileType::directory;
581583
newListItem.loaded = false;
582584

583585
_listItems.push_back(std::move(newListItem));
@@ -593,7 +595,7 @@ namespace OpenRCT2::Ui::Windows
593595
{
594596
LoadSaveListItem newListItem;
595597
newListItem.path = scanner->GetPath();
596-
newListItem.type = TYPE_FILE;
598+
newListItem.type = FileType::file;
597599
newListItem.date_modified = Platform::FileGetModifiedTime(newListItem.path.c_str());
598600

599601
// Cache a human-readable version of the modified date.
@@ -950,7 +952,7 @@ namespace OpenRCT2::Ui::Windows
950952
if (selectedItem >= no_list_items)
951953
return;
952954

953-
if (_listItems[selectedItem].type == TYPE_DIRECTORY)
955+
if (_listItems[selectedItem].type == FileType::directory)
954956
{
955957
// The selected item is a folder
956958
int32_t includeNewItem;
@@ -967,9 +969,8 @@ namespace OpenRCT2::Ui::Windows
967969

968970
no_list_items = static_cast<uint16_t>(_listItems.size());
969971
}
970-
else
972+
else // FileType::file
971973
{
972-
// TYPE_FILE
973974
// Load or overwrite
974975
if ((_type & 0x01) == LOADSAVETYPE_SAVE)
975976
WindowOverwritePromptOpen(_listItems[selectedItem].name, _listItems[selectedItem].path);
@@ -1011,15 +1012,21 @@ namespace OpenRCT2::Ui::Windows
10111012
DrawTextBasic(dpi, { 0, y }, stringId, ft);
10121013
}
10131014

1015+
// Folders get a folder icon
1016+
if (_listItems[i].type == FileType::directory)
1017+
{
1018+
GfxDrawSprite(dpi, ImageId(SPR_G2_FOLDER), { 1, y });
1019+
}
1020+
10141021
// Print filename
10151022
auto ft = Formatter();
10161023
ft.Add<StringId>(STR_STRING);
10171024
ft.Add<char*>(_listItems[i].name.c_str());
1018-
int32_t max_file_width = widgets[WIDX_SORT_NAME].width() - 10;
1019-
DrawTextEllipsised(dpi, { 10, y }, max_file_width, stringId, ft);
1025+
int32_t max_file_width = widgets[WIDX_SORT_NAME].width() - 15;
1026+
DrawTextEllipsised(dpi, { 15, y }, max_file_width, stringId, ft);
10201027

10211028
// Print formatted modified date, if this is a file
1022-
if (_listItems[i].type == TYPE_FILE)
1029+
if (_listItems[i].type == FileType::file)
10231030
{
10241031
ft = Formatter();
10251032
ft.Add<StringId>(STR_STRING);

src/openrct2/sprites.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,9 +972,9 @@ enum : ImageIndex
972972
SPR_G2_MAP_GEN_TERRAIN_TAB,
973973
SPR_G2_MAP_GEN_BTN,
974974
SPR_G2_PEEP_SPAWN,
975-
976975
SPR_G2_ICON_PALETTE_INVISIBLE,
977976
SPR_G2_ICON_PALETTE_INVISIBLE_PRESSED,
977+
SPR_G2_FOLDER,
978978

979979
// G2 Loading progress
980980

0 commit comments

Comments
 (0)