[App] Minor Fixes

Added F9
[Controller Hotkeys] Call RunTitle from the UI thread
This commit is contained in:
Adrian 2023-02-03 19:54:42 +00:00 committed by Radosław Gliński
parent 036f19c66e
commit 3d3810fa98
3 changed files with 32 additions and 45 deletions

View File

@ -12,6 +12,7 @@
#include "third_party/discord-rpc/include/discord_rpc.h"
#include "xenia/base/string.h"
// TODO: This library has been deprecated in favor of Discord's GameSDK.
namespace xe {
namespace discord {

View File

@ -1195,11 +1195,11 @@ const std::map<int, EmulatorWindow::ControllerHotKey> controller_hotkey_map = {
{X_INPUT_GAMEPAD_DPAD_DOWN,
EmulatorWindow::ControllerHotKey(
EmulatorWindow::ButtonFunctions::IncTitleSelect,
"D-PAD Down + Guide = Title Selection +1", true, false)},
"D-PAD Down = Title Selection +1", true, false)},
{X_INPUT_GAMEPAD_DPAD_UP,
EmulatorWindow::ControllerHotKey(
EmulatorWindow::ButtonFunctions::DecTitleSelect,
"D-PAD Up + Guide = Title Selection -1", true, false)}};
"D-PAD Up = Title Selection -1", true, false)}};
EmulatorWindow::ControllerHotKey EmulatorWindow::ProcessControllerHotkey(
int buttons) {
@ -1247,12 +1247,10 @@ EmulatorWindow::ControllerHotKey EmulatorWindow::ProcessControllerHotkey(
case ButtonFunctions::RunTitle: {
if (selected_title_index == -1) selected_title_index++;
xe::X_STATUS title_success = RunTitle(
recently_launched_titles_[selected_title_index].path_to_file);
app_context().CallInUIThread([this]() {
RunTitle(recently_launched_titles_[selected_title_index].path_to_file);
});
if (title_success == X_ERROR_SUCCESS) {
imgui_drawer_.get()->ClearDialogs();
}
} break;
case ButtonFunctions::ClearMemoryPageState:
ToggleGPUSetting(gpu_cvar::ClearMemoryPageState);
@ -1311,6 +1309,7 @@ EmulatorWindow::ControllerHotKey EmulatorWindow::ProcessControllerHotkey(
selected_title_index = std::clamp(
selected_title_index, 0, (int)recently_launched_titles_.size() - 1);
// Must clear dialogs to prevent stacking
imgui_drawer_.get()->ClearDialogs();
// Titles may contain Unicode characters such as At Worlds End
@ -1338,7 +1337,7 @@ void EmulatorWindow::VibrateController(xe::hid::InputSystem* input_sys,
// otherwise the rumble may fail.
auto input_lock = input_sys->lock();
X_INPUT_VIBRATION vibration{};
X_INPUT_VIBRATION vibration = {};
vibration.left_motor_speed = toggle_rumble ? UINT16_MAX : 0;
vibration.right_motor_speed = toggle_rumble ? UINT16_MAX : 0;
@ -1473,11 +1472,12 @@ void EmulatorWindow::DisplayHotKeysConfig() {
msg);
}
xe::X_STATUS EmulatorWindow::RunTitle(std::filesystem::path path) {
bool titleExists = !std::filesystem::exists(path);
xe::X_STATUS EmulatorWindow::RunTitle(std::filesystem::path path_to_file) {
bool titleExists = !std::filesystem::exists(path_to_file);
if (path.empty() || titleExists) {
char* log_msg = path.empty() ? "Failed to launch title path is empty."
if (path_to_file.empty() || titleExists) {
char* log_msg = path_to_file.empty()
? "Failed to launch title path is empty."
: "Failed to launch title path is invalid.";
XELOGE(log_msg);
@ -1501,19 +1501,19 @@ xe::X_STATUS EmulatorWindow::RunTitle(std::filesystem::path path) {
// Prevent crashing the emulator by not loading a game if a game is already
// loaded.
auto abs_path = std::filesystem::absolute(path);
auto abs_path = std::filesystem::absolute(path_to_file);
auto result = emulator_->LaunchPath(abs_path);
imgui_drawer_.get()->ClearDialogs();
if (result) {
XELOGE("Failed to launch target: {:08X}", result);
imgui_drawer_.get()->ClearDialogs();
xe::ui::ImGuiDialog::ShowMessageBox(
imgui_drawer_.get(), "Title Launch Failed!",
"Failed to launch title.\n\nCheck xenia.log for technical details.");
} else {
AddRecentlyLaunchedTitle(path, emulator_->title_name());
AddRecentlyLaunchedTitle(path_to_file, emulator_->title_name());
}
return result;
@ -1525,32 +1525,19 @@ void EmulatorWindow::RunPreviouslyPlayedTitle() {
}
}
void EmulatorWindow::RunRecentlyPlayedTitle(
std::filesystem::path path_to_file) {
if (path_to_file.empty()) {
return;
}
auto abs_path = std::filesystem::absolute(path_to_file);
auto result = emulator_->LaunchPath(abs_path);
if (XFAILED(result)) {
// TODO: Display a message box.
XELOGE("Failed to launch target: {:08X}", result);
return;
}
AddRecentlyLaunchedTitle(path_to_file, emulator_->title_name());
}
void EmulatorWindow::FillRecentlyLaunchedTitlesMenu(
xe::ui::MenuItem* recent_menu) {
for (const RecentTitleEntry& entry : recently_launched_titles_) {
std::string item_text = !entry.title_name.empty()
? entry.title_name
: entry.path_to_file.string();
recent_menu->AddChild(
MenuItem::Create(MenuItem::Type::kString, item_text,
std::bind(&EmulatorWindow::RunRecentlyPlayedTitle,
this, entry.path_to_file)));
for (int i = 0; i < recently_launched_titles_.size(); ++i) {
std::string hotkey = (i == 0) ? "F9" : "";
const RecentTitleEntry& entry = recently_launched_titles_[i];
const std::string item_text = entry.title_name.empty()
? entry.path_to_file.string()
: entry.title_name;
recent_menu->AddChild(MenuItem::Create(
MenuItem::Type::kString, item_text, hotkey,
std::bind(&EmulatorWindow::RunTitle, this, entry.path_to_file)));
}
}

View File

@ -56,7 +56,7 @@ class EmulatorWindow {
std::unique_ptr<xe::threading::Thread> Gamepad_HotKeys_Listener;
int selected_title_index = -1;
int32_t selected_title_index = -1;
Emulator* emulator() const { return emulator_; }
ui::WindowedAppContext& app_context() const { return app_context_; }
@ -210,9 +210,8 @@ class EmulatorWindow {
std::string BoolToString(bool value);
void DisplayHotKeysConfig();
xe::X_STATUS RunTitle(std::filesystem::path path);
xe::X_STATUS RunTitle(std::filesystem::path path_to_file);
void RunPreviouslyPlayedTitle();
void RunRecentlyPlayedTitle(std::filesystem::path path_to_file);
void FillRecentlyLaunchedTitlesMenu(xe::ui::MenuItem* recent_menu);
void LoadRecentlyLaunchedTitles();
void AddRecentlyLaunchedTitle(std::filesystem::path path_to_file,