#Scrolling menu with arbitrary amount of entries

1 messages · Page 1 of 1 (latest)

main spire
#

Hello world! I'm not sure what to look up, but in short, I want to make a "bestiary" which has descriptions of a bunch of different entities throughout the game. Something like the Piklopedia from Pikmin, or the Suburban Almanac from PVZ. I have these three problems to solve...

  • Storing the entries themselves (icon, description, etc)
  • Finding a good way to save which entries are actually unlocked (tamper prevention...)
  • Performing well with a large amount of entries (because there are going to be a LOT of entries, given my plan for the game)
  • Actually creating the buttons in-code
azure stormBOT
main spire
#

Also, to be clear: the image is just a mockup, the final game won't look much like this

#

Actually I'll make a separate forum post for the first two questions

feral swallow
#

For organizing static data in gdscript, I think one of the better ways is dictionary with enum keys. It would look something like this in your case:

enum monster {
    RAT,
    SLIME
}
var monster_stats: Dictionary[monster, Dictionary] = {
    RAT = {
        full_name = "Rat",
        some_stat = 1},
    SLIME = {
        full_name = "Slime",
        some_stat = 3}
}

As enums are just integers, they are easy to save as well. For the menu itself, you would create a vertical container with a scrollbar and fill it with copies of the button scene:

var instance: Node = preload("res://scenes/button.tscn").instantiate()
instance.some_property = some_value
some_node.add_child(instance)
#

For an UX tip, you don't need to make the "Open" button separate. Just make the name a button

main spire
#

Thank you!

feral swallow
#

Good luck

main spire
#

One more thing: how can I avoid a lagspike for opening the menu?

#

Maybe I load all of the buttons one at a time?

alpine niche
feral swallow
#

Tbh a bunch of buttons are not going to cause a lag spike

#

But yes, you could have the whole thing preloaded somewhere and show it when needed, or add to the tree when needed

main spire
#

Okay, that's all the things I was looking for I think

#

But I have one more question: how can I add a search bar? (the hboxcontainers are added in-code)

feral swallow
#

It's not going to be trivial. You will probably need a text field that, on enter pressed, searches its text through names of all monsters and rebuilds the container with only buttons for monsters that have a match

#

Could also add the name as a property of a button (can't really rely on node names), just hide the wrong ones instead of rebuilding the thing

#

For the field itself, its just LineEdit probably

main spire
#

Thank you!

#

Also, I know I said that was my last question, but I have one more fr: is there a simple way to change the sorting of the entries?

feral swallow
#

I don't think so. All your container sees is a bunch of control nodes as its children. It does not know their names, their stats. It has no way to sort them other than by the children order

main spire
#

Fair enough, thank you!