2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef GAME_CLIENT_COMPONENTS_SKINS_H
|
|
|
|
#define GAME_CLIENT_COMPONENTS_SKINS_H
|
2022-05-29 16:33:38 +00:00
|
|
|
|
2021-12-24 11:17:46 +00:00
|
|
|
#include <engine/shared/http.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <game/client/component.h>
|
2020-10-09 07:07:05 +00:00
|
|
|
#include <game/client/skin.h>
|
2022-05-23 20:20:10 +00:00
|
|
|
#include <vector>
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
class CSkins : public CComponent
|
|
|
|
{
|
|
|
|
public:
|
2022-05-05 12:49:25 +00:00
|
|
|
class CGetPngFile : public CHttpRequest
|
2020-12-12 11:37:43 +00:00
|
|
|
{
|
|
|
|
CSkins *m_pSkins;
|
|
|
|
|
|
|
|
protected:
|
2022-01-30 23:43:56 +00:00
|
|
|
virtual int OnCompletion(int State) override;
|
2020-12-12 11:37:43 +00:00
|
|
|
|
|
|
|
public:
|
2022-05-05 12:49:25 +00:00
|
|
|
CGetPngFile(CSkins *pSkins, const char *pUrl, IStorage *pStorage, const char *pDest);
|
2020-12-12 11:37:43 +00:00
|
|
|
CImageInfo m_Info;
|
|
|
|
};
|
|
|
|
|
2020-09-18 21:06:35 +00:00
|
|
|
struct CDownloadSkin
|
2020-09-20 00:19:24 +00:00
|
|
|
{
|
2020-12-12 11:37:43 +00:00
|
|
|
std::shared_ptr<CSkins::CGetPngFile> m_pTask;
|
2021-09-13 08:06:34 +00:00
|
|
|
char m_aPath[IO_MAX_PATH_LENGTH];
|
2020-09-18 21:06:35 +00:00
|
|
|
char m_aName[24];
|
|
|
|
|
2022-07-04 16:24:34 +00:00
|
|
|
CDownloadSkin(CDownloadSkin &&Other) = default;
|
|
|
|
CDownloadSkin() = default;
|
|
|
|
|
2022-06-26 22:29:52 +00:00
|
|
|
~CDownloadSkin()
|
|
|
|
{
|
|
|
|
if(m_pTask)
|
|
|
|
m_pTask->Abort();
|
|
|
|
}
|
2020-10-08 05:28:53 +00:00
|
|
|
bool operator<(const CDownloadSkin &Other) const { return str_comp(m_aName, Other.m_aName) < 0; }
|
|
|
|
bool operator<(const char *pOther) const { return str_comp(m_aName, pOther) < 0; }
|
|
|
|
bool operator==(const char *pOther) const { return !str_comp(m_aName, pOther); }
|
2022-07-04 16:24:34 +00:00
|
|
|
|
|
|
|
CDownloadSkin &operator=(CDownloadSkin &&Other) = default;
|
2020-09-20 00:19:24 +00:00
|
|
|
};
|
|
|
|
|
2022-04-02 11:37:59 +00:00
|
|
|
typedef std::function<void(int)> TSkinLoadedCBFunc;
|
|
|
|
|
2022-01-31 02:11:47 +00:00
|
|
|
virtual int Sizeof() const override { return sizeof(*this); }
|
2022-01-30 23:43:56 +00:00
|
|
|
void OnInit() override;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2022-04-02 11:37:59 +00:00
|
|
|
void Refresh(TSkinLoadedCBFunc &&SkinLoadedFunc);
|
2010-05-29 07:25:38 +00:00
|
|
|
int Num();
|
|
|
|
const CSkin *Get(int Index);
|
2020-09-04 14:40:35 +00:00
|
|
|
int Find(const char *pName);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2022-10-04 16:40:24 +00:00
|
|
|
bool IsDownloadingSkins() { return m_DownloadingSkins; }
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
private:
|
2022-06-11 19:38:18 +00:00
|
|
|
std::vector<CSkin> m_vSkins;
|
|
|
|
std::vector<CDownloadSkin> m_vDownloadSkins;
|
2022-10-04 16:40:24 +00:00
|
|
|
size_t m_DownloadingSkins = 0;
|
2022-06-30 22:36:32 +00:00
|
|
|
char m_aEventSkinPrefix[24];
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2020-12-12 11:37:43 +00:00
|
|
|
bool LoadSkinPNG(CImageInfo &Info, const char *pName, const char *pPath, int DirType);
|
2020-11-02 20:21:57 +00:00
|
|
|
int LoadSkin(const char *pName, const char *pPath, int DirType);
|
2020-12-12 11:37:43 +00:00
|
|
|
int LoadSkin(const char *pName, CImageInfo &Info);
|
2020-09-04 14:40:35 +00:00
|
|
|
int FindImpl(const char *pName);
|
2011-02-21 10:23:30 +00:00
|
|
|
static int SkinScan(const char *pName, int IsDir, int DirType, void *pUser);
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
#endif
|