SelectionTab.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. class CToggleButton;
  23. enum ESortBy
  24. {
  25. _playerAm, _size, _format, _name, _viccon, _loscon, _numOfMaps, _fileName, _changeDate
  26. }; //_numOfMaps is for campaigns
  27. class ElementInfo : public CMapInfo
  28. {
  29. public:
  30. ElementInfo() : CMapInfo() { }
  31. ~ElementInfo() { }
  32. std::string folderName = "";
  33. std::string name = "";
  34. bool isFolder = false;
  35. bool isAutoSaveFolder = false;
  36. };
  37. /// Class which handles map sorting by different criteria
  38. class mapSorter
  39. {
  40. public:
  41. ESortBy sortBy;
  42. bool operator()(const std::shared_ptr<ElementInfo> aaa, const std::shared_ptr<ElementInfo> bbb);
  43. mapSorter(ESortBy es) : sortBy(es){};
  44. };
  45. class SelectionTab : public CIntObject
  46. {
  47. struct ListItem : public CIntObject
  48. {
  49. std::shared_ptr<CLabel> labelAmountOfPlayers;
  50. std::shared_ptr<CLabel> labelNumberOfCampaignMaps;
  51. std::shared_ptr<CLabel> labelMapSizeLetter;
  52. std::shared_ptr<CPicture> iconFolder;
  53. std::shared_ptr<CAnimImage> iconFormat;
  54. std::shared_ptr<CAnimImage> iconVictoryCondition;
  55. std::shared_ptr<CAnimImage> iconLossCondition;
  56. std::shared_ptr<CPicture> pictureEmptyLine;
  57. std::shared_ptr<CLabel> labelName;
  58. const int LABEL_POS_X = 184;
  59. ListItem(Point position);
  60. void updateItem(std::shared_ptr<ElementInfo> info = {}, bool selected = false);
  61. };
  62. std::vector<std::shared_ptr<ListItem>> listItems;
  63. std::shared_ptr<CAnimation> iconsMapFormats;
  64. // FIXME: CSelectionBase use them too!
  65. std::shared_ptr<CAnimation> iconsVictoryCondition;
  66. std::shared_ptr<CAnimation> iconsLossCondition;
  67. std::vector<std::shared_ptr<ListItem>> unSupportedSaves;
  68. JsonNode campaignSets;
  69. public:
  70. std::vector<std::shared_ptr<ElementInfo>> allItems;
  71. std::vector<std::shared_ptr<ElementInfo>> curItems;
  72. std::string curFolder;
  73. size_t selectionPos;
  74. std::function<void(std::shared_ptr<ElementInfo>)> callOnSelect;
  75. ESortBy sortingBy;
  76. ESortBy generalSortingBy;
  77. bool sortModeAscending;
  78. int currentMapSizeFilter = 0;
  79. bool showRandom;
  80. std::shared_ptr<CTextInput> inputName;
  81. SelectionTab(ESelectionScreen Type);
  82. void toggleMode();
  83. void clickReleased(const Point & cursorPosition) override;
  84. void keyPressed(EShortcut key) override;
  85. void clickDouble(const Point & cursorPosition) override;
  86. void showPopupWindow(const Point & cursorPosition) override;
  87. bool receiveEvent(const Point & position, int eventType) const override;
  88. void filter(int size, bool selectFirst = false); //0 - all
  89. void sortBy(int criteria);
  90. void sort();
  91. void select(int position); //position: <0 - positions> position on the screen
  92. void selectAbs(int position); //position: absolute position in curItems vector
  93. void sliderMove(int slidPos);
  94. void updateListItems();
  95. int getLine() const;
  96. int getLine(const Point & position) const;
  97. void selectFileName(std::string fname);
  98. void selectNewestFile();
  99. std::shared_ptr<ElementInfo> getSelectedMapInfo() const;
  100. void rememberCurrentSelection();
  101. void restoreLastSelection();
  102. private:
  103. std::shared_ptr<CPicture> background;
  104. std::shared_ptr<CSlider> slider;
  105. std::vector<std::shared_ptr<CButton>> buttonsSortBy;
  106. std::shared_ptr<CLabel> labelTabTitle;
  107. std::shared_ptr<CLabel> labelMapSizes;
  108. ESelectionScreen tabType;
  109. Rect inputNameRect;
  110. std::shared_ptr<CButton> buttonDeleteMode;
  111. bool deleteMode;
  112. bool enableUiEnhancements;
  113. std::shared_ptr<CButton> buttonCampaignSet;
  114. auto checkSubfolder(std::string path);
  115. bool isMapSupported(const CMapInfo & info);
  116. void parseMaps(const std::unordered_set<ResourcePath> & files);
  117. std::vector<ResourcePath> parseSaves(const std::unordered_set<ResourcePath> & files);
  118. void parseCampaigns(const std::unordered_set<ResourcePath> & files);
  119. std::unordered_set<ResourcePath> getFiles(std::string dirURI, EResType resType);
  120. void handleUnsupportedSavegames(const std::vector<ResourcePath> & files);
  121. };
  122. class CampaignSetSelector : public CWindowObject
  123. {
  124. std::shared_ptr<FilledTexturePlayerColored> filledBackground;
  125. std::vector<std::shared_ptr<CToggleButton>> buttons;
  126. std::shared_ptr<CSlider> slider;
  127. const int LINES = 10;
  128. std::vector<std::string> texts;
  129. std::function<void(int selectedIndex)> cb;
  130. void update(int to);
  131. public:
  132. CampaignSetSelector(const std::vector<std::string> & texts, const std::function<void(int selectedIndex)> & cb);
  133. };