Path code cleanup, move some UI code (#21037)

* Move a bunch of path logic into Core/Util/PathUtil.cpp/h

.

* Move GameImageView out from SaveDataScreen

* More cleanup, add a translation string
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2025-11-25 00:44:24 +01:00
1 parent 3116eba395
commit b8fced5b41
72 files changed
+416 -330

No files matched your search

+6 -3
View File
@@ -402,13 +402,16 @@ void GameInfo::SetTitle(const std::string &newTitle) {
}
void GameInfo::FinishPendingTextureLoads(Draw::DrawContext *draw) {
if (draw && icon.dataLoaded && !icon.texture) {
if (!draw) {
return;
}
if (icon.dataLoaded && !icon.texture) {
SetupTexture(draw, icon);
}
if (draw && pic0.dataLoaded && !pic0.texture) {
if (pic0.dataLoaded && !pic0.texture) {
SetupTexture(draw, pic0);
}
if (draw && pic1.dataLoaded && !pic1.texture) {
if (pic1.dataLoaded && !pic1.texture) {
SetupTexture(draw, pic1);
}
}
+1
View File
@@ -197,6 +197,7 @@ public:
// redrawing the UI often. Only set flags to GAMEINFO_WANTBG or WANTSND if you really want them
// because they're big. bgTextures and sound may be discarded over time as well.
// NOTE: This never returns null, so you don't need to check for that. Do check Ready() flags though.
// It's OK to pass in nullptr for draw if you don't need the actual texture right now.
std::shared_ptr<GameInfo> GetInfo(Draw::DrawContext *draw, const Path &gamePath, GameInfoFlags wantFlags, GameInfoFlags *outHasFlags = nullptr);
void FlushBGs(); // Gets rid of all BG textures. Also gets rid of bg sounds.
+7 -4
View File
@@ -519,10 +519,11 @@ GameBrowser::GameBrowser(int token, const Path &path, BrowseFlags browseFlags, b
using namespace UI;
path_.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION));
Path memstickRoot = GetSysDirectory(DIRECTORY_MEMSTICK_ROOT);
aliasMatch_ = memstickRoot;
if (memstickRoot == GetSysDirectory(DIRECTORY_PSP)) {
path_.SetRootAlias("ms:/PSP/", memstickRoot);
aliasDisplay_ = "ms:/PSP/";
} else {
path_.SetRootAlias("ms:/", memstickRoot);
aliasDisplay_ = "ms:/";
}
if (System_GetPropertyBool(SYSPROP_LIMITED_FILE_BROWSING) &&
(path.Type() == PathType::NATIVE || path.Type() == PathType::CONTENT_URI)) {
@@ -782,13 +783,15 @@ void GameBrowser::Refresh() {
const bool pathOnSeparateLine = g_display.dp_xres < 1050 || portrait_;
std::string pathStr = GetFriendlyPath(path_.GetPath(), aliasMatch_, aliasDisplay_);
if (pathOnSeparateLine) {
Add(new TextView(path_.GetFriendlyPath(), ALIGN_VCENTER | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, Margins(8, 0, 8, 0))));
Add(new TextView(pathStr, ALIGN_VCENTER | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, Margins(8, 0, 8, 0))));
}
if (browseFlags_ & BrowseFlags::NAVIGATE) {
if (!pathOnSeparateLine) {
topBar->Add(new Spacer(2.0f));
topBar->Add(new TextView(path_.GetFriendlyPath(), ALIGN_VCENTER | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, 64.0f, 1.0f)));
topBar->Add(new TextView(pathStr, ALIGN_VCENTER | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, 64.0f, 1.0f)));
}
topBar->Add(new Choice(ImageID("I_HOME"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::OnHomeClick);
if (System_GetPropertyBool(SYSPROP_HAS_ADDITIONAL_STORAGE)) {
+2
View File
@@ -116,6 +116,8 @@ private:
ScreenManager *screenManager_;
int token_ = -1;
bool portrait_ = false;
Path aliasMatch_;
std::string aliasDisplay_;
};
class RemoteISOBrowseScreen;
+52
View File
@@ -158,3 +158,55 @@ PaneTitleBar::PaneTitleBar(const Path &gamePath, std::string_view title, const s
});
}
}
void GameImageView::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
w = textureWidth_;
h = textureHeight_;
}
void GameImageView::Draw(UIContext &dc) {
using namespace UI;
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(dc.GetDrawContext(), gamePath_, image_);
if (!info->Ready(image_) || !info->icon.texture) {
return;
}
Draw::Texture *texture = nullptr;
switch (image_) {
case GameInfoFlags::ICON:
texture = info->icon.texture;
break;
case GameInfoFlags::PIC0:
texture = info->pic0.texture;
break;
case GameInfoFlags::PIC1:
texture = info->pic1.texture;
break;
}
if (!texture) {
return;
}
textureWidth_ = texture->Width() * scale_;
textureHeight_ = texture->Height() * scale_;
// Fade icon with the backgrounds.
double loadTime = info->icon.timeLoaded;
auto pic = info->GetPIC1();
if (pic) {
loadTime = std::max(loadTime, pic->timeLoaded);
}
uint32_t color = whiteAlpha(ease((time_now_d() - loadTime) * 3));
// Adjust size so we don't stretch the image vertically or horizontally.
// Make sure it's not wider than 144 (like Doom Legacy homebrew), ugly in the grid mode.
float nw = std::min(bounds_.h * textureWidth_ / textureHeight_, (float)bounds_.w);
int x = bounds_.x + (bounds_.w - nw) / 2.0f;
dc.Flush();
dc.GetDrawContext()->BindTexture(0, texture);
dc.Draw()->Rect(x, bounds_.y, nw, bounds_.h, color);
dc.Flush();
dc.RebindTexture();
}
+19
View File
@@ -3,6 +3,7 @@
#include "Common/Common.h"
#include "Common/UI/View.h"
#include "UI/ViewGroup.h"
#include "UI/GameInfoCache.h"
// Compound view, showing a text with an icon.
class TextWithImage : public UI::LinearLayout {
@@ -57,3 +58,21 @@ public:
private:
Path gamePath_;
};
class GameImageView : public UI::InertView {
public:
GameImageView(const Path &gamePath, GameInfoFlags image, float scale, UI::LayoutParams *layoutParams = 0)
: InertView(layoutParams), image_(image), gamePath_(gamePath), scale_(scale) {
}
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
void Draw(UIContext &dc) override;
std::string DescribeText() const override { return ""; }
private:
Path gamePath_;
GameInfoFlags image_;
float scale_ = 1.0f;
int textureWidth_ = 0;
int textureHeight_ = 0;
};
+1 -10
View File
@@ -111,6 +111,7 @@
#include "Core/Util/PortManager.h"
#include "Core/Util/AudioFormat.h"
#include "Core/Util/RecentFiles.h"
#include "Core/Util/PathUtil.h"
#include "Core/WebServer.h"
#include "Core/TiltEventProcessor.h"
@@ -257,16 +258,6 @@ void PostLoadConfig() {
#endif
}
static Path GetFailedBackendsDir() {
Path failedBackendsDir;
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) {
failedBackendsDir = GetSysDirectory(DIRECTORY_APP_CACHE);
} else {
failedBackendsDir = GetSysDirectory(DIRECTORY_SYSTEM);
}
return failedBackendsDir;
}
static void CheckFailedGPUBackends() {
#ifdef _DEBUG
// If you're in debug mode, you probably don't want a fallback. If you're in release mode, use IGNORE below.
-1
View File
@@ -257,7 +257,6 @@ static bool LoadGameList(const Path &url, std::vector<Path> &games) {
browser.SetPath(url);
std::vector<File::FileInfo> files;
browser.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION));
browser.SetRootAlias("ms:", GetSysDirectory(DIRECTORY_MEMSTICK_ROOT));
browser.GetListing(files, "iso:cso:chd:pbp:elf:prx:ppdmp:", &scanCancelled);
if (scanCancelled) {
return false;
+1 -52
View File
@@ -45,6 +45,7 @@
#include "Core/SaveState.h"
#include "Core/System.h"
#include "Core/HLE/sceUtility.h"
#include "UI/MiscViews.h"
class SavedataButton;
@@ -722,55 +723,3 @@ void SavedataScreen::sendMessage(UIMessage message, const char *value) {
stateBrowser_->SetSearchFilter(searchFilter_);
}
}
void GameImageView::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
w = textureWidth_;
h = textureHeight_;
}
void GameImageView::Draw(UIContext &dc) {
using namespace UI;
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(dc.GetDrawContext(), gamePath_, image_);
if (!info->Ready(image_) || !info->icon.texture) {
return;
}
Draw::Texture *texture = nullptr;
switch (image_) {
case GameInfoFlags::ICON:
texture = info->icon.texture;
break;
case GameInfoFlags::PIC0:
texture = info->pic0.texture;
break;
case GameInfoFlags::PIC1:
texture = info->pic1.texture;
break;
}
if (!texture) {
return;
}
textureWidth_ = texture->Width() * scale_;
textureHeight_ = texture->Height() * scale_;
// Fade icon with the backgrounds.
double loadTime = info->icon.timeLoaded;
auto pic = info->GetPIC1();
if (pic) {
loadTime = std::max(loadTime, pic->timeLoaded);
}
uint32_t color = whiteAlpha(ease((time_now_d() - loadTime) * 3));
// Adjust size so we don't stretch the image vertically or horizontally.
// Make sure it's not wider than 144 (like Doom Legacy homebrew), ugly in the grid mode.
float nw = std::min(bounds_.h * textureWidth_ / textureHeight_, (float)bounds_.w);
int x = bounds_.x + (bounds_.w - nw) / 2.0f;
dc.Flush();
dc.GetDrawContext()->BindTexture(0, texture);
dc.Draw()->Rect(x, bounds_.y, nw, bounds_.h, color);
dc.Flush();
dc.RebindTexture();
}
-17
View File
@@ -97,23 +97,6 @@ private:
std::string searchFilter_;
};
class GameImageView : public UI::InertView {
public:
GameImageView(const Path &gamePath, GameInfoFlags image, float scale, UI::LayoutParams *layoutParams = 0)
: InertView(layoutParams), image_(image), gamePath_(gamePath), scale_(scale) {}
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
void Draw(UIContext &dc) override;
std::string DescribeText() const override { return ""; }
private:
Path gamePath_;
GameInfoFlags image_;
float scale_ = 1.0f;
int textureWidth_ = 0;
int textureHeight_ = 0;
};
class SavedataButton : public UI::Clickable {
public:
SavedataButton(const Path &gamePath, UI::LayoutParams *layoutParams = 0)