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-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-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 = {
|
|
|
|
|
.sizing = {.width = CLAY_SIZING_FIXED(gui.io.windowSize.x()), .height = CLAY_SIZING_FIXED(gui.io.windowSize.y())},
|
2026-04-19 17:44:48 +03:00
|
|
|
.padding = CLAY_PADDING_ALL(15),
|
2026-04-18 20:51:45 +03:00
|
|
|
.childGap = 15,
|
|
|
|
|
.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-19 17:44:48 +03:00
|
|
|
text_label(gui, "File selector");
|
|
|
|
|
auto& fileList = get_file_list();
|
|
|
|
|
gui.element<GridScrollArea>("File selector grid", GridScrollArea::Options{
|
|
|
|
|
.entryMaximumWidth = 200.0f,
|
2026-04-18 20:51:45 +03:00
|
|
|
.childAlignmentX = CLAY_ALIGN_X_LEFT,
|
2026-04-19 17:44:48 +03:00
|
|
|
.entryHeight = 250.0f,
|
|
|
|
|
.entryCount = fileList.size(),
|
2026-04-18 20:51:45 +03:00
|
|
|
.elementContent = [&](size_t i) {
|
|
|
|
|
CLAY_AUTO_ID({
|
|
|
|
|
.layout = {
|
2026-04-19 17:44:48 +03:00
|
|
|
.sizing = { .width = CLAY_SIZING_FIXED(150), .height = CLAY_SIZING_GROW(0)},
|
|
|
|
|
.padding = CLAY_PADDING_ALL(gui.io.theme->padding1),
|
|
|
|
|
.childGap = 2,
|
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({
|
|
|
|
|
.layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) }},
|
|
|
|
|
.aspectRatio = { .aspectRatio = 1.0f }
|
|
|
|
|
}) {
|
|
|
|
|
gui.element<ImageDisplay>("ico", main.conf.configPath / "saveThumbnails" / (fileList[i] + ".jpg"));
|
|
|
|
|
}
|
|
|
|
|
text_label(gui, fileList[i]);
|
2026-04-18 20:51:45 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-04-17 19:32:49 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 17:44:48 +03:00
|
|
|
const std::vector<std::string>& FileSelectScreen::get_file_list() {
|
|
|
|
|
if(!fileListOptional.has_value()) {
|
|
|
|
|
std::filesystem::path savePath = main.conf.configPath / "saves";
|
|
|
|
|
fileListOptional = std::vector<std::string>();
|
|
|
|
|
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();
|
|
|
|
|
if(fExt == "." + World::FILE_EXTENSION)
|
|
|
|
|
fL.emplace_back(p.stem().string());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|