added Remove button in demos browser (#66)

This commit is contained in:
Choupom 2010-09-03 20:05:22 +02:00 committed by oy
parent 2800832e12
commit fcfaa8389f
5 changed files with 41 additions and 7 deletions

View file

@ -1,4 +1,5 @@
// copyright (c) 2007 magnus auvinen, see licence.txt for more info
#include <stdio.h> //remove()
#include <base/system.h>
#include <engine/storage.h>
#include "engine.h"
@ -193,6 +194,18 @@ public:
pBuffer[0] = 0;
return 0;
}
virtual bool RemoveFile(const char *pFilename)
{
char aBuffer[1024];
str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_aApplicationSavePath, pFilename);
bool Fail = remove(aBuffer);
if(Fail)
Fail = remove(pFilename);
return !Fail;
}
static IStorage *Create(const char *pApplicationName, int NumArgs, const char **ppArguments)
{

View file

@ -17,6 +17,7 @@ public:
virtual void ListDirectory(int Types, const char *pPath, FS_LISTDIR_CALLBACK pfnCallback, void *pUser) = 0;
virtual IOHANDLE OpenFile(const char *pFilename, int Flags, char *pBuffer = 0, int BufferSize = 0) = 0;
virtual bool RemoveFile(const char *pFilename) = 0;
};
extern IStorage *CreateStorage(const char *pApplicationName, int NumArgs, const char **ppArguments);

View file

@ -91,6 +91,7 @@ CMenus::CMenus()
m_EscapePressed = false;
m_EnterPressed = false;
m_DeletePressed = false;
m_NumInputEvents = 0;
m_LastInput = time_get();
@ -1029,9 +1030,14 @@ bool CMenus::OnInput(IInput::CEvent e)
if(IsActive())
{
// special for popups
if(e.m_Flags&IInput::FLAG_PRESS && e.m_Key == KEY_RETURN)
m_EnterPressed = true;
if(e.m_Flags&IInput::FLAG_PRESS)
{
// special for popups
if(e.m_Key == KEY_RETURN)
m_EnterPressed = true;
else if(e.m_Key == KEY_DELETE)
m_DeletePressed = true;
}
if(m_NumInputEvents < MAX_INPUTEVENTS)
m_aInputEvents[m_NumInputEvents++] = e;
@ -1116,6 +1122,7 @@ void CMenus::OnRender()
{
m_EscapePressed = false;
m_EnterPressed = false;
m_DeletePressed = false;
m_NumInputEvents = 0;
return;
}
@ -1183,6 +1190,7 @@ void CMenus::OnRender()
m_EscapePressed = false;
m_EnterPressed = false;
m_DeletePressed = false;
m_NumInputEvents = 0;
}

View file

@ -146,6 +146,7 @@ class CMenus : public CComponent
//
bool m_EscapePressed;
bool m_EnterPressed;
bool m_DeletePressed;
// for call vote
int m_CallvoteSelectedOption;

View file

@ -4,6 +4,7 @@
#include <engine/demo.h>
#include <engine/keys.h>
#include <engine/graphics.h>
#include <engine/storage.h>
#include <game/client/render.h>
#include <game/client/gameclient.h>
@ -472,10 +473,11 @@ void CMenus::RenderDemoList(CUIRect MainView)
bool Activated = false;
s_SelectedItem = UiDoListboxEnd(&s_ScrollValue, &Activated);
CUIRect RefreshRect, PlayRect;
ButtonBar.VSplitRight(250.0f, &ButtonBar, &RefreshRect);
RefreshRect.VSplitRight(130.0f, &RefreshRect, &PlayRect);
PlayRect.VSplitRight(120.0f, 0x0, &PlayRect);
CUIRect RefreshRect, PlayRect, DeleteRect;
ButtonBar.VSplitRight(130.0f, &ButtonBar, &PlayRect);
ButtonBar.VSplitLeft(130.0f, &RefreshRect, &ButtonBar);
ButtonBar.VSplitLeft(10.0f, &DeleteRect, &ButtonBar);
ButtonBar.VSplitLeft(120.0f, &DeleteRect, &ButtonBar);
bool IsDir = false;
if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size())
@ -524,6 +526,15 @@ void CMenus::RenderDemoList(CUIRect MainView)
}
}
static int s_DeleteButton = 0;
if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &DeleteRect) || m_DeletePressed)
{
if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size() && !IsDir)
{
Storage()->RemoveFile(m_lDemos[s_SelectedItem].m_aFilename);
DemolistPopulate();
}
}
}
void CMenus::DemoSetParentDirectory()