ddnet/src/game/client/components/skins.h

69 lines
2 KiB
C
Raw Normal View History

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
#include <engine/shared/http.h>
2010-05-29 07:25:38 +00:00
#include <game/client/component.h>
#include <game/client/skin.h>
#include <vector>
2010-05-29 07:25:38 +00:00
class CSkins : public CComponent
{
public:
class CGetPngFile : public CHttpRequest
{
CSkins *m_pSkins;
protected:
virtual int OnCompletion(int State) override;
public:
CGetPngFile(CSkins *pSkins, const char *pUrl, IStorage *pStorage, const char *pDest);
CImageInfo m_Info;
};
struct CDownloadSkin
{
std::shared_ptr<CSkins::CGetPngFile> m_pTask;
char m_aPath[IO_MAX_PATH_LENGTH];
char m_aName[24];
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); }
CDownloadSkin &operator=(CDownloadSkin &&Other) = default;
};
typedef std::function<void(int)> TSkinLoadedCBFunc;
virtual int Sizeof() const override { return sizeof(*this); }
void OnInit() override;
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);
2010-05-29 07:25:38 +00:00
private:
std::vector<CSkin> m_vSkins;
std::vector<CDownloadSkin> m_vDownloadSkins;
char m_EventSkinPrefix[24];
2010-05-29 07:25:38 +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);
int LoadSkin(const char *pName, CImageInfo &Info);
2020-09-04 14:40:35 +00:00
int FindImpl(const char *pName);
static int SkinScan(const char *pName, int IsDir, int DirType, void *pUser);
2010-05-29 07:25:38 +00:00
};
#endif