about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2010-06-06 14:53:55 +0200
committerMagnus Auvinen <magnus.auvinen@gmail.com>2010-06-06 14:53:55 +0200
commit7d03e70d1e6b0cd0b55c741d90b33fd4e2e51cb5 (patch)
tree047c6cbbee087cbbe83a1f2fc287c1bbfab385ef /src
parent4ca43196d7e56fa155625c95ff33ad31ad3651b7 (diff)
parent747d972d389ab39ad712a766b9ca5e0598f87b21 (diff)
downloadzcatch-7d03e70d1e6b0cd0b55c741d90b33fd4e2e51cb5.tar.gz
zcatch-7d03e70d1e6b0cd0b55c741d90b33fd4e2e51cb5.zip
Merge remote branch 'choupom/master'
Diffstat (limited to 'src')
-rw-r--r--src/base/system.c3
-rw-r--r--src/engine/server/server.cpp10
-rw-r--r--src/game/client/components/menus.cpp2
-rw-r--r--src/game/client/components/menus.h7
-rw-r--r--src/game/client/components/menus_demo.cpp82
5 files changed, 90 insertions, 14 deletions
diff --git a/src/base/system.c b/src/base/system.c
index 47893aa3..a1a1b33e 100644
--- a/src/base/system.c
+++ b/src/base/system.c
@@ -863,8 +863,7 @@ int fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, void *user)
 	/* add all the entries */
 	do
 	{
-		if(finddata.cFileName[0] != '.')
-			cb(finddata.cFileName, 0, user);
+		cb(finddata.cFileName, 0, user);
 	} while (FindNextFileA(handle, &finddata));
 
 	FindClose(handle);
diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp
index 6dd5a959..96071ceb 100644
--- a/src/engine/server/server.cpp
+++ b/src/engine/server/server.cpp
@@ -552,8 +552,16 @@ int CServer::DelClientCallback(int ClientId, void *pUser)
 
 void CServer::SendMap(int ClientId)
 {
+	//get the name of the map without his path
+	char * pMapShortName = &g_Config.m_SvMap[0];
+	for(int i = 0; i < 128; i++)
+	{
+		if(g_Config.m_SvMap[i] == '/' || g_Config.m_SvMap[i] == '\\' && i+1 < 128)
+			pMapShortName = &g_Config.m_SvMap[i+1];
+	}
+	
 	CMsgPacker Msg(NETMSG_MAP_CHANGE);
-	Msg.AddString(g_Config.m_SvMap, 0);
+	Msg.AddString(pMapShortName, 0);
 	Msg.AddInt(m_CurrentMapCrc);
 	SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientId, true);
 }
diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp
index fc919409..76943620 100644
--- a/src/game/client/components/menus.cpp
+++ b/src/game/client/components/menus.cpp
@@ -94,6 +94,8 @@ CMenus::CMenus()
 	m_NumInputEvents = 0;
 	
 	m_LastInput = time_get();
+	
+	str_copy(m_aCurrentDemoFolder, "demos", sizeof(m_aCurrentDemoFolder));
 }
 
 vec4 CMenus::ButtonColorMul(const void *pID)
diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h
index c09e6e96..229fce80 100644
--- a/src/game/client/components/menus.h
+++ b/src/game/client/components/menus.h
@@ -160,11 +160,14 @@ class CMenus : public CComponent
 	};
 	
 	sorted_array<CDemoItem> m_lDemos;
-		
+	char m_aCurrentDemoFolder[256];
+	
 	void DemolistPopulate();
 	static void DemolistCountCallback(const char *pName, int IsDir, void *pUser);
 	static void DemolistFetchCallback(const char *pName, int IsDir, void *pUser);
-
+	static void IsDirCallback(const char *pName, int IsDir, void *pUser);
+	void DemoSetParentDirectory();
+	
 	// found in menus.cpp
 	int Render();
 	//void render_background();
diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp
index f3a6bc88..ec1ead8e 100644
--- a/src/game/client/components/menus_demo.cpp
+++ b/src/game/client/components/menus_demo.cpp
@@ -1,4 +1,5 @@
 
+#include <string.h>
 #include <base/math.h>
 
 
@@ -390,17 +391,32 @@ void CMenus::DemolistFetchCallback(const char *pName, int IsDir, void *pUser)
 	pInfo->m_pSelf->m_lDemos.add(Item);
 }
 
+void CMenus::IsDirCallback(const char *pName, int IsDir, void *pUser)
+{
+	*((bool *)pUser) = true;
+}
+
 void CMenus::DemolistPopulate()
 {
 	m_lDemos.clear();
 	
+	
+	if(strncmp(m_aCurrentDemoFolder, "demos", 256)) //add parent folder
+	{
+		CDemoItem Item;
+		str_copy(Item.m_aName, "..", sizeof(Item.m_aName));
+		str_copy(Item.m_aFilename, "..", sizeof(Item.m_aFilename));
+		m_lDemos.add(Item);
+	}
+	
+	
 	char aBuf[512];
-	str_format(aBuf, sizeof(aBuf), "%s/demos", Client()->UserDirectory());
-
+	str_format(aBuf, sizeof(aBuf), "%s/%s", Client()->UserDirectory(), m_aCurrentDemoFolder);
+	
 	FETCH_CALLBACKINFO Info = {this, aBuf, 0};
 	fs_listdir(aBuf, DemolistFetchCallback, &Info);
-	Info.m_pPrefix = "demos";
-	fs_listdir("demos", DemolistFetchCallback, &Info);
+	Info.m_pPrefix = m_aCurrentDemoFolder;
+	fs_listdir(m_aCurrentDemoFolder, DemolistFetchCallback, &Info);
 }
 
 
@@ -439,22 +455,70 @@ void CMenus::RenderDemoList(CUIRect MainView)
 	RefreshRect.VSplitRight(130.0f, &RefreshRect, &PlayRect);
 	PlayRect.VSplitRight(120.0f, 0x0, &PlayRect);
 	
+	
+	bool IsDir = false;
+	if(!strncmp(m_lDemos[s_SelectedItem].m_aName, "..", 256)) //parent folder
+		IsDir = true;
+	else
+		fs_listdir(m_lDemos[s_SelectedItem].m_aFilename, IsDirCallback, &IsDir);
+	
+	
 	static int s_RefreshButton = 0;
 	if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &RefreshRect))
 	{
 		DemolistPopulate();
 	}
-		
+	
 	static int s_PlayButton = 0;
-	if(DoButton_Menu(&s_PlayButton, Localize("Play"), 0, &PlayRect) || Activated)
+	char aTitleButton[8];
+	if(IsDir)
+		str_copy(aTitleButton, "Open", sizeof(aTitleButton));
+	else
+		str_copy(aTitleButton, "Play", sizeof(aTitleButton));
+	// /!\ TODO: Add "Open" in Localization /!\ 
+	if(DoButton_Menu(&s_PlayButton, Localize(aTitleButton), 0, &PlayRect) || Activated)
 	{		
 		if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size())
 		{
-			const char *pError = Client()->DemoPlayer_Play(m_lDemos[s_SelectedItem].m_aFilename);
-			if(pError)
-				PopupMessage(Localize("Error"), Localize(pError), Localize("Ok"));
+			if(!strncmp(m_lDemos[s_SelectedItem].m_aName, "..", 256))
+			{
+				DemoSetParentDirectory();
+				DemolistPopulate();
+				s_SelectedItem = 0;
+			}
+			else if(IsDir)
+			{
+				str_format(m_aCurrentDemoFolder, sizeof(m_aCurrentDemoFolder), "%s/%s", m_aCurrentDemoFolder, m_lDemos[s_SelectedItem].m_aName);
+				DemolistPopulate();
+				s_SelectedItem = 0;
+			}
+			else
+			{
+				const char *pError = Client()->DemoPlayer_Play(m_lDemos[s_SelectedItem].m_aFilename);
+				if(pError)
+					PopupMessage(Localize("Error"), pError, Localize("Ok"));
+			}
 		}
 	}
 	
 }
 
+
+
+void CMenus::DemoSetParentDirectory()
+{
+	int Stop = 0;
+	int i;
+	for(i = 0; i < 256; i++)
+	{
+		if(m_aCurrentDemoFolder[i] == '/')
+			Stop = i;
+	}
+	
+	//keeps chars which are before the last '/' and remove chars which are after
+	for(i = 0; i < 256; i++)
+	{
+		if(i >= Stop)
+			m_aCurrentDemoFolder[i] = NULL;
+	}
+}