From 6ac4cc4559c55cb7e4d8dffcfa32d8757fc4f292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 28 Dec 2023 15:34:40 +0100 Subject: [PATCH] Remote disc streaming: Add an option for a "Remote" tab on the main screen --- Core/Config.cpp | 1 + Core/Config.h | 1 + UI/MainScreen.cpp | 32 ++++++++++++++++++++++++++++++-- UI/MainScreen.h | 15 +++++++++++---- UI/RemoteISOScreen.cpp | 36 ++++++++++++------------------------ UI/RemoteISOScreen.h | 6 +++++- 6 files changed, 60 insertions(+), 31 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 750ab894c3..845dbb2e38 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -265,6 +265,7 @@ static const ConfigSetting generalSettings[] = { ConfigSetting("RemoteShareOnStartup", &g_Config.bRemoteShareOnStartup, false, CfgFlag::DEFAULT), ConfigSetting("RemoteISOSubdir", &g_Config.sRemoteISOSubdir, "/", CfgFlag::DEFAULT), ConfigSetting("RemoteDebuggerOnStartup", &g_Config.bRemoteDebuggerOnStartup, false, CfgFlag::DEFAULT), + ConfigSetting("RemoteTab", &g_Config.bRemoteTab, false, CfgFlag::DEFAULT), #ifdef __ANDROID__ ConfigSetting("ScreenRotation", &g_Config.iScreenRotation, ROTATION_AUTO_HORIZONTAL), diff --git a/Core/Config.h b/Core/Config.h index eacd1ecfa0..fbb49859d4 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -129,6 +129,7 @@ public: bool bRemoteShareOnStartup; std::string sRemoteISOSubdir; bool bRemoteDebuggerOnStartup; + bool bRemoteTab; bool bMemStickInserted; int iMemStickSizeGB; bool bLoadPlugins; diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 9213bac6db..6852cf9a8b 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -55,6 +55,7 @@ #include "UI/GameSettingsScreen.h" #include "UI/MiscScreens.h" #include "UI/ControlMappingScreen.h" +#include "UI/RemoteISOScreen.h" #include "UI/DisplayLayoutScreen.h" #include "UI/SavedataScreen.h" #include "UI/Store.h" @@ -645,6 +646,9 @@ UI::EventReturn GameBrowser::OnHomeClick(UI::EventParams &e) { // Maybe we should have no home directory in this case. Or it should just navigate to the root // of the current folder tree. Path GameBrowser::HomePath() { + if (!homePath_.empty()) { + return homePath_; + } #if PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(SWITCH) || defined(USING_WIN_UI) || PPSSPP_PLATFORM(UWP) return g_Config.memStickDirectory; #else @@ -771,7 +775,7 @@ void GameBrowser::Refresh() { // we show just the image, because we don't need to emphasize the button on Darwin topBar->Add(new Choice(ImageID("I_FOLDER_OPEN"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::BrowseClick); #else - if (System_GetPropertyBool(SYSPROP_HAS_FOLDER_BROWSER)) { + if ((browseFlags_ & BrowseFlags::BROWSE) && System_GetPropertyBool(SYSPROP_HAS_FOLDER_BROWSER)) { topBar->Add(new Choice(mm->T("Browse"), ImageID("I_FOLDER_OPEN"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::BrowseClick); } if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_TV) { @@ -932,7 +936,7 @@ void GameBrowser::Refresh() { Add(new TextView(mm->T("UseBrowseOrLoad", "Use Browse to choose a folder, or Load to choose a file."))); } - if (!lastText_.empty() && gameButtons.empty()) { + if (!lastText_.empty()) { Add(new Spacer()); Add(new Choice(lastText_, new UI::LinearLayoutParams(UI::WRAP_CONTENT, UI::WRAP_CONTENT)))->OnClick.Handle(this, &GameBrowser::LastClick); } @@ -1108,6 +1112,7 @@ void MainScreen::CreateViews() { ScrollView *scrollHomebrew = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); scrollHomebrew->SetTag("MainScreenHomebrew"); + GameBrowser *tabAllGames = new GameBrowser(Path(g_Config.currentDirectory), BrowseFlags::STANDARD, &g_Config.bGridView2, screenManager(), mm->T("How to get games"), "https://www.ppsspp.org/getgames", new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); @@ -1133,6 +1138,29 @@ void MainScreen::CreateViews() { tabAllGames->OnHighlight.Handle(this, &MainScreen::OnGameHighlight); tabHomebrew->OnHighlight.Handle(this, &MainScreen::OnGameHighlight); + if (g_Config.bRemoteTab && !g_Config.sLastRemoteISOServer.empty()) { + auto ri = GetI18NCategory(I18NCat::REMOTEISO); + + ScrollView *scrollRemote = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); + scrollRemote->SetTag("MainScreenRemote"); + + Path remotePath(FormatRemoteISOUrl(g_Config.sLastRemoteISOServer.c_str(), g_Config.iLastRemoteISOPort, RemoteSubdir().c_str())); + + GameBrowser *tabRemote = new GameBrowser(remotePath, BrowseFlags::NAVIGATE, &g_Config.bGridView3, screenManager(), + ri->T("Remote disc streaming"), "https://www.ppsspp.org/docs/reference/disc-streaming", + new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); + tabRemote->SetHomePath(remotePath); + + scrollRemote->Add(tabRemote); + gameBrowsers_.push_back(tabRemote); + + tabHolder_->AddTab(ri->T("Remote disc streaming"), scrollRemote); + + tabRemote->OnChoice.Handle(this, &MainScreen::OnGameSelectedInstant); + tabRemote->OnHoldChoice.Handle(this, &MainScreen::OnGameSelected); + tabRemote->OnHighlight.Handle(this, &MainScreen::OnGameHighlight); + } + if (g_Config.HasRecentIsos()) { tabHolder_->SetCurrentTab(0, true); } else if (g_Config.iMaxRecent > 0) { diff --git a/UI/MainScreen.h b/UI/MainScreen.h index aaea6bff14..994cb82ba2 100644 --- a/UI/MainScreen.h +++ b/UI/MainScreen.h @@ -32,10 +32,11 @@ enum GameBrowserFlags { enum class BrowseFlags { NONE = 0, NAVIGATE = 1, - ARCHIVES = 2, - PIN = 4, - HOMEBREW_STORE = 8, - STANDARD = 1 | 2 | 4, + BROWSE = 2, + ARCHIVES = 4, + PIN = 8, + HOMEBREW_STORE = 16, + STANDARD = 1 | 2 | 4 | 8, }; ENUM_CLASS_BITOPS(BrowseFlags); @@ -55,6 +56,10 @@ public: void Draw(UIContext &dc) override; void Update() override; + void SetHomePath(const Path &path) { + homePath_ = path; + } + protected: virtual bool DisplayTopBar(); virtual bool HasSpecialFiles(std::vector &filenames); @@ -63,6 +68,8 @@ protected: void Refresh(); + Path homePath_; + private: bool IsCurrentPathPinned(); const std::vector GetPinnedPaths(); diff --git a/UI/RemoteISOScreen.cpp b/UI/RemoteISOScreen.cpp index f12005e30f..53266234db 100644 --- a/UI/RemoteISOScreen.cpp +++ b/UI/RemoteISOScreen.cpp @@ -96,7 +96,7 @@ static ServerAllowStatus IsServerAllowed(int port) { #endif } -static std::string RemoteSubdir() { +std::string RemoteSubdir() { if (g_Config.bRemoteISOManual) { return g_Config.sRemoteISOSubdir; } @@ -484,9 +484,13 @@ ScanStatus RemoteISOConnectScreen::GetStatus() { return status_; } +std::string FormatRemoteISOUrl(const char *host, int port, const char *subdir) { + return StringFromFormat("http://%s:%d%s", host, port, subdir); +} + void RemoteISOConnectScreen::ExecuteLoad() { std::string subdir = RemoteSubdir(); - url_ = StringFromFormat("http://%s:%d%s", host_.c_str(), port_, subdir.c_str()); + url_ = FormatRemoteISOUrl(host_.c_str(), port_, subdir.c_str()); bool result = LoadGameList(Path(url_), games_); if (scanAborted) { return; @@ -501,25 +505,6 @@ void RemoteISOConnectScreen::ExecuteLoad() { status_ = result ? ScanStatus::LOADED : ScanStatus::FAILED; } -class RemoteGameBrowser : public GameBrowser { -public: - RemoteGameBrowser(const Path &url, BrowseFlags browseFlags, bool *gridStyle, ScreenManager *screenManager, std::string lastText, std::string lastLink, UI::LayoutParams *layoutParams = nullptr) - : GameBrowser(url, browseFlags, gridStyle, screenManager, lastText, lastLink, layoutParams) { - initialPath_ = url; - } - -protected: - Path HomePath() override { - return initialPath_; - } - - Path initialPath_; -}; - -RemoteISOBrowseScreen::RemoteISOBrowseScreen(const std::string &url, const std::vector &games) - : url_(url), games_(games) { -} - void RemoteISOBrowseScreen::CreateViews() { auto di = GetI18NCategory(I18NCat::DIALOG); auto ri = GetI18NCategory(I18NCat::REMOTEISO); @@ -535,9 +520,11 @@ void RemoteISOBrowseScreen::CreateViews() { ScrollView *scrollRecentGames = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); scrollRecentGames->SetTag("RemoteGamesTab"); - GameBrowser *tabRemoteGames = new RemoteGameBrowser( - Path(url_), BrowseFlags::PIN | BrowseFlags::NAVIGATE, &g_Config.bGridView1, screenManager(), "", "", + GameBrowser *tabRemoteGames = new GameBrowser( + Path(url_), BrowseFlags::NAVIGATE, &g_Config.bGridView1, screenManager(), "", "", new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); + tabRemoteGames->SetHomePath(Path(url_)); + scrollRecentGames->Add(tabRemoteGames); gameBrowsers_.push_back(tabRemoteGames); @@ -599,13 +586,14 @@ void RemoteISOSettingsScreen::CreateViews() { remoteisoSettings->Add(new ItemHeader(ri->T("Remote disc streaming"))); remoteisoSettings->Add(new CheckBox(&g_Config.bRemoteShareOnStartup, ri->T("Share on PPSSPP startup"))); remoteisoSettings->Add(new CheckBox(&g_Config.bRemoteISOManual, ri->T("Manual Mode Client", "Manually configure client"))); + remoteisoSettings->Add(new CheckBox(&g_Config.bRemoteTab, ri->T("Show Remote tab on main screen"))); UI::Choice *remoteServer; remoteServer = new PopupTextInputChoice(&g_Config.sLastRemoteISOServer, ri->T("Remote Server"), "", 255, screenManager()); remoteisoSettings->Add(remoteServer); remoteServer->SetEnabledPtr(&g_Config.bRemoteISOManual); - PopupSliderChoice *remotePort = remoteisoSettings->Add(new PopupSliderChoice(&g_Config.iLastRemoteISOPort, 0, 65535, 0, ri->T("Remote Port", "Remote Port"), 100, screenManager())); + PopupSliderChoice *remotePort = remoteisoSettings->Add(new PopupSliderChoice(&g_Config.iLastRemoteISOPort, 0, 65535, 0, ri->T("Remote Port"), 100, screenManager())); remotePort->SetEnabledPtr(&g_Config.bRemoteISOManual); UI::Choice *remoteSubdir; diff --git a/UI/RemoteISOScreen.h b/UI/RemoteISOScreen.h index 884dba8fe2..6452c9419e 100644 --- a/UI/RemoteISOScreen.h +++ b/UI/RemoteISOScreen.h @@ -85,7 +85,8 @@ protected: class RemoteISOBrowseScreen : public MainScreen { public: - RemoteISOBrowseScreen(const std::string &url, const std::vector &games); + RemoteISOBrowseScreen(const std::string &url, const std::vector &games) + : url_(url), games_(games) {} const char *tag() const override { return "RemoteISOBrowse"; } @@ -110,3 +111,6 @@ protected: bool serverRunning_ = false; }; + +std::string RemoteSubdir(); +std::string FormatRemoteISOUrl(const char *host, int port, const char *subdir);