1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge pull request #3991 from Laserlicht/preselect_last_save_while_loading

[1.5.2] preselect last save in loading screen
This commit is contained in:
Ivan Savenko 2024-05-19 15:42:59 +03:00 committed by GitHub
commit 9ed749e104
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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();