From 8b262e49a6310c9a32c830c8c4dcdbbdadfd44af Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 7 Jan 2024 20:17:44 +0100 Subject: [PATCH] add sort for changedate --- .../vcmi/Sprites/lobby/selectionTabSortDate.json | 7 +++++++ Mods/vcmi/Sprites/lobby/selectionTabSortDate.png | Bin 0 -> 1472 bytes Mods/vcmi/config/vcmi/english.json | 1 + Mods/vcmi/config/vcmi/german.json | 1 + client/lobby/SelectionTab.cpp | 14 ++++++++++++-- client/lobby/SelectionTab.h | 2 +- lib/mapping/CMapInfo.cpp | 4 ++-- lib/mapping/CMapInfo.h | 5 +++-- 8 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 Mods/vcmi/Sprites/lobby/selectionTabSortDate.json create mode 100644 Mods/vcmi/Sprites/lobby/selectionTabSortDate.png diff --git a/Mods/vcmi/Sprites/lobby/selectionTabSortDate.json b/Mods/vcmi/Sprites/lobby/selectionTabSortDate.json new file mode 100644 index 000000000..9022e4244 --- /dev/null +++ b/Mods/vcmi/Sprites/lobby/selectionTabSortDate.json @@ -0,0 +1,7 @@ +{ + "basepath" : "lobby/", + "images" : + [ + { "frame" : 0, "file" : "selectionTabSortDate.png"} + ] +} diff --git a/Mods/vcmi/Sprites/lobby/selectionTabSortDate.png b/Mods/vcmi/Sprites/lobby/selectionTabSortDate.png new file mode 100644 index 0000000000000000000000000000000000000000..4e58b28386f213c5dd564496f54136f1b0e4de10 GIT binary patch literal 1472 zcmV;x1wZQJ4D0004mX+uL$Nkc;* zaB^>EX>4Tx04R}tkv&MmP!xqvQ>7vm5j%)D1guULL`5963Pq?8YK2xEOkVm2O&XFE z7e~Rh;NZ_<)xpJCR|i)?5c~mgc5qU3krMAq3N2#1@OU5R-E(;FK0v6KnPzp21DbA| zsYG1NWLL$|D*_0i55ow^%rfRADGA^Dx~FccyBN>%@B6cQ)SShDfJi*c4AUmwAfDc| z4bJ<-5muB{;&b9LlP*a7$aTfzH_io@1)do()2Vsl2(egbW2KE*(bR~ih@+~eQ@)V# zSmnIMSu0mr^Pc>L;hes*%yn8rNMI35kRU=q6(y8mBSyPUiiH%N$9?>Ru3sXTLaq`R zITlcX2HEw4|H1FsTKUNdFDV=cI$s>;V+0880*#vEd>=bb;{*sk16O*>U#SB#pQP7X zTJ#9$-3BhMTbi;5Tk8{ps& z7%foty3f12+UNFfPjh}h48U@JJ{`=i00006VoOIv0PFzl0PGzj7B&C?010qNS#tmY zE+YT{E+YYWr9XB600YoTL_t(Y$E}vnt5jti#y{`-p7;Ekxp%r_sVIt>1cinaML!_) zQsAad3n2m_s71Tz4{+tGT~WC452%H^h!%kh-2@6@gd&nrSl6_fJ2Q9Yob&!{F*tqY{+5b7x* zbI82F8c(hRRq$j%BXfbZ4&@8TG}2Z8$a|oCX_+vyq&biYkP#U@sSs3y4KkS`LkFxv zMvHe9&2WIXv_Z9ZiBpv$V8*MJHdOTkTmrWK|!QOl{s2& zBkN}b>+#Z%epYKU^EqoIS;~a;?Fe zR*nm2PjThOc;UIhoi@l${=9#nc3iwNcxZw{j1T$gO0Nx4y2CU3mT7GG*RMvVCC$Z2 z8zj?hym|a1?8dJE=^Ey!)$#BJOp2J?V+TlxTIFy2(Za>QV$hV%I- zceBu)J#6WhyA4TaQ)^}{kV#4J$yeu5AJD*-zD!EA3T;r{>&-9kk4y87&h9O>Dz=xvLGT>mjg|tP!R{CM%eFLa1xJ@kH+s zB09MZ|eQk_wt;N^}+Za!y@USS&&~?DY2CBw0TKkNhMDUwg*_`jLMkR##W~ aKi1z4xft|yCYLGz0000 aaa, const std::sh return boost::ilexicographical_compare(a->name.toString(), b->name.toString()); case _fileName: //by filename return boost::ilexicographical_compare(aaa->fileURI, bbb->fileURI); + case _changeDate: //by changedate + return aaa->lastWrite < bbb->lastWrite; default: return boost::ilexicographical_compare(a->name.toString(), b->name.toString()); } @@ -149,9 +151,11 @@ SelectionTab::SelectionTab(ESelectionScreen Type) : CIntObject(LCLICK | SHOW_POPUP | KEYBOARD | DOUBLECLICK), callOnSelect(nullptr), tabType(Type), selectionPos(0), sortModeAscending(true), inputNameRect{32, 539, 350, 20}, curFolder(""), currentMapSizeFilter(0), showRandom(false) { OBJ_CONSTRUCTION; - + generalSortingBy = getSortBySelectionScreen(tabType); + bool enableUiEnhancements = settings["general"]["enableUiEnhancements"].Bool(); + if(tabType != ESelectionScreen::campaignList) { sortingBy = _format; @@ -208,6 +212,12 @@ SelectionTab::SelectionTab(ESelectionScreen Type) break; } + if(enableUiEnhancements) + { + buttonsSortBy.push_back(std::make_shared(Point(371, 85), AnimationPath::builtin("lobby/selectionTabSortDate"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.sortDate")), std::bind(&SelectionTab::sortBy, this, ESortBy::_changeDate))); + buttonsSortBy.back()->setAnimateLonelyFrame(true); + } + iconsMapFormats = GH.renderHandler().loadAnimation(AnimationPath::builtin("SCSELC.DEF")); iconsVictoryCondition = GH.renderHandler().loadAnimation(AnimationPath::builtin("SCNRVICT.DEF")); iconsLossCondition = GH.renderHandler().loadAnimation(AnimationPath::builtin("SCNRLOSS.DEF")); @@ -215,7 +225,7 @@ SelectionTab::SelectionTab(ESelectionScreen Type) listItems.push_back(std::make_shared(Point(30, 129 + i * 25), iconsMapFormats, iconsVictoryCondition, iconsLossCondition)); labelTabTitle = std::make_shared(205, 28, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, tabTitle); - slider = std::make_shared(Point(372, 86), tabType != ESelectionScreen::saveGame ? 480 : 430, std::bind(&SelectionTab::sliderMove, this, _1), positionsToShow, (int)curItems.size(), 0, Orientation::VERTICAL, CSlider::BLUE); + slider = std::make_shared(Point(372, 86 + (enableUiEnhancements ? 30 : 0)), (tabType != ESelectionScreen::saveGame ? 480 : 430) - (enableUiEnhancements ? 30 : 0), std::bind(&SelectionTab::sliderMove, this, _1), positionsToShow, (int)curItems.size(), 0, Orientation::VERTICAL, CSlider::BLUE); slider->setPanningStep(24); // create scroll bounds that encompass all area in this UI element to the left of slider (including area of slider itself) diff --git a/client/lobby/SelectionTab.h b/client/lobby/SelectionTab.h index b457bcef8..529c2487f 100644 --- a/client/lobby/SelectionTab.h +++ b/client/lobby/SelectionTab.h @@ -23,7 +23,7 @@ class IImage; enum ESortBy { - _playerAm, _size, _format, _name, _viccon, _loscon, _numOfMaps, _fileName + _playerAm, _size, _format, _name, _viccon, _loscon, _numOfMaps, _fileName, _changeDate }; //_numOfMaps is for campaigns class ElementInfo : public CMapInfo diff --git a/lib/mapping/CMapInfo.cpp b/lib/mapping/CMapInfo.cpp index 0c6e03cff..39a0ee831 100644 --- a/lib/mapping/CMapInfo.cpp +++ b/lib/mapping/CMapInfo.cpp @@ -64,8 +64,8 @@ void CMapInfo::saveInit(const ResourcePath & file) 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 = TextOperations::getFormattedDateTimeLocal(time); + lastWrite = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(file)); + date = TextOperations::getFormattedDateTimeLocal(lastWrite); // We absolutely not need this data for lobby and server will read it from save // FIXME: actually we don't want them in CMapHeader! diff --git a/lib/mapping/CMapInfo.h b/lib/mapping/CMapInfo.h index 512cff481..b086a38af 100644 --- a/lib/mapping/CMapInfo.h +++ b/lib/mapping/CMapInfo.h @@ -28,8 +28,9 @@ public: std::unique_ptr 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 originalFileURI; // no need to serialize + std::string fullFileURI; // no need to serialize + std::time_t lastWrite; // no need to serialize std::string date; int amountOfPlayersOnMap; int amountOfHumanControllablePlayers;