add support for changing the left-side menu.

fixes #148
This commit is contained in:
ITotalJustice
2025-05-26 22:55:06 +01:00
parent e2a5454263
commit c11d9edc4e
27 changed files with 164 additions and 63 deletions

View File

@@ -382,6 +382,11 @@ FsView::FsView(Menu* menu, const fs::FsPath& path, const FsEntry& entry, ViewSid
}}),
std::make_pair(Button::B, Action{"Back"_i18n, [this](){
if (!m_menu->IsTab() && App::GetApp()->m_controller.GotHeld(Button::R2)) {
m_menu->PromptIfShouldExit();
return;
}
std::string_view view{m_path};
if (view != m_fs->Root()) {
const auto end = view.find_last_of('/');
@@ -392,6 +397,10 @@ FsView::FsView(Menu* menu, const fs::FsPath& path, const FsEntry& entry, ViewSid
} else {
Scan(view.substr(0, end), true);
}
} else {
if (!m_menu->IsTab()) {
m_menu->PromptIfShouldExit();
}
}
}}),
@@ -1390,7 +1399,7 @@ auto FsView::CheckIfUpdateFolder() -> Result {
if (!m_daybreak_path.has_value()) {
auto daybreak_path = DAYBREAK_PATH;
if (!m_fs->FileExists(DAYBREAK_PATH)) {
if (auto e = nro_find(m_menu->m_nro_entries, "Daybreak", "Atmosphere-NX", {}); e.has_value()) {
if (auto e = nro_find(homebrew::GetNroEntries(), "Daybreak", "Atmosphere-NX", {}); e.has_value()) {
daybreak_path = e.value().path;
} else {
log_write("failed to find daybreak\n");
@@ -1893,11 +1902,17 @@ void FsView::DisplayAdvancedOptions() {
}));
}
Menu::Menu(const std::vector<NroEntry>& nro_entries) : MenuBase{"FileBrowser"_i18n}, m_nro_entries{nro_entries} {
Menu::Menu(u32 flags) : MenuBase{"FileBrowser"_i18n, flags} {
SetAction(Button::L3, Action{"Split"_i18n, [this](){
SetSplitScreen(IsSplitScreen() ^ 1);
}});
if (!IsTab()) {
SetAction(Button::SELECT, Action{"Close"_i18n, [this](){
PromptIfShouldExit();
}});
}
view = view_left = std::make_shared<FsView>(this, ViewSide::Left);
}
@@ -2063,7 +2078,7 @@ void Menu::LoadAssocEntriesPath(const fs::FsPath& path) {
file_exists = view->m_fs->FileExists(assoc.path);
} else {
const auto nro_name = assoc.name + ".nro";
for (const auto& nro : m_nro_entries) {
for (const auto& nro : homebrew::GetNroEntries()) {
const auto len = std::strlen(nro.path);
if (len < nro_name.length()) {
continue;
@@ -2160,4 +2175,19 @@ void Menu::RefreshViews() {
}
}
void Menu::PromptIfShouldExit() {
if (IsTab()) {
return;
}
App::Push(std::make_shared<ui::OptionBox>(
"Close FileBrowser?"_i18n,
"No"_i18n, "Yes"_i18n, 1, [this](auto op_index){
if (op_index && *op_index) {
SetPop();
}
}
));
}
} // namespace sphaira::ui::menu::filebrowser