SelectionTab.h 3.6 KB

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