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

preselect last save in loading screen

This commit is contained in:
Laserlicht 2024-05-16 13:16:14 +02:00
parent e00046dd70
commit 359503f878
2 changed files with 19 additions and 3 deletions

View File

@ -677,6 +677,9 @@ void SelectionTab::selectFileName(std::string fname)
}
}
filter(-1);
selectAbs(-1);
for(int i = (int)curItems.size() - 1; i >= 0; i--)
{
if(curItems[i]->fileURI == fname)
@ -687,13 +690,23 @@ void SelectionTab::selectFileName(std::string fname)
}
}
filter(-1);
selectAbs(-1);
if(tabType == ESelectionScreen::saveGame && inputName->getText().empty())
inputName->setText("NEWGAME");
}
void SelectionTab::selectNewestFile()
{
time_t newestTime = 0;
std::string newestFile = "";
for(int i = (int)allItems.size() - 1; i >= 0; i--)
if(allItems[i]->lastWrite > newestTime)
{
newestTime = allItems[i]->lastWrite;
newestFile = allItems[i]->fileURI;
}
selectFileName(newestFile);
}
std::shared_ptr<ElementInfo> SelectionTab::getSelectedMapInfo() const
{
return curItems.empty() || curItems[selectionPos]->isFolder ? nullptr : curItems[selectionPos];
@ -733,6 +746,8 @@ void SelectionTab::restoreLastSelection()
selectFileName(settings["general"]["lastCampaign"].String());
break;
case ESelectionScreen::loadGame:
selectNewestFile();
break;
case ESelectionScreen::saveGame:
selectFileName(settings["general"]["lastSave"].String());
}

View File

@ -101,6 +101,7 @@ public:
int getLine() const;
int getLine(const Point & position) const;
void selectFileName(std::string fname);
void selectNewestFile();
std::shared_ptr<ElementInfo> getSelectedMapInfo() const;
void rememberCurrentSelection();
void restoreLastSelection();