From aafee689ca5e9ecdc8e019bed1258676c217741a Mon Sep 17 00:00:00 2001 From: dobrykafe <121701317+dobrykafe@users.noreply.github.com> Date: Wed, 18 Oct 2023 13:27:31 +0200 Subject: [PATCH 1/4] stop/pause sound previews --- src/engine/client/client.cpp | 4 ++++ src/engine/editor.h | 1 + src/game/editor/editor.cpp | 34 +++++++++++++++++++++++++++++++++- src/game/editor/editor.h | 5 +++++ src/game/editor/popups.cpp | 4 ++++ 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 3de110b780e..e0ea2dd5f02 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -3182,7 +3182,11 @@ void CClient::Run() g_Config.m_DbgGraphs ^= 1; if(CtrlShiftKey(KEY_E, LastE)) + { + if(g_Config.m_ClEditor) + m_pEditor->OnClose(); g_Config.m_ClEditor = g_Config.m_ClEditor ^ 1; + } // render { diff --git a/src/engine/editor.h b/src/engine/editor.h index 9acefc5d43e..feaff50a1fa 100644 --- a/src/engine/editor.h +++ b/src/engine/editor.h @@ -14,6 +14,7 @@ class IEditor : public IInterface virtual void OnRender() = 0; virtual void OnActivate() = 0; virtual void OnWindowResize() = 0; + virtual void OnClose() = 0; virtual bool HasUnsavedData() const = 0; virtual bool HandleMapDrop(const char *pFilename, int StorageType) = 0; virtual bool Load(const char *pFilename, int StorageType) = 0; diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index ff93b072dce..92360bd9cc9 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -901,9 +901,16 @@ void CEditor::DoAudioPreview(CUIRect View, const void *pPlayPauseButtonID, const (m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_SPACE))) { if(Sound()->IsPlaying(SampleID)) + { Sound()->Pause(SampleID); + } else + { + if(SampleID != m_ToolbarPreviewSound && m_ToolbarPreviewSound && Sound()->IsPlaying(m_ToolbarPreviewSound)) + Sound()->Pause(m_ToolbarPreviewSound); + Sound()->Play(CSounds::CHN_GUI, SampleID, ISound::FLAG_PREVIEW); + } } } // stop button @@ -1340,12 +1347,14 @@ void CEditor::DoToolbarSounds(CUIRect ToolBar) CUIRect ToolBarTop, ToolBarBottom; ToolBar.HSplitMid(&ToolBarTop, &ToolBarBottom, 5.0f); + m_ToolbarPreviewSound = -1; if(m_SelectedSound >= 0 && (size_t)m_SelectedSound < m_Map.m_vpSounds.size()) { const std::shared_ptr pSelectedSound = m_Map.m_vpSounds[m_SelectedSound]; + m_ToolbarPreviewSound = pSelectedSound->m_SoundID; static int s_PlayPauseButton, s_StopButton, s_SeekBar = 0; - DoAudioPreview(ToolBarBottom, &s_PlayPauseButton, &s_StopButton, &s_SeekBar, pSelectedSound->m_SoundID); + DoAudioPreview(ToolBarBottom, &s_PlayPauseButton, &s_StopButton, &s_SeekBar, m_ToolbarPreviewSound); } } @@ -4062,6 +4071,11 @@ bool CEditor::AddSound(const char *pFileName, int StorageType, void *pUser) } } + if(pEditor->m_FilePreviewSound) + { + pEditor->Sound()->UnloadSample(pEditor->m_FilePreviewSound); + pEditor->m_FilePreviewSound = -1; + } pEditor->m_Dialog = DIALOG_NONE; return true; } @@ -4913,7 +4927,14 @@ void CEditor::RenderFileDialog() ButtonBar.VSplitRight(ButtonSpacing, &ButtonBar, nullptr); ButtonBar.VSplitRight(50.0f, &ButtonBar, &Button); if(DoButton_Editor(&s_CancelButton, "Cancel", 0, &Button, 0, nullptr) || (s_ListBox.Active() && UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))) + { + if(m_FilePreviewSound) + { + Sound()->UnloadSample(m_FilePreviewSound); + m_FilePreviewSound = -1; + } m_Dialog = DIALOG_NONE; + } ButtonBar.VSplitRight(ButtonSpacing, &ButtonBar, nullptr); ButtonBar.VSplitRight(50.0f, &ButtonBar, &Button); @@ -7157,7 +7178,10 @@ void CEditor::RenderMenubar(CUIRect MenuBar) static int s_CloseButton = 0; if(DoButton_Editor(&s_CloseButton, "×", 0, &Close, 0, "Exits from the editor") || (m_Dialog == DIALOG_NONE && !UI()->IsPopupOpen() && !m_PopupEventActivated && Input()->KeyPress(KEY_ESCAPE))) + { + OnClose(); g_Config.m_ClEditor = 0; + } } void CEditor::Render() @@ -7911,6 +7935,14 @@ void CEditor::OnWindowResize() UI()->OnWindowResize(); } +void CEditor::OnClose() +{ + if(m_ToolbarPreviewSound && Sound()->IsPlaying(m_ToolbarPreviewSound)) + Sound()->Pause(m_ToolbarPreviewSound); + if(m_FilePreviewSound && Sound()->IsPlaying(m_FilePreviewSound)) + Sound()->Pause(m_FilePreviewSound); +} + void CEditor::LoadCurrentMap() { if(Load(m_pClient->GetCurrentMapPath(), IStorage::TYPE_SAVE)) diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 8e3946f8f12..81dfd6d1429 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -356,6 +356,8 @@ class CEditor : public IEditor m_FilePreviewSound = -1; m_FilePreviewState = PREVIEW_UNLOADED; + m_ToolbarPreviewSound = -1; + m_SelectEntitiesImage = "DDNet"; m_ResetZoomEnvelope = true; @@ -416,6 +418,7 @@ class CEditor : public IEditor void OnRender() override; void OnActivate() override; void OnWindowResize() override; + void OnClose() override; bool HasUnsavedData() const override { return m_Map.m_Modified; } void UpdateMentions() override { m_Mentions++; } void ResetMentions() override { m_Mentions = 0; } @@ -568,6 +571,8 @@ class CEditor : public IEditor CImageInfo m_FilePreviewImageInfo; bool m_FileDialogOpening; + int m_ToolbarPreviewSound; + struct CFilelistItem { char m_aFilename[IO_MAX_PATH_LENGTH]; diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 9b3193badb0..15234c514c7 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -141,7 +141,10 @@ CUI::EPopupMenuFunctionResult CEditor::PopupMenuFile(void *pContext, CUIRect Vie pEditor->m_PopupEventActivated = true; } else + { + pEditor->OnClose(); g_Config.m_ClEditor = 0; + } return CUI::POPUP_CLOSE_CURRENT; } @@ -1972,6 +1975,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupEvent(void *pContext, CUIRect View, { if(pEditor->m_PopupEventType == POPEVENT_EXIT) { + pEditor->OnClose(); g_Config.m_ClEditor = 0; } else if(pEditor->m_PopupEventType == POPEVENT_LOAD) From 697bd8980df4a4c297097e1338ddc0a8047fdba3 Mon Sep 17 00:00:00 2001 From: dobrykafe <121701317+dobrykafe@users.noreply.github.com> Date: Wed, 18 Oct 2023 14:47:47 +0200 Subject: [PATCH 2/4] stop sound preview in more places --- src/game/editor/editor.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 92360bd9cc9..556a2f85046 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -884,6 +884,11 @@ bool CEditor::CallbackSaveSound(const char *pFileName, int StorageType, void *pU { io_write(File, pSound->m_pData, pSound->m_DataSize); io_close(File); + if(pEditor->m_FilePreviewSound) + { + pEditor->Sound()->UnloadSample(pEditor->m_FilePreviewSound); + pEditor->m_FilePreviewSound = -1; + } pEditor->m_Dialog = DIALOG_NONE; return true; } @@ -1347,15 +1352,18 @@ void CEditor::DoToolbarSounds(CUIRect ToolBar) CUIRect ToolBarTop, ToolBarBottom; ToolBar.HSplitMid(&ToolBarTop, &ToolBarBottom, 5.0f); - m_ToolbarPreviewSound = -1; if(m_SelectedSound >= 0 && (size_t)m_SelectedSound < m_Map.m_vpSounds.size()) { const std::shared_ptr pSelectedSound = m_Map.m_vpSounds[m_SelectedSound]; + if(pSelectedSound->m_SoundID != m_ToolbarPreviewSound && m_ToolbarPreviewSound && Sound()->IsPlaying(m_ToolbarPreviewSound)) + Sound()->Stop(m_ToolbarPreviewSound); m_ToolbarPreviewSound = pSelectedSound->m_SoundID; static int s_PlayPauseButton, s_StopButton, s_SeekBar = 0; DoAudioPreview(ToolBarBottom, &s_PlayPauseButton, &s_StopButton, &s_SeekBar, m_ToolbarPreviewSound); } + else + m_ToolbarPreviewSound = -1; } static void Rotate(const CPoint *pCenter, CPoint *pPoint, float Rotation) From c304b3eef8f0eda6ff5d376a9dad73eb7dc3b7e0 Mon Sep 17 00:00:00 2001 From: dobrykafe <121701317+dobrykafe@users.noreply.github.com> Date: Mon, 23 Oct 2023 12:48:53 +0200 Subject: [PATCH 3/4] extract `CEditor::OnDialogClose` --- src/engine/editor.h | 1 + src/game/editor/editor.cpp | 27 ++++++++++++--------------- src/game/editor/editor.h | 1 + 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/engine/editor.h b/src/engine/editor.h index feaff50a1fa..a8f8b16ae27 100644 --- a/src/engine/editor.h +++ b/src/engine/editor.h @@ -15,6 +15,7 @@ class IEditor : public IInterface virtual void OnActivate() = 0; virtual void OnWindowResize() = 0; virtual void OnClose() = 0; + virtual void OnDialogClose() = 0; virtual bool HasUnsavedData() const = 0; virtual bool HandleMapDrop(const char *pFilename, int StorageType) = 0; virtual bool Load(const char *pFilename, int StorageType) = 0; diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 556a2f85046..f212c6c96bb 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -884,11 +884,7 @@ bool CEditor::CallbackSaveSound(const char *pFileName, int StorageType, void *pU { io_write(File, pSound->m_pData, pSound->m_DataSize); io_close(File); - if(pEditor->m_FilePreviewSound) - { - pEditor->Sound()->UnloadSample(pEditor->m_FilePreviewSound); - pEditor->m_FilePreviewSound = -1; - } + pEditor->OnDialogClose(); pEditor->m_Dialog = DIALOG_NONE; return true; } @@ -4079,11 +4075,7 @@ bool CEditor::AddSound(const char *pFileName, int StorageType, void *pUser) } } - if(pEditor->m_FilePreviewSound) - { - pEditor->Sound()->UnloadSample(pEditor->m_FilePreviewSound); - pEditor->m_FilePreviewSound = -1; - } + pEditor->OnDialogClose(); pEditor->m_Dialog = DIALOG_NONE; return true; } @@ -4936,11 +4928,7 @@ void CEditor::RenderFileDialog() ButtonBar.VSplitRight(50.0f, &ButtonBar, &Button); if(DoButton_Editor(&s_CancelButton, "Cancel", 0, &Button, 0, nullptr) || (s_ListBox.Active() && UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))) { - if(m_FilePreviewSound) - { - Sound()->UnloadSample(m_FilePreviewSound); - m_FilePreviewSound = -1; - } + OnDialogClose(); m_Dialog = DIALOG_NONE; } @@ -7951,6 +7939,15 @@ void CEditor::OnClose() Sound()->Pause(m_FilePreviewSound); } +void CEditor::OnDialogClose() +{ + if(m_FilePreviewSound) + { + Sound()->UnloadSample(m_FilePreviewSound); + m_FilePreviewSound = -1; + } +} + void CEditor::LoadCurrentMap() { if(Load(m_pClient->GetCurrentMapPath(), IStorage::TYPE_SAVE)) diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 81dfd6d1429..f3c20c3d3aa 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -419,6 +419,7 @@ class CEditor : public IEditor void OnActivate() override; void OnWindowResize() override; void OnClose() override; + void OnDialogClose() override; bool HasUnsavedData() const override { return m_Map.m_Modified; } void UpdateMentions() override { m_Mentions++; } void ResetMentions() override { m_Mentions = 0; } From 35e5c114bac56012c02cb9852b093f1311381239 Mon Sep 17 00:00:00 2001 From: dobrykafe <121701317+dobrykafe@users.noreply.github.com> Date: Mon, 23 Oct 2023 12:50:59 +0200 Subject: [PATCH 4/4] stop sound preview in more places --- src/game/editor/editor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index f212c6c96bb..41bb14c408d 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -4127,6 +4127,7 @@ bool CEditor::ReplaceSound(const char *pFileName, int StorageType, bool CheckDup pSound->m_pData = pData; pSound->m_DataSize = DataSize; + OnDialogClose(); m_Dialog = DIALOG_NONE; return true; }