The defaultImage property can now be used to display a static image in case no video file was found.

Also fixed a bug where the static image would not get displayed in the grouped custom collections view if there was no game found for the system and the previously selected entry already had it's video playing when navigating away from it.
This commit is contained in:
Leon Styhre 2022-12-21 19:53:03 +01:00
parent c59606e01d
commit 251e826589
6 changed files with 28 additions and 6 deletions

View file

@ -561,14 +561,14 @@ void GamelistView::updateView(const CursorState& state)
}
}
bool fadingOut = false;
bool fadingOut {false};
if (file == nullptr) {
if (mVideoPlaying) {
for (auto& video : mVideoComponents) {
video->stopVideoPlayer(!mStaticVideoAudio);
video->setVideo("");
if (!video->hasStartDelay())
video->setImage("");
video->setImageNoDefault("");
}
}
mVideoPlaying = false;
@ -588,7 +588,6 @@ void GamelistView::updateView(const CursorState& state)
for (auto& video : mVideoComponents) {
setGameImage(mRandomGame, video.get());
video->stopVideoPlayer(!mStaticVideoAudio);
if (video->hasStaticVideo())
@ -609,12 +608,15 @@ void GamelistView::updateView(const CursorState& state)
video->stopVideoPlayer(!mStaticVideoAudio);
video->setImage("");
video->setVideo("");
if (video->hasStaticVideo()) {
video->setStaticVideo();
}
else {
video->setDefaultVideo();
}
video->startVideoPlayer();
}
}
}
@ -991,6 +993,6 @@ void GamelistView::setGameImage(FileData* file, GuiComponent* comp)
}
}
// This is needed so the default image is set if no game media was found.
if (path == "" && comp->getThemeImageTypes().size() > 0)
if (path == "" && (comp->getThemeImageTypes().size() > 0 || comp->getDefaultImage() != ""))
comp->setImage("");
}

View file

@ -1046,7 +1046,8 @@ void SystemView::updateGameSelectors()
}
for (auto& video : mSystemElements[cursor].videoComponents) {
if (video->hasStaticVideo() || video->getThemeImageTypes().size() == 0)
if (video->hasStaticVideo() ||
(video->getThemeImageTypes().size() == 0 && video->getDefaultImage() == ""))
continue;
GameSelectorComponent* gameSelector {nullptr};
if (multipleSelectors) {
@ -1155,7 +1156,8 @@ void SystemView::updateGameSelectors()
}
}
// This is needed so the default image is set if no game media was found.
if (path == "" && video->getThemeImageTypes().size() > 0)
if (path == "" &&
(video->getThemeImageTypes().size() > 0 || video->getDefaultImage() != ""))
video->setImage("");
}
else {

View file

@ -261,6 +261,7 @@ public:
const std::vector<std::string>& getThemeImageTypes() { return mThemeImageTypes; }
const std::string& getThemeGameSelector() const { return mThemeGameSelector; }
const unsigned int getThemeGameSelectorEntry() const { return mThemeGameSelectorEntry; }
virtual const std::string getDefaultImage() const { return ""; }
virtual std::shared_ptr<Font> getFont() const { return nullptr; }

View file

@ -100,6 +100,16 @@ void VideoComponent::setImage(const std::string& path, bool tile)
mStaticImagePath = imagePath;
}
void VideoComponent::setImageNoDefault(const std::string& path)
{
// Check if the image has changed.
if (path == mStaticImagePath)
return;
mStaticImage.setImage(path, false);
mStaticImagePath = path;
}
void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view,
const std::string& element,
@ -257,6 +267,9 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
}
if (mThemeImageTypes.empty())
mConfig.startDelay = 0;
if (elem->has("color")) {
mColorShift = elem->get<unsigned int>("color");
mColorShiftEnd = mColorShift;

View file

@ -41,6 +41,8 @@ public:
void setStaticVideo() { setVideo(mConfig.staticVideoPath); }
// Loads a static image that is displayed if the video cannot be played.
void setImage(const std::string& path, bool tile = false) override;
// Same as setImage() but does not set the default image if the path argument is empty.
void setImageNoDefault(const std::string& path);
// Sets whether we're in media viewer mode.
void setMediaViewerMode(bool isMediaViewer) { mMediaViewerMode = isMediaViewer; }
// Sets whether we're in screensaver mode.

View file

@ -53,6 +53,8 @@ public:
void handleLooping() override;
// Used to immediately mute audio even if there are samples to play in the buffer.
void muteVideoPlayer() override;
// Needed to be able to display the default image even if no image types have been defined.
const std::string getDefaultImage() const override { return mDefaultImagePath; }
private:
void startVideoStream() override;