SelectionTab.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. class CSlider;
  17. class CLabel;
  18. class CPicture;
  19. class IImage;
  20. enum ESortBy
  21. {
  22. _playerAm, _size, _format, _name, _viccon, _loscon, _numOfMaps, _fileName
  23. }; //_numOfMaps is for campaigns
  24. class ElementInfo : public CMapInfo
  25. {
  26. public:
  27. ElementInfo() : CMapInfo() { }
  28. ~ElementInfo() { }
  29. std::string folderName = "";
  30. bool isFolder = false;
  31. };
  32. /// Class which handles map sorting by different criteria
  33. class mapSorter
  34. {
  35. public:
  36. ESortBy sortBy;
  37. bool operator()(const std::shared_ptr<ElementInfo> aaa, const std::shared_ptr<ElementInfo> bbb);
  38. mapSorter(ESortBy es) : sortBy(es){};
  39. };
  40. class SelectionTab : public CIntObject
  41. {
  42. struct ListItem : public CIntObject
  43. {
  44. std::shared_ptr<CLabel> labelAmountOfPlayers;
  45. std::shared_ptr<CLabel> labelNumberOfCampaignMaps;
  46. std::shared_ptr<CLabel> labelMapSizeLetter;
  47. std::shared_ptr<CPicture> iconFolder;
  48. std::shared_ptr<CAnimImage> iconFormat;
  49. std::shared_ptr<CAnimImage> iconVictoryCondition;
  50. std::shared_ptr<CAnimImage> iconLossCondition;
  51. std::shared_ptr<CPicture> pictureEmptyLine;
  52. std::shared_ptr<CLabel> labelName;
  53. ListItem(Point position, std::shared_ptr<CAnimation> iconsFormats, std::shared_ptr<CAnimation> iconsVictory, std::shared_ptr<CAnimation> iconsLoss);
  54. void updateItem(std::shared_ptr<ElementInfo> info = {}, bool selected = false);
  55. };
  56. std::vector<std::shared_ptr<ListItem>> listItems;
  57. std::shared_ptr<CAnimation> iconsMapFormats;
  58. // FIXME: CSelectionBase use them too!
  59. std::shared_ptr<CAnimation> iconsVictoryCondition;
  60. std::shared_ptr<CAnimation> iconsLossCondition;
  61. class CMapInfoTooltipBox : public CWindowObject
  62. {
  63. const int IMAGE_SIZE = 169;
  64. const int BORDER = 30;
  65. bool drawPlayerElements;
  66. bool renderImage;
  67. std::shared_ptr<CFilledTexture> backgroundTexture;
  68. std::shared_ptr<CTextBox> label;
  69. std::shared_ptr<CPicture> image1;
  70. std::shared_ptr<CPicture> image2;
  71. Canvas createMinimapForLayer(std::unique_ptr<CMap> & map, int layer);
  72. std::vector<std::shared_ptr<IImage>> createMinimaps(ResourceID resource, int size);
  73. public:
  74. CMapInfoTooltipBox(std::string text, ResourceID resource, ESelectionScreen tabType);
  75. };
  76. public:
  77. std::vector<std::shared_ptr<ElementInfo>> allItems;
  78. std::vector<std::shared_ptr<ElementInfo>> curItems;
  79. std::string curFolder;
  80. size_t selectionPos;
  81. std::function<void(std::shared_ptr<ElementInfo>)> callOnSelect;
  82. ESortBy sortingBy;
  83. ESortBy generalSortingBy;
  84. bool sortModeAscending;
  85. int currentMapSizeFilter = 0;
  86. std::shared_ptr<CTextInput> inputName;
  87. SelectionTab(ESelectionScreen Type);
  88. void toggleMode();
  89. void clickReleased(const Point & cursorPosition) override;
  90. void keyPressed(EShortcut key) override;
  91. void clickDouble(const Point & cursorPosition) override;
  92. void showPopupWindow(const Point & cursorPosition) override;
  93. bool receiveEvent(const Point & position, int eventType) const override;
  94. void filter(int size, bool selectFirst = false); //0 - all
  95. void sortBy(int criteria);
  96. void sort();
  97. void select(int position); //position: <0 - positions> position on the screen
  98. void selectAbs(int position); //position: absolute position in curItems vector
  99. void sliderMove(int slidPos);
  100. void updateListItems();
  101. int getLine() const;
  102. int getLine(const Point & position) const;
  103. void selectFileName(std::string fname);
  104. std::shared_ptr<ElementInfo> getSelectedMapInfo() const;
  105. void rememberCurrentSelection();
  106. void restoreLastSelection();
  107. private:
  108. std::shared_ptr<CPicture> background;
  109. std::shared_ptr<CSlider> slider;
  110. std::vector<std::shared_ptr<CButton>> buttonsSortBy;
  111. std::shared_ptr<CLabel> labelTabTitle;
  112. std::shared_ptr<CLabel> labelMapSizes;
  113. ESelectionScreen tabType;
  114. Rect inputNameRect;
  115. auto checkSubfolder(std::string path);
  116. bool isMapSupported(const CMapInfo & info);
  117. void parseMaps(const std::unordered_set<ResourceID> & files);
  118. void parseSaves(const std::unordered_set<ResourceID> & files);
  119. void parseCampaigns(const std::unordered_set<ResourceID> & files);
  120. std::unordered_set<ResourceID> getFiles(std::string dirURI, int resType);
  121. };