Skip to content

Commit

Permalink
World-specific custom title screen levels (#2667)
Browse files Browse the repository at this point in the history
Worlds now contain the "title-screen" property, which determines the title screen level, which should play, if this world is the last entered world on the current profile.

Additionally, the title screen level property of a world can be overriden for a certain savegame using the `worldmap.settings.set_title_level(filename)` scripting function.

Custom title screens can be toggled from the "Extras" options category.

Changing profiles or toggling the custom title screens option will now automatically change the title level in the background, if needed, applying a fade transition.
  • Loading branch information
Vankata453 authored Dec 14, 2023
1 parent 2272053 commit 41356f0
Show file tree
Hide file tree
Showing 40 changed files with 445 additions and 176 deletions.
15 changes: 7 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ else()
option(HIDE_NONMOBILE_OPTIONS "Hide options that are impractical on mobile devices (e. g. changing screen resolution)" OFF)
endif()

# Configure main menu logo
if(("${SUPERTUX_VERSION_STRING}" MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+$") OR IS_SUPERTUX_RELEASE OR STEAM_BUILD)
set(LOGO_FILE "logo.png")
else()
set(LOGO_FILE "logo_dev.png")
endif()

if(WIN32)
include(SuperTux/Win32)
endif()
Expand Down Expand Up @@ -297,14 +304,6 @@ include(SuperTux/BuildInstall)
## Create config.h now that INSTALL_SUBDIR_* have been set.
configure_file(config.h.cmake ${CMAKE_BINARY_DIR}/config.h )

## Configure main menu logo
if(("${SUPERTUX_VERSION_STRING}" MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+$") OR IS_SUPERTUX_RELEASE OR STEAM_BUILD)
set(LOGO_FILE "logo_final.sprite")
else()
set(LOGO_FILE "logo.sprite")
endif()
configure_file(data/levels/misc/menu.stl.in ${CMAKE_BINARY_DIR}/data/levels/misc/menu.stl )

## Build tests
include(SuperTux/BuildTests)

Expand Down
2 changes: 0 additions & 2 deletions data/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions data/images/engine/menu/logo.sprite

This file was deleted.

6 changes: 0 additions & 6 deletions data/images/engine/menu/logo_santahat.sprite

This file was deleted.

6 changes: 0 additions & 6 deletions data/images/objects/logo/logo.sprite

This file was deleted.

6 changes: 0 additions & 6 deletions data/images/objects/logo/logo_final.sprite

This file was deleted.

47 changes: 16 additions & 31 deletions data/levels/misc/menu.stl.in → data/levels/misc/menu.stl
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,25 @@
(sector
(name "main")
(init-script "
logo <- FloatingImage(\"images/objects/logo/@LOGO_FILE@\");
if(is_christmas()) {
christmas_hat <- FloatingImage(\"images/objects/logo/logo_santahat.sprite\");
christmas_hat.set_anchor_point(ANCHOR_MIDDLE);
christmas_hat.set_pos(35, -255);
christmas_hat.set_visible(true);
if (is_christmas())
{
// enable snow particles
snow_particles.set_enabled(true);

// enable snow particles
snow_particles.set_enabled(true);
// change ambient light
settings.fade_to_ambient_light(0.8, 0.82, 1, 0);

// change ambient light
settings.fade_to_ambient_light(0.8, 0.82, 1, 0);
// change background
background.set_color1(0, 0, 0);
background.set_color2(0, 0, 0.4);
parallax1.set_color(0.32, 0.42, 0.5, 1);
parallax2.set_color(0.125, 0.18, 0.35, 1);
skybox.set_image(\"images/background/misc/skybox_night.png\");

// change background
background.set_color1(0, 0, 0);
background.set_color2(0, 0, 0.4);
parallax1.set_color(0.32, 0.42, 0.5, 1);
parallax2.set_color(0.125, 0.18, 0.35, 1);
skybox.set_image(\"images/background/misc/skybox_night.png\");


// change music
settings.set_music(\"music/misc/christmas_theme.music\");

// change tilemaps
sector.christmas.set_alpha(1);
}
logo.set_anchor_point(ANCHOR_MIDDLE);
logo.set_pos(0, -200);
logo.set_visible(true);
")
// change tilemaps
christmas.set_alpha(1);
}
")
(ambient-light
(color 1 1 1)
)
Expand Down Expand Up @@ -86,9 +74,6 @@ logo.set_visible(true);
(x 18240)
(y 1408)
)
(music
(file "/music/misc/theme.music")
)
(particles-snow
(enabled #f)
(name "snow_particles")
Expand Down
8 changes: 2 additions & 6 deletions mk/cmake/SuperTux/BuildInstall.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,12 @@ if(CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo")
DESTINATION ${INSTALL_SUBDIR_SHARE}
PATTERN "data/levels/test" EXCLUDE
PATTERN "data/levels/test_old" EXCLUDE
PATTERN "data/levels/incubator" EXCLUDE
PATTERN "data/levels/misc/menu.stl.in" EXCLUDE)
PATTERN "data/levels/incubator" EXCLUDE)
else()
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/levels
DESTINATION ${INSTALL_SUBDIR_SHARE}
PATTERN "data/levels/misc/menu.stl.in" EXCLUDE)
DESTINATION ${INSTALL_SUBDIR_SHARE})
endif()

install(FILES "${CMAKE_BINARY_DIR}/data/levels/misc/menu.stl" DESTINATION "${INSTALL_SUBDIR_SHARE}/levels/misc")

# move some config clutter to the advanced section
mark_as_advanced(
INSTALL_SUBDIR_BIN
Expand Down
8 changes: 8 additions & 0 deletions src/audio/stream_sound_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ StreamSoundSource::set_sound_file(std::unique_ptr<SoundFile> newfile)
}
}

void
StreamSoundSource::resume()
{
OpenALSoundSource::resume();
set_gain(1.0);
m_fade_state = NoFading;
}

void
StreamSoundSource::update()
{
Expand Down
1 change: 1 addition & 0 deletions src/audio/stream_sound_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class StreamSoundSource final : public OpenALSoundSource
StreamSoundSource();
~StreamSoundSource() override;

virtual void resume() override;
virtual void update() override;
virtual void set_looping(bool looping_) override { m_looping = looping_; }

Expand Down
4 changes: 2 additions & 2 deletions src/object/music_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ MusicObject::play_music(MusicType type)
}

void
MusicObject::resume_music()
MusicObject::resume_music(bool instantly)
{
if (SoundManager::current()->get_current_music() == m_music)
{
SoundManager::current()->resume_music(3.2f);
SoundManager::current()->resume_music(instantly ? 0.f : 3.2f);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/object/music_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MusicObject : public GameObject
virtual ObjectSettings get_settings() override;

void play_music(MusicType musictype);
void resume_music();
void resume_music(bool instantly = false);
MusicType get_music_type() const;

void set_music(const std::string& music);
Expand Down
12 changes: 12 additions & 0 deletions src/scripting/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "supertux/shrinkfade.hpp"
#include "supertux/textscroller_screen.hpp"
#include "supertux/tile.hpp"
#include "supertux/title_screen.hpp"
#include "video/renderer.hpp"
#include "video/video_system.hpp"
#include "video/viewport.hpp"
Expand Down Expand Up @@ -484,6 +485,17 @@ void play_demo(const std::string& filename)
session->play_demo(filename);
}

void set_title_frame(const std::string& image)
{
auto title_screen = TitleScreen::current();
if (!title_screen)
{
log_info << "No title screen loaded." << std::endl;
return;
}
title_screen->set_frame(image);
}

}

/* EOF */
6 changes: 6 additions & 0 deletions src/scripting/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ void record_demo(const std::string& filename);
*/
void play_demo(const std::string& filename);

/**
* Sets the frame, displayed on the title screen.
* @param string $image
*/
void set_title_frame(const std::string& image);

#ifdef DOXYGEN_SCRIPTING
}
#endif
Expand Down
7 changes: 7 additions & 0 deletions src/scripting/worldmap_sector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ WorldMapSector::get_filename() const
return worldmap.get_filename();
}

void
WorldMapSector::set_title_level(const std::string& filename)
{
SCRIPT_GUARD_WORLDMAP;
worldmap.get_savegame().get_player_status().title_level = filename;
}

} // namespace scripting

/* EOF */
6 changes: 6 additions & 0 deletions src/scripting/worldmap_sector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ class WorldMapSector final : public GameObjectManager
*/
std::string get_filename() const;

/**
* Overrides the "Title Screen Level" property for the world with ""filename"".
The newly set level will be used for the title screen, after exiting the world.
* @param string $filename
*/
void set_title_level(const std::string& filename);
};

} // namespace scripting
Expand Down
67 changes: 67 additions & 0 deletions src/scripting/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11539,6 +11539,36 @@ static SQInteger WorldMapSector_get_filename_wrapper(HSQUIRRELVM vm)

}

static SQInteger WorldMapSector_set_title_level_wrapper(HSQUIRRELVM vm)
{
SQUserPointer data;
if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr, SQTrue)) || !data) {
sq_throwerror(vm, _SC("'set_title_level' called without instance"));
return SQ_ERROR;
}
scripting::WorldMapSector* _this = reinterpret_cast<scripting::WorldMapSector*> (data);

const SQChar* arg0;
if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) {
sq_throwerror(vm, _SC("Argument 1 not a string"));
return SQ_ERROR;
}

try {
_this->set_title_level(arg0);

return 0;

} catch(std::exception& e) {
sq_throwerror(vm, e.what());
return SQ_ERROR;
} catch(...) {
sq_throwerror(vm, _SC("Unexpected exception while executing function 'set_title_level'"));
return SQ_ERROR;
}

}

static SQInteger display_wrapper(HSQUIRRELVM vm)
{
return scripting::display(vm);
Expand Down Expand Up @@ -12549,6 +12579,29 @@ static SQInteger play_demo_wrapper(HSQUIRRELVM vm)

}

static SQInteger set_title_frame_wrapper(HSQUIRRELVM vm)
{
const SQChar* arg0;
if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) {
sq_throwerror(vm, _SC("Argument 1 not a string"));
return SQ_ERROR;
}

try {
scripting::set_title_frame(arg0);

return 0;

} catch(std::exception& e) {
sq_throwerror(vm, e.what());
return SQ_ERROR;
} catch(...) {
sq_throwerror(vm, _SC("Unexpected exception while executing function 'set_title_frame'"));
return SQ_ERROR;
}

}

static SQInteger Level_finish_wrapper(HSQUIRRELVM vm)
{
SQBool arg0;
Expand Down Expand Up @@ -14030,6 +14083,13 @@ void register_supertux_wrapper(HSQUIRRELVM v)
throw SquirrelError(v, "Couldn't register function 'play_demo'");
}

sq_pushstring(v, "set_title_frame", -1);
sq_newclosure(v, &set_title_frame_wrapper, 0);
sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".s");
if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register function 'set_title_frame'");
}

sq_pushstring(v, "Level_finish", -1);
sq_newclosure(v, &Level_finish_wrapper, 0);
sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".b|n");
Expand Down Expand Up @@ -15680,6 +15740,13 @@ void register_supertux_wrapper(HSQUIRRELVM v)
throw SquirrelError(v, "Couldn't register function 'get_filename'");
}

sq_pushstring(v, "set_title_level", -1);
sq_newclosure(v, &WorldMapSector_set_title_level_wrapper, 0);
sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".s");
if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register function 'set_title_level'");
}

if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register class 'WorldMapSector'");
}
Expand Down
8 changes: 8 additions & 0 deletions src/supertux/game_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

#include "supertux/game_manager.hpp"

#include "editor/editor.hpp"
#include "sdk/integration.hpp"
#include "supertux/levelset_screen.hpp"
#include "supertux/player_status.hpp"
#include "supertux/profile.hpp"
#include "supertux/savegame.hpp"
#include "supertux/screen.hpp"
#include "supertux/screen_fade.hpp"
Expand Down Expand Up @@ -49,6 +51,9 @@ GameManager::start_level(const World& world, const std::string& level_filename,
*m_savegame,
start_pos);
ScreenManager::current()->push_screen(std::move(screen));

if (!Editor::current())
m_savegame->get_profile().set_last_world(world.get_basename());
}

void
Expand Down Expand Up @@ -78,6 +83,9 @@ GameManager::start_worldmap(const World& world, const std::string& worldmap_file
auto worldmap = std::make_unique<worldmap::WorldMap>(filename, *m_savegame, sector, spawnpoint);
auto worldmap_screen = std::make_unique<worldmap::WorldMapScreen>(std::move(worldmap));
ScreenManager::current()->push_screen(std::move(worldmap_screen));

if (!Editor::current())
m_savegame->get_profile().set_last_world(world.get_basename());
}
catch(std::exception& e)
{
Expand Down
Loading

0 comments on commit 41356f0

Please sign in to comment.