#How to implement inheritance in scenes?

8 messages · Page 1 of 1 (latest)

spice robin
#

Hello,

I want to implement 2 UI scenes, which are very similar, but have some differences. Please see images for examples.

Basically I need the data input to be different for each type and the button at the bottom has to do different things. But they layout (except height) and such are the same.

What would be the best way to have one scene for the layout stuff and then one scene each for the different type? SO basically inheritance in programming.

I was thinking of building wrapper scene around the basic scene. But then I am not so sure how I can inject different functionality into it?

EDIT: For Tooltips I want to use the same again, but without a button at the bottom

vague mural
#

An easy way would be to have a "Base" scene which has the same layout that both share. Then make both of your actually used scenes inherit that one.

But this sounds like a difference that should come from the code, not the scene (?)

It is hard to tell what would be a good approach without context.

spice robin
#

To be honest, I am not sure what context is missing?

In an esseence:

  • both have an icon on the top left
  • both have a title and subtitle
  • both have a list of effects (good or bad)
  • both have a button at the bottom
  • the button works vastly different
  • the actual text comes form a different data set
#

Another idea I had was using Wrapper Scenes. They could inject into the UI component what data should be used and what the button should do.

But I am not sure if that is that is the correct way to go in Godot.
I come from a fullstack webdev background

safe crow
#

you can try injection, certainly, but that sounds painful for long inheritance chains

spice robin
safe crow
#

uhhh, i meant doing that in that order, i dont think its possible to do in one atomic editor provided action