Replace POPUP_REPLACE_VIDEO with generic confirmation popup

And show the name of the video that will be overwriten in the popup.

Make the buttons in `POPUP_RENDER_DEMO` the same height as in all other popups.
This commit is contained in:
Robert Müller 2022-11-30 23:21:36 +01:00
parent 8da68bf52a
commit cb1d9ccc98
2 changed files with 21 additions and 50 deletions

View file

@ -1569,11 +1569,6 @@ int CMenus::Render()
{ {
pTitle = Localize("Render demo"); pTitle = Localize("Render demo");
} }
else if(m_Popup == POPUP_REPLACE_VIDEO)
{
pTitle = Localize("Replace video");
pExtraText = Localize("File already exists, do you want to overwrite it?");
}
#endif #endif
else if(m_Popup == POPUP_PASSWORD) else if(m_Popup == POPUP_PASSWORD)
{ {
@ -1969,7 +1964,7 @@ int CMenus::Render()
#if defined(CONF_VIDEORECORDER) #if defined(CONF_VIDEORECORDER)
else if(m_Popup == POPUP_RENDER_DEMO) else if(m_Popup == POPUP_RENDER_DEMO)
{ {
CUIRect Label, TextBox, Ok, Abort, IncSpeed, DecSpeed, Button, Buttons; CUIRect Label, TextBox, Ok, Abort, IncSpeed, DecSpeed, Button;
Box.HSplitBottom(20.f, &Box, &Part); Box.HSplitBottom(20.f, &Box, &Part);
#if defined(__ANDROID__) #if defined(__ANDROID__)
@ -1979,8 +1974,7 @@ int CMenus::Render()
#endif #endif
Part.VMargin(80.0f, &Part); Part.VMargin(80.0f, &Part);
Part.HSplitBottom(20.0f, &Part, &Buttons); Part.VSplitMid(&Abort, &Ok);
Buttons.VSplitMid(&Abort, &Ok);
Ok.VMargin(20.0f, &Ok); Ok.VMargin(20.0f, &Ok);
Abort.VMargin(20.0f, &Abort); Abort.VMargin(20.0f, &Abort);
@ -1996,22 +1990,19 @@ int CMenus::Render()
// name video // name video
if(m_DemolistSelectedIndex >= 0 && !m_DemolistSelectedIsDir) if(m_DemolistSelectedIndex >= 0 && !m_DemolistSelectedIsDir)
{ {
char aBufOld[IO_MAX_PATH_LENGTH];
str_format(aBufOld, sizeof(aBufOld), "%s/%s", m_aCurrentDemoFolder, m_vDemos[m_DemolistSelectedIndex].m_aFilename);
if(!str_endswith(m_aCurrentDemoFile, ".mp4")) if(!str_endswith(m_aCurrentDemoFile, ".mp4"))
str_append(m_aCurrentDemoFile, ".mp4", sizeof(m_aCurrentDemoFile)); str_append(m_aCurrentDemoFile, ".mp4", sizeof(m_aCurrentDemoFile));
char aWholePath[IO_MAX_PATH_LENGTH]; char aWholePath[IO_MAX_PATH_LENGTH];
// store new video filename to origin buffer // store new video filename to origin buffer
if(Storage()->FindFile(m_aCurrentDemoFile, "videos", IStorage::TYPE_ALL, aWholePath, sizeof(aWholePath))) if(Storage()->FindFile(m_aCurrentDemoFile, "videos", IStorage::TYPE_ALL, aWholePath, sizeof(aWholePath)))
{ {
m_Popup = POPUP_REPLACE_VIDEO; char aMessage[128 + IO_MAX_PATH_LENGTH];
str_format(aMessage, sizeof(aMessage), Localize("File '%s' already exists, do you want to overwrite it?"), m_aCurrentDemoFile);
PopupConfirm(Localize("Replace video"), aMessage, Localize("Yes"), Localize("No"), &CMenus::PopupConfirmDemoReplaceVideo, POPUP_NONE, &CMenus::DefaultButtonCallback, POPUP_RENDER_DEMO);
} }
else else
{ {
const char *pError = Client()->DemoPlayer_Render(aBufOld, m_vDemos[m_DemolistSelectedIndex].m_StorageType, m_aCurrentDemoFile, m_Speed); PopupConfirmDemoReplaceVideo();
m_Speed = 4;
if(pError)
PopupMessage(Localize("Error"), str_comp(pError, "error loading demo") ? pError : Localize("Error loading demo"), Localize("Ok"));
} }
} }
} }
@ -2082,38 +2073,6 @@ int CMenus::Render()
static float s_Offset = 0.0f; static float s_Offset = 0.0f;
UI()->DoEditBox(&s_Offset, &TextBox, m_aCurrentDemoFile, sizeof(m_aCurrentDemoFile), 12.0f, &s_Offset); UI()->DoEditBox(&s_Offset, &TextBox, m_aCurrentDemoFile, sizeof(m_aCurrentDemoFile), 12.0f, &s_Offset);
} }
else if(m_Popup == POPUP_REPLACE_VIDEO)
{
CUIRect Yes, No;
Box.HSplitBottom(20.f, &Box, &Part);
#if defined(__ANDROID__)
Box.HSplitBottom(60.f, &Box, &Part);
#else
Box.HSplitBottom(24.f, &Box, &Part);
#endif
Part.VMargin(80.0f, &Part);
Part.VSplitMid(&No, &Yes);
Yes.VMargin(20.0f, &Yes);
No.VMargin(20.0f, &No);
static CButtonContainer s_ButtonAbort;
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
m_Popup = POPUP_RENDER_DEMO;
static CButtonContainer s_ButtonTryAgain;
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
{
m_Popup = POPUP_NONE;
// render video
str_format(aBuf, sizeof(aBuf), "%s/%s", m_aCurrentDemoFolder, m_vDemos[m_DemolistSelectedIndex].m_aFilename);
const char *pError = Client()->DemoPlayer_Render(aBuf, m_vDemos[m_DemolistSelectedIndex].m_StorageType, m_aCurrentDemoFile, m_Speed);
m_Speed = 4;
if(pError)
PopupMessage(Localize("Error"), str_comp(pError, "error loading demo") ? pError : Localize("Error loading demo"), Localize("Ok"));
}
}
#endif #endif
else if(m_Popup == POPUP_FIRST_LAUNCH) else if(m_Popup == POPUP_FIRST_LAUNCH)
{ {
@ -2244,6 +2203,18 @@ int CMenus::Render()
return 0; return 0;
} }
#if defined(CONF_VIDEORECORDER)
void CMenus::PopupConfirmDemoReplaceVideo()
{
char aBuf[IO_MAX_PATH_LENGTH];
str_format(aBuf, sizeof(aBuf), "%s/%s", m_aCurrentDemoFolder, m_vDemos[m_DemolistSelectedIndex].m_aFilename);
const char *pError = Client()->DemoPlayer_Render(aBuf, m_vDemos[m_DemolistSelectedIndex].m_StorageType, m_aCurrentDemoFile, m_Speed);
m_Speed = 4;
if(pError)
PopupMessage(Localize("Error"), str_comp(pError, "error loading demo") ? pError : Localize("Error loading demo"), Localize("Ok"));
}
#endif
void CMenus::RenderThemeSelection(CUIRect MainView, bool Header) void CMenus::RenderThemeSelection(CUIRect MainView, bool Header)
{ {
std::vector<CTheme> &vThemesRef = m_pBackground->GetThemes(); std::vector<CTheme> &vThemesRef = m_pBackground->GetThemes();

View file

@ -508,8 +508,9 @@ protected:
// found in menus.cpp // found in menus.cpp
int Render(); int Render();
//void render_background(); #if defined(CONF_VIDEORECORDER)
//void render_loading(float percent); void PopupConfirmDemoReplaceVideo();
#endif
int RenderMenubar(CUIRect r); int RenderMenubar(CUIRect r);
void RenderNews(CUIRect MainView); void RenderNews(CUIRect MainView);
static void ConchainUpdateMusicState(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); static void ConchainUpdateMusicState(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
@ -727,7 +728,6 @@ public:
POPUP_COUNTRY, POPUP_COUNTRY,
POPUP_RENAME_DEMO, POPUP_RENAME_DEMO,
POPUP_RENDER_DEMO, POPUP_RENDER_DEMO,
POPUP_REPLACE_VIDEO,
POPUP_PASSWORD, POPUP_PASSWORD,
POPUP_QUIT, POPUP_QUIT,
POPUP_WARNING, POPUP_WARNING,