From 9a1853249bec348421a188ad275cf9d5126eefa8 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 30 Dec 2021 18:25:55 -0500 Subject: [PATCH] finally make the save option work --- res/Info.plist | 6 +++--- src/engine/engine.h | 4 ++-- src/gui/gui.cpp | 35 ++++++++++++++++++++++++++++++++--- src/gui/gui.h | 4 ++-- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/res/Info.plist b/res/Info.plist index a12cd6ae..7b00bf21 100644 --- a/res/Info.plist +++ b/res/Info.plist @@ -15,17 +15,17 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleLongVersionString - 1.0 + 0.2 CFBundleName Furnace CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + 0.2 CFBundleSignature ???? CFBundleVersion - 1.0 + 0.2 NSHumanReadableCopyright NSHighResolutionCapable diff --git a/src/engine/engine.h b/src/engine/engine.h index 5550f008..144165f5 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -9,8 +9,8 @@ #include #include -#define DIV_VERSION "0.1" -#define DIV_ENGINE_VERSION 11 +#define DIV_VERSION "0.2" +#define DIV_ENGINE_VERSION 12 enum DivStatusView { DIV_STATUS_NOTHING=0, diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 52505711..c10e1765 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -495,6 +495,7 @@ void FurnaceGUI::drawInsList() { if (ImGui::Begin("Instruments",&insListOpen)) { if (ImGui::Button(ICON_FA_PLUS "##InsAdd")) { curIns=e->addInstrument(); + modified=true; } ImGui::SameLine(); if (ImGui::ArrowButton("InsUp",ImGuiDir_Up)) { @@ -507,6 +508,7 @@ void FurnaceGUI::drawInsList() { ImGui::SameLine(); if (ImGui::Button(ICON_FA_TIMES "##InsDelete")) { e->delInstrument(curIns); + modified=true; if (curIns>=(int)e->song.ins.size()) { curIns--; } @@ -878,6 +880,7 @@ void FurnaceGUI::drawWaveList() { if (ImGui::Begin("Wavetables",&waveListOpen)) { if (ImGui::Button(ICON_FA_PLUS "##WaveAdd")) { curWave=e->addWave(); + modified=true; } ImGui::SameLine(); if (ImGui::ArrowButton("WaveUp",ImGuiDir_Up)) { @@ -890,6 +893,7 @@ void FurnaceGUI::drawWaveList() { ImGui::SameLine(); if (ImGui::Button(ICON_FA_TIMES "##WaveDelete")) { e->delWave(curWave); + modified=true; if (curWave>=(int)e->song.wave.size()) { curWave--; } @@ -958,6 +962,7 @@ void FurnaceGUI::drawSampleList() { if (ImGui::Begin("Samples",&sampleListOpen)) { if (ImGui::Button(ICON_FA_PLUS "##SampleAdd")) { curSample=e->addSample(); + modified=true; } ImGui::SameLine(); if (ImGui::Button(ICON_FA_FOLDER_OPEN "##SampleLoad")) { @@ -978,6 +983,7 @@ void FurnaceGUI::drawSampleList() { ImGui::SameLine(); if (ImGui::Button(ICON_FA_TIMES "##SampleDelete")) { e->delSample(curSample); + modified=true; if (curSample>=(int)e->song.sample.size()) { curSample--; } @@ -1775,6 +1781,7 @@ void FurnaceGUI::makeUndo(ActionType action) { break; } if (doPush) { + modified=true; undoHist.push_back(s); redoHist.clear(); if (undoHist.size()>maxUndoSteps) undoHist.pop_front(); @@ -2066,6 +2073,7 @@ void FurnaceGUI::doUndo() { if (undoHist.empty()) return; UndoStep& us=undoHist.back(); redoHist.push_back(us); + modified=true; switch (us.type) { case GUI_ACTION_CHANGE_SYSTEM: @@ -2106,6 +2114,7 @@ void FurnaceGUI::doRedo() { if (redoHist.empty()) return; UndoStep& us=redoHist.back(); undoHist.push_back(us); + modified=true; switch (us.type) { case GUI_ACTION_CHANGE_SYSTEM: @@ -2421,6 +2430,8 @@ int FurnaceGUI::save(String path) { #endif fclose(outFile); w->finish(); + curFileName=path; + modified=false; return 0; } @@ -2479,6 +2490,8 @@ int FurnaceGUI::load(String path) { return 1; } } + curFileName=path; + modified=false; lastError="everything OK"; undoHist.clear(); redoHist.clear(); @@ -2551,6 +2564,7 @@ bool FurnaceGUI::loop() { processDrags(ev.motion.x,ev.motion.y); break; case SDL_MOUSEBUTTONUP: + if (macroDragActive || macroLoopDragActive || waveDragActive) modified=true; macroDragActive=false; macroLoopDragActive=false; waveDragActive=false; @@ -2607,7 +2621,15 @@ bool FurnaceGUI::loop() { openFileDialog(GUI_FILE_OPEN); } ImGui::Separator(); - ImGui::MenuItem("save"); + if (ImGui::MenuItem("save")) { + if (curFileName=="") { + openFileDialog(GUI_FILE_SAVE); + } else { + if (save(curFileName)>0) { + showError(fmt::sprintf("Error while saving file! (%s)",lastError)); + } + } + } if (ImGui::MenuItem("save as...")) { openFileDialog(GUI_FILE_SAVE); } @@ -2674,12 +2696,17 @@ bool FurnaceGUI::loop() { } ImGui::EndMenu(); } + ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PLAYBACK_STAT]); if (e->isPlaying()) { - ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PLAYBACK_STAT]); int totalTicks=e->getTotalTicks(); int hz=e->getHz(); ImGui::Text("| Speed %d:%d | Order %d/%d | Row %d/%d | %d:%.2d:%.2d.%.2d",e->getSpeed1(),e->getSpeed2(),e->getOrder(),e->song.ordersLen,e->getRow(),e->song.patLen,totalTicks/(hz*3600),(totalTicks/(hz*60))%60,(totalTicks/hz)%60,(totalTicks%hz)*100/hz); - ImGui::PopStyleColor(); + } else { + if (curFileName!="") ImGui::Text("| %s",curFileName.c_str()); + } + ImGui::PopStyleColor(); + if (modified) { + ImGui::Text("| modified"); } ImGui::EndMainMenuBar(); @@ -2726,6 +2753,7 @@ bool FurnaceGUI::loop() { break; case GUI_FILE_SAMPLE_OPEN: e->addSampleFromFile(copyOfName.c_str()); + modified=true; break; case GUI_FILE_SAMPLE_SAVE: if (curSample>=0 && curSample<(int)e->song.sample.size()) { @@ -2878,6 +2906,7 @@ FurnaceGUI::FurnaceGUI(): quit(false), willCommit(false), edit(false), + modified(false), curFileDialog(GUI_FILE_OPEN), scrW(1280), scrH(800), diff --git a/src/gui/gui.h b/src/gui/gui.h index 53eae607..792875ed 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -131,9 +131,9 @@ class FurnaceGUI { SDL_Window* sdlWin; SDL_Renderer* sdlRend; - String workingDir, fileName, clipboard, errorString, lastError; + String workingDir, fileName, clipboard, errorString, lastError, curFileName; - bool quit, willCommit, edit; + bool quit, willCommit, edit, modified; FurnaceGUIFileDialogs curFileDialog;