diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 90862b31398..6fe4a17bbf8 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -2983,7 +2983,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..a8f8b16ae27 100644 --- a/src/engine/editor.h +++ b/src/engine/editor.h @@ -14,6 +14,8 @@ class IEditor : public IInterface virtual void OnRender() = 0; 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 ff93b072dce..41bb14c408d 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -884,6 +884,7 @@ bool CEditor::CallbackSaveSound(const char *pFileName, int StorageType, void *pU { io_write(File, pSound->m_pData, pSound->m_DataSize); io_close(File); + pEditor->OnDialogClose(); pEditor->m_Dialog = DIALOG_NONE; return true; } @@ -901,9 +902,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 @@ -1343,10 +1351,15 @@ void CEditor::DoToolbarSounds(CUIRect ToolBar) 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, pSelectedSound->m_SoundID); + DoAudioPreview(ToolBarBottom, &s_PlayPauseButton, &s_StopButton, &s_SeekBar, m_ToolbarPreviewSound); } + else + m_ToolbarPreviewSound = -1; } static void Rotate(const CPoint *pCenter, CPoint *pPoint, float Rotation) @@ -4062,6 +4075,7 @@ bool CEditor::AddSound(const char *pFileName, int StorageType, void *pUser) } } + pEditor->OnDialogClose(); pEditor->m_Dialog = DIALOG_NONE; return true; } @@ -4113,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; } @@ -4913,7 +4928,10 @@ 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))) + { + OnDialogClose(); m_Dialog = DIALOG_NONE; + } ButtonBar.VSplitRight(ButtonSpacing, &ButtonBar, nullptr); ButtonBar.VSplitRight(50.0f, &ButtonBar, &Button); @@ -7157,7 +7175,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 +7932,23 @@ 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::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 8e3946f8f12..f3c20c3d3aa 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,8 @@ class CEditor : public IEditor void OnRender() override; 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; } @@ -568,6 +572,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)