AppList.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef FREESHOP_APPLIST_HPP
  2. #define FREESHOP_APPLIST_HPP
  3. #include <vector>
  4. #include <string>
  5. #include <memory>
  6. #include <TweenEngine/TweenManager.h>
  7. #include <cpp3ds/System/Thread.hpp>
  8. #include <cpp3ds/Window/Event.hpp>
  9. #include <cpp3ds/System/Clock.hpp>
  10. #include <cpp3ds/Audio/Sound.hpp>
  11. #include "GUI/AppItem.hpp"
  12. #include "RichText.hpp"
  13. namespace FreeShop
  14. {
  15. class AppList : public cpp3ds::Drawable, public util3ds::TweenTransformable<cpp3ds::Transformable> {
  16. public:
  17. enum SortType {
  18. Name,
  19. Size,
  20. VoteScore,
  21. VoteCount,
  22. ReleaseDate,
  23. };
  24. static AppList &getInstance();
  25. ~AppList();
  26. void refresh();
  27. void setSortType(SortType sortType, bool ascending);
  28. void setSelectedIndex(int index);
  29. int getSelectedIndex() const;
  30. size_t getCount() const;
  31. size_t getVisibleCount() const;
  32. GUI::AppItem* getSelected();
  33. std::vector<std::unique_ptr<GUI::AppItem>> &getList();
  34. void setCollapsed(bool collapsed);
  35. bool isCollapsed() const;
  36. void filterBySearch(const std::string& searchTerm, std::vector<util3ds::RichText> &textMatches);
  37. void update(float delta);
  38. bool processEvent(const cpp3ds::Event& event);
  39. void setFilterGenres(const std::vector<int> &genres);
  40. void setFilterPlatforms(const std::vector<int> &genres);
  41. void setFilterLanguages(int languages);
  42. void setFilterRegions(int regions);
  43. protected:
  44. AppList(std::string jsonFilename);
  45. virtual void draw(cpp3ds::RenderTarget& target, cpp3ds::RenderStates states) const;
  46. void sort();
  47. void filter();
  48. void reposition();
  49. void processKeyRepeat();
  50. private:
  51. SortType m_sortType;
  52. bool m_sortAscending;
  53. float m_targetPosX;
  54. cpp3ds::Sound m_soundBlip;
  55. cpp3ds::Clock m_clockKeyRepeat;
  56. int m_indexDelta;
  57. bool m_processedFirstKey;
  58. bool m_startKeyRepeat;
  59. std::vector<int> m_filterGenres;
  60. std::vector<int> m_filterPlatforms;
  61. int m_filterRegions;
  62. int m_filterLanguages;
  63. std::string m_jsonFilename;
  64. int m_selectedIndex;
  65. std::vector<std::shared_ptr<AppItem>> m_appItems;
  66. std::vector<std::unique_ptr<GUI::AppItem>> m_guiAppItems;
  67. std::vector<cpp3ds::Texture*> m_iconTextures;
  68. bool m_collapsed;
  69. TweenEngine::TweenManager m_tweenManager;
  70. };
  71. } // namespace FreeShop
  72. #endif // FREESHOP_APPLIST_HPP