mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
added info in the demo browser by Choupom
This commit is contained in:
parent
7ad4d3224c
commit
85b9c60158
|
@ -25,6 +25,7 @@ public:
|
|||
virtual void Unpause() = 0;
|
||||
virtual const CInfo *BaseInfo() const = 0;
|
||||
virtual char *GetDemoName() = 0;
|
||||
virtual bool GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, char *pMap, int BufferSize) const = 0;
|
||||
};
|
||||
|
||||
class IDemoRecorder : public IInterface
|
||||
|
|
|
@ -742,3 +742,22 @@ char *CDemoPlayer::GetDemoName()
|
|||
return pDemoShortName;
|
||||
}
|
||||
|
||||
bool CDemoPlayer::GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, char *pMap, int BufferSize) const
|
||||
{
|
||||
IOHANDLE File = pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType);
|
||||
if(!File)
|
||||
return false;
|
||||
|
||||
CDemoHeader Header;
|
||||
io_read(File, &Header, sizeof(Header));
|
||||
if(mem_comp(Header.m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) != 0)
|
||||
{
|
||||
io_close(File);
|
||||
return false;
|
||||
}
|
||||
|
||||
str_copy(pMap, Header.m_aMap, BufferSize);
|
||||
|
||||
io_close(File);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -112,6 +112,7 @@ public:
|
|||
int SetPos(float Precent);
|
||||
const CInfo *BaseInfo() const { return &m_Info.m_Info; }
|
||||
char *GetDemoName();
|
||||
bool GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, char *pMap, int BufferSize) const;
|
||||
|
||||
int Update();
|
||||
|
||||
|
|
|
@ -160,6 +160,8 @@ class CMenus : public CComponent
|
|||
char m_aName[128];
|
||||
bool m_IsDir;
|
||||
int m_StorageType;
|
||||
bool m_Valid;
|
||||
char m_aMap[64];
|
||||
|
||||
bool operator<(const CDemoItem &Other) { return !str_comp(m_aFilename, "..") ? true : !str_comp(Other.m_aFilename, "..") ? false :
|
||||
m_IsDir && !Other.m_IsDir ? true : !m_IsDir && Other.m_IsDir ? false :
|
||||
|
|
|
@ -429,9 +429,19 @@ void CMenus::DemolistFetchCallback(const char *pName, int IsDir, int StorageType
|
|||
CDemoItem Item;
|
||||
str_copy(Item.m_aFilename, pName, sizeof(Item.m_aFilename));
|
||||
if(IsDir)
|
||||
{
|
||||
str_format(Item.m_aName, sizeof(Item.m_aName), "%s/", pName);
|
||||
Item.m_aMap[0] = 0;
|
||||
Item.m_Valid = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
str_format(Item.m_aName, min(static_cast<int>(sizeof(Item.m_aName)), Length), " %s", pName);
|
||||
char aBuffer[512];
|
||||
str_format(aBuffer, sizeof(aBuffer), "%s/%s", pSelf->m_aCurrentDemoFolder, Item.m_aFilename);
|
||||
// TODO: many items slow this down, don't load the info from every file when making the filelist
|
||||
Item.m_Valid = pSelf->DemoPlayer()->GetDemoInfo(pSelf->Storage(), aBuffer, StorageType, Item.m_aMap, sizeof(Item.m_aMap));
|
||||
}
|
||||
Item.m_IsDir = IsDir != 0;
|
||||
Item.m_StorageType = StorageType;
|
||||
pSelf->m_lDemos.add(Item);
|
||||
|
@ -475,6 +485,19 @@ void CMenus::RenderDemoList(CUIRect MainView)
|
|||
}
|
||||
m_DemolistDelEntry = false;
|
||||
}
|
||||
|
||||
char aFooterLabel[128] = {0};
|
||||
if(m_DemolistSelectedIndex >= 0)
|
||||
{
|
||||
if(str_comp(m_lDemos[m_DemolistSelectedIndex].m_aFilename, "..") == 0)
|
||||
str_copy(aFooterLabel, Localize("Parent Folder"), sizeof(aFooterLabel));
|
||||
else if(m_DemolistSelectedIsDir)
|
||||
str_copy(aFooterLabel, Localize("Folder"), sizeof(aFooterLabel));
|
||||
else if(!m_lDemos[m_DemolistSelectedIndex].m_Valid)
|
||||
str_copy(aFooterLabel, Localize("Invalid Demo"), sizeof(aFooterLabel));
|
||||
else
|
||||
str_format(aFooterLabel, sizeof(aFooterLabel), "%s: %s", Localize("Map"), m_lDemos[m_DemolistSelectedIndex].m_aMap);
|
||||
}
|
||||
|
||||
// render background
|
||||
RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f);
|
||||
|
@ -490,7 +513,7 @@ void CMenus::RenderDemoList(CUIRect MainView)
|
|||
|
||||
static int s_DemoListId = 0;
|
||||
static float s_ScrollValue = 0;
|
||||
UiDoListboxStart(&s_DemoListId, &MainView, 17.0f, Localize("Demos"), "", m_lDemos.size(), 1, m_DemolistSelectedIndex, s_ScrollValue);
|
||||
UiDoListboxStart(&s_DemoListId, &MainView, 17.0f, Localize("Demos"), aFooterLabel, m_lDemos.size(), 1, m_DemolistSelectedIndex, s_ScrollValue);
|
||||
for(sorted_array<CDemoItem>::range r = m_lDemos.all(); !r.empty(); r.pop_front())
|
||||
{
|
||||
CListboxItem Item = UiDoListboxNextItem((void*)(&r.front()));
|
||||
|
@ -507,7 +530,7 @@ void CMenus::RenderDemoList(CUIRect MainView)
|
|||
DemolistPopulate();
|
||||
DemolistOnUpdate(false);
|
||||
}
|
||||
|
||||
|
||||
static int s_PlayButton = 0;
|
||||
if(DoButton_Menu(&s_PlayButton, m_DemolistSelectedIsDir?Localize("Open"):Localize("Play"), 0, &PlayRect) || Activated)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue