Gui Question

  • So I was messing around with the API's gui part and wanted to ask about something I noticed.


    I created my Gui panel and added a few labels and images as children to it then I initialised them as GuiElement.setVisible(false) and added them to the player's HUD when they spawned.


    Now when I tried calling just player.setGuiElementVisible(myElement, true) on the Panel parent then only the parent appeared and no children so I have to call player.setGuiElementVisible(myElement, true) on each of my elements separately for them all to appear for the player.


    But when I call player.setGuiElementVisible(myElement, false) on the Panel parent then everything disappears both parent and children.


    Is that behaviour intended or not? If yes, would it be possible to change it so that children appear too when you call the player.setGuiElementVisible(myElement, true) method on their parent if that doesn't cause any more issues on your end @red51 ?

  • I do not know if this is intended behaviour or not; but you are playing on two levels here:


    1) The visibility of a GuiElement is set in general with GuiElement.setVisibility(boolean)


    2) the visibility of a GuiElement is set for a specific player with Player.setGuiElementVisible(boolean)


    The documentation for Player.setGuiElementVisible() says:


    "calling this method ignores the current visibility state of the GUI element (see GuiElement.setVisible(boolean)). However, changes to the GUI element itself will restore the original visibility value of the GUI element."


    So, it seems to me that:


    A) if you set off the (general) visibility of several GuiElement's, you need to turn it on for each GuiElement (and for each player). Are you turning off the (general) visibility of the panel parent only or of the panel children too? If the latter, then the need to turn it on for each child is clearly intended behaviour.


    B) On another plan, of course if you add the same panel child to all players, it will have the same content for each player. Not knowing what you are trying to achieve, I have no idea if this is correct or not; in most cases, the contents shown to each player is player-specific. So, you may want to examine this point.
    ____________________


    Making Player.setGuiElementVisible(boolean) recursive:


    I am not sure this would be generally preferable. For instance, assuming you create a dialogue box with some (rare or secondary) options turned invisible; when you turn the whole dialogue boxvisible, you do not want those options becoming visible.


    As GUI elements are by default visible and a call is needed to make them invisible, if such a call is made, I think it should be honoured when changing the visibility of the parent (my opinion, though).

  • "calling this method ignores the current visibility state of the GUI element (see GuiElement.setVisible(boolean)). However, changes to the GUI element itself will restore the original visibility value of the GUI element."

    I had read this line and then was looking for it to confirm my suspicions but couldn't find which method it was written under, ty for copying it here :D

    A) if you set off the (general) visibility of several GuiElement's, you need to turn it on for each GuiElement (and for each player). Are you turning off the (general) visibility of the panel parent only or of the panel children too? If the latter, then the need to turn it on for each child is clearly intended behaviour.

    Good point my question rose from the fact I was trying to write an if loop that will edit a label when the label is visible so having set the general visibility of my label to false meant that even if I overwrote that and made it visible for a player the oberall default setting remained false and thus my if loop didn't work. I will probably need to rethink how to write that if loop by somehow storing the current player specific GuiElement Visibility.

    B) On another plan, of course if you add the same panel child to all players, it will have the same content for each player. Not knowing what you are trying to achieve, I have no idea if this is correct or not; in most cases, the contents shown to each player is player-specific. So, you may want to examine this point.

    No don't worry about that, my panel/labels are created and stored for each player individualy in attributes :)

  • No don't worry about that, my panel/labels are created and stored for each player individualy in attributes :)

    Then I do not understand why you need to distinguish between GuiElement visibility in general and for a specific player.


    As these GuiElement's belong each to just one player, simply turn on/off the general visibility with GuiElement.setVisibility(true/false), so that the element is visible/hidden to its player and GuiElement.isVisible() returns the 'correct' value.


    Or am I missing something?

  • I don't really need to distinguish I was just testing the different options and stumbled on the question :D

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!