Skip to content

Comments

Display world screenshot previews and progress#2349

Open
provigz wants to merge 47 commits intoSuperTux:masterfrom
provigz:world-previews
Open

Display world screenshot previews and progress#2349
provigz wants to merge 47 commits intoSuperTux:masterfrom
provigz:world-previews

Conversation

@provigz
Copy link
Member

@provigz provigz commented Dec 4, 2022

WorldSetMenu and SortedContribMenu now inherit the new WorldPreviewMenu class, which allows displaying profile-specific world previews and progress. A preview for a world is generated each time the user leaves its worldmap. Only worldmap levelsets support this feature.
Supported also are optional placeholder world previews, which have to be named preview.png, and stored in the relative to levels directory for the world.

image

FileSystemMenu also now shows previews of images, when hovering over an image file.

image

fixes #2286

@mrkubax10 mrkubax10 added type:feature category:code status:needs-review Work needs to be reviewed by other people labels Dec 6, 2022
@provigz provigz marked this pull request as draft June 24, 2023 14:47
@provigz provigz marked this pull request as ready for review August 5, 2023 23:46
@provigz provigz requested review from Rusty-Box and mrkubax10 August 5, 2023 23:46
@Frostwithasideofsalt
Copy link
Member

builds failing, cant test

@tobbi
Copy link
Member

tobbi commented Apr 15, 2025

Needs another rebase against master

Copy link
Member

@Frostwithasideofsalt Frostwithasideofsalt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of my issues have been resolved.

@provigz
Copy link
Member Author

provigz commented Jun 29, 2025

Only issue I see left with this PR is that the worldmap menu is shown in the world screenshot when using the OpenGL renderer on Windows. Considering the default renderer now is SDL, maybe we should merge this and maybe consider this issue for another time, as it's minor and likely directly related to the OpenGL video code.

The OpenGL bug in question

@bruhmoent
Copy link
Member

I'd say that if it ONLY happens with the OpenGL renderer, I'd let it slip by for now.

@provigz
Copy link
Member Author

provigz commented Jun 29, 2025

From my testing, SDL was fine. I encourage you to test it.

@tobbi
Copy link
Member

tobbi commented Jul 2, 2025

Instead of "perfected", how about "perfect"?

Copy link
Member

@bruhmoent bruhmoent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
image

First image steps: Start game -> Contrib Levels -> Community Levels -> Back -> Back -> Start menu shifted
And when there are no add-ons installed, the contrib levels menu shouldn't shift

@provigz
Copy link
Member Author

provigz commented Jul 2, 2025

Isn't it shifted in the first screenshot because of Story Mode?

@bruhmoent
Copy link
Member

There isn't a preview visible, as shown in the screenshot

@provigz
Copy link
Member Author

provigz commented Jul 2, 2025

And there is no progression or anything from Story Mode that shows up on the right? Then sure.

@Alasdairbugs
Copy link
Contributor

"Perfected" is the proper english term for perfecting a level, so that should stay @tobbi

@tobbi
Copy link
Member

tobbi commented Aug 24, 2025

"Perfected" is the proper english term for perfecting a level, so that should stay @tobbi

Ah, alright!

@provigz
Copy link
Member Author

provigz commented Aug 27, 2025

This PR should be ready (review if you could), however I am getting a segfault/signal 6 when making a screenshot on the SDL renderer.

It might be a bug within SDL_RenderReadPixels on SDL2-compat. I'm also getting the following error when SDLPainter::get_pixel() runs, which also uses the function:

src/video/sdl/sdl_painter.cpp:635 failed to read pixels: Can't read outside the current viewport

@provigz provigz requested a review from swagtoy December 14, 2025 20:55
Copy link
Member

@swagtoy swagtoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase too

#include "util/string_util.hpp"

static const size_t MAX_TITLE_CHARS = 30;
static const std::vector<std::string> IMAGE_EXTENSIONS = { ".jpg", ".png", ".surface" };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std array or just a C style array. Try std stringview

}

bool
FileSystemMenu::is_image(const std::string& file) const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smells like unsound logic anyway. sdl image might have something to check this? try running it through and seeing if a valid surface is returned if it doesnt.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

granted, thats kinda rare. plus, what about .jpeg and whatever? maybe im looking at this wrong

void
MenuItem::set_preview(const std::string& preview_file)
{
m_preview = Surface::from_file(preview_file);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error check

.set_help(_("Enable screen transitions and smooth menu animation"));

add_toggle(MNID_WORLD_PREVIEWS, _("Show world previews"), &g_config->show_world_previews)
.set_help(_("Show screenshot previews of the last worldmap state, when hovering over a world."));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comma

@@ -1,5 +1,6 @@
// SuperTux
// Copyright (C) 2021 mrkubax10 <mrkubax10@onet.pl>
// 2022-2023 Vankata453
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump, change name to yours

WorldPreviewMenu::menu_action(MenuItem& item)
{
const int index = item.get_id();
if (index >= 0 && index < static_cast<int>(m_world_entries.size())) // Valid world index.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flip logic and early return

}

uint32_t
Savegame::Progress::get_percentage() const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not int? also its a percentage, why not double?

{}
uint32_t solved;
uint32_t perfect;
uint32_t total;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use unsigned



void
WorldMap::take_preview_screenshot()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

show a dialog and also log SDL_GetError (if applicable(

@swagtoy
Copy link
Member

swagtoy commented Dec 14, 2025

We could probably use getpixel api instead of sdl screenshot. dunno how thatd work on the gl backend

@provigz provigz modified the milestones: 0.7.0, 0.7.1 Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category:code status:needs-review Work needs to be reviewed by other people type:feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

World select suggestions

10 participants