Skip to content

Commit

Permalink
ui: add games directory to popup-menu
Browse files Browse the repository at this point in the history
  • Loading branch information
TrentSeed committed Mar 30, 2024
1 parent 94d826a commit 280e461
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 12 deletions.
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
73 changes: 64 additions & 9 deletions ui/xui/popup-menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include "ui/xemu-notifications.h"
#include <string>
#include <vector>
#include "misc.hh"
#include "popup-menu.hh"
#include "../xemu-snapshots.h"
#include "IconsFontAwesome6.h"
#include "actions.hh"
#include "font-manager.hh"
#include "viewport-manager.hh"
#include "scene-manager.hh"
#include "popup-menu.hh"
#include "input-manager.hh"
#include "xemu-hud.h"
#include "IconsFontAwesome6.h"
#include "../xemu-snapshots.h"
#include "main-menu.hh"
#include "misc.hh"
#include "scene-manager.hh"
#include "viewport-manager.hh"
#include "xemu-hud.h"
#include <filesystem>
#include <map>
#include <string>
#include <vector>

PopupMenuItemDelegate::~PopupMenuItemDelegate() {}
void PopupMenuItemDelegate::PushMenu(PopupMenu &menu) {}
Expand Down Expand Up @@ -338,9 +340,58 @@ class SettingsPopupMenu : public virtual PopupMenu {
}
};

class GamesPopupMenu : public virtual PopupMenu {
public:
bool DrawItems(PopupMenuItemDelegate &nav) override
{
bool pop = false;

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

const char *games_dir = g_config.general.games_dir;
std::filesystem::path directory(games_dir);
std::multimap<std::string, std::string> sorted_file_names;

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

for (const auto &[label, file_path] : sorted_file_names) {
if (PopupMenuButton(label, ICON_FA_GAMEPAD)) {
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;
}
};

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

public:
Expand Down Expand Up @@ -378,6 +429,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

0 comments on commit 280e461

Please sign in to comment.