diff --git a/src/scenedit/scen.core.cpp b/src/scenedit/scen.core.cpp index 3cc2911b..5f70b0d1 100644 --- a/src/scenedit/scen.core.cpp +++ b/src/scenedit/scen.core.cpp @@ -3972,8 +3972,12 @@ static bool edit_custom_sound_action(cDialog& me, std::string action, std::vecto } else if(action == "del") { if(which_snd - 100 < snd_names.size()) snd_names[which_snd - 100].clear(); + sf::SoundBuffer sound_for_undo; + sound_for_undo.loadFromFile(sndfile.string()); fs::remove(sndfile); me["name" + std::to_string(which_snd % 10)].setText(""); + + undo_list.add(action_ptr(new aCreateDeleteSound(false, which_snd, sound_for_undo))); } else if(action == "open") { fs::path fpath = nav_get_rsrc({"wav"}); if(fpath.empty()) return true; @@ -3982,6 +3986,14 @@ static bool edit_custom_sound_action(cDialog& me, std::string action, std::vecto beep(); return true; } + // Replace custom sound + if(fs::exists(sndfile)){ + + } + // First import + else{ + undo_list.add(action_ptr(new aCreateDeleteSound(true, which_snd, snd))); + } fs::copy_file(fpath, sndfile, fs::copy_options::overwrite_existing); ResMgr::sounds.free(sound_to_fname(which_snd)); if(which_snd > max_snd) @@ -4058,6 +4070,8 @@ void edit_custom_sounds() { get_sound_names_from_dlg(snd_dlg, snd_names, curPage); snd_names.swap(scenario.snd_names); } + + update_edit_menu(); } fs::path run_file_picker(bool saving){ diff --git a/src/scenedit/scen.undo.cpp b/src/scenedit/scen.undo.cpp index fdcf9a4b..e89f3fa0 100644 --- a/src/scenedit/scen.undo.cpp +++ b/src/scenedit/scen.undo.cpp @@ -4,6 +4,8 @@ #include "gfx/gfxsheets.hpp" #include "fileio/resmgr/res_image.hpp" +#include "fileio/resmgr/res_sound.hpp" +#include "sounds.hpp" #include "scenario/scenario.hpp" #include "scenario/area.hpp" @@ -835,3 +837,15 @@ bool aReplaceGraphicsSheet::redo_me() { return true; } + +extern fs::path get_snd_path(size_t index); + +bool aCreateDeleteSound::undo_me() { + fs::remove(get_snd_path(index).string()); + return true; +} + +bool aCreateDeleteSound::redo_me() { + ResMgr::sounds.free(sound_to_fname(index)); + return sound.saveToFile(get_snd_path(index).string()); +} diff --git a/src/scenedit/scen.undo.hpp b/src/scenedit/scen.undo.hpp index edba3432..65a2f973 100644 --- a/src/scenedit/scen.undo.hpp +++ b/src/scenedit/scen.undo.hpp @@ -1,6 +1,8 @@ #ifndef BoE_scen_undo_h #define BoE_scen_undo_h +#include + #include "location.hpp" #include "tools/undo.hpp" #include "scenario/town.hpp" @@ -487,4 +489,15 @@ public: cAction(name), index(index), old_image(old_image), new_image(new_image) {} }; +class aCreateDeleteSound : public cAction { + size_t index; + sf::SoundBuffer sound; + bool undo_me() override; + bool redo_me() override; +public: + aCreateDeleteSound(bool create, size_t index, sf::SoundBuffer sound) : + cAction(create ? "Import Custom Sound" : "Delete Custom Sound", !create), + index(index), sound(sound) {} +}; + #endif \ No newline at end of file