Animate transformers in cards panel
This commit is contained in:
parent
90349f60c1
commit
9bde6bbed3
1 changed files with 33 additions and 15 deletions
|
|
@ -1123,7 +1123,7 @@ namespace gmtk
|
|||
painter.rect({sbox[0], wbox[1]}, color);
|
||||
}
|
||||
|
||||
void draw_card(geom::box<float, 2> const & bbox, card_type type, gfx::painter & painter)
|
||||
void draw_card(geom::box<float, 2> 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<float, 2> 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<card_type> selected_card_;
|
||||
std::optional<card_type> active_card_;
|
||||
|
||||
util::hash_map<card_type, float> card_animation_;
|
||||
struct card_animation_state
|
||||
{
|
||||
float shift = 0.f;
|
||||
float phase = 0.f;
|
||||
};
|
||||
|
||||
util::hash_map<card_type, card_animation_state> card_animation_;
|
||||
|
||||
int tutorial_state_ = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue