mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
suggestions; use internally uppercase; fix; fullname
This commit is contained in:
parent
6ca5518ff1
commit
f0b60cf166
@ -242,6 +242,7 @@ void SelectionTab::toggleMode()
|
||||
case ESelectionScreen::saveGame:
|
||||
parseSaves(getFiles("Saves/", EResType::SAVEGAME));
|
||||
inputName->enable();
|
||||
inputName->activate();
|
||||
restoreLastSelection();
|
||||
break;
|
||||
|
||||
@ -347,7 +348,7 @@ void SelectionTab::showPopupWindow(const Point & cursorPosition)
|
||||
|
||||
if(!curItems[py]->isFolder)
|
||||
{
|
||||
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);
|
||||
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]->fullFileURI);
|
||||
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);
|
||||
|
||||
@ -414,7 +415,7 @@ void SelectionTab::filter(int size, bool selectFirst)
|
||||
{
|
||||
if((elem->mapHeader && (!size || elem->mapHeader->width == size)) || tabType == ESelectionScreen::campaignList)
|
||||
{
|
||||
auto [folderName, baseFolder, parentExists, fileInFolder] = checkSubfolder(elem->fileURI);
|
||||
auto [folderName, baseFolder, parentExists, fileInFolder] = checkSubfolder(elem->originalFileURI);
|
||||
|
||||
if(parentExists)
|
||||
{
|
||||
@ -618,8 +619,16 @@ int SelectionTab::getLine(const Point & clickPos) const
|
||||
|
||||
void SelectionTab::selectFileName(std::string fname)
|
||||
{
|
||||
auto [folderName, baseFolder, parentExists, fileInFolder] = checkSubfolder(fname);
|
||||
curFolder = baseFolder != "" ? baseFolder + "/" : "";
|
||||
boost::to_upper(fname);
|
||||
|
||||
for(int i = (int)allItems.size() - 1; i >= 0; i--)
|
||||
{
|
||||
if(allItems[i]->fileURI == fname)
|
||||
{
|
||||
auto [folderName, baseFolder, parentExists, fileInFolder] = checkSubfolder(allItems[i]->originalFileURI);
|
||||
curFolder = baseFolder != "" ? baseFolder + "/" : "";
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = (int)curItems.size() - 1; i >= 0; i--)
|
||||
{
|
||||
@ -776,12 +785,12 @@ std::unordered_set<ResourceID> SelectionTab::getFiles(std::string dirURI, int re
|
||||
boost::to_upper(dirURI);
|
||||
CResourceHandler::get()->updateFilteredFiles([&](const std::string & mount)
|
||||
{
|
||||
return boost::algorithm::starts_with(boost::algorithm::to_upper_copy(mount), dirURI);
|
||||
return boost::algorithm::starts_with(mount, dirURI);
|
||||
});
|
||||
|
||||
std::unordered_set<ResourceID> ret = CResourceHandler::get()->getFilteredFiles([&](const ResourceID & ident)
|
||||
{
|
||||
return ident.getType() == resType && boost::algorithm::starts_with(boost::algorithm::to_upper_copy(ident.getName()), dirURI);
|
||||
return ident.getType() == resType && boost::algorithm::starts_with(ident.getName(), dirURI);
|
||||
});
|
||||
|
||||
return ret;
|
||||
|
@ -45,7 +45,7 @@ static inline EResType::Type readType(const std::string& name)
|
||||
return EResTypeHelper::getTypeFromExtension(FileInfo::GetExtension(name).to_string());
|
||||
}
|
||||
|
||||
static inline std::string readName(std::string name, EResType::Type type)
|
||||
static inline std::string readName(std::string name, bool uppercase)
|
||||
{
|
||||
const auto dotPos = name.find_last_of('.');
|
||||
|
||||
@ -61,7 +61,7 @@ static inline std::string readName(std::string name, EResType::Type type)
|
||||
name.resize(dotPos);
|
||||
}
|
||||
|
||||
if(type != EResType::MAP && type != EResType::CAMPAIGN && type != EResType::SAVEGAME)
|
||||
if(uppercase)
|
||||
toUpper(name);
|
||||
|
||||
return name;
|
||||
@ -76,12 +76,14 @@ ResourceID::ResourceID()
|
||||
|
||||
ResourceID::ResourceID(std::string name_):
|
||||
type{readType(name_)},
|
||||
name{readName(std::move(name_), readType(name_))}
|
||||
name{readName(name_, true)},
|
||||
originalName{readName(std::move(name_), false)}
|
||||
{}
|
||||
|
||||
ResourceID::ResourceID(std::string name_, EResType::Type type_):
|
||||
type{type_},
|
||||
name{readName(std::move(name_), type_)}
|
||||
name{readName(name_, true)},
|
||||
originalName{readName(std::move(name_), false)}
|
||||
{}
|
||||
#if 0
|
||||
std::string ResourceID::getName() const
|
||||
|
@ -99,6 +99,7 @@ public:
|
||||
}
|
||||
|
||||
std::string getName() const {return name;}
|
||||
std::string getOriginalName() const {return originalName;}
|
||||
EResType::Type getType() const {return type;}
|
||||
//void setName(std::string name);
|
||||
//void setType(EResType::Type type);
|
||||
@ -112,6 +113,9 @@ private:
|
||||
|
||||
/** Specifies the resource name. No extension so .pcx and .png can override each other, always in upper case. **/
|
||||
std::string name;
|
||||
|
||||
/** name in original case **/
|
||||
std::string originalName;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -43,7 +43,10 @@ void CMapInfo::mapInit(const std::string & fname)
|
||||
{
|
||||
fileURI = fname;
|
||||
CMapService mapService;
|
||||
mapHeader = mapService.loadMapHeader(ResourceID(fname, EResType::MAP));
|
||||
ResourceID resource = ResourceID(fname, EResType::MAP);
|
||||
originalFileURI = resource.getOriginalName();
|
||||
fullFileURI = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(resource)).string();
|
||||
mapHeader = mapService.loadMapHeader(resource);
|
||||
countPlayers();
|
||||
}
|
||||
|
||||
@ -55,9 +58,17 @@ void CMapInfo::saveInit(const ResourceID & file)
|
||||
mapHeader = std::make_unique<CMapHeader>();
|
||||
lf >> *(mapHeader) >> scenarioOptionsOfSave;
|
||||
fileURI = file.getName();
|
||||
originalFileURI = file.getOriginalName();
|
||||
fullFileURI = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(file)).string();
|
||||
countPlayers();
|
||||
std::time_t time = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(file));
|
||||
date = std::asctime(std::localtime(&time));
|
||||
|
||||
std::tm tm = *std::localtime(&time);
|
||||
std::stringstream s;
|
||||
s.imbue(std::locale(""));
|
||||
s << std::put_time(&tm, "%x %X");
|
||||
date = s.str();
|
||||
|
||||
// We absolutely not need this data for lobby and server will read it from save
|
||||
// FIXME: actually we don't want them in CMapHeader!
|
||||
mapHeader->triggeredEvents.clear();
|
||||
@ -65,6 +76,9 @@ void CMapInfo::saveInit(const ResourceID & file)
|
||||
|
||||
void CMapInfo::campaignInit()
|
||||
{
|
||||
ResourceID resource = ResourceID(fileURI, EResType::CAMPAIGN);
|
||||
originalFileURI = resource.getOriginalName();
|
||||
fullFileURI = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(resource)).string();
|
||||
campaign = CampaignHandler::getHeader(fileURI);
|
||||
}
|
||||
|
||||
@ -105,7 +119,7 @@ std::string CMapInfo::getNameForList() const
|
||||
{
|
||||
// TODO: this could be handled differently
|
||||
std::vector<std::string> path;
|
||||
boost::split(path, fileURI, boost::is_any_of("\\/"));
|
||||
boost::split(path, originalFileURI, boost::is_any_of("\\/"));
|
||||
return path[path.size()-1];
|
||||
}
|
||||
else
|
||||
|
@ -28,6 +28,8 @@ public:
|
||||
std::unique_ptr<Campaign> campaign; //may be nullptr if scenario
|
||||
StartInfo * scenarioOptionsOfSave; // Options with which scenario has been started (used only with saved games)
|
||||
std::string fileURI;
|
||||
std::string originalFileURI;
|
||||
std::string fullFileURI;
|
||||
std::string date;
|
||||
int amountOfPlayersOnMap;
|
||||
int amountOfHumanControllablePlayers;
|
||||
|
Loading…
Reference in New Issue
Block a user