Individual unit menus while having multiple units present

Godot Version

`4.3

Question

Im trying to make some sort of system where individual units have a dynamic amount of skills/cards unique to each other.

And by selecting that unit you are able to see and select individual skills for that unit alone.
The skill logic itself is handled within a sub-scene of the MovableUnit instance

Theres about like 2 methods I can think of to handle this, but im missing some important information but I dont know what I need to know to carry these out:

  • Remaking the buttons as a branch of the Menu node every time a new unit is selected (and removed when deselected) (i dont wanna do this because it sounds needlessly ressource intensive, and i also dont know how to link to the corresponding events within the nested scene if i instantiate new buttons)

  • The units have their skill stuff loaded and then shown when they are selected (what i currently am using), however I dont know the best way to show these and access these from the main scene, using a default Control node makes them visible but not clickable

Are SubViewports usable? Another plan was to put the contents of SkillControllerStuff and then show it via a Viewport of specifically the selected unit in the menu, where you can press the respective buttons to call the needed events.
And having it set focus on another unit if you select that one.
But the godot documentation wasnt much helpful in that regard in terms of helping me figure out if thats possible.

Main instance tree (SkillControllerStuff is only there for visuals)
SkillControllerStuff just has 3 buttons for testing purposes

One possible option:

You can make a dynamic menu by using a VBox and adding button children to it.

When you create a button, you can name it. You can have a dictionary that’s populated with the button names and their corresponding actions; give all the buttons the same handler, and have the handler take the button name and feed it into the dictionary to get what to do.

You mean sorta like this?

With the SkillStuffSelectionStuff basically handling the inputs and sending them all the way back to be handled with SkillStuff

Dont think it would be neccessary then having the SkillController be a Control node but just a regular node like main to handle the scripting

You could do that.

Wherever you handle it, the idea would be you have gui controls with names. Let’s say you’ve got “Fireball”, “Heal” and “Appraise”. You can dynamically make buttons for all of those, or you can manually make buttons for all of them and just show/hide appropriately. If they’re in a vbox, they pack based on visibility.

At that point, you can either manually hook up all the button handlers, or you can do something like:

func process(delta: float):
    if is_visible_in_tree(): # Don't do anything if menu is hidden...
        for ch in menu.get_children():
            if ch.has_focus() && Input.is_action_just_pressed("GUI Select"):
                match(ch.name):
                    "Fireball":
                        [...]
                    "Heal":
                        [...]
                    "Appraise":
                        [...]

For extra points, make a dictionary called Skills where the key is the skill name and the value is a callable. That would let you replace the match with something like Skills[ch.name].call()

1 Like

I could give it a try when i get to it then, thank you