CytopiaTeam / Cytopia

:deciduous_tree::house_with_garden::office::evergreen_tree: A city building simulation game
https://www.cytopia.net
GNU General Public License v3.0
1.97k stars 104 forks source link

Implement Z-Order for UI elements #102

Closed SimplyLiz closed 3 years ago

SimplyLiz commented 5 years ago

I think for the Z-Order it'd be ok to have two containers:

vector<UiElement> allElements
std::map<int Z, std::vector<UiElement> elementsForEventHandling

The first container contains all UI Elements and is used for the UI renderloop. The second container only contains UiElements that are not in groups AND the containing group instead. (ButtonGroup is derived from UiElement). In the main event loop, try dynamic_cast to see if it's a group and needs to be treated differently, or else treat it as "normal" UiElement as before.

This way all elements could be handled in the same loop, maintaining correct click order and not handling buttons before other elements first.

Also, UiElements should have a "natural order". If a dialog is in the same Z-Order, buttons should always be drawn / handled before other elements.

ghost commented 5 years ago

Yes please!

Screenshot 2019-05-18 at 17 18 01
ghost commented 5 years ago

Moving to v0.3

ghost commented 3 years ago

Closing because it has been fixed with order of add() calls in #657. If we need more functionality, like changing the z-index at runtime, then it should be enclosed in a different issue