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

Merge pull request #4854 from Laserlicht/autosave_name

Autosave name
This commit is contained in:
Ivan Savenko 2024-11-06 23:19:35 +02:00 committed by GitHub
commit 22ee5110a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 43 additions and 10 deletions

View File

@ -238,7 +238,7 @@ void CPlayerInterface::performAutosave()
std::string name = cb->getMapHeader()->name.toString();
int txtlen = TextOperations::getUnicodeCharactersCount(name);
TextOperations::trimRightUnicode(name, std::max(0, txtlen - 15));
TextOperations::trimRightUnicode(name, std::max(0, txtlen - 14));
auto const & isSymbolIllegal = [&](char c) {
static const std::string forbiddenChars("\\/:*?\"<>| ");
@ -249,7 +249,7 @@ void CPlayerInterface::performAutosave()
};
std::replace_if(name.begin(), name.end(), isSymbolIllegal, '_' );
prefix = name + "_" + cb->getStartInfo()->startTimeIso8601 + "/";
prefix = vstd::getFormattedDateTime(cb->getStartInfo()->startTime, "%Y-%m-%d_%H-%M") + "_" + name + "/";
}
}

View File

@ -307,7 +307,7 @@ void SelectionTab::clickReleased(const Point & cursorPosition)
{
int line = getLine();
if(line != -1)
if(line != -1 && curItems.size() > line)
{
select(line);
}
@ -501,6 +501,7 @@ void SelectionTab::filter(int size, bool selectFirst)
auto folder = std::make_shared<ElementInfo>();
folder->isFolder = true;
folder->folderName = folderName;
folder->isAutoSaveFolder = boost::starts_with(baseFolder, "Autosave/") && folderName != "Autosave";
auto itemIt = boost::range::find_if(curItems, [folder](std::shared_ptr<ElementInfo> e) { return e->folderName == folder->folderName; });
if (itemIt == curItems.end() && folderName != "") {
curItems.push_back(folder);
@ -561,7 +562,11 @@ void SelectionTab::sort()
int firstMapIndex = boost::range::find_if(curItems, [](std::shared_ptr<ElementInfo> e) { return !e->isFolder; }) - curItems.begin();
if(!sortModeAscending)
{
if(firstMapIndex)
std::reverse(std::next(curItems.begin(), boost::starts_with(curItems[0]->folderName, "..") ? 1 : 0), std::next(curItems.begin(), firstMapIndex - 1));
std::reverse(std::next(curItems.begin(), firstMapIndex), curItems.end());
}
updateListItems();
redraw();
@ -903,7 +908,7 @@ SelectionTab::ListItem::ListItem(Point position)
{
OBJECT_CONSTRUCTION;
pictureEmptyLine = std::make_shared<CPicture>(ImagePath::builtin("camcust"), Rect(25, 121, 349, 26), -8, -14);
labelName = std::make_shared<CLabel>(184, 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, "", 185);
labelName = std::make_shared<CLabel>(LABEL_POS_X, 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, "", 185);
labelName->setAutoRedraw(false);
labelAmountOfPlayers = std::make_shared<CLabel>(8, 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
labelAmountOfPlayers->setAutoRedraw(false);
@ -947,6 +952,16 @@ void SelectionTab::ListItem::updateItem(std::shared_ptr<ElementInfo> info, bool
labelNumberOfCampaignMaps->disable();
labelName->enable();
labelName->setMaxWidth(316);
if(info->isAutoSaveFolder) // align autosave folder left (starting timestamps in list should be in one line)
{
labelName->alignment = ETextAlignment::CENTERLEFT;
labelName->moveTo(Point(pos.x + 80, labelName->pos.y));
}
else
{
labelName->alignment = ETextAlignment::CENTER;
labelName->moveTo(Point(pos.x + LABEL_POS_X, labelName->pos.y));
}
labelName->setText(info->folderName);
labelName->setColor(color);
return;
@ -968,6 +983,8 @@ void SelectionTab::ListItem::updateItem(std::shared_ptr<ElementInfo> info, bool
labelNumberOfCampaignMaps->setText(ostr.str());
labelNumberOfCampaignMaps->setColor(color);
labelName->setMaxWidth(316);
labelName->alignment = ETextAlignment::CENTER;
labelName->moveTo(Point(pos.x + LABEL_POS_X, labelName->pos.y));
}
else
{
@ -989,6 +1006,8 @@ void SelectionTab::ListItem::updateItem(std::shared_ptr<ElementInfo> info, bool
iconLossCondition->enable();
iconLossCondition->setFrame(info->mapHeader->defeatIconIndex, 0);
labelName->setMaxWidth(185);
labelName->alignment = ETextAlignment::CENTER;
labelName->moveTo(Point(pos.x + LABEL_POS_X, labelName->pos.y));
}
labelName->setText(info->name);
labelName->setColor(color);

View File

@ -35,6 +35,7 @@ public:
std::string folderName = "";
std::string name = "";
bool isFolder = false;
bool isAutoSaveFolder = false;
};
/// Class which handles map sorting by different criteria
@ -60,6 +61,8 @@ class SelectionTab : public CIntObject
std::shared_ptr<CPicture> pictureEmptyLine;
std::shared_ptr<CLabel> labelName;
const int LABEL_POS_X = 184;
ListItem(Point position);
void updateItem(std::shared_ptr<ElementInfo> info = {}, bool selected = false);
};

View File

@ -146,7 +146,7 @@ struct DLL_LINKAGE StartInfo : public Serializeable
using TPlayerInfos = std::map<PlayerColor, PlayerSettings>;
TPlayerInfos playerInfos; //color indexed
std::string startTimeIso8601;
time_t startTime;
std::string fileURI;
SimturnsInfo simturnsInfo;
TurnTimerInfo turnTimerInfo;
@ -180,7 +180,17 @@ struct DLL_LINKAGE StartInfo : public Serializeable
h & oldSeeds;
h & oldSeeds;
}
h & startTimeIso8601;
if (h.version < Handler::Version::FOLDER_NAME_REWORK)
{
std::string startTimeLegacy;
h & startTimeLegacy;
struct std::tm tm;
std::istringstream ss(startTimeLegacy);
ss >> std::get_time(&tm, "%Y%m%dT%H%M%S");
startTime = mktime(&tm);
}
else
h & startTime;
h & fileURI;
h & simturnsInfo;
h & turnTimerInfo;
@ -193,7 +203,7 @@ struct DLL_LINKAGE StartInfo : public Serializeable
StartInfo()
: mode(EStartMode::INVALID)
, difficulty(1)
, startTimeIso8601(vstd::getDateTimeISO8601Basic(std::time(nullptr)))
, startTime(std::time(nullptr))
{
}

View File

@ -66,6 +66,7 @@ enum class ESerializationVersion : int32_t
REMOVE_TOWN_PTR, // 867 - removed pointer to CTown from CGTownInstance
REMOVE_OBJECT_TYPENAME, // 868 - remove typename from CGObjectInstance
REMOVE_VLC_POINTERS, // 869 removed remaining pointers to VLC entities
FOLDER_NAME_REWORK, // 870 - rework foldername
CURRENT = REMOVE_VLC_POINTERS
CURRENT = FOLDER_NAME_REWORK
};

View File

@ -245,7 +245,7 @@ bool CVCMIServer::prepareToStartGame()
{
case EStartMode::CAMPAIGN:
logNetwork->info("Preparing to start new campaign");
si->startTimeIso8601 = vstd::getDateTimeISO8601Basic(std::time(nullptr));
si->startTime = std::time(nullptr);
si->fileURI = mi->fileURI;
si->campState->setCurrentMap(campaignMap);
si->campState->setCurrentMapBonus(campaignBonus);
@ -254,7 +254,7 @@ bool CVCMIServer::prepareToStartGame()
case EStartMode::NEW_GAME:
logNetwork->info("Preparing to start new game");
si->startTimeIso8601 = vstd::getDateTimeISO8601Basic(std::time(nullptr));
si->startTime = std::time(nullptr);
si->fileURI = mi->fileURI;
gh->init(si.get(), progressTracking);
break;