Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Add games directory and allow switching of games via controller in popup-menu #1627

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ general:
type: bool
default: true
screenshot_dir: string
games_dir: string
skip_boot_anim: bool
# throttle_io: bool
last_viewed_menu_index: integer
Expand Down
11 changes: 8 additions & 3 deletions ui/xui/actions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ void ActionEjectDisc(void)

void ActionLoadDisc(void)
{
Error *err = NULL;

const char *iso_file_filters = ".iso Files\0*.iso\0All Files\0*.*\0";
const char *new_disc_path =
PausedFileOpen(NOC_FILE_DIALOG_OPEN, iso_file_filters,
Expand All @@ -47,7 +45,14 @@ void ActionLoadDisc(void)
return;
}

xemu_load_disc(new_disc_path, &err);
ActionLoadDiscFile(new_disc_path);
}

void ActionLoadDiscFile(const char *file_path)
{
Error *err = NULL;
xemu_load_disc(file_path, &err);

if (err) {
xemu_queue_error_message(error_get_pretty(err));
error_free(err);
Expand Down
1 change: 1 addition & 0 deletions ui/xui/actions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

void ActionEjectDisc();
void ActionLoadDisc();
void ActionLoadDiscFile(const char *file_path);
void ActionTogglePause();
void ActionReset();
void ActionShutdown();
Expand Down
1 change: 1 addition & 0 deletions ui/xui/main-menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void MainMenuGeneralView::Draw()
"Skip the full Xbox boot animation sequence");
FilePicker("Screenshot output directory", &g_config.general.screenshot_dir,
NULL, true);
FilePicker("Games directory", &g_config.general.games_dir, NULL, true);
// toggle("Throttle DVD/HDD speeds", &g_config.general.throttle_io,
// "Limit DVD/HDD throughput to approximate Xbox load times");
}
Expand Down
66 changes: 66 additions & 0 deletions ui/xui/popup-menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "ui/xemu-notifications.h"
#include <string>
#include <vector>
#include <filesystem>
#include <map>
#include "misc.hh"
#include "actions.hh"
#include "font-manager.hh"
Expand Down Expand Up @@ -338,9 +340,69 @@ class SettingsPopupMenu : public virtual PopupMenu {
}
};

class GamesPopupMenu : public virtual PopupMenu {
protected:
std::multimap<std::string, std::string> sorted_file_names;

public:
void Show(const ImVec2 &direction) override
{
PopupMenu::Show(direction);
PopulateGameList();
}

bool DrawItems(PopupMenuItemDelegate &nav) override
{
bool pop = false;

if (m_focus && !m_pop_focus) {
ImGui::SetKeyboardFocusHere();
}

for (const auto &[label, file_path] : sorted_file_names) {
if (PopupMenuButton(label, ICON_FA_COMPACT_DISC)) {
ActionLoadDiscFile(file_path.c_str());
nav.ClearMenuStack();
pop = true;
}
}

if (sorted_file_names.size() == 0) {
if (PopupMenuButton("No games found", ICON_FA_SLIDERS)) {
nav.ClearMenuStack();
g_scene_mgr.PushScene(g_main_menu);
}
}

if (m_pop_focus) {
nav.PopFocus();
}
return pop;
}

void PopulateGameList() {
const char *games_dir = g_config.general.games_dir;

sorted_file_names.clear();
std::filesystem::path directory(games_dir);
if (std::filesystem::is_directory(directory)) {
for (const auto &file :
std::filesystem::directory_iterator(directory)) {
const auto &file_path = file.path();
if (std::filesystem::is_regular_file(file_path) &&
file_path.extension() == ".iso") {
sorted_file_names.insert(
{ file_path.stem().string(), file_path });
}
}
}
}
};

class RootPopupMenu : public virtual PopupMenu {
protected:
SettingsPopupMenu settings;
GamesPopupMenu games;
bool refocus_first_item;

public:
Expand Down Expand Up @@ -378,6 +440,10 @@ class RootPopupMenu : public virtual PopupMenu {
xemu_queue_notification("Created new snapshot");
pop = true;
}
if (PopupMenuSubmenuButton("Games", ICON_FA_GAMEPAD)) {
nav.PushFocus();
nav.PushMenu(games);
}
if (PopupMenuButton("Eject Disc", ICON_FA_EJECT)) {
ActionEjectDisc();
pop = true;
Expand Down
2 changes: 1 addition & 1 deletion ui/xui/popup-menu.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public:
PopupMenu();
void InitFocus();
virtual ~PopupMenu();
void Show(const ImVec2 &direction);
virtual void Show(const ImVec2 &direction);
void Hide(const ImVec2 &direction);
bool IsAnimating();
void Draw(PopupMenuItemDelegate &nav);
Expand Down
Loading