From bc31750d9c4e96fb8b86a889dae214ed3ef79a92 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 25 Apr 2025 23:17:14 -0400 Subject: [PATCH] Fix from ORBLISH suggestion to stop any component that's not hover/clicked on in the mouse handler. --- guecs.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/guecs.cpp b/guecs.cpp index 2257b82..7fd30fb 100644 --- a/guecs.cpp +++ b/guecs.cpp @@ -65,6 +65,12 @@ namespace guecs { } } + void Sound::stop(bool hover) { + if(!hover) { + sound::stop(on_click); + } + } + void Background::init() { sf::Vector2f size{float(w), float(h)}; if(shape == nullptr) shape = make_shared(size); @@ -107,6 +113,10 @@ namespace guecs { return $shader; } + void Effect::stop() { + $active = false; + } + UI::UI() { $font = make_shared(FONT_FILE_NAME); } @@ -242,7 +252,7 @@ namespace guecs { sound.play(hover); }); - if(hover) return; // kinda gross + if(hover) return; if(auto action_data = get_if(ent)) { clicked.action(ent, action_data->data); @@ -252,9 +262,14 @@ namespace guecs { action_count++; } else { - // via ORBLISHJ - // just reset the hover trigger for all that aren't hit - // then in the ^^ positive branch play it and set it played + do_if(ent, [hover](auto& effect) { + effect.stop(); + }); + + do_if(ent, [hover](auto& sound) { + // here set that it played then only play once + sound.stop(hover); + }); } });