FullscreenUI: Hook up to disc change hotkey

old-dev v0.1-8520
Stenzek 1 month ago
parent 9096402a30
commit 9666abc172
No known key found for this signature in database

@ -261,8 +261,8 @@ static void DoToggleFastForward();
static void ConfirmIfSavingMemoryCards(std::string action, std::function<void(bool)> callback); static void ConfirmIfSavingMemoryCards(std::string action, std::function<void(bool)> callback);
static void RequestShutdown(bool save_state); static void RequestShutdown(bool save_state);
static void RequestReset(); static void RequestReset();
static void DoChangeDiscFromFile(); static void BeginChangeDiscOnCPUThread(bool needs_pause);
static void DoChangeDisc(); static void StartChangeDiscFromFile();
static void DoRequestExit(); static void DoRequestExit();
static void DoDesktopMode(); static void DoDesktopMode();
static void DoToggleFullscreen(); static void DoToggleFullscreen();
@ -817,14 +817,27 @@ void FullscreenUI::OpenCheatsMenu()
if (!System::IsValid()) if (!System::IsValid())
return; return;
GPUThread::RunOnThread([]() {
if (!Initialize() || s_state.current_main_window != MainWindowType::None || !SwitchToGameSettings()) if (!Initialize() || s_state.current_main_window != MainWindowType::None || !SwitchToGameSettings())
return; return;
PauseForMenuOpen(false);
s_state.current_main_window = MainWindowType::Settings;
s_state.settings_page = SettingsPage::Cheats; s_state.settings_page = SettingsPage::Cheats;
PauseForMenuOpen(true); QueueResetFocus(FocusResetType::ViewChanged);
ForceKeyNavEnabled(); ForceKeyNavEnabled();
UpdateRunIdleState(); UpdateRunIdleState();
FixStateIfPaused(); FixStateIfPaused();
});
}
void FullscreenUI::OpenDiscChangeMenu()
{
if (!System::IsValid())
return;
DebugAssert(!GPUThread::IsOnThread());
BeginChangeDiscOnCPUThread(true);
} }
void FullscreenUI::FixStateIfPaused() void FullscreenUI::FixStateIfPaused()
@ -1259,17 +1272,17 @@ void FullscreenUI::DoToggleFastForward()
}); });
} }
void FullscreenUI::DoChangeDiscFromFile() void FullscreenUI::StartChangeDiscFromFile()
{ {
ConfirmIfSavingMemoryCards(FSUI_STR("change disc"), [](bool result) { auto callback = [](const std::string& path) {
if (!result) if (path.empty())
{ {
ClosePauseMenu(); ReturnToPreviousWindow();
return; return;
} }
auto callback = [](const std::string& path) { ConfirmIfSavingMemoryCards(FSUI_STR("change disc"), [path](bool result) {
if (!path.empty()) if (result)
{ {
if (!GameList::IsScannableFilename(path)) if (!GameList::IsScannableFilename(path))
{ {
@ -1283,18 +1296,27 @@ void FullscreenUI::DoChangeDiscFromFile()
} }
ReturnToPreviousWindow(); ReturnToPreviousWindow();
});
}; };
OpenFileSelector(FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Select Disc Image"), false, std::move(callback), OpenFileSelector(FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Select Disc Image"), false, std::move(callback),
GetDiscImageFilters(), std::string(Path::GetDirectory(s_state.current_game_path))); GetDiscImageFilters(), std::string(Path::GetDirectory(s_state.current_game_path)));
});
} }
void FullscreenUI::DoChangeDisc() void FullscreenUI::BeginChangeDiscOnCPUThread(bool needs_pause)
{ {
Host::RunOnCPUThread([]() {
ImGuiFullscreen::ChoiceDialogOptions options; ImGuiFullscreen::ChoiceDialogOptions options;
auto pause_if_needed = [needs_pause]() {
if (!needs_pause)
return;
PauseForMenuOpen(false);
ForceKeyNavEnabled();
UpdateRunIdleState();
FixStateIfPaused();
};
if (System::HasMediaSubImages()) if (System::HasMediaSubImages())
{ {
const u32 current_index = System::GetMediaSubImageIndex(); const u32 current_index = System::GetMediaSubImageIndex();
@ -1305,23 +1327,33 @@ void FullscreenUI::DoChangeDisc()
for (u32 i = 0; i < count; i++) for (u32 i = 0; i < count; i++)
options.emplace_back(System::GetMediaSubImageTitle(i), i == current_index); options.emplace_back(System::GetMediaSubImageTitle(i), i == current_index);
GPUThread::RunOnThread([options = std::move(options)]() mutable { GPUThread::RunOnThread([options = std::move(options), pause_if_needed = std::move(pause_if_needed)]() mutable {
if (!Initialize())
return;
auto callback = [](s32 index, const std::string& title, bool checked) { auto callback = [](s32 index, const std::string& title, bool checked) {
if (index == 0) if (index == 0)
{ {
DoChangeDiscFromFile(); StartChangeDiscFromFile();
return;
} }
else if (index > 0) else if (index > 0)
{ {
ConfirmIfSavingMemoryCards(FSUI_STR("change disc"), [index](bool result) {
if (result)
System::SwitchMediaSubImage(static_cast<u32>(index - 1)); System::SwitchMediaSubImage(static_cast<u32>(index - 1));
}
ReturnToPreviousWindow(); ReturnToPreviousWindow();
});
}
else
{
ReturnToPreviousWindow();
}
}; };
OpenChoiceDialog(FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Select Disc Image"), false, std::move(options), OpenChoiceDialog(FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Select Disc Image"), false, std::move(options),
std::move(callback)); std::move(callback));
pause_if_needed();
}); });
return; return;
@ -1346,30 +1378,46 @@ void FullscreenUI::DoChangeDisc()
paths.push_back(glentry->path); paths.push_back(glentry->path);
} }
GPUThread::RunOnThread([options = std::move(options), paths = std::move(paths)]() mutable { GPUThread::RunOnThread([options = std::move(options), paths = std::move(paths),
auto callback = [paths = std::move(paths)](s32 index, const std::string& title, bool checked) { pause_if_needed = std::move(pause_if_needed)]() mutable {
if (!Initialize())
return;
auto callback = [paths = std::move(paths)](s32 index, const std::string& title, bool checked) mutable {
if (index == 0) if (index == 0)
{ {
DoChangeDiscFromFile(); StartChangeDiscFromFile();
return;
} }
else if (index > 0) else if (index > 0)
{ {
ConfirmIfSavingMemoryCards(FSUI_STR("change disc"), [paths = std::move(paths), index](bool result) {
if (result)
Host::RunOnCPUThread([path = std::move(paths[index - 1])]() { System::InsertMedia(path.c_str()); }); Host::RunOnCPUThread([path = std::move(paths[index - 1])]() { System::InsertMedia(path.c_str()); });
}
ReturnToMainWindow(); ReturnToPreviousWindow();
});
}
else
{
ReturnToPreviousWindow();
}
}; };
OpenChoiceDialog(FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Select Disc Image"), false, std::move(options), OpenChoiceDialog(FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Select Disc Image"), false, std::move(options),
std::move(callback)); std::move(callback));
pause_if_needed();
}); });
return; return;
} }
} }
GPUThread::RunOnThread([]() { DoChangeDiscFromFile(); }); GPUThread::RunOnThread([pause_if_needed = std::move(pause_if_needed)]() {
if (!Initialize())
return;
StartChangeDiscFromFile();
pause_if_needed();
}); });
} }
@ -2204,8 +2252,8 @@ void FullscreenUI::BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::T
{ {
s_state.input_binding_value_ranges.emplace_back(key, std::make_pair(initial_value, min_value)); s_state.input_binding_value_ranges.emplace_back(key, std::make_pair(initial_value, min_value));
// forward the event to imgui if it's a new key and a release, because this is what triggered the binding to start // forward the event to imgui if it's a new key and a release, because this is what triggered the binding to
// if we don't do this, imgui thinks the activate button is held down // start if we don't do this, imgui thinks the activate button is held down
default_action = (value == 0.0f) ? InputInterceptHook::CallbackResult::ContinueProcessingEvent : default_action = (value == 0.0f) ? InputInterceptHook::CallbackResult::ContinueProcessingEvent :
InputInterceptHook::CallbackResult::StopProcessingEvent; InputInterceptHook::CallbackResult::StopProcessingEvent;
} }
@ -6619,7 +6667,7 @@ void FullscreenUI::DrawPauseMenu()
if (ActiveButton(FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Change Disc"), false)) if (ActiveButton(FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Change Disc"), false))
{ {
s_state.current_main_window = MainWindowType::None; s_state.current_main_window = MainWindowType::None;
DoChangeDisc(); Host::RunOnCPUThread([]() { BeginChangeDiscOnCPUThread(false); });
} }
if (ActiveButton(FSUI_ICONSTR(ICON_FA_SLIDERS_H, "Settings"), false)) if (ActiveButton(FSUI_ICONSTR(ICON_FA_SLIDERS_H, "Settings"), false))

@ -28,6 +28,7 @@ void OnRunningGameChanged(const std::string& path, const std::string& serial, co
#ifndef __ANDROID__ #ifndef __ANDROID__
void OpenPauseMenu(); void OpenPauseMenu();
void OpenCheatsMenu(); void OpenCheatsMenu();
void OpenDiscChangeMenu();
void OpenAchievementsWindow(); void OpenAchievementsWindow();
void OpenLeaderboardsWindow(); void OpenLeaderboardsWindow();
void ReturnToMainWindow(); void ReturnToMainWindow();

@ -215,6 +215,12 @@ DEFINE_HOTKEY("OpenCheatsMenu", TRANSLATE_NOOP("Hotkeys", "General"), TRANSLATE_
FullscreenUI::OpenCheatsMenu(); FullscreenUI::OpenCheatsMenu();
}) })
DEFINE_HOTKEY("ChangeDisc", TRANSLATE_NOOP("Hotkeys", "System"), TRANSLATE_NOOP("Hotkeys", "Change Disc"),
[](s32 pressed) {
if (!pressed)
FullscreenUI::OpenDiscChangeMenu();
})
DEFINE_HOTKEY("Screenshot", TRANSLATE_NOOP("Hotkeys", "General"), TRANSLATE_NOOP("Hotkeys", "Save Screenshot"), DEFINE_HOTKEY("Screenshot", TRANSLATE_NOOP("Hotkeys", "General"), TRANSLATE_NOOP("Hotkeys", "Save Screenshot"),
[](s32 pressed) { [](s32 pressed) {
if (!pressed) if (!pressed)
@ -264,17 +270,6 @@ DEFINE_HOTKEY("Reset", TRANSLATE_NOOP("Hotkeys", "System"), TRANSLATE_NOOP("Hotk
Host::RunOnCPUThread(System::ResetSystem); Host::RunOnCPUThread(System::ResetSystem);
}) })
DEFINE_HOTKEY("ChangeDisc", TRANSLATE_NOOP("Hotkeys", "System"), TRANSLATE_NOOP("Hotkeys", "Change Disc"),
[](s32 pressed) {
if (!pressed && System::IsValid() && System::HasMediaSubImages())
{
const u32 current = System::GetMediaSubImageIndex();
const u32 next = (current + 1) % System::GetMediaSubImageCount();
if (current != next)
Host::RunOnCPUThread([next]() { System::SwitchMediaSubImage(next); });
}
})
DEFINE_HOTKEY("SwapMemoryCards", TRANSLATE_NOOP("Hotkeys", "System"), DEFINE_HOTKEY("SwapMemoryCards", TRANSLATE_NOOP("Hotkeys", "System"),
TRANSLATE_NOOP("Hotkeys", "Swap Memory Card Slots"), [](s32 pressed) { TRANSLATE_NOOP("Hotkeys", "Swap Memory Card Slots"), [](s32 pressed) {
if (!pressed) if (!pressed)

Loading…
Cancel
Save