diff --git a/src/animation/screen-transition.cpp b/src/animation/screen-transition.cpp index 186af0c..2f42b97 100644 --- a/src/animation/screen-transition.cpp +++ b/src/animation/screen-transition.cpp @@ -70,7 +70,7 @@ void screen_transition::set_visible(bool visible) billboard.set_active(visible); } -void screen_transition::transition(float duration, bool reverse, ::animation::interpolator_type interpolator, bool hide) +void screen_transition::transition(float duration, bool reverse, ::animation::interpolator_type interpolator, bool hide, const std::function& callback) { float initial_state = (reverse) ? 1.0f : 0.0f; float final_state = (reverse) ? 0.0f : 1.0f; @@ -83,17 +83,23 @@ void screen_transition::transition(float duration, bool reverse, ::animationcallback = callback; if (hide) { // Setup animation end callback to hide transition billboard animation.set_end_callback ( - std::bind(&scene::object_base::set_active, &billboard, false) + [this]() + { + this->billboard.set_active(false); + if (this->callback) + this->callback(); + } ); } else { - animation.set_end_callback(nullptr); + animation.set_end_callback(callback); } // Update tweens diff --git a/src/animation/screen-transition.hpp b/src/animation/screen-transition.hpp index b31c528..c88acd0 100644 --- a/src/animation/screen-transition.hpp +++ b/src/animation/screen-transition.hpp @@ -35,7 +35,7 @@ public: void set_visible(bool visible); - void transition(float duration, bool reverse, animation::interpolator_type interpolator, bool hide = true); + void transition(float duration, bool reverse, animation::interpolator_type interpolator, bool hide = true, const std::function& callback = nullptr); scene::billboard* get_billboard(); render::material* get_material(); @@ -47,6 +47,7 @@ private: render::material_property* progress; ::animation animation; ::animation::channel* channel; + std::function callback; }; inline scene::billboard* screen_transition::get_billboard() diff --git a/src/game/context.hpp b/src/game/context.hpp index 473e90b..f2f8370 100644 --- a/src/game/context.hpp +++ b/src/game/context.hpp @@ -116,7 +116,7 @@ namespace render namespace game { -/// Container for data that is shared between game states. +/// Container for data shared between game states. struct context { /// Hierarchichal state machine @@ -216,11 +216,10 @@ struct context // Scene utilities scene::collection* active_scene; - // UI scene + // UI scene::collection* ui_scene; scene::camera* ui_camera; scene::billboard* camera_flash_billboard; - float font_size; bool dyslexia_font; ui::mouse_tracker* menu_mouse_tracker; diff --git a/src/game/state/boot.cpp b/src/game/state/boot.cpp index 2d78c4b..4b47ed4 100644 --- a/src/game/state/boot.cpp +++ b/src/game/state/boot.cpp @@ -792,9 +792,12 @@ void boot::setup_animation() ctx.menu_bg_fade_in_animation->set_frame_callback(menu_bg_frame_callback); ctx.menu_bg_fade_in_animation->set_start_callback ( - [&ctx = this->ctx]() + [&ctx = this->ctx, menu_bg_tint]() { ctx.ui_scene->add_object(ctx.menu_bg_billboard); + + menu_bg_tint->set_value(float4{0.0f, 0.0f, 0.0f, 0.0f}); + menu_bg_tint->update_tweens(); ctx.menu_bg_billboard->set_active(true); } ); diff --git a/src/game/state/main-menu.cpp b/src/game/state/main-menu.cpp index 289cce6..4cb00c1 100644 --- a/src/game/state/main-menu.cpp +++ b/src/game/state/main-menu.cpp @@ -30,7 +30,6 @@ #include "animation/animator.hpp" #include "animation/screen-transition.hpp" #include "animation/ease.hpp" -#include "animation/timeline.hpp" #include "application.hpp" #include @@ -102,7 +101,7 @@ main_menu::main_menu(game::context& ctx, bool fade_in): game::menu::add_text_to_ui(ctx); game::menu::setup_animations(ctx); - auto select_start_callback = [&ctx]() + auto select_start_callback = [this, &ctx]() { // Disable controls and menu callbacks game::menu::clear_controls(ctx); @@ -122,17 +121,15 @@ main_menu::main_menu(game::context& ctx, bool fade_in): ); }; - // Set up timing - const float fade_out_duration = 1.0f; + // Fade out title + this->fade_out_title(); - // Schedule state change - timeline* timeline = ctx.timeline; - float t = timeline->get_position(); - timeline->add_sequence({{t + fade_out_duration, change_state_nuptial_flight}}); + // Fade out menu + game::menu::fade_out(ctx, nullptr); // Start fade out to white ctx.fade_transition_color->set_value({1, 1, 1}); - ctx.fade_transition->transition(fade_out_duration, false, ease::out_cubic, false); + ctx.fade_transition->transition(1.0f, false, ease::out_cubic, false, change_state_nuptial_flight); }; auto select_options_callback = [this, &ctx]() { @@ -185,9 +182,19 @@ main_menu::main_menu(game::context& ctx, bool fade_in): } ); }; - auto select_quit_callback = [&ctx]() + auto select_quit_callback = [this, &ctx]() { - ctx.app->close(); + // Disable controls + game::menu::clear_controls(ctx); + + // Fade out title + this->fade_out_title(); + + // Fade out menu + game::menu::fade_out(ctx, nullptr); + + // Fade to black then quit + ctx.fade_transition->transition(0.5f, false, ease::out_cubic, false, std::bind(&application::close, ctx.app)); }; // Build list of menu select callbacks diff --git a/src/game/state/nuptial-flight.cpp b/src/game/state/nuptial-flight.cpp index fb1999b..e6fb47c 100644 --- a/src/game/state/nuptial-flight.cpp +++ b/src/game/state/nuptial-flight.cpp @@ -78,6 +78,17 @@ nuptial_flight::nuptial_flight(game::context& ctx): // Enable clouds in sky pass //ctx.surface_sky_pass->set_clouds_model(ctx.resource_manager->load("cloud-plane.mdl")); + // Create biome terrain component + entity::component::terrain biome_terrain; + biome_terrain.max_lod = 18; + biome_terrain.patch_material = ctx.resource_manager->load("desert-terrain.mtl"); + biome_terrain.elevation = [](double, double) -> double + { + return 0.0; + }; + // Replace planet terrain component with biome terrain component + ctx.entity_registry->replace(planet_eid, biome_terrain); + // Create observer entity::id observer_eid = ctx.entity_registry->create(); { @@ -104,7 +115,7 @@ nuptial_flight::nuptial_flight(game::context& ctx): // Queue fade in ctx.fade_transition_color->set_value({1, 1, 1}); - ctx.function_queue.push(std::bind(&screen_transition::transition, ctx.fade_transition, 5.0f, true, math::lerp, true)); + ctx.function_queue.push(std::bind(&screen_transition::transition, ctx.fade_transition, 5.0f, true, math::lerp, true, nullptr)); // Queue control setup ctx.function_queue.push(std::bind(&nuptial_flight::enable_controls, this)); @@ -206,7 +217,7 @@ void nuptial_flight::setup_camera() ctx.entity_registry->assign(camera_eid, constraint_stack); } - ctx.surface_camera->set_exposure(-12.0f); + ctx.surface_camera->set_exposure(-14.0f); } void nuptial_flight::enable_controls() @@ -537,6 +548,22 @@ void nuptial_flight::enable_controls() void nuptial_flight::disable_controls() { + ctx.controls["move_forward"]->set_active_callback(nullptr); + ctx.controls["move_back"]->set_active_callback(nullptr); + ctx.controls["move_right"]->set_active_callback(nullptr); + ctx.controls["move_left"]->set_active_callback(nullptr); + ctx.controls["move_up"]->set_active_callback(nullptr); + ctx.controls["move_down"]->set_active_callback(nullptr); + ctx.controls["mouse_look"]->set_activated_callback(nullptr); + ctx.controls["mouse_look"]->set_deactivated_callback(nullptr); + ctx.controls["look_left_gamepad"]->set_active_callback(nullptr); + ctx.controls["look_left_mouse"]->set_active_callback(nullptr); + ctx.controls["look_right_gamepad"]->set_active_callback(nullptr); + ctx.controls["look_right_mouse"]->set_active_callback(nullptr); + ctx.controls["look_up_gamepad"]->set_active_callback(nullptr); + ctx.controls["look_up_mouse"]->set_active_callback(nullptr); + ctx.controls["look_down_gamepad"]->set_active_callback(nullptr); + ctx.controls["look_down_mouse"]->set_active_callback(nullptr); ctx.controls["pause"]->set_activated_callback(nullptr); } diff --git a/src/game/state/pause-menu.cpp b/src/game/state/pause-menu.cpp index e532432..025ebf3 100644 --- a/src/game/state/pause-menu.cpp +++ b/src/game/state/pause-menu.cpp @@ -28,6 +28,7 @@ #include "application.hpp" #include "scene/text.hpp" #include "debug/logger.hpp" +#include "animation/screen-transition.hpp" namespace game { namespace state { @@ -124,26 +125,29 @@ pause_menu::pause_menu(game::context& ctx): // Disable menu controls game::menu::clear_controls(ctx); - // Clear paused state - //ctx.paused_state.reset(); + // Clear resume callback + ctx.resume_callback = nullptr; - // Fade out pause menu then return to main menu - game::menu::fade_out - ( - ctx, - [&ctx]() - { - // Queue change to main menu state - ctx.function_queue.push - ( - [&ctx]() - { - ctx.state_machine.pop(); - ctx.state_machine.emplace(new game::state::main_menu(ctx, true)); - } - ); - } - ); + auto fade_out_callback = [&ctx]() + { + // Queue change to main menu state + ctx.function_queue.push + ( + [&ctx]() + { + ctx.menu_bg_billboard->set_active(false); + ctx.state_machine.pop(); + ctx.state_machine.emplace(new game::state::main_menu(ctx, true)); + } + ); + }; + + // Fade out pause menu + game::menu::fade_out(ctx, nullptr); + + // Fade out to black then return to main menu + ctx.fade_transition_color->set_value({0, 0, 0}); + ctx.fade_transition->transition(1.0f, false, ease::out_cubic, false, fade_out_callback); }; auto select_quit_callback = [&ctx]() { @@ -156,8 +160,12 @@ pause_menu::pause_menu(game::context& ctx): // Clear paused state //ctx.paused_state.reset(); - // Fade out then quit - game::menu::fade_out(ctx, std::bind(&application::close, ctx.app)); + // Fade out pause menu + game::menu::fade_out(ctx, nullptr); + + // Fade out to black then quit + ctx.fade_transition_color->set_value({0, 0, 0}); + ctx.fade_transition->transition(1.0f, false, ease::out_cubic, false, std::bind(&application::close, ctx.app)); }; // Build list of menu select callbacks