From a468e5703450defef7decb0c23e51678093dff3c Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 20 Aug 2024 14:56:45 +0300 Subject: [PATCH] Current level & mode indication --- source/application.cpp | 44 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/source/application.cpp b/source/application.cpp index db9ea78..b6cd845 100644 --- a/source/application.cpp +++ b/source/application.cpp @@ -378,6 +378,7 @@ namespace gmtk util::hash_map cards = {}; int stage = 0; + float stage_animation = 0.f; int resource_count = 0; @@ -813,11 +814,14 @@ namespace gmtk } } - void draw_item(resource_type const & type, geom::point const & pos, float scale, gfx::painter & painter, bool selected = false) + void draw_item(resource_type const & type, geom::point const & pos, float scale, gfx::painter & painter, bool selected = false, int opacity = 255) { auto color = color_of(type); gfx::color_rgba bcolor = selected ? gfx::white : gfx::black; + color[3] = opacity; + bcolor[3] = opacity; + switch (type.shape) { case shape_type::circle: @@ -1213,15 +1217,24 @@ namespace gmtk if (!sandbox) { - auto pen = v.location.bbox(-0.4f).corner(0.5f, 1.f); + for (int i = -1; i <= 0; ++i) + { + auto pen = v.location.bbox(-0.4f).corner(0.5f, 1.f); - float vs = 2.f * pixel_size; + float vs = 2.f * pixel_size; - draw_item(stages[map.stage].type, pen, 1.f, painter); + int opacity = std::round(255 * (1.f - std::abs(i + map.stage_animation))); - pen[1] -= 24.f * vs; + if (map.stage + i >= 1 && map.stage + i < std::size(stages)) + draw_item(stages[map.stage + i].type, pen + geom::vector{(i + map.stage_animation) * 40.f * vs, 0.f}, 1.f, painter, false, opacity); - painter.text(pen, std::format("{}/{}", map.resource_count, stages[map.stage].count), {.scale = {vs, -vs}, .c = {0, 0, 0, 255}}); + if (i == 0) + { + pen[1] -= 24.f * vs; + + painter.text(pen, std::format("{}/{}", map.resource_count, stages[map.stage].count), {.scale = {vs, -vs}, .c = {0, 0, 0, 255}}); + } + } } }); @@ -1597,6 +1610,7 @@ namespace gmtk } map_.stage += 1; + map_.stage_animation += 1.f; map_.resource_count = 0; if (map_.stage > 1 && tutorial_state_ <= 2) @@ -1789,6 +1803,8 @@ namespace gmtk map_.world->attach(map_.world->index().get(i.start), occupied{entity}); }); + map_.stage_animation = std::max(0.f, map_.stage_animation - 3.f * dt); + map_.world->apply([&](source & s) { s.animate = std::max(0.f, s.animate - 3.f * dt); @@ -2192,6 +2208,22 @@ namespace gmtk } } + if (!in_start_menu_) + { + geom::point pen = view_box_.corner(0, 0) + geom::vector{18.f, 24.f} * pixel_size; + float s = 2.f * pixel_size; + + gfx::color_rgba c{127, 127, 127, 255}; + + gfx::painter::text_options opts + { + .scale = {s, -s}, .x = gfx::painter::x_align::left, .y = gfx::painter::y_align::bottom, .c = c + }; + + painter_.text(pen + geom::vector{0.f, 32.f * pixel_size}, std::format("Level {}/{}", map_.stage, std::size(stages) - 1), opts); + painter_.text(pen, is_sandbox_mode_ ? "Sandbox" : is_challenge_mode_ ? "Challenge" : "Campaign", opts); + } + selected_button_ = std::nullopt; if (in_menu())