|
|
@ -36,17 +36,17 @@ credits::credits(game::context& ctx): |
|
|
|
ctx.logger->push_task("Entering credits state"); |
|
|
|
|
|
|
|
// Construct credits text
|
|
|
|
ctx.credits_text = new scene::text(); |
|
|
|
ctx.credits_text->set_material(&ctx.menu_font_material); |
|
|
|
ctx.credits_text->set_font(&ctx.menu_font); |
|
|
|
ctx.credits_text->set_color({1.0f, 1.0f, 1.0f, 0.0f}); |
|
|
|
ctx.credits_text->set_content((*ctx.strings)["credits"]); |
|
|
|
credits_text.set_material(&ctx.menu_font_material); |
|
|
|
credits_text.set_font(&ctx.menu_font); |
|
|
|
credits_text.set_color({1.0f, 1.0f, 1.0f, 0.0f}); |
|
|
|
credits_text.set_content((*ctx.strings)["credits"]); |
|
|
|
|
|
|
|
// Align credits text
|
|
|
|
const auto& credits_aabb = static_cast<const geom::aabb<float>&>(ctx.credits_text->get_local_bounds()); |
|
|
|
const auto& credits_aabb = static_cast<const geom::aabb<float>&>(credits_text.get_local_bounds()); |
|
|
|
float credits_w = credits_aabb.max_point.x - credits_aabb.min_point.x; |
|
|
|
float credits_h = credits_aabb.max_point.y - credits_aabb.min_point.y; |
|
|
|
ctx.credits_text->set_translation({std::round(-credits_w * 0.5f), std::round(-credits_h * 0.5f), 0.0f}); |
|
|
|
credits_text.set_translation({std::round(-credits_w * 0.5f), std::round(-credits_h * 0.5f), 0.0f}); |
|
|
|
credits_text.update_tweens(); |
|
|
|
|
|
|
|
// Load animation timing configuration
|
|
|
|
double credits_fade_in_duration = 0.0; |
|
|
@ -56,47 +56,33 @@ credits::credits(game::context& ctx): |
|
|
|
if (ctx.config->contains("credits_scroll_duration")) |
|
|
|
credits_scroll_duration = (*ctx.config)["credits_scroll_duration"].get<double>(); |
|
|
|
|
|
|
|
auto set_credits_opacity = [&ctx](int channel, const float& opacity) |
|
|
|
auto set_credits_opacity = [this](int channel, const float& opacity) |
|
|
|
{ |
|
|
|
ctx.credits_text->set_color({1.0f, 1.0f, 1.0f, opacity}); |
|
|
|
this->credits_text.set_color({1.0f, 1.0f, 1.0f, opacity}); |
|
|
|
}; |
|
|
|
|
|
|
|
// Build credits fade in animation
|
|
|
|
ctx.credits_fade_in_animation = new animation<float>(); |
|
|
|
animation_channel<float>* credits_fade_in_opacity_channel = ctx.credits_fade_in_animation->add_channel(0); |
|
|
|
ctx.credits_fade_in_animation->set_interpolator(ease<float>::in_quad); |
|
|
|
credits_fade_in_animation.set_interpolator(ease<float>::in_quad); |
|
|
|
animation_channel<float>* credits_fade_in_opacity_channel = credits_fade_in_animation.add_channel(0); |
|
|
|
credits_fade_in_opacity_channel->insert_keyframe({0.0, 0.0f}); |
|
|
|
credits_fade_in_opacity_channel->insert_keyframe({credits_fade_in_duration, 1.0f}); |
|
|
|
ctx.credits_fade_in_animation->set_frame_callback(set_credits_opacity); |
|
|
|
|
|
|
|
// Build credits scroll in animation
|
|
|
|
ctx.credits_scroll_animation = new animation<float>(); |
|
|
|
|
|
|
|
// Trigger credits scroll animation after credits fade in animation ends
|
|
|
|
ctx.credits_fade_in_animation->set_end_callback |
|
|
|
( |
|
|
|
[&ctx]() |
|
|
|
{ |
|
|
|
ctx.credits_scroll_animation->play(); |
|
|
|
} |
|
|
|
); |
|
|
|
credits_fade_in_animation.set_frame_callback(set_credits_opacity); |
|
|
|
|
|
|
|
// Add credits animations to animator
|
|
|
|
ctx.animator->add_animation(ctx.credits_fade_in_animation); |
|
|
|
ctx.animator->add_animation(ctx.credits_scroll_animation); |
|
|
|
ctx.animator->add_animation(&credits_fade_in_animation); |
|
|
|
|
|
|
|
// Start credits fade in animation
|
|
|
|
ctx.credits_fade_in_animation->play(); |
|
|
|
credits_fade_in_animation.play(); |
|
|
|
|
|
|
|
// Set up credits skipper
|
|
|
|
ctx.input_listener->set_callback |
|
|
|
( |
|
|
|
[&ctx](const event_base& event) |
|
|
|
[this, &ctx](const event_base& event) |
|
|
|
{ |
|
|
|
auto id = event.get_event_type_id(); |
|
|
|
if (id != mouse_moved_event::event_type_id && id != mouse_wheel_scrolled_event::event_type_id && id != gamepad_axis_moved_event::event_type_id) |
|
|
|
{ |
|
|
|
if (ctx.credits_text->get_color()[3] > 0.0f) |
|
|
|
if (this->credits_text.get_color()[3] > 0.0f) |
|
|
|
{ |
|
|
|
ctx.input_listener->set_enabled(false); |
|
|
|
|
|
|
@ -109,8 +95,7 @@ credits::credits(game::context& ctx): |
|
|
|
); |
|
|
|
ctx.input_listener->set_enabled(true); |
|
|
|
|
|
|
|
ctx.ui_scene->add_object(ctx.credits_text); |
|
|
|
ctx.credits_text->update_tweens(); |
|
|
|
ctx.ui_scene->add_object(&credits_text); |
|
|
|
|
|
|
|
ctx.logger->pop_task(EXIT_SUCCESS); |
|
|
|
} |
|
|
@ -124,17 +109,10 @@ credits::~credits() |
|
|
|
ctx.input_listener->set_callback(nullptr); |
|
|
|
|
|
|
|
// Destruct credits text
|
|
|
|
ctx.ui_scene->remove_object(ctx.credits_text); |
|
|
|
delete ctx.credits_text; |
|
|
|
ctx.credits_text = nullptr; |
|
|
|
ctx.ui_scene->remove_object(&credits_text); |
|
|
|
|
|
|
|
// Destruct credits animations
|
|
|
|
ctx.animator->remove_animation(ctx.credits_fade_in_animation); |
|
|
|
ctx.animator->remove_animation(ctx.credits_scroll_animation); |
|
|
|
delete ctx.credits_fade_in_animation; |
|
|
|
delete ctx.credits_scroll_animation; |
|
|
|
ctx.credits_fade_in_animation = nullptr; |
|
|
|
ctx.credits_scroll_animation = nullptr; |
|
|
|
ctx.animator->remove_animation(&credits_fade_in_animation); |
|
|
|
|
|
|
|
ctx.logger->pop_task(EXIT_SUCCESS); |
|
|
|
} |
|
|
|