Get a UIElement from the HUD?

  • Sorry to be a pain... :wacko:


    Is it currently possible to get a UIElement from the games HUD?


    For example grabing the UIElement of HudLayer/hudContainer/statusContainer/statusBarContainer/locationLabelContainer/locationLabel


    I want to add children to an existing vanilla UI element.


    This is what I've been trying (amongst others)


    Java
    Style parentStyle = new Style();// create a new style
    parentStyle.overflow.set(Overflow.Visible); // ensure children can render outside
    Internals.overwriteUIStyle(player, LOCATION_LABEL_PATH, parentStyle); //use internals class to overwrite with new style
    myUIElement = new MRUIElement(plugin, player);//my new element
    myUIElement.style.position.set(Position.Absolute);//my new element
    myUIElement.setPivot(Pivot.LowerCenter);//my new element central pivot
    myUIElement.setPosition(50f, 0f, true);//horizontally (50%) relative to parent
    myUIElement.style.translate.set(initposx, initposy - 10f);


    :dizzy:

  • You can't get existing UI elements directly, but you can still add UI elements to existing elements :) You'll have to use the Internals class for this. By default you'd use the Player.addUIElement() method to add the element to a player screen. This method also has an overload which accepts a UITarget, but this only supports a few, pre-defined targets.

    However, if you want to add a UI element to an arbitrary existing element, you should use the Internals.addUIElementToPlayer() method instead to add the element to the player screen. Just provide the path of the target element as parameter ;) Example:


    Java
    UIElement myElement = new UIElement();
    myElement.setSize(16, 16, false);
    myElement.style.backgroundColor.set(1f, 0f, 0f, 1f);
    Internals.addUIElementToPlayer(player, myElement, "HudLayer/hudContainer/statusContainer/statusBarContainer/locationLabelContainer/locationLabel");


    But the location label is a tricky UI element... not sure if you will get satisfying results when attaching childs to it...

  • Post by yahwho ().

    This post was deleted by the author themselves: So the problem is mine to resolve - Red's code does work! ().
  • All working :D

    I was also using...


    Java
    this.player.addUIElement(this);


    ...because I use my own UIElements that extend the base UIElement class.


    Java
    if (autoAttach) {
    this.player.addUIElement(this);
    }


    I added a simple boolean to my constructor for these special cases.

    Adding addUIElement() caused the element to go to the default UI bucket and therefore the coords were all off.

Participate now!

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