/* * SelectionTab.h, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * */ #pragma once #include "CSelectionBase.h" VCMI_LIB_NAMESPACE_BEGIN class CMap; VCMI_LIB_NAMESPACE_END #include "../../lib/mapping/CMapInfo.h" #include "../../lib/filesystem/ResourcePath.h" class CSlider; class CLabel; class CPicture; class IImage; class CAnimation; enum ESortBy { _playerAm, _size, _format, _name, _viccon, _loscon, _numOfMaps, _fileName, _changeDate }; //_numOfMaps is for campaigns class ElementInfo : public CMapInfo { public: ElementInfo() : CMapInfo() { } ~ElementInfo() { } std::string folderName = ""; bool isFolder = false; }; /// Class which handles map sorting by different criteria class mapSorter { public: ESortBy sortBy; bool operator()(const std::shared_ptr aaa, const std::shared_ptr bbb); mapSorter(ESortBy es) : sortBy(es){}; }; class SelectionTab : public CIntObject { struct ListItem : public CIntObject { std::shared_ptr labelAmountOfPlayers; std::shared_ptr labelNumberOfCampaignMaps; std::shared_ptr labelMapSizeLetter; std::shared_ptr iconFolder; std::shared_ptr iconFormat; std::shared_ptr iconVictoryCondition; std::shared_ptr iconLossCondition; std::shared_ptr pictureEmptyLine; std::shared_ptr labelName; ListItem(Point position); void updateItem(std::shared_ptr info = {}, bool selected = false); }; std::vector> listItems; std::shared_ptr iconsMapFormats; // FIXME: CSelectionBase use them too! std::shared_ptr iconsVictoryCondition; std::shared_ptr iconsLossCondition; public: std::vector> allItems; std::vector> curItems; std::string curFolder; size_t selectionPos; std::function)> callOnSelect; ESortBy sortingBy; ESortBy generalSortingBy; bool sortModeAscending; int currentMapSizeFilter = 0; bool showRandom; std::shared_ptr inputName; SelectionTab(ESelectionScreen Type); void toggleMode(); void clickReleased(const Point & cursorPosition) override; void keyPressed(EShortcut key) override; void clickDouble(const Point & cursorPosition) override; void showPopupWindow(const Point & cursorPosition) override; bool receiveEvent(const Point & position, int eventType) const override; void filter(int size, bool selectFirst = false); //0 - all void sortBy(int criteria); void sort(); void select(int position); //position: <0 - positions> position on the screen void selectAbs(int position); //position: absolute position in curItems vector void sliderMove(int slidPos); void updateListItems(); int getLine() const; int getLine(const Point & position) const; void selectFileName(std::string fname); void selectNewestFile(); std::shared_ptr getSelectedMapInfo() const; void rememberCurrentSelection(); void restoreLastSelection(); private: std::shared_ptr background; std::shared_ptr slider; std::vector> buttonsSortBy; std::shared_ptr labelTabTitle; std::shared_ptr labelMapSizes; ESelectionScreen tabType; Rect inputNameRect; auto checkSubfolder(std::string path); bool isMapSupported(const CMapInfo & info); void parseMaps(const std::unordered_set & files); void parseSaves(const std::unordered_set & files); void parseCampaigns(const std::unordered_set & files); std::unordered_set getFiles(std::string dirURI, EResType resType); };