1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/client/lobby/SelectionTab.h

125 lines
3.8 KiB
C++
Raw Normal View History

/*
* 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"
2023-08-20 13:16:39 +02:00
VCMI_LIB_NAMESPACE_BEGIN
class CMap;
VCMI_LIB_NAMESPACE_END
2023-08-08 00:38:13 +02:00
#include "../../lib/mapping/CMapInfo.h"
#include "../../lib/filesystem/ResourcePath.h"
class CSlider;
class CLabel;
2023-08-17 23:09:20 +02:00
class CPicture;
class IImage;
enum ESortBy
{
_playerAm, _size, _format, _name, _viccon, _loscon, _numOfMaps, _fileName
}; //_numOfMaps is for campaigns
2023-08-08 00:38:13 +02:00
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;
2023-08-08 00:38:13 +02:00
bool operator()(const std::shared_ptr<ElementInfo> aaa, const std::shared_ptr<ElementInfo> bbb);
mapSorter(ESortBy es) : sortBy(es){};
};
class SelectionTab : public CIntObject
{
struct ListItem : public CIntObject
{
std::shared_ptr<CLabel> labelAmountOfPlayers;
std::shared_ptr<CLabel> labelNumberOfCampaignMaps;
std::shared_ptr<CLabel> labelMapSizeLetter;
2023-08-10 23:37:19 +02:00
std::shared_ptr<CPicture> iconFolder;
std::shared_ptr<CAnimImage> iconFormat;
std::shared_ptr<CAnimImage> iconVictoryCondition;
std::shared_ptr<CAnimImage> iconLossCondition;
2023-08-10 23:37:19 +02:00
std::shared_ptr<CPicture> pictureEmptyLine;
std::shared_ptr<CLabel> labelName;
ListItem(Point position, std::shared_ptr<CAnimation> iconsFormats, std::shared_ptr<CAnimation> iconsVictory, std::shared_ptr<CAnimation> iconsLoss);
2023-08-08 00:38:13 +02:00
void updateItem(std::shared_ptr<ElementInfo> info = {}, bool selected = false);
};
std::vector<std::shared_ptr<ListItem>> listItems;
std::shared_ptr<CAnimation> iconsMapFormats;
// FIXME: CSelectionBase use them too!
std::shared_ptr<CAnimation> iconsVictoryCondition;
std::shared_ptr<CAnimation> iconsLossCondition;
public:
2023-08-08 00:38:13 +02:00
std::vector<std::shared_ptr<ElementInfo>> allItems;
std::vector<std::shared_ptr<ElementInfo>> curItems;
2023-08-07 00:10:06 +02:00
std::string curFolder;
size_t selectionPos;
2023-08-08 00:38:13 +02:00
std::function<void(std::shared_ptr<ElementInfo>)> callOnSelect;
ESortBy sortingBy;
ESortBy generalSortingBy;
bool sortModeAscending;
2023-08-10 22:15:32 +02:00
int currentMapSizeFilter = 0;
2023-10-21 02:12:34 +02:00
bool showRandom;
std::shared_ptr<CTextInput> inputName;
SelectionTab(ESelectionScreen Type);
void toggleMode();
void clickReleased(const Point & cursorPosition) override;
void keyPressed(EShortcut key) override;
void clickDouble(const Point & cursorPosition) override;
2023-07-20 01:53:33 +02:00
void showPopupWindow(const Point & cursorPosition) override;
bool receiveEvent(const Point & position, int eventType) const override;
2023-08-08 00:38:13 +02:00
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);
2023-08-08 00:38:13 +02:00
std::shared_ptr<ElementInfo> getSelectedMapInfo() const;
void rememberCurrentSelection();
void restoreLastSelection();
private:
std::shared_ptr<CPicture> background;
std::shared_ptr<CSlider> slider;
std::vector<std::shared_ptr<CButton>> buttonsSortBy;
std::shared_ptr<CLabel> labelTabTitle;
std::shared_ptr<CLabel> labelMapSizes;
ESelectionScreen tabType;
Rect inputNameRect;
2023-08-10 22:15:32 +02:00
auto checkSubfolder(std::string path);
2023-08-08 00:38:13 +02:00
bool isMapSupported(const CMapInfo & info);
void parseMaps(const std::unordered_set<ResourcePath> & files);
void parseSaves(const std::unordered_set<ResourcePath> & files);
void parseCampaigns(const std::unordered_set<ResourcePath> & files);
std::unordered_set<ResourcePath> getFiles(std::string dirURI, EResType resType);
};