#VBoxContainer as button

1 messages · Page 1 of 1 (latest)

quasi osprey
#

Hello, I've been working on an inventory system for my rpg game but I'm having trouble implementing the skills menu.

I want to have it so the player selects skills on the left-most menu, then they have the option to select one of the characters on the right.

I want a button to emcompass the entire character's info box but I'm not sure how to do that since buttons can't overlap with other ui elements to my knowledge.
Is there some way to turn the vbox into a button, or have a button overlap with the vbox containing the character's information?

jolly cipher
#

If you set all the VBoxContainer's children's mouse filter to ignore, you can override _unhandled_input in the container:```php
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouse:
if event.button_mask & MOUSE_BUTTON_LEFT:
# do stuff

radiant sage
#

You could also make the character's info box a TextureButton, I think

quasi osprey
#

TextureButtons also seem to have the undesirable outcome of behaving very inconsistently in the ui and sometimes conflicting with the player information rather than always covering it.

quasi osprey
jolly cipher
quasi osprey
sage wasp
#

What you need to do is to use a regular container, add a button as its first child and then, in the SORT_CHILDREN notification, make the button use the full container rect

jolly cipher
quasi osprey
quasi osprey
quasi osprey
sage wasp
quasi osprey
#

ahh, all good

sage wasp
#

basically, in your container (name it BoxContainer or PanelContainer, any container) add this code:

func _notification(what):
  if what == NOTIFICATION_SORT_CHILDREN:
    fit_child_in_rect(button, Rect2(Vector2(), size))
#

where button is a reference to your button node

#

it must be a valid reference, so you need to verify if is_instance_valid(button) before calling the function, specially for @onready references

#

I suggest to call queue_sort() on _ready just to ensure that the button is always covering the container

#

also I suggest that button is the first child, and all other siblings has mouse_filter set to pass or ignore

quasi osprey
#

What does the what variable do for the _notification function?

sage wasp
#

is just a single number that corresponds to a certain notification

quasi osprey
#

I see

sage wasp
quasi osprey
# sage wasp the passed notification, `what` is the name used in documentation to define the ...

Is the notification system function handled automatically or is it called manually?

I tried calling the fit_child_in_rect arbitarily in _ready but noticed that didn't do anything, I see the _notification function doesn't appear to bring the what data into the fit_child_in_rect function either though.
I assumed it wouldn't need to be in the notification function specifically but I'm not sure if I'm wrong in that assumption or if it's an issue of my implementation.

Sorry for all the questions, the notification system is completely new to me and i'm having a little trouble understanding it

sage wasp
#

that's why i suggest to use fit_child_in_rect in the notification, and calling queue_sort in ready

quasi osprey
#

Ohhh

sage wasp
#

forgot to mention that both functions are from Container class, so your script must be attached to a container and it must have a button reference

quasi osprey
#

Alright

#

I'll need to sit down and read through the documentation proper at some point but this seems enough to be functioning for now

sage wasp
#

you'll not see changes in editor btw, try seeing the changes re-launching the scene

#

oh you already managed to do it, nice

quasi osprey
#

Thankyou ❤️❤️❤️

sage wasp
#

don't forget to call if is_instance_valid(button) in the notification to avoid errors

sage wasp
quasi osprey
#

Ah, right

#

Gotcha

sage wasp
#

congrats

quasi osprey
#

Thankyou for the help Dex