SelectionTab.h 4.2 KB

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