SelectionTab.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * SelectionTab.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "CSelectionBase.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class CMap;
  14. VCMI_LIB_NAMESPACE_END
  15. #include "../../lib/mapping/CMapInfo.h"
  16. #include "../../lib/filesystem/ResourcePath.h"
  17. class CSlider;
  18. class CLabel;
  19. class CPicture;
  20. class IImage;
  21. class CAnimation;
  22. enum ESortBy
  23. {
  24. _playerAm, _size, _format, _name, _viccon, _loscon, _numOfMaps, _fileName, _changeDate
  25. }; //_numOfMaps is for campaigns
  26. class ElementInfo : public CMapInfo
  27. {
  28. public:
  29. ElementInfo() : CMapInfo() { }
  30. ~ElementInfo() { }
  31. std::string folderName = "";
  32. std::string name = "";
  33. bool isFolder = false;
  34. };
  35. /// Class which handles map sorting by different criteria
  36. class mapSorter
  37. {
  38. public:
  39. ESortBy sortBy;
  40. bool operator()(const std::shared_ptr<ElementInfo> aaa, const std::shared_ptr<ElementInfo> bbb);
  41. mapSorter(ESortBy es) : sortBy(es){};
  42. };
  43. class SelectionTab : public CIntObject
  44. {
  45. struct ListItem : public CIntObject
  46. {
  47. std::shared_ptr<CLabel> labelAmountOfPlayers;
  48. std::shared_ptr<CLabel> labelNumberOfCampaignMaps;
  49. std::shared_ptr<CLabel> labelMapSizeLetter;
  50. std::shared_ptr<CPicture> iconFolder;
  51. std::shared_ptr<CAnimImage> iconFormat;
  52. std::shared_ptr<CAnimImage> iconVictoryCondition;
  53. std::shared_ptr<CAnimImage> iconLossCondition;
  54. std::shared_ptr<CPicture> pictureEmptyLine;
  55. std::shared_ptr<CLabel> labelName;
  56. ListItem(Point position);
  57. void updateItem(std::shared_ptr<ElementInfo> info = {}, bool selected = false);
  58. };
  59. std::vector<std::shared_ptr<ListItem>> listItems;
  60. std::shared_ptr<CAnimation> iconsMapFormats;
  61. // FIXME: CSelectionBase use them too!
  62. std::shared_ptr<CAnimation> iconsVictoryCondition;
  63. std::shared_ptr<CAnimation> iconsLossCondition;
  64. public:
  65. std::vector<std::shared_ptr<ElementInfo>> allItems;
  66. std::vector<std::shared_ptr<ElementInfo>> curItems;
  67. std::string curFolder;
  68. size_t selectionPos;
  69. std::function<void(std::shared_ptr<ElementInfo>)> callOnSelect;
  70. ESortBy sortingBy;
  71. ESortBy generalSortingBy;
  72. bool sortModeAscending;
  73. int currentMapSizeFilter = 0;
  74. bool showRandom;
  75. std::shared_ptr<CTextInput> inputName;
  76. SelectionTab(ESelectionScreen Type);
  77. void toggleMode();
  78. void clickReleased(const Point & cursorPosition) override;
  79. void keyPressed(EShortcut key) override;
  80. void clickDouble(const Point & cursorPosition) override;
  81. void showPopupWindow(const Point & cursorPosition) override;
  82. bool receiveEvent(const Point & position, int eventType) const override;
  83. void filter(int size, bool selectFirst = false); //0 - all
  84. void sortBy(int criteria);
  85. void sort();
  86. void select(int position); //position: <0 - positions> position on the screen
  87. void selectAbs(int position); //position: absolute position in curItems vector
  88. void sliderMove(int slidPos);
  89. void updateListItems();
  90. int getLine() const;
  91. int getLine(const Point & position) const;
  92. void selectFileName(std::string fname);
  93. void selectNewestFile();
  94. std::shared_ptr<ElementInfo> getSelectedMapInfo() const;
  95. void rememberCurrentSelection();
  96. void restoreLastSelection();
  97. private:
  98. std::shared_ptr<CPicture> background;
  99. std::shared_ptr<CSlider> slider;
  100. std::vector<std::shared_ptr<CButton>> buttonsSortBy;
  101. std::shared_ptr<CLabel> labelTabTitle;
  102. std::shared_ptr<CLabel> labelMapSizes;
  103. ESelectionScreen tabType;
  104. Rect inputNameRect;
  105. auto checkSubfolder(std::string path);
  106. bool isMapSupported(const CMapInfo & info);
  107. void parseMaps(const std::unordered_set<ResourcePath> & files);
  108. void parseSaves(const std::unordered_set<ResourcePath> & files);
  109. void parseCampaigns(const std::unordered_set<ResourcePath> & files);
  110. std::unordered_set<ResourcePath> getFiles(std::string dirURI, EResType resType);
  111. };