From b28fd496388245e7efcb67eb51cc4e414984f214 Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Thu, 27 Jun 2013 22:16:30 +0000 Subject: [PATCH] -added a WIP file explorer, for now you can just search through you partition and play mp3/ogg files (to get into it use the third icon down left in the coverflow) --- source/menu/menu.cpp | 1 + source/menu/menu.hpp | 7 + source/menu/menu_config_coverbnr.cpp | 17 ++- source/menu/menu_explorer.cpp | 202 +++++++++++++++++++++++++++ source/menu/menu_main.cpp | 14 ++ 5 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 source/menu/menu_explorer.cpp diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index a527ee47..40ce2558 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -1168,6 +1168,7 @@ void CMenu::_buildMenus(void) _initNandEmuMenu(); _initHomeAndExitToMenu(); _initCoverBanner(); + _initExplorer(); _initBoot(); _loadCFCfg(); diff --git a/source/menu/menu.hpp b/source/menu/menu.hpp index 91327938..e8a6f756 100644 --- a/source/menu/menu.hpp +++ b/source/menu/menu.hpp @@ -150,6 +150,7 @@ private: TexData m_mainBgLQ; //Main Coverflow s16 m_mainBtnConfig; + s16 m_mainBtnExplorer; s16 m_mainBtnInfo; s16 m_mainBtnFavoritesOn; s16 m_mainBtnFavoritesOff; @@ -851,6 +852,7 @@ private: void _initNandEmuMenu(); void _initHomeAndExitToMenu(); void _initCoverBanner(); + void _initExplorer(); // void _textSource(void); void _textPluginSettings(void); @@ -878,8 +880,10 @@ private: void _textExitTo(void); void _textBoot(void); void _textCoverBanner(void); + void _textExplorer(void); // void _refreshBoot(); + void _refreshExplorer(s8 direction = 0); // void _hideCheatSettings(bool instant = false); void _hideError(bool instant = false); @@ -909,6 +913,7 @@ private: void _hideHome(bool instant = false); void _hideExitTo(bool instant = false); void _hideCoverBanner(bool instant = false); + void _hideExplorer(bool instant = false); // void _showError(void); void _showMain(void); @@ -939,6 +944,7 @@ private: void _showHome(void); void _showExitTo(void); void _showCoverBanner(void); + void _showExplorer(void); void _updateSourceBtns(void); void _updatePluginText(void); void _updatePluginCheckboxes(void); @@ -983,6 +989,7 @@ private: void _gameinfo(void); void _gameSettings(void); void _CoverBanner(void); + void _Explorer(void); void _CheatSettings(); bool _Source(); void _PluginSettings(); diff --git a/source/menu/menu_config_coverbnr.cpp b/source/menu/menu_config_coverbnr.cpp index eb1abf7a..18533bb5 100644 --- a/source/menu/menu_config_coverbnr.cpp +++ b/source/menu/menu_config_coverbnr.cpp @@ -1,4 +1,19 @@ - +/**************************************************************************** + * Copyright (C) 2013 FIX94 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ #include "menu.hpp" #include "defines.h" #include "fileOps/fileOps.h" diff --git a/source/menu/menu_explorer.cpp b/source/menu/menu_explorer.cpp new file mode 100644 index 00000000..da05bc8f --- /dev/null +++ b/source/menu/menu_explorer.cpp @@ -0,0 +1,202 @@ +/**************************************************************************** + * Copyright (C) 2013 FIX94 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ +#include +#include +#include "menu.hpp" +#include "defines.h" +#include "fileOps/fileOps.h" + +extern const u8 blank_png[]; + +TexData m_explorerBg; +s16 entries[8]; +s16 entries_sel[8]; +char dir[MAX_FAT_PATH]; +char entries_char[7][NAME_MAX+1]; +void CMenu::_hideExplorer(bool instant) +{ + for(u8 i = 0; i < 8; ++i) + { + m_btnMgr.hide(entries[i], instant); + m_btnMgr.hide(entries_sel[i], instant); + } + /* general movement */ + m_btnMgr.hide(m_mainBtnNext, instant); + m_btnMgr.hide(m_mainBtnPrev, instant); +} + +void CMenu::_showExplorer(void) +{ + _setBg(m_explorerBg, m_explorerBg); + for(u8 i = 0; i < 8; ++i) + { + m_btnMgr.show(entries[i]); + m_btnMgr.show(entries_sel[i]); + } + /* general movement */ + m_btnMgr.show(m_mainBtnNext); + m_btnMgr.show(m_mainBtnPrev); +} + +void CMenu::_Explorer(void) +{ + _showExplorer(); + _refreshExplorer(); + while(!m_exit) + { + _mainLoopCommon(); + if(BTN_HOME_PRESSED || BTN_B_PRESSED) + break; + else if(BTN_A_PRESSED) + { + if(m_btnMgr.selected(m_mainBtnNext)) + { + _refreshExplorer(1); + } + else if(m_btnMgr.selected(m_mainBtnPrev)) + { + _refreshExplorer(-1); + } + else if(m_btnMgr.selected(entries_sel[0]) && dir[0] != '\0') + { + if(strchr(dir, '/') != NULL) + { + *strrchr(dir, '/') = '\0'; + if(strchr(dir, '/') != NULL) + *(strrchr(dir, '/')+1) = '\0'; + } + if(strchr(dir, '/') == NULL) + { + memset(dir, 0, MAX_FAT_PATH); + for(u8 i = 1; i < 7; ++i) + memset(entries_char, 0, NAME_MAX+1); + } + _refreshExplorer(); + } + for(u8 i = 1; i < 8; ++i) + { + if(m_btnMgr.selected(entries_sel[i])) + { + if(dir[0] == '\0') + { + if(DeviceHandle.IsInserted(i-1)) + strcpy(dir, fmt("%s:/", DeviceName[i-1])); + _refreshExplorer(); + } + else if(!fsop_FileExist(fmt("%s%s", dir, entries_char[i-1]))) + { + strcat(dir, entries_char[i-1]); + /* otherwise it fails */ + strcat(dir, "/"); + _refreshExplorer(); + } + else + { + const char *file = fmt("%s%s", dir, entries_char[i-1]); + if(strstr(file, ".mp3") != NULL || strstr(file, ".ogg") != NULL) + MusicPlayer.LoadFile(file, false); + } + } + } + } + } + _hideExplorer(); +} + +void CMenu::_initExplorer() +{ + memset(dir, 0, MAX_FAT_PATH); + TexData blank_btn; + TexHandle.fromPNG(blank_btn, blank_png); + + m_explorerBg = _texture("EXPLORER/BG", "texture", theme.bg, false); + for(u8 i = 0; i < 8; ++i) + { + entries[i] = _addLabel(fmt("EXPLORER/ENTRY_%i", i), theme.lblFont, L"", 120, 50+(i*50), 480, 40, theme.lblFontColor, FTGX_JUSTIFY_LEFT); + entries_sel[i] = _addPicButton(fmt("EXPLORER/ENTRY_%i_BTN", i), blank_btn, blank_btn, 120, 50+(i*50), 380, 45); + _setHideAnim(entries[i], fmt("EXPLORER/ENTRY_%i", i), 0, 0, 1.f, 0.f); + _setHideAnim(entries_sel[i], fmt("EXPLORER/ENTRY_%i_BTN", i), 0, 0, 1.f, 0.f); + } + _hideExplorer(true); + _textExplorer(); +} + +void CMenu::_textExplorer(void) +{ + m_btnMgr.setText(entries[0], L". . ."); + for(u8 i = 1; i < 8; ++i) + m_btnMgr.setText(entries[i], L" "); +} + +u32 cur_pos = 0; +void CMenu::_refreshExplorer(s8 direction) +{ + _textExplorer(); + if(direction == 0) + cur_pos = 0; + + if(dir[0] == '\0') + { + for(u8 i = 1; i < 8; ++i) + { + if(DeviceHandle.IsInserted(i-1)) + m_btnMgr.setText(entries[i], wfmt(L"%s:/", DeviceName[i-1])); + } + } + else + { + dirent *pent = NULL; + DIR *pdir = NULL; + u8 limit = 1; + u32 itr = 0; + if(direction == -1) + cur_pos = cur_pos > 14 ? cur_pos - 14 : 0; + pdir = opendir(dir); + while((pent = readdir(pdir)) != NULL && limit < 8) + { + if(pent->d_name[0] == '.') + continue; + if(pent->d_type == DT_DIR) + { + if(itr < cur_pos) + { + itr++; + continue; + } + strcpy(entries_char[limit-1], pent->d_name); + m_btnMgr.setText(entries[limit], wfmt(L"/%.32s", pent->d_name)); + cur_pos++; + itr++; + limit++; + } + else if(pent->d_type == DT_REG) + { + if(itr < cur_pos) + { + itr++; + continue; + } + strcpy(entries_char[limit-1], pent->d_name); + m_btnMgr.setText(entries[limit], wfmt(L"%.32s", pent->d_name)); + cur_pos++; + itr++; + limit++; + } + } + closedir(pdir); + } +} diff --git a/source/menu/menu_main.cpp b/source/menu/menu_main.cpp index e81925c7..a6de183d 100644 --- a/source/menu/menu_main.cpp +++ b/source/menu/menu_main.cpp @@ -53,6 +53,7 @@ void CMenu::_hideMain(bool instant) m_btnMgr.hide(m_mainBtnNext, instant); m_btnMgr.hide(m_mainBtnPrev, instant); m_btnMgr.hide(m_mainBtnConfig, instant); + m_btnMgr.hide(m_mainBtnExplorer, instant); m_btnMgr.hide(m_mainBtnInfo, instant); m_btnMgr.hide(m_mainBtnQuit, instant); m_btnMgr.hide(m_mainBtnHomebrew, instant); @@ -90,6 +91,7 @@ void CMenu::_showMain(void) _setBg(m_gameBg, m_gameBgLQ); m_btnMgr.show(m_mainBtnInfo); m_btnMgr.show(m_mainBtnConfig); + m_btnMgr.show(m_mainBtnExplorer); m_btnMgr.show(m_mainBtnQuit); switch(m_current_view) @@ -447,6 +449,14 @@ int CMenu::main(void) if(BTN_B_HELD) bUsed = true; } + else if(m_btnMgr.selected(m_mainBtnExplorer)) + { + _hideMain(); + _Explorer(); + _showMain(); + if(BTN_B_HELD) + bUsed = true; + } else if(m_btnMgr.selected(m_mainBtnInfo)) { _hideMain(); @@ -742,6 +752,7 @@ int CMenu::main(void) m_btnMgr.show(m_mainLblUser[1]); m_btnMgr.show(m_mainBtnInfo); m_btnMgr.show(m_mainBtnConfig); + m_btnMgr.show(m_mainBtnExplorer); m_btnMgr.show(m_mainBtnQuit); static bool change = m_favorites; m_btnMgr.show(m_favorites ? m_mainBtnFavoritesOn : m_mainBtnFavoritesOff, change != m_favorites); @@ -754,6 +765,7 @@ int CMenu::main(void) m_btnMgr.hide(m_mainLblUser[1]); if(!m_gameList.empty()) m_btnMgr.hide(m_mainBtnConfig); + m_btnMgr.hide(m_mainBtnExplorer); m_btnMgr.hide(m_mainBtnInfo); m_btnMgr.hide(m_mainBtnQuit); m_btnMgr.hide(m_mainBtnFavoritesOn); @@ -930,6 +942,7 @@ void CMenu::_initMainMenu() m_mainBtnInfo = _addPicButton("MAIN/INFO_BTN", texInfo, texInfoS, 20, 400, 48, 48); m_mainBtnConfig = _addPicButton("MAIN/CONFIG_BTN", texConfig, texConfigS, 70, 400, 48, 48); + m_mainBtnExplorer = _addPicButton("MAIN/EXPLORER_BTN", texEmu, texEmus, 120, 400, 48, 48); m_mainBtnQuit = _addPicButton("MAIN/QUIT_BTN", texQuit, texQuitS, 570, 400, 48, 48); m_mainBtnChannel = _addPicButton("MAIN/CHANNEL_BTN", texChannel, texChannels, 520, 400, 48, 48); m_mainBtnHomebrew = _addPicButton("MAIN/HOMEBREW_BTN", texHomebrew, texHomebrews, 520, 400, 48, 48); @@ -985,6 +998,7 @@ void CMenu::_initMainMenu() _setHideAnim(m_mainBtnNext, "MAIN/NEXT_BTN", 0, 0, 0.f, 0.f); _setHideAnim(m_mainBtnPrev, "MAIN/PREV_BTN", 0, 0, 0.f, 0.f); _setHideAnim(m_mainBtnConfig, "MAIN/CONFIG_BTN", 0, 40, 0.f, 0.f); + _setHideAnim(m_mainBtnExplorer, "MAIN/EXPLORER_BTN", 0, 40, 0.f, 0.f); _setHideAnim(m_mainBtnInfo, "MAIN/INFO_BTN", 0, 40, 0.f, 0.f); _setHideAnim(m_mainBtnQuit, "MAIN/QUIT_BTN", 0, 40, 0.f, 0.f); _setHideAnim(m_mainBtnChannel, "MAIN/CHANNEL_BTN", 0, 40, 0.f, 0.f);