From 4bbfc22c2a4ce4281eddd6b1974e5eaedf4d6d1d Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 9 Jan 2022 16:36:47 -0500 Subject: [PATCH] GUI: add/remove options --- src/engine/engine.cpp | 29 ++++++++++++++++++++- src/gui/gui.cpp | 59 ++++++++++++++++++++++++++++++------------- src/gui/gui.h | 2 +- 3 files changed, 70 insertions(+), 20 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index cb5ab8cf8..38149e462 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -946,6 +946,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { ds.arpLen=reader.readC(); ds.hz=reader.readF(); ds.pal=(ds.hz>=53); + if (ds.hz!=50 && ds.hz!=60) ds.customTempo=true; ds.patLen=reader.readS(); ds.ordersLen=reader.readS(); @@ -2168,7 +2169,7 @@ void DivEngine::changeSystem(int index, DivSystem which) { bool DivEngine::addSystem(DivSystem which) { if (song.systemLen>32) { - lastError="cannot add more than 32 systems"; + lastError="cannot add more than 32"; return false; } if (chans+getChannelCount(which)>DIV_MAX_CHANS) { @@ -2188,6 +2189,32 @@ bool DivEngine::addSystem(DivSystem which) { return true; } +bool DivEngine::removeSystem(int index) { + if (song.systemLen<=1) { + lastError="cannot remove the last one"; + return false; + } + if (index<0 || index>=song.systemLen) { + lastError="invalid index"; + return false; + } + quitDispatch(); + isBusy.lock(); + song.system[index]=DIV_SYSTEM_NULL; + song.systemLen--; + for (int i=index; iOpenModal("FileDialog","Open File","Furnace song{.fur},DefleMask module{.dmf},.*",workingDir); + ImGuiFileDialog::Instance()->OpenModal("FileDialog","Open File","compatible files{.fur,.dmf},.*",workingDir); break; case GUI_FILE_SAVE: ImGuiFileDialog::Instance()->OpenModal("FileDialog","Save File","Furnace song{.fur},DefleMask module{.dmf}",workingDir); @@ -2524,7 +2524,7 @@ void FurnaceGUI::showWarning(String what, FurnaceGUIWarnings type) { void FurnaceGUI::showError(String what) { errorString=what; - ImGui::OpenPopup("Error"); + displayError=true; } void FurnaceGUI::processDrags(int dragX, int dragY) { @@ -2563,14 +2563,14 @@ void FurnaceGUI::processDrags(int dragX, int dragY) { #define sysAddOption(x) \ if (ImGui::MenuItem(e->getSystemName(x))) { \ if (!e->addSystem(x)) { \ - showError("cannot add system! ("+e->getLastError()+")"); \ + showError("cannot add platform! ("+e->getLastError()+")"); \ } \ updateWindowTitle(); \ } -#define sysChangeOption(x) \ - if (ImGui::MenuItem(e->getSystemName(x),NULL,e->song.system[0]==x)) { \ - e->changeSystem(0,x); \ +#define sysChangeOption(x,y) \ + if (ImGui::MenuItem(e->getSystemName(y),NULL,e->song.system[x]==y)) { \ + e->changeSystem(x,y); \ updateWindowTitle(); \ } @@ -2654,6 +2654,7 @@ bool FurnaceGUI::loop() { redoHist.clear(); curFileName=""; modified=false; + updateWindowTitle(); } } if (ImGui::MenuItem("open...")) { @@ -2691,18 +2692,33 @@ bool FurnaceGUI::loop() { sysAddOption(DIV_SYSTEM_YM2610_EXT); ImGui::EndMenu(); } - if (ImGui::BeginMenu("change first platform...")) { - sysChangeOption(DIV_SYSTEM_GENESIS); - sysChangeOption(DIV_SYSTEM_GENESIS_EXT); - sysChangeOption(DIV_SYSTEM_SMS); - sysChangeOption(DIV_SYSTEM_GB); - sysChangeOption(DIV_SYSTEM_PCE); - sysChangeOption(DIV_SYSTEM_NES); - sysChangeOption(DIV_SYSTEM_C64_8580); - sysChangeOption(DIV_SYSTEM_C64_6581); - sysChangeOption(DIV_SYSTEM_ARCADE); - sysChangeOption(DIV_SYSTEM_YM2610); - sysChangeOption(DIV_SYSTEM_YM2610_EXT); + if (ImGui::BeginMenu("change platform...")) { + for (int i=0; isong.systemLen; i++) { + if (ImGui::BeginMenu(fmt::sprintf("%d. %s##_SYSC%d",i+1,e->getSystemName(e->song.system[i]),i).c_str())) { + sysChangeOption(i,DIV_SYSTEM_GENESIS); + sysChangeOption(i,DIV_SYSTEM_GENESIS_EXT); + sysChangeOption(i,DIV_SYSTEM_SMS); + sysChangeOption(i,DIV_SYSTEM_GB); + sysChangeOption(i,DIV_SYSTEM_PCE); + sysChangeOption(i,DIV_SYSTEM_NES); + sysChangeOption(i,DIV_SYSTEM_C64_8580); + sysChangeOption(i,DIV_SYSTEM_C64_6581); + sysChangeOption(i,DIV_SYSTEM_ARCADE); + sysChangeOption(i,DIV_SYSTEM_YM2610); + sysChangeOption(i,DIV_SYSTEM_YM2610_EXT); + ImGui::EndMenu(); + } + } + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("remove platform...")) { + for (int i=0; isong.systemLen; i++) { + if (ImGui::MenuItem(fmt::sprintf("%d. %s##_SYSR%d",i+1,e->getSystemName(e->song.system[i]),i).c_str())) { + if (!e->removeSystem(i)) { + showError("cannot remove platform! ("+e->getLastError()+")"); + } + } + } ImGui::EndMenu(); } ImGui::Separator(); @@ -2845,6 +2861,11 @@ bool FurnaceGUI::loop() { ImGui::OpenPopup("Warning"); } + if (displayError) { + displayError=false; + ImGui::OpenPopup("Error"); + } + if (aboutOpen) drawAbout(); if (ImGui::BeginPopupModal("Error",NULL,ImGuiWindowFlags_AlwaysAutoResize)) { @@ -2869,6 +2890,7 @@ bool FurnaceGUI::loop() { redoHist.clear(); curFileName=""; modified=false; + updateWindowTitle(); break; case GUI_WARN_OPEN: openFileDialog(GUI_FILE_OPEN); @@ -3059,6 +3081,7 @@ FurnaceGUI::FurnaceGUI(): willCommit(false), edit(false), modified(false), + displayError(false), curFileDialog(GUI_FILE_OPEN), warnAction(GUI_WARN_OPEN), scrW(1280), diff --git a/src/gui/gui.h b/src/gui/gui.h index 93fba3c2a..a2c29e5d5 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -137,7 +137,7 @@ class FurnaceGUI { String workingDir, fileName, clipboard, warnString, errorString, lastError, curFileName; - bool quit, warnQuit, willCommit, edit, modified; + bool quit, warnQuit, willCommit, edit, modified, displayError; FurnaceGUIFileDialogs curFileDialog; FurnaceGUIWarnings warnAction;