25 #include <engine/config.hpp>
56 const math::fvec2 viewport_center = viewport_size * 0.5f;
59 title_text = std::make_unique<scene::text>();
61 title_text->set_color({1.0f, 1.0f, 1.0f, (
fade_in) ? 1.0f : 0.0f});
64 const auto& title_aabb = title_text->get_bounds();
65 float title_w = title_aabb.max.x() - title_aabb.min.x();
66 float title_h = title_aabb.max.y() - title_aabb.min.y();
67 title_text->set_translation({
std::round(viewport_center.
x() - title_w * 0.5f),
std::round(viewport_center.
y() - title_h * 0.5f + (viewport_size.
y() / 3.0f) / 2.0f), 0.0f});
77 [
this, &
ctx](
int channel,
const float& opacity)
81 this->title_text->set_color(
color);
87 start_text = std::make_unique<scene::text>();
88 options_text = std::make_unique<scene::text>();
89 extras_text = std::make_unique<scene::text>();
90 quit_text = std::make_unique<scene::text>();
100 options_text->set_content(
get_string(
ctx,
"main_menu_options"));
101 extras_text->set_content(
get_string(
ctx,
"main_menu_extras"));
113 auto select_start_callback = [
this, &
ctx]()
119 auto change_state = [&
ctx]()
137 this->fade_out_title();
147 auto select_options_callback = [
this, &
ctx]()
153 this->fade_out_title();
173 auto select_extras_callback = [
this, &
ctx]()
179 this->fade_out_title();
199 auto select_quit_callback = [
this, &
ctx]()
205 this->fade_out_title();
271 window_resized_subscription =
ctx.
window->get_resized_channel().subscribe
273 [&](
const auto&
event)
276 const math::fvec2 viewport_center = viewport_size * 0.5f;
279 const auto& title_aabb = title_text->get_bounds();
280 float title_w = title_aabb.max.x() - title_aabb.min.x();
281 float title_h = title_aabb.max.y() - title_aabb.min.y();
282 title_text->set_translation({
std::round(viewport_center.
x() - title_w * 0.5f),
std::round(viewport_center.
y() - title_h * 0.5f + (viewport_size.
y() / 3.0f) / 2.0f), 0.0f});
309 ctx.
animator->remove_animation(&title_fade_animation);
317 void main_menu_state::fade_in_title()
322 opacity_channel->
insert_keyframe({config::menu_fade_in_duration, 1.0f});
323 title_fade_animation.
stop();
324 title_fade_animation.
play();
327 void main_menu_state::fade_out_title()
332 opacity_channel->
insert_keyframe({config::menu_fade_out_duration, 0.0f});
333 title_fade_animation.
stop();
334 title_fade_animation.
play();
void play()
Plays the animation.
void stop()
Stops the animation, rewinds it, and resets the loop count.
Single channel in a keyframe animation.
void remove_keyframes(float start, float end)
Removes all keyframes on [start, end).
void insert_keyframe(const keyframe &k)
Adds a keyframe to the animation.
const channel * get_channel(int id) const
Returns the channel with the specified ID.
void set_interpolator(interpolator_type interpolator)
Sets the frame interpolator function object.
channel * add_channel(int id)
Adds a channel to the animation.
void set_frame_callback(std::function< void(int, const T &)> callback)
Sets the callback that's executed on each frame of animation.
Abstract base class for game states.
std::unique_ptr< scene::collection > ui_scene
std::vector< std::function< void()> > menu_left_callbacks
std::vector< std::function< void()> > menu_right_callbacks
hsm::state_machine< game_state > state_machine
std::unique_ptr< screen_transition > fade_transition
std::shared_ptr< scene::camera > surface_camera
std::unique_ptr< animator > animator
std::vector< std::function< void()> > menu_select_callbacks
std::vector< std::tuple< scene::text *, scene::text * > > menu_item_texts
std::unique_ptr< render::sky_pass > sky_pass
std::shared_ptr< app::window > window
std::queue< std::function< void()> > function_queue
std::shared_ptr< render::matvar_fvec3 > fade_transition_color
type::bitmap_font title_font
std::shared_ptr< render::material > title_font_material
std::function< void()> menu_back_callback
std::unordered_map< hash::fnv1a32_t, entity::id > entities
virtual ~main_menu_state()
main_menu_state(::game &ctx, bool fade_in)
log_message< log_message_severity::trace, Args... > log_trace
Formats and logs a trace message.
Publish-subscribe messaging.
constexpr vector< T, N > round(const vector< T, N > &x)
Performs a element-wise round operation.
T from_settings(T n, T t, T s)
Exposure value from exposure settings.
void cosmogenesis(::game &ctx)
Creates the cosmos.
void create_observer(::game &ctx)
Creates the observer.
void set_time_scale(::game &ctx, double scale)
Sets rate at which time passes.
void set_time(::game &ctx, double t)
Sets the current time.
std::string get_string(const ::game &ctx, hash::fnv1a32_t key)
Returns a localized string.
Container for templated easing functions.
constexpr element_type & x() noexcept
Returns a reference to the first element.
constexpr element_type & y() noexcept
Returns a reference to the second element.