Possible bug with layouts and panels

Started by Dincio, 08 March 2017, 00:09:05


I need a system in which every instance of type entity in my game holds its own gui (I need to do this for multiple reasons: the gui is relative to the position of the entity; shown only when the entity is visible; clickable only when the entity is interactable, etc...). I also use a "model/clone" system in which I load entity models from a file and then clone them when they are spawned, ergo the need to copy their guis...


Having a gui in each entity misses the point of what the gui is about. You should be creating panels inside the entities, not guis. You should store a single Gui instance in a similar way that you are storing a single RenderWindow and that you try to attach the panels to the guis in a similar way as how you manage to "connect" (handle events and draw) your entities to the window.

I was going to make the Gui copyable to not arbitrary limit you but I just found a reason on why I shouldn't make them copyable that I think is good enough and probably was the reason why I designed the code like this in the first place. If the gui is used like intended then making it copyable allows some very hard to spot issues when your code is wrong. If you forget to pass the object by reference and make a copy instead then your code would no longer work as intended. Calls to e.g. handleEvent would be done on the wrong gui. These are difficult issues to find because stuff just doesn't work in complex code but everything is fine in any minimal code. I vaguely remember such an issue.

I also can't make the handleEvent function from Panel public because it looks like it is the Gui which maps events from window to world view. This code can't be moved to Panel because it must only be done once on a place that can't occur inside the hierarchy (Panels could be nested and thus the code would be run multiple times).

TGUI is not made for what you intend to do. The code is designed to have a single Gui where interaction is handled. It is made for menu screens and static HUD, not for being part of your entities. I'm afraid you will either have to adapt your code so that it works with a single gui or else simply not rely on TGUI to do these things.


Ok you were completely clear, thanks again for the attention you dedicated to solving my issue. I will think of a way to handle everything based on your statements  :)