Skip to content

Commit

Permalink
CR feedback: fixed popup-menu.cc include ordering, no longer querying…
Browse files Browse the repository at this point in the history
… filesystem on draw loop, games within menu use disk icon instead of game pad
  • Loading branch information
TrentSeed authored and mborgerson committed Jun 15, 2024
1 parent 4fc36b8 commit c889f91
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
67 changes: 39 additions & 28 deletions ui/xui/popup-menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include "ui/xemu-notifications.h"
#include "popup-menu.hh"
#include "../xemu-snapshots.h"
#include "IconsFontAwesome6.h"
#include <string>
#include <vector>
#include <filesystem>
#include <map>
#include "misc.hh"
#include "actions.hh"
#include "font-manager.hh"
#include "input-manager.hh"
#include "main-menu.hh"
#include "misc.hh"
#include "scene-manager.hh"
#include "viewport-manager.hh"
#include "scene-manager.hh"
#include "popup-menu.hh"
#include "input-manager.hh"
#include "xemu-hud.h"
#include <filesystem>
#include <map>
#include <string>
#include <vector>
#include "IconsFontAwesome6.h"
#include "../xemu-snapshots.h"
#include "main-menu.hh"

PopupMenuItemDelegate::~PopupMenuItemDelegate() {}
void PopupMenuItemDelegate::PushMenu(PopupMenu &menu) {}
Expand Down Expand Up @@ -341,7 +341,16 @@ 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;
Expand All @@ -350,24 +359,8 @@ class GamesPopupMenu : public virtual PopupMenu {
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)) {
if (PopupMenuButton(label, ICON_FA_COMPACT_DISC)) {
ActionLoadDiscFile(file_path.c_str());
nav.ClearMenuStack();
pop = true;
Expand All @@ -386,6 +379,24 @@ class GamesPopupMenu : public virtual PopupMenu {
}
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 {
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

0 comments on commit c889f91

Please sign in to comment.