Core: Add a file open dialog and refactor logic around loading new games
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
#include "xenia/base/threading.h"
|
||||
#include "xenia/emulator.h"
|
||||
#include "xenia/gpu/graphics_system.h"
|
||||
|
||||
#include "xenia/ui/file_picker.h"
|
||||
#include "xenia/ui/imgui_dialog.h"
|
||||
#include "xenia/ui/imgui_drawer.h"
|
||||
|
||||
@@ -114,7 +116,6 @@ bool EmulatorWindow::Initialize() {
|
||||
// TODO: Spawn a new thread to do this.
|
||||
emulator()->RestoreFromFile(L"test.sav");
|
||||
} break;
|
||||
|
||||
case 0x7A: { // VK_F11
|
||||
ToggleFullscreen();
|
||||
} break;
|
||||
@@ -145,6 +146,9 @@ bool EmulatorWindow::Initialize() {
|
||||
auto main_menu = MenuItem::Create(MenuItem::Type::kNormal);
|
||||
auto file_menu = MenuItem::Create(MenuItem::Type::kPopup, L"&File");
|
||||
{
|
||||
file_menu->AddChild(
|
||||
MenuItem::Create(MenuItem::Type::kString, L"&Open", L"Ctrl+O",
|
||||
std::bind(&EmulatorWindow::FileOpen, this)));
|
||||
file_menu->AddChild(MenuItem::Create(MenuItem::Type::kString, L"E&xit",
|
||||
L"Alt+F4",
|
||||
[this]() { window_->Close(); }));
|
||||
@@ -239,6 +243,40 @@ bool EmulatorWindow::Initialize() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void EmulatorWindow::FileOpen() {
|
||||
std::wstring path;
|
||||
|
||||
auto file_picker = xe::ui::FilePicker::Create();
|
||||
file_picker->set_mode(ui::FilePicker::Mode::kOpen);
|
||||
file_picker->set_type(ui::FilePicker::Type::kFile);
|
||||
file_picker->set_multi_selection(false);
|
||||
file_picker->set_title(L"Select Content Package");
|
||||
file_picker->set_extensions({
|
||||
{L"Supported Files", L"*.iso;*.xex;*.xcp;*.*"},
|
||||
{L"Disc Image (*.iso)", L"*.iso"},
|
||||
{L"Xbox Executable (*.xex)", L"*.xex"},
|
||||
//{ L"Content Package (*.xcp)", L"*.xcp" },
|
||||
{L"All Files (*.*)", L"*.*"},
|
||||
});
|
||||
if (file_picker->Show(window_->native_handle())) {
|
||||
auto selected_files = file_picker->selected_files();
|
||||
if (!selected_files.empty()) {
|
||||
path = selected_files[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (!path.empty()) {
|
||||
// Normalize the path and make absolute.
|
||||
std::wstring abs_path = xe::to_absolute_path(path);
|
||||
|
||||
auto result = emulator_->LaunchPath(abs_path);
|
||||
if (XFAILED(result)) {
|
||||
// TODO: Display a message box.
|
||||
XELOGE("Failed to launch target: %.8X", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EmulatorWindow::CpuTimeScalarReset() {
|
||||
Clock::set_guest_time_scalar(1.0);
|
||||
UpdateTitle();
|
||||
|
||||
@@ -42,6 +42,7 @@ class EmulatorWindow {
|
||||
|
||||
bool Initialize();
|
||||
|
||||
void FileOpen();
|
||||
void CpuTimeScalarReset();
|
||||
void CpuTimeScalarSetHalf();
|
||||
void CpuTimeScalarSetDouble();
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
#include "xenia/app/emulator_window.h"
|
||||
#include "xenia/base/debugging.h"
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/main.h"
|
||||
#include "xenia/base/profiling.h"
|
||||
#include "xenia/base/threading.h"
|
||||
#include "xenia/debug/ui/debug_window.h"
|
||||
#include "xenia/emulator.h"
|
||||
#include "xenia/ui/file_picker.h"
|
||||
@@ -159,6 +161,18 @@ int xenia_main(const std::vector<std::wstring>& args) {
|
||||
});
|
||||
}
|
||||
|
||||
auto evt = xe::threading::Event::CreateAutoResetEvent(false);
|
||||
emulator->on_launch.AddListener([&]() {
|
||||
emulator_window->UpdateTitle();
|
||||
evt->Set();
|
||||
});
|
||||
|
||||
bool exiting = false;
|
||||
emulator_window->loop()->on_quit.AddListener([&](ui::UIEvent* e) {
|
||||
exiting = true;
|
||||
evt->Set();
|
||||
});
|
||||
|
||||
// Grab path from the flag or unnamed argument.
|
||||
std::wstring path;
|
||||
if (!FLAGS_target.empty() || args.size() >= 2) {
|
||||
@@ -173,43 +187,23 @@ int xenia_main(const std::vector<std::wstring>& args) {
|
||||
}
|
||||
}
|
||||
|
||||
// If no path passed, ask the user.
|
||||
if (path.empty()) {
|
||||
auto file_picker = xe::ui::FilePicker::Create();
|
||||
file_picker->set_mode(ui::FilePicker::Mode::kOpen);
|
||||
file_picker->set_type(ui::FilePicker::Type::kFile);
|
||||
file_picker->set_multi_selection(false);
|
||||
file_picker->set_title(L"Select Content Package");
|
||||
file_picker->set_extensions({
|
||||
{L"Supported Files", L"*.iso;*.xex;*.xcp;*.*"},
|
||||
{L"Disc Image (*.iso)", L"*.iso"},
|
||||
{L"Xbox Executable (*.xex)", L"*.xex"},
|
||||
//{ L"Content Package (*.xcp)", L"*.xcp" },
|
||||
{L"All Files (*.*)", L"*.*"},
|
||||
});
|
||||
if (file_picker->Show(emulator->display_window()->native_handle())) {
|
||||
auto selected_files = file_picker->selected_files();
|
||||
if (!selected_files.empty()) {
|
||||
path = selected_files[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!path.empty()) {
|
||||
// Normalize the path and make absolute.
|
||||
std::wstring abs_path = xe::to_absolute_path(path);
|
||||
|
||||
result = emulator->LaunchPath(abs_path,
|
||||
[&]() { emulator_window->UpdateTitle(); });
|
||||
result = emulator->LaunchPath(abs_path);
|
||||
if (XFAILED(result)) {
|
||||
XELOGE("Failed to launch target: %.8X", result);
|
||||
emulator.reset();
|
||||
emulator_window.reset();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait until we are exited.
|
||||
emulator->display_window()->loop()->AwaitQuit();
|
||||
// Now, we're going to use the main thread to drive events related to
|
||||
// emulation.
|
||||
while (!exiting) {
|
||||
xe::threading::Wait(evt.get(), false);
|
||||
emulator->WaitUntilExit();
|
||||
}
|
||||
|
||||
debug_window.reset();
|
||||
|
||||
Reference in New Issue
Block a user