SelectionTab.h 4.3 KB

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