A question about event target when it is a UI Button

(Matt ) #1

Hi Amethyst,

I have a UI created with a prefab. I have added a couple buttons like the complex buttons from the UI examples with ids like “btn_new_game”, “btn_load_game”. I can get the event in the event loop from the MenuState handle_event. I am having some trouble figuring out how to associate the target of the event with the specific button pressed.

LSOI
How do you take the target Entity (or entity id) from the event and compare it to the id/text/widget of the UI Button clicked?

Thanks,
Matt

#2

If I understand your question correctly; if you click one of the buttons your State’s handle_event function is called, but you have no way of knowing which of the buttons was clicked?

You might want to have a look at the Evoli showcase game’s pause state. In its update() function, it uses a UiFinder to get the Entities of both both the exit and the resume button. It then compares the event target to those entities in its handle_event() function.

1 Like
(Matt ) #3

Thank you! Yes that is what I needed.

1 Like