Okay, so let's say I wanted to have a character be able to select from a certain set of options. Let's say that in a hand of cards, they have to pick a suit that exists in that hand of cards. So, they could either be given the maximum number of suits as options (if the hand had at least one card with a diamond, spade, heart, and club), or just one option (if the hand had only cards that were diamonds), or any number between it. How might I set up a collection of buttons like that where all of the buttons are presented evenly, no matter what combination of possibilities there are?
#How to have a range of possible buttons?
13 messages · Page 1 of 1 (latest)
I usually use some sort of custom Prompt scene that:
-Is displayed using a function requiring the options (as Strings) as a parameter.
-It then generates a button for each option and sets the button text to that option.
-When an option button is pressed, it emits a custom signal option_selected
-It then just frees itself
This way I can use it for anything, from simple yes/no prompts to dialogue choices.
So like, instantiate()ing a button from an independent button node, and relying on them all using the same signal?
Obviously using the same signal makes sense, since I could just pass a variable idetifying the specific button throught here, I just want to make sure I understand what you're suggesting.
The Prompt scene is a container node.
This container would then create a button for each option that was passed to it.
This container has the custom signal and emits it once an option is chosen. That way we don't need other nodes to go and figure out which button was pressed, the custom signal has which of the options inputted to it was chosen.
A good example that I looked at when making this system is Dialogue Managers response options. If you look at how Nathan set up the plugin you see what he uses to dynamically provide option selections.
I'll give it a shot and update as I go along, I won't look at the plugin yet, but I might if I end up struggling.
Since this is a "proof of concept" build and I have no need to overcomplicate it, I want to list the buttons going down the side. Should I just calculate the places the buttons spawn by determining them beforehand, and adding how much the globalposition would offset the next one below it to the Y value of the next button's globalposition vector, or is there a more eloquent solution for that kind of thing?
Uhh you may want to read up on containers and using controls in general. You are very much over complicating it. I would suggest watching a good video on building UI like: https://youtu.be/1_OFJLyqlXI?si=JUpQHW_tCT5A0Rgu.
But if you don't want to watch a long video like that, at least read through the docs here: https://docs.godotengine.org/en/stable/tutorials/ui/gui_containers.html
Hello Godotneers! Building a nice-looking user interface Godot that works across screen sizes and aspect ratios can be quite a daunting task. This video will provide you with the basics that you need to build your very own user interfaces with the Godot game engine that work everywhere. With it you get a good foundation on which you can build in...
Godot Engine documentation
Anchors are an efficient way to handle different aspect ratios for basic multiple resolution handling in GUIs. For more complex user interfaces, they can become difficult to use. This is often the ...
I'm down for a tutorial, I'll check it out!
Hi, updating this since I've had some time to look at the tutorial. So, from what I'm seeing, the correct course of action would be to add button children to a container, which is able to handle the proper "spacing" I'd require?
Yes, adding the buttons as children of a VBoxContainer will space the buttons in a list for you