SelectionTab.h 3.0 KB

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