Skip to content

Commit

Permalink
Fixed|UI|libgui: Loading package icons
Browse files Browse the repository at this point in the history
The UI attempted to load icons from packages that didn’t have a custom icon. This caused some error messages.
  • Loading branch information
skyjake committed Dec 1, 2018
1 parent 4e48a6a commit 7b4dcbb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 1 addition & 2 deletions doomsday/apps/client/src/ui/widgets/packageswidget.cpp
Expand Up @@ -247,10 +247,9 @@ DENG_GUI_PIMPL(PackagesWidget)
{
_iconId = Id::None;

if (_item && _item->file)
if (_item && _item->file && iconBank().packageContainsIcon(*_item->file))
{
_packagePath = _item->file->path();

if (Id pkgIcon = iconBank().packageIcon(*_item->file))
{
setPackageIcon(pkgIcon);
Expand Down
4 changes: 3 additions & 1 deletion doomsday/sdk/libgui/include/de/graphics/packageiconbank.h
Expand Up @@ -47,6 +47,8 @@ class LIBGUI_PUBLIC PackageIconBank : public TextureBank
*/
void setDisplaySize(Size const &displaySize);

bool packageContainsIcon(const File &packageFile) const;

/**
* Returns the ID of a package icon, if one is loaded and available in the atlas.
* If the icon is not yet available, loading it is requested. The caller can use
Expand All @@ -56,7 +58,7 @@ class LIBGUI_PUBLIC PackageIconBank : public TextureBank
*
* @return Allocation ID, or Id::None.
*/
Id packageIcon(File const &packageFile);
Id packageIcon(const File &packageFile);

private:
DENG2_PRIVATE(d)
Expand Down
15 changes: 13 additions & 2 deletions doomsday/sdk/libgui/src/graphics/packageiconbank.cpp
Expand Up @@ -37,7 +37,7 @@ DENG2_PIMPL_NOREF(PackageIconBank)

Image load() const override
{
String const iconPath = sourcePath() / QStringLiteral("icon");
const String iconPath = sourcePath() / QStringLiteral("icon");

Image img;
if (ImageFile const *file = FS::tryLocate<ImageFile const>(iconPath + ".jpg"))
Expand Down Expand Up @@ -77,6 +77,12 @@ DENG2_PIMPL_NOREF(PackageIconBank)
};

Size displaySize;

static bool doesPackageHaveIcon(const Path &packagePath)
{
return FS::exists(packagePath / "icon.jpg") ||
FS::exists(packagePath / "icon.png");
}
};

PackageIconBank::PackageIconBank()
Expand All @@ -93,7 +99,7 @@ void PackageIconBank::setDisplaySize(Size const &displaySize)

Id PackageIconBank::packageIcon(File const &packageFile)
{
Path const packagePath = packageFile.path();
const Path packagePath = packageFile.path();
if (!has(packagePath))
{
add(packagePath, new Impl::PackageImageSource(packagePath, d->displaySize));
Expand All @@ -110,4 +116,9 @@ Id PackageIconBank::packageIcon(File const &packageFile)
return Id::None;
}

bool PackageIconBank::packageContainsIcon(const de::File &packageFile) const
{
return Impl::doesPackageHaveIcon(packageFile.path());
}

} // namespace de

0 comments on commit 7b4dcbb

Please sign in to comment.