1#ifndef GAME_CLIENT_COMPONENTS_COMMUNITY_ICONS_H
2#define GAME_CLIENT_COMPONENTS_COMMUNITY_ICONS_H
3
4#include <base/hash.h>
5
6#include <engine/graphics.h>
7#include <engine/serverbrowser.h>
8#include <engine/shared/http.h>
9#include <engine/shared/jobs.h>
10
11#include <game/client/component.h>
12#include <game/client/ui_rect.h>
13
14class CCommunityIcon
15{
16 friend class CCommunityIcons;
17
18private:
19 char m_aCommunityId[CServerInfo::MAX_COMMUNITY_ID_LENGTH];
20 SHA256_DIGEST m_Sha256;
21 IGraphics::CTextureHandle m_OrgTexture;
22 IGraphics::CTextureHandle m_GreyTexture;
23};
24
25class CCommunityIcons : public CComponentInterfaces
26{
27public:
28 const CCommunityIcon *Find(const char *pCommunityId);
29 void Render(const CCommunityIcon *pIcon, CUIRect Rect, bool Active);
30 void Load();
31 void Update();
32 void Shutdown();
33
34private:
35 class CAbstractCommunityIconJob
36 {
37 protected:
38 CCommunityIcons *m_pCommunityIcons;
39 char m_aCommunityId[CServerInfo::MAX_COMMUNITY_ID_LENGTH];
40 char m_aPath[IO_MAX_PATH_LENGTH];
41 int m_StorageType;
42 bool m_Success = false;
43 SHA256_DIGEST m_Sha256;
44
45 CAbstractCommunityIconJob(CCommunityIcons *pCommunityIcons, const char *pCommunityId, int StorageType);
46
47 public:
48 const char *CommunityId() const { return m_aCommunityId; }
49 bool Success() const { return m_Success; }
50 const SHA256_DIGEST &Sha256() const { return m_Sha256; }
51 virtual ~CAbstractCommunityIconJob() = default;
52 };
53
54 class CCommunityIconLoadJob : public IJob, public CAbstractCommunityIconJob
55 {
56 CImageInfo m_ImageInfo;
57 CImageInfo m_ImageInfoGrayscale;
58
59 protected:
60 void Run() override;
61
62 public:
63 CCommunityIconLoadJob(CCommunityIcons *pCommunityIcons, const char *pCommunityId, int StorageType);
64 ~CCommunityIconLoadJob() override;
65
66 CImageInfo &ImageInfo() { return m_ImageInfo; }
67 CImageInfo &ImageInfoGrayscale() { return m_ImageInfoGrayscale; }
68 };
69
70 class CCommunityIconDownloadJob : public CHttpRequest, public CAbstractCommunityIconJob
71 {
72 public:
73 CCommunityIconDownloadJob(CCommunityIcons *pCommunityIcons, const char *pCommunityId, const char *pUrl, const SHA256_DIGEST &Sha256);
74 };
75
76 std::vector<CCommunityIcon> m_vCommunityIcons;
77 std::deque<std::shared_ptr<CCommunityIconLoadJob>> m_CommunityIconLoadJobs;
78 std::deque<std::shared_ptr<CCommunityIconDownloadJob>> m_CommunityIconDownloadJobs;
79 SHA256_DIGEST m_CommunityIconsInfoSha256 = SHA256_ZEROED;
80 static int FileScan(const char *pName, int IsDir, int DirType, void *pUser);
81 bool LoadFile(const char *pPath, int DirType, CImageInfo &Info, CImageInfo &InfoGrayscale, SHA256_DIGEST &Sha256);
82 void LoadFinish(const char *pCommunityId, CImageInfo &Info, CImageInfo &InfoGrayscale, const SHA256_DIGEST &Sha256);
83};
84
85#endif
86