From 9bde6bbed3fda58d095be70131436d64021e3159 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 20 Aug 2024 18:20:04 +0300 Subject: [PATCH] Animate transformers in cards panel --- source/application.cpp | 48 +++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/source/application.cpp b/source/application.cpp index 4b7ff62..3dcb138 100644 --- a/source/application.cpp +++ b/source/application.cpp @@ -1123,7 +1123,7 @@ namespace gmtk painter.rect({sbox[0], wbox[1]}, color); } - void draw_card(geom::box const & bbox, card_type type, gfx::painter & painter) + void draw_card(geom::box const & bbox, card_type type, gfx::painter & painter, float animation = 0.f) { switch (type) { @@ -1134,10 +1134,7 @@ namespace gmtk case card_type::reshaper: case card_type::hue_shifter: { - float animate = 0.f; - if (type == card_type::reshaper) - animate = 0.875f; - draw_structure(bbox, transformer{.type = card_to_transformer(type).value(), .animate = animate}, painter); + draw_structure(bbox, transformer{.type = card_to_transformer(type).value(), .animate = animation}, painter); } break; case card_type::zoomer: @@ -2037,8 +2034,20 @@ namespace gmtk for (auto & p : card_animation_) { - float const target = p.first == active_card_; - p.second += (target - p.second) * (- std::expm1(- 20.f * frame_dt)); + p.second.shift += ((p.first == active_card_ ? 1.f : 0.f) - p.second.shift) * (- std::expm1(- 20.f * frame_dt)); + + if (p.first == selected_card_) + { + p.second.phase += dt * 3.f; + if (p.second.phase >= 1.f) + p.second.phase -= 1.f; + } + else if (p.second.phase > 0.f) + { + p.second.phase += dt * 3.f; + if (p.second.phase >= 1.f) + p.second.phase = 0.f; + } } menu_transition_ += ((in_menu() ? 1.f : 0.f) - menu_transition_) * (- std::expm1(- 20.f * frame_dt)); @@ -2254,13 +2263,11 @@ namespace gmtk continue; geom::box box{{{pen[0] - step, pen[0]}, {pen[1] - step, pen[1]}}}; - box[0] -= step * card_animation_[type] / 2.f; + box[0] -= step * card_animation_[type].shift / 2.f; - if (active_card_ == type) - { - draw_selection(box, painter_, {64, 64, 64, 255}, true); - } - else if (geom::contains(box, mouse_world_)) + float animation = card_animation_[type].phase; + + if (geom::contains(box, mouse_world_)) { selected_card_ = type; if (old_selected_card != type) @@ -2268,7 +2275,12 @@ namespace gmtk draw_selection(box, painter_, {128, 128, 128, 255}); } - draw_card(box, type, painter_); + if (active_card_ == type) + { + draw_selection(box, painter_, {64, 64, 64, 255}, true); + } + + draw_card(box, type, painter_, 1.f - animation); if (map_.cards.at(type) < 1000) painter_.text(box.center() - geom::vector{step, 0.f}, std::to_string(map_.cards.at(type)), {.scale = {vs, -vs}, .c = gfx::black}); @@ -2585,7 +2597,13 @@ namespace gmtk std::optional selected_card_; std::optional active_card_; - util::hash_map card_animation_; + struct card_animation_state + { + float shift = 0.f; + float phase = 0.f; + }; + + util::hash_map card_animation_; int tutorial_state_ = 0;