about summary refs log tree commit diff
path: root/src/game
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/game
parent4ca43196d7e56fa155625c95ff33ad31ad3651b7 (diff)
parent747d972d389ab39ad712a766b9ca5e0598f87b21 (diff)
downloadzcatch-7d03e70d1e6b0cd0b55c741d90b33fd4e2e51cb5.tar.gz
zcatch-7d03e70d1e6b0cd0b55c741d90b33fd4e2e51cb5.zip
Merge remote branch 'choupom/master'
Diffstat (limited to 'src/game')
-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
3 files changed, 80 insertions, 11 deletions
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;
+	}
+}