1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Folder Icon, Save, Folder on top...

This commit is contained in:
Michael 2023-08-08 23:46:30 +02:00 committed by GitHub
parent 855b94b316
commit bbe04c747d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 48 deletions

View File

@ -2,6 +2,7 @@
"basepath" : "mapFormatIcons/", "basepath" : "mapFormatIcons/",
"images" : "images" :
[ [
{ "frame" : 3, "file" : "vcmi1.png"} { "frame" : 3, "file" : "vcmi1.png"},
{ "frame" : 99, "file" : "folder.png"}
] ]
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -70,7 +70,7 @@ void CSavingScreen::saveGame()
if(!(tabSel && tabSel->inputName && tabSel->inputName->getText().size())) if(!(tabSel && tabSel->inputName && tabSel->inputName->getText().size()))
return; return;
std::string path = "Saves/" + tabSel->inputName->getText(); std::string path = "Saves/" + tabSel->curFolder + tabSel->inputName->getText();
auto overWrite = [this, path]() -> void auto overWrite = [this, path]() -> void
{ {

View File

@ -345,14 +345,17 @@ void SelectionTab::showPopupWindow(const Point & cursorPosition)
if(py >= curItems.size()) if(py >= curItems.size())
return; return;
std::string text = boost::str(boost::format("{%1%}\r\n\r\n%2%:\r\n%3%") % curItems[py]->getName() % CGI->generaltexth->translate("vcmi.lobby.filename") % curItems[py]->fileURI); if(!curItems[py]->isFolder)
if(curItems[py]->date != "") {
text += boost::str(boost::format("\r\n\r\n%1%:\r\n%2%") % CGI->generaltexth->translate("vcmi.lobby.creationDate") % curItems[py]->date); std::string text = boost::str(boost::format("{%1%}\r\n\r\n%2%:\r\n%3%") % curItems[py]->getName() % CGI->generaltexth->translate("vcmi.lobby.filename") % curItems[py]->fileURI);
if(curItems[py]->date != "")
text += boost::str(boost::format("\r\n\r\n%1%:\r\n%2%") % CGI->generaltexth->translate("vcmi.lobby.creationDate") % curItems[py]->date);
CRClickPopup::createAndPush(text); CRClickPopup::createAndPush(text);
}
} }
std::tuple<std::string, bool, bool> SelectionTab::checkSubfolder(std::string path) std::tuple<std::string, std::string, bool, bool> SelectionTab::checkSubfolder(std::string path)
{ {
std::string folderName = ""; std::string folderName = "";
bool parentExists = (curFolder != ""); bool parentExists = (curFolder != "");
@ -364,13 +367,11 @@ std::tuple<std::string, bool, bool> SelectionTab::checkSubfolder(std::string pat
filetree.erase(filetree.begin()); filetree.erase(filetree.begin());
std::string pathWithoutPrefix = boost::algorithm::join(filetree, "/"); std::string pathWithoutPrefix = boost::algorithm::join(filetree, "/");
std::string folder = boost::filesystem::path(pathWithoutPrefix).parent_path().string(); std::string baseFolder = boost::filesystem::path(pathWithoutPrefix).parent_path().string();
if(boost::algorithm::starts_with(folder, curFolder)) if(boost::algorithm::starts_with(baseFolder, curFolder))
{ {
folder = folder.substr(curFolder.size()); std::string folder = baseFolder.substr(curFolder.size());
if(boost::algorithm::starts_with(folder, "/"))
folder = folder.substr(1);
if(folder != "") if(folder != "")
{ {
@ -383,50 +384,40 @@ std::tuple<std::string, bool, bool> SelectionTab::checkSubfolder(std::string pat
if(boost::count(pathWithoutPrefix.substr(curFolder.size()), '/') == 0) if(boost::count(pathWithoutPrefix.substr(curFolder.size()), '/') == 0)
fileInFolder = true; fileInFolder = true;
return {folderName, parentExists, fileInFolder}; return {folderName, baseFolder, parentExists, fileInFolder};
} }
// A new size filter (Small, Medium, ...) has been selected. Populate // A new size filter (Small, Medium, ...) has been selected. Populate
// selMaps with the relevant data. // selMaps with the relevant data.
void SelectionTab::filter(int size, bool selectFirst) void SelectionTab::filter(int size, bool selectFirst)
{ {
std::string path = "";
curItems.clear(); curItems.clear();
if(tabType == ESelectionScreen::campaignList) for(auto elem : allItems)
{ {
for(auto elem : allItems) if((elem->mapHeader && (!size || elem->mapHeader->width == size)) || tabType == ESelectionScreen::campaignList)
curItems.push_back(elem);
}
else
{
for(auto elem : allItems)
{ {
if(elem->mapHeader && (!size || elem->mapHeader->width == size)) auto [folderName, baseFolder, parentExists, fileInFolder] = checkSubfolder(elem->fileURI);
if(parentExists)
{ {
auto [folderName, parentExists, fileInFolder] = checkSubfolder(elem->fileURI); auto folder = std::make_shared<ElementInfo>();
if(parentExists)
{
auto folder = std::make_shared<ElementInfo>();
folder->isFolder = true;
folder->folderName = "..";
if (boost::range::find_if(curItems, [](std::shared_ptr<ElementInfo> e) { return e->folderName == ".."; }) == curItems.end()) {
curItems.push_back(folder);
}
}
std::shared_ptr<ElementInfo> folder = std::make_shared<ElementInfo>();
folder->isFolder = true; folder->isFolder = true;
folder->folderName = folderName; folder->folderName = "..";
if (boost::range::find_if(curItems, [folder](std::shared_ptr<ElementInfo> e) { return e->folderName == folder->folderName; }) == curItems.end() && folderName != "") { if (boost::range::find_if(curItems, [](std::shared_ptr<ElementInfo> e) { return e->folderName == ".."; }) == curItems.end()) {
curItems.push_back(folder); curItems.push_back(folder);
} }
if(fileInFolder)
curItems.push_back(elem);
} }
std::shared_ptr<ElementInfo> folder = std::make_shared<ElementInfo>();
folder->isFolder = true;
folder->folderName = folderName;
if (boost::range::find_if(curItems, [folder](std::shared_ptr<ElementInfo> e) { return e->folderName == folder->folderName; }) == curItems.end() && folderName != "") {
curItems.push_back(folder);
}
if(fileInFolder)
curItems.push_back(elem);
} }
} }
@ -472,8 +463,9 @@ void SelectionTab::sort()
std::stable_sort(curItems.begin(), curItems.end(), mapSorter(generalSortingBy)); std::stable_sort(curItems.begin(), curItems.end(), mapSorter(generalSortingBy));
std::stable_sort(curItems.begin(), curItems.end(), mapSorter(sortingBy)); std::stable_sort(curItems.begin(), curItems.end(), mapSorter(sortingBy));
int firstMap = boost::range::find_if(curItems, [](std::shared_ptr<ElementInfo> e) { return !e->isFolder; }) - curItems.begin();
if(!sortModeAscending) if(!sortModeAscending)
std::reverse(curItems.begin(), curItems.end()); std::reverse(std::next(curItems.begin(), firstMap), curItems.end());
updateListItems(); updateListItems();
redraw(); redraw();
@ -496,8 +488,6 @@ void SelectionTab::select(int position)
else if(position >= listItems.size()) else if(position >= listItems.size())
slider->scrollBy(position - (int)listItems.size() + 1); slider->scrollBy(position - (int)listItems.size() + 1);
rememberCurrentSelection();
if(curItems[py]->isFolder) { if(curItems[py]->isFolder) {
if(curItems[py]->folderName == "..") if(curItems[py]->folderName == "..")
{ {
@ -510,9 +500,13 @@ void SelectionTab::select(int position)
else else
curFolder += curItems[py]->folderName + "/"; curFolder += curItems[py]->folderName + "/";
filter(0); filter(0);
slider->scrollTo(0);
return; return;
} }
rememberCurrentSelection();
if(inputName && inputName->isActive()) if(inputName && inputName->isActive())
{ {
auto filename = *CResourceHandler::get("local")->getResourceName(ResourceID(curItems[py]->fileURI, EResType::SAVEGAME)); auto filename = *CResourceHandler::get("local")->getResourceName(ResourceID(curItems[py]->fileURI, EResType::SAVEGAME));
@ -594,6 +588,10 @@ int SelectionTab::getLine(const Point & clickPos) const
void SelectionTab::selectFileName(std::string fname) void SelectionTab::selectFileName(std::string fname)
{ {
boost::to_upper(fname); boost::to_upper(fname);
auto [folderName, baseFolder, parentExists, fileInFolder] = checkSubfolder(fname);
curFolder = baseFolder != "" ? baseFolder + "/" : "";
for(int i = (int)curItems.size() - 1; i >= 0; i--) for(int i = (int)curItems.size() - 1; i >= 0; i--)
{ {
if(curItems[i]->fileURI == fname) if(curItems[i]->fileURI == fname)
@ -604,12 +602,13 @@ void SelectionTab::selectFileName(std::string fname)
} }
} }
filter(0);
selectAbs(-1); selectAbs(-1);
} }
std::shared_ptr<ElementInfo> SelectionTab::getSelectedMapInfo() const std::shared_ptr<ElementInfo> SelectionTab::getSelectedMapInfo() const
{ {
return curItems.empty() ? nullptr : curItems[selectionPos]; return curItems.empty() || curItems[selectionPos]->isFolder ? nullptr : curItems[selectionPos];
} }
void SelectionTab::rememberCurrentSelection() void SelectionTab::rememberCurrentSelection()
@ -799,7 +798,8 @@ void SelectionTab::ListItem::updateItem(std::shared_ptr<ElementInfo> info, bool
{ {
labelAmountOfPlayers->disable(); labelAmountOfPlayers->disable();
labelMapSizeLetter->disable(); labelMapSizeLetter->disable();
iconFormat->disable(); iconFormat->enable();
iconFormat->setFrame(99);
iconVictoryCondition->disable(); iconVictoryCondition->disable();
iconLossCondition->disable(); iconLossCondition->disable();
labelNumberOfCampaignMaps->disable(); labelNumberOfCampaignMaps->disable();

View File

@ -106,7 +106,7 @@ private:
ESelectionScreen tabType; ESelectionScreen tabType;
Rect inputNameRect; Rect inputNameRect;
std::tuple<std::string, bool, bool> checkSubfolder(std::string path); std::tuple<std::string, std::string, bool, bool> checkSubfolder(std::string path);
bool isMapSupported(const CMapInfo & info); bool isMapSupported(const CMapInfo & info);
void parseMaps(const std::unordered_set<ResourceID> & files); void parseMaps(const std::unordered_set<ResourceID> & files);