diff --git a/src/frontend/KaizenGui.cpp b/src/frontend/KaizenGui.cpp index 3302ec6e..2e55e555 100644 --- a/src/frontend/KaizenGui.cpp +++ b/src/frontend/KaizenGui.cpp @@ -34,6 +34,23 @@ void KaizenGui::QueryDevices(SDL_Event event) { } } +void KaizenGui::FileDialog() { + NFD::Guard guard; + NFD::UniquePath path; + static const std::vector filterItems = { + {"Nintendo 64 rom archive", "rar,RAR,tar,TAR,zip,ZIP,7z,7Z"}, + {"Nintendo 64 rom", "n64,z64,v64,N64,Z64,V64"} + }; + + auto result = NFD::OpenDialog(path, filterItems.data(), filterItems.size()); + if(result == NFD_ERROR) + Util::panic("Error: {}", NFD::GetError()); + + if(result != NFD_CANCEL) { + LoadROM(path.get()); + } +} + void KaizenGui::HandleInput(SDL_Event event) { n64::PIF &pif = core->cpu->GetMem().mmio.si.pif; switch(event.type) { @@ -90,6 +107,24 @@ void KaizenGui::HandleInput(SDL_Event event) { break; { auto keys = SDL_GetKeyboardState(nullptr); + if((keys[SDL_SCANCODE_LCTRL] || keys[SDL_SCANCODE_RCTRL]) && keys[SDL_SCANCODE_O]) { + FileDialog(); + } + + if(core->romLoaded) { + if(keys[SDL_SCANCODE_P]) { + emuThread.TogglePause(); + } + + if(keys[SDL_SCANCODE_R]) { + emuThread.Reset(); + } + + if(keys[SDL_SCANCODE_Q]) { + emuThread.Stop(); + } + } + pif.UpdateButton(0, n64::Controller::Key::Z, keys[SDL_SCANCODE_Z]); pif.UpdateButton(0, n64::Controller::Key::CUp, keys[SDL_SCANCODE_HOME]); pif.UpdateButton(0, n64::Controller::Key::CDown, keys[SDL_SCANCODE_END]); @@ -115,26 +150,10 @@ void KaizenGui::HandleInput(SDL_Event event) { void KaizenGui::RenderUI() { gui::StartFrame(); - static bool actionsEnabled = false; - if(ImGui::BeginMainMenuBar()) { if(ImGui::BeginMenu("File")) { - if(ImGui::MenuItem("Open")) { - NFD::Guard guard; - NFD::UniquePath path; - static const std::vector filterItems = { - {"Nintendo 64 rom archive", "rar,RAR,tar,TAR,zip,ZIP,7z,7Z"}, - {"Nintendo 64 rom", "n64,z64,v64,N64,Z64,V64"} - }; - - auto result = NFD::OpenDialog(path, filterItems.data(), filterItems.size()); - if(result == NFD_ERROR) - Util::panic("Error: {}", NFD::GetError()); - - if(result != NFD_CANCEL) { - LoadROM(path.get()); - actionsEnabled = true; - } + if(ImGui::MenuItem("Open", "Ctrl-O")) { + FileDialog(); } if(ImGui::MenuItem("Exit")) { quit = true; @@ -143,19 +162,19 @@ void KaizenGui::RenderUI() { ImGui::EndMenu(); } if(ImGui::BeginMenu("Emulation")) { - ImGui::BeginDisabled(!actionsEnabled); + ImGui::BeginDisabled(!core->romLoaded); - if(ImGui::MenuItem(core->pause ? "Resume" : "Pause")) { + if(ImGui::MenuItem(core->pause ? "Resume" : "Pause", "P")) { emuThread.TogglePause(); } - if(ImGui::MenuItem("Reset")) { + if(ImGui::MenuItem("Reset", "R")) { emuThread.Reset(); } - if(ImGui::MenuItem("Stop")) { + if(ImGui::MenuItem("Stop", "Q")) { emuThread.Stop(); - actionsEnabled = false; + core->romLoaded = false; } ImGui::EndDisabled(); @@ -199,7 +218,7 @@ void KaizenGui::RenderUI() { ImGui::RenderPlatformWindowsDefault(); } - if(!core->pause && core->romLoaded) { + if(core->romLoaded) { core->parallel.UpdateScreen(*core.get()); return; } diff --git a/src/frontend/KaizenGui.hpp b/src/frontend/KaizenGui.hpp index 852f2063..d213dda2 100644 --- a/src/frontend/KaizenGui.hpp +++ b/src/frontend/KaizenGui.hpp @@ -27,6 +27,7 @@ public: private: bool quit = false; std::function emuExitFunc; + void FileDialog(); void RenderUI(); void HandleInput(SDL_Event event); void QueryDevices(SDL_Event event); diff --git a/src/frontend/SettingsWindow.cpp b/src/frontend/SettingsWindow.cpp index 0dd60bd3..b1da5ea0 100644 --- a/src/frontend/SettingsWindow.cpp +++ b/src/frontend/SettingsWindow.cpp @@ -8,7 +8,6 @@ std::string savePath; bool SettingsWindow::render() { - static bool applyEnabled = false; ImGui::OpenPopup("Settings", ImGuiPopupFlags_None); ImVec2 center = ImGui::GetMainViewport()->GetCenter(); ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); diff --git a/src/frontend/SettingsWindow.hpp b/src/frontend/SettingsWindow.hpp index 8741c175..6561c423 100644 --- a/src/frontend/SettingsWindow.hpp +++ b/src/frontend/SettingsWindow.hpp @@ -8,6 +8,7 @@ class SettingsWindow final { CPUSettings cpuSettings; AudioSettings audioSettings; std::string savesPath; + bool applyEnabled = false; public: bool render(); SettingsWindow() = default;