2026-04-12 17:31:32 +03:00
|
|
|
#include "FileSelectScreen.hpp"
|
2026-04-17 19:32:49 +03:00
|
|
|
#include "../MainProgram.hpp"
|
|
|
|
|
#include "../GUIHolder.hpp"
|
|
|
|
|
#include "../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
2026-04-21 18:38:24 +03:00
|
|
|
#include "../GUIStuff/ElementHelpers/ButtonHelpers.hpp"
|
2026-04-18 20:51:45 +03:00
|
|
|
#include "Helpers/ConvertVec.hpp"
|
|
|
|
|
#include "../GUIStuff/Elements/GridScrollArea.hpp"
|
2026-04-19 17:44:48 +03:00
|
|
|
#include "../GUIStuff/Elements/ImageDisplay.hpp"
|
|
|
|
|
#include "../World.hpp"
|
2026-04-20 18:56:39 +03:00
|
|
|
#include "Helpers/StringHelpers.hpp"
|
2026-04-20 20:16:15 +03:00
|
|
|
#include <SDL3/SDL_timer.h>
|
2026-04-17 19:32:49 +03:00
|
|
|
|
|
|
|
|
FileSelectScreen::FileSelectScreen(MainProgram& m): Screen(m) {}
|
|
|
|
|
|
|
|
|
|
void FileSelectScreen::gui_layout_run() {
|
|
|
|
|
using namespace GUIStuff;
|
|
|
|
|
using namespace ElementHelpers;
|
2026-04-18 20:51:45 +03:00
|
|
|
auto& gui = main.g.gui;
|
|
|
|
|
|
2026-04-17 19:32:49 +03:00
|
|
|
CLAY_AUTO_ID({
|
2026-04-18 20:51:45 +03:00
|
|
|
.layout = {
|
2026-04-21 18:38:24 +03:00
|
|
|
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
|
|
|
|
|
.padding = CLAY_PADDING_ALL(gui.io.theme->padding1),
|
|
|
|
|
.childGap = gui.io.theme->childGap1,
|
2026-04-18 20:51:45 +03:00
|
|
|
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP },
|
|
|
|
|
.layoutDirection = CLAY_TOP_TO_BOTTOM,
|
|
|
|
|
},
|
2026-04-17 19:32:49 +03:00
|
|
|
}) {
|
2026-04-21 18:38:24 +03:00
|
|
|
CLAY_AUTO_ID({
|
|
|
|
|
.layout = {
|
|
|
|
|
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(40)},
|
|
|
|
|
.padding = CLAY_PADDING_ALL(gui.io.theme->padding1),
|
|
|
|
|
.childGap = gui.io.theme->childGap1,
|
|
|
|
|
.childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER },
|
|
|
|
|
.layoutDirection = CLAY_LEFT_TO_RIGHT,
|
|
|
|
|
}
|
|
|
|
|
}) {
|
|
|
|
|
svg_icon_button(gui, "main settings button", "data/icons/menu.svg", {
|
|
|
|
|
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL
|
|
|
|
|
});
|
|
|
|
|
text_label(gui, "File selector");
|
|
|
|
|
}
|
2026-04-19 17:44:48 +03:00
|
|
|
auto& fileList = get_file_list();
|
|
|
|
|
gui.element<GridScrollArea>("File selector grid", GridScrollArea::Options{
|
2026-04-21 18:38:24 +03:00
|
|
|
.entryWidth = 200.0f,
|
2026-04-18 20:51:45 +03:00
|
|
|
.childAlignmentX = CLAY_ALIGN_X_LEFT,
|
2026-04-20 18:56:39 +03:00
|
|
|
.entryHeight = 220.0f,
|
2026-04-19 17:44:48 +03:00
|
|
|
.entryCount = fileList.size(),
|
2026-04-18 20:51:45 +03:00
|
|
|
.elementContent = [&](size_t i) {
|
|
|
|
|
CLAY_AUTO_ID({
|
|
|
|
|
.layout = {
|
2026-04-20 18:56:39 +03:00
|
|
|
.sizing = { .width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
|
2026-04-19 17:44:48 +03:00
|
|
|
.padding = CLAY_PADDING_ALL(gui.io.theme->padding1),
|
2026-04-20 18:56:39 +03:00
|
|
|
.childGap = 6,
|
2026-04-18 20:51:45 +03:00
|
|
|
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER },
|
2026-04-19 17:44:48 +03:00
|
|
|
.layoutDirection = CLAY_TOP_TO_BOTTOM
|
2026-04-18 20:51:45 +03:00
|
|
|
}
|
|
|
|
|
}) {
|
2026-04-19 17:44:48 +03:00
|
|
|
CLAY_AUTO_ID({
|
2026-04-21 18:52:11 +03:00
|
|
|
.layout = { .sizing = {.width = CLAY_SIZING_FIXED(150), .height = CLAY_SIZING_FIXED(150) }},
|
2026-04-19 17:44:48 +03:00
|
|
|
}) {
|
2026-04-20 18:56:39 +03:00
|
|
|
gui.element<ImageDisplay>("ico", ImageDisplay::Data{
|
|
|
|
|
.imgPath = main.conf.configPath / "saveThumbnails" / (fileList[i].fileName + ".jpg"),
|
|
|
|
|
.radius = 20
|
|
|
|
|
});
|
2026-04-19 17:44:48 +03:00
|
|
|
}
|
2026-04-20 18:56:39 +03:00
|
|
|
text_label(gui, fileList[i].fileName);
|
2026-04-20 20:16:15 +03:00
|
|
|
text_label_light(gui, fileList[i].lastModifyDate);
|
2026-04-18 20:51:45 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-04-17 19:32:49 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-20 18:56:39 +03:00
|
|
|
const std::vector<FileSelectScreen::FileInfo>& FileSelectScreen::get_file_list() {
|
2026-04-19 17:44:48 +03:00
|
|
|
if(!fileListOptional.has_value()) {
|
|
|
|
|
std::filesystem::path savePath = main.conf.configPath / "saves";
|
2026-04-20 18:56:39 +03:00
|
|
|
fileListOptional = std::vector<FileInfo>();
|
2026-04-19 17:44:48 +03:00
|
|
|
auto& fL = fileListOptional.value();
|
|
|
|
|
int globCount;
|
|
|
|
|
char** filesInPath = SDL_GlobDirectory(savePath.string().c_str(), "*", 0, &globCount);
|
|
|
|
|
if(filesInPath) {
|
|
|
|
|
for(int i = 0; i < globCount; i++) {
|
|
|
|
|
std::filesystem::path p = filesInPath[i];
|
|
|
|
|
std::string fExt = p.extension().string();
|
2026-04-20 18:56:39 +03:00
|
|
|
if(fExt == "." + World::FILE_EXTENSION) {
|
2026-04-20 20:16:15 +03:00
|
|
|
std::filesystem::path fullPath = savePath / filesInPath[i];
|
|
|
|
|
FileInfo fileInfoToAdd;
|
|
|
|
|
fileInfoToAdd.fileName = p.stem().string();
|
|
|
|
|
|
2026-04-20 18:56:39 +03:00
|
|
|
SDL_PathInfo pathInfo;
|
2026-04-20 20:16:15 +03:00
|
|
|
if(SDL_GetPathInfo(fullPath.string().c_str(), &pathInfo)) {
|
|
|
|
|
SDL_DateTime pathDt;
|
|
|
|
|
fileInfoToAdd.lastModifyTime = pathInfo.modify_time;
|
|
|
|
|
if(SDL_TimeToDateTime(pathInfo.modify_time, &pathDt, true)) {
|
|
|
|
|
fileInfoToAdd.lastModifyDate = sdl_time_to_nice_access_time(pathDt, main.conf.dateFormat, main.conf.timeFormat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fL.emplace_back(fileInfoToAdd);
|
2026-04-20 18:56:39 +03:00
|
|
|
}
|
2026-04-19 17:44:48 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fileListOptional.value();
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-17 19:32:49 +03:00
|
|
|
void FileSelectScreen::draw(SkCanvas* canvas) {
|
2026-04-19 17:44:48 +03:00
|
|
|
canvas->clear(main.g.gui.io.theme->backColor1);
|
2026-04-17 19:32:49 +03:00
|
|
|
}
|