GUI example

  • It would be nice to have a proper GUI example. Just a demonstration reel in order to show a few components implementation. Because, right now, I struggle with how GuiElement s work together. For example, I try to have a semi-transparent panel, but always end up with a black and opaque rectangle. Then I try to add a label inside that rectangle, but nothing shows. Then I try to resize these components, but have no idea if the relative size is relative to parents or the entire screen, etc.


    In short, GUI design is a pain.

  • For example, is there any reason why this :



    Produces this :



    While this :


    JavaScript
    GuiElement element = new GuiPanel(0.1f, 0.1f, true, 0.8f, 0.8f, true);
    element.setColor(0, 0, 0, 0.5f);
    element.setPivot(PivotPosition.BottomLeft);
    player.addGuiElement(element);


    Produces this :



    ?(?(?(

  • Damn NetBeans!


    WIth Eclipse, third party projects are build alongside, but NetBeans don't bother to update third party sources when building a project, and happily take existing Jars even of the third party sources have changed.


    :cursing:


    So much wasted time on this!

  • GuiElement.addChild(GuiElement child)



    JavaDoc


    "Note: Even if you adds an element as a child to another element, you still have to add every element to the player manually (see Player.addGuiElement(net.risingworld.api.gui.GuiElement)). Maybe this will change in future releases./


    Question


    But why? If player.addGuiElement(element) is already doing the job, why aren't every added children notified also? Same thing when removing an element?

  • Yep I saw that too, seems a bit counter intuitive that childs are not added together with the parent element. Though if that is how red want's to have it you can just run a loop to add all elements to the player's UI. Don't think that takes so much more time computationally.

  • For example, is there any reason why this :

    Hmm... I tried the snipped you posted and actually it produces a semi-transparent panel, as intended 8| More precisely, both snippets result in the same output ?( Or was it related to the Netbeans issue?


    WIth Eclipse, third party projects are build alongside, but NetBeans don't bother to update third party sources when building a project, and happily take existing Jars even of the third party sources have changed.

    Did you link the libraries, i.e. the jar files, or did you link the whole projects? In this case, Netbeans should recompile the third-party projects automatically. Also make sure the "Compile on Save" setting is active (otherwise it apparently results in awkward situations)


    But why? If player.addGuiElement(element) is already doing the job, why aren't every added children notified also? Same thing when removing an element?

    Well, right now it is unfortunately necessary to register every single element to the player :/ But it's definitely our intention to change that in the future, so the game handles that automatically. We need to make sure that every situation is definitely covered when introducing automatic child-parent handling.


    In short, GUI design is a pain.

    What part is causing a pain exactly? The child-parent handling is obviously suboptimal, although adding the elements manually shouldn't cause too much hassle ^^ I know that the chances are higher to forget adding certain elements in this case, but especially when you compile plugins on the fly (and reload them with the reloadplugins command) these issues should be easily resolvable :)

  • The entire issue of the panel transparency was my setup, and how I tried to handle the UI from a generic lib (as a separate project) that I linked from the plugin. Netbeans made me believe that it compiled both projects, when it really didn't. So I thought something was odd because I had inconsistent states when making modifications. I ended up resolving this by "Clean and Build" both projects separately. I have asked on SO for help to automate that, but the only solution given so far is Maven... and I really don't like Maven :)


    Well, the plugin I intend to write involves complicated GUIs, and the thought of having to manually add every single GuiElement is what I call a pain. Since elements are hierarchical, I expected that adding the parent would propagate the children to the player also, just as any typical UI manager would handle this situation. I mean, each GuiElement has a parent, but no way to know the presence of children (!!) despite the addChild and [removeChild methods. I mean, I do not know the internal implementation of GuiElement, but it seem odd to me that users would be responsible to preserve the states of elements added to players.


    I mean, the method is simple, player.addGuiElement(element) sends it's footprint, including children, to the player. Voilà. If a child is added or removed from the GuiElement, then it should simply be added again to the player to be updated. Since the GuiElement has an ID, it is easy to sync UI elements with the player. There is no need to manually drill down GUI elements, manually making this synchronization.

Participate now!

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