From 58dcfb11736ce6e92b00527b8aee3625e4d36144 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 20 Aug 2024 15:06:28 +0300 Subject: [PATCH] Transformer card UX tweaks --- source/application.cpp | 124 +++++++++++++++++++++++++++-------------- 1 file changed, 82 insertions(+), 42 deletions(-) diff --git a/source/application.cpp b/source/application.cpp index b6cd845..0a04417 100644 --- a/source/application.cpp +++ b/source/application.cpp @@ -562,53 +562,74 @@ namespace gmtk else if (acc.contains()) { map.put_card(card_type::zoomer); - // TODO: CLEAR ZOOMER - - for (int y = 0; y < 3; ++y) - { - for (int x = 0; x < 3; ++x) - { - location p{l.level + 1, {3 * l.coords[0] + x, 3 * l.coords[1] + y}}; - clear_tile(map, p); - } - } - - auto & index = map.world->index(); - - for (int y = 0; y < 9; ++y) - { - for (int x = 0; x < 9; ++x) - { - location p{l.level + 2, {9 * l.coords[0] + x, 9 * l.coords[1] + y}}; - - if (auto e = index.find(p)) - { - auto & v = map.world->get(*e).get(); - - for (auto to : v.belts_to) - { - auto & tv = map.world->get(to).get(); - if (!within_tile(l, tv.location)) - remove_belt(*map.world, to, *tv.belts_to.begin()); - remove_belt(*map.world, *e, to); - } - - for (auto from : v.belts_from) - { - auto & fv = map.world->get(from).get(); - if (!within_tile(l, fv.location)) - remove_belt(*map.world, *fv.belts_from.begin(), from); - remove_belt(*map.world, from, *e); - } - } - } - } } else if (auto t = acc.get_if()) { map.put_card(transformer_to_card(t->type)); } + auto & index = map.world->index(); + + for (int y = 0; y < 3; ++y) + { + for (int x = 0; x < 3; ++x) + { + location p{l.level + 1, {3 * l.coords[0] + x, 3 * l.coords[1] + y}}; + + clear_tile(map, p); + + if (auto e = index.find(p)) + { + auto & v = map.world->get(*e).get(); + + for (auto to : v.belts_to) + { + auto & tv = map.world->get(to).get(); + if (!within_tile(l, tv.location)) + remove_belt(*map.world, to, *tv.belts_to.begin()); + remove_belt(*map.world, *e, to); + } + + for (auto from : v.belts_from) + { + auto & fv = map.world->get(from).get(); + if (!within_tile(l, fv.location)) + remove_belt(*map.world, *fv.belts_from.begin(), from); + remove_belt(*map.world, from, *e); + } + } + } + } + + for (int y = 0; y < 9; ++y) + { + for (int x = 0; x < 9; ++x) + { + location p{l.level + 2, {9 * l.coords[0] + x, 9 * l.coords[1] + y}}; + + if (auto e = index.find(p)) + { + auto & v = map.world->get(*e).get(); + + for (auto to : v.belts_to) + { + auto & tv = map.world->get(to).get(); + if (!within_tile(l, tv.location)) + remove_belt(*map.world, to, *tv.belts_to.begin()); + remove_belt(*map.world, *e, to); + } + + for (auto from : v.belts_from) + { + auto & fv = map.world->get(from).get(); + if (!within_tile(l, fv.location)) + remove_belt(*map.world, *fv.belts_from.begin(), from); + remove_belt(*map.world, from, *e); + } + } + } + } + map.world->destroy(*entity); } @@ -1378,6 +1399,18 @@ namespace gmtk { clear_tile(map_, *selected_); } + else if (auto t = map_.world->get(*entity).get_if()) + { + if (auto n = card_to_transformer(*active_card_); n && n != t->type) + { + if (map_.take_card(*active_card_)) + { + map_.put_card(transformer_to_card(t->type)); + t->type = *n; + active_card_ = std::nullopt; + } + } + } } else { @@ -1952,8 +1985,15 @@ namespace gmtk { if (auto entity = map_.world->index().find(*selected_)) { + auto n = card_to_transformer(*active_card_); auto acc = map_.world->get(*entity); - if (*active_card_ != card_type::eraser || (!acc.contains() && !acc.contains())) + auto t = acc.get_if(); + if (n && t && n != t->type) + { + gfx::color_rgba color = {64, 64, 64, 255}; + draw_selection(selected_->bbox(), painter_, color, true); + } + else if (*active_card_ != card_type::eraser || (!acc.contains() && !acc.contains())) { gfx::color_rgba color = {255, 128, 128, 255}; draw_selection(selected_->bbox(), painter_, color, true);