diff --git a/src/GUI/DefaultAircraftLocator.cxx b/src/GUI/DefaultAircraftLocator.cxx index d0dfb6acb..67bc8b89d 100644 --- a/src/GUI/DefaultAircraftLocator.cxx +++ b/src/GUI/DefaultAircraftLocator.cxx @@ -50,11 +50,16 @@ string_list defaultSplashScreenPaths() { string_list result; SGPath tpath = globals->get_fg_root() / "Textures"; - simgear::Dir d(tpath); - for (auto c : d.children(simgear::Dir::TYPE_FILE, ".png")) { - if (c.file_base().find("Splash") == 0) { - result.push_back(c.utf8Str()); - } + auto paths = simgear::Dir(tpath).children(simgear::Dir::TYPE_FILE); + paths.erase(std::remove_if(paths.begin(), paths.end(), [](const SGPath& p) { + const auto f = p.file(); + if (f.find("Splash") != 0) return true; + const auto ext = p.extension(); + return ext != "png" && ext != "jpg"; + }), paths.end()); + + for (auto c : paths) { + result.push_back(c.utf8Str()); } return result; diff --git a/src/GUI/qml/Summary.qml b/src/GUI/qml/Summary.qml index 9600eed60..7445bc781 100644 --- a/src/GUI/qml/Summary.qml +++ b/src/GUI/qml/Summary.qml @@ -35,7 +35,8 @@ Item { } onUrlsListChanged: { - __currentUrl = 0; + var len = preview.urlsList.length; + __currentUrl = Math.floor(Math.random() * len) } Timer { diff --git a/src/Viewer/splash.cxx b/src/Viewer/splash.cxx index 5e8a3bccc..678a7a56d 100644 --- a/src/Viewer/splash.cxx +++ b/src/Viewer/splash.cxx @@ -45,6 +45,7 @@ #include #include #include +#include #include #include
@@ -453,13 +454,24 @@ std::string SplashScreen::selectSplashImage() return paths.at(index).utf8Str(); } - // no splash screen specified - select random image + // no splash screen specified - use one of the default ones SGPath tpath = globals->get_fg_root() / "Textures"; - int num = (int)(sg_random() * 3.0 + 1.0); - std::ostringstream oss; - oss << "Splash" << num << ".png"; - tpath.append(oss.str()); - return tpath.utf8Str(); + paths = simgear::Dir(tpath).children(simgear::Dir::TYPE_FILE); + paths.erase(std::remove_if(paths.begin(), paths.end(), [](const SGPath& p) { + const auto f = p.file(); + if (f.find("Splash") != 0) return true; + const auto ext = p.extension(); + return ext != "png" && ext != "jpg"; + }), paths.end()); + + if (!paths.empty()) { + // Select a random useable texture + const int index = (int)(sg_random() * paths.size()); + return paths.at(index).utf8Str(); + } + + SG_LOG(SG_GUI, SG_ALERT, "Couldn't find any splash screens at all"); + return {}; } void SplashScreen::doUpdate()