Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow inherit from BaseButton when creating new script to create custom buttons #8101

Open
acgc99 opened this issue Oct 13, 2023 · 10 comments
Open

Comments

@acgc99
Copy link

acgc99 commented Oct 13, 2023

Describe the project you are working on

A plugin for app development widgets.

Describe the problem or limitation you are having in your project

I want to create custom buttons, therefore inherit from BaseButton, however you cannot create a script that inherits from BaseButton from the FileSystem tab.

image

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add the option to inherit from BaseButton to allow users to create scripts that inherit from it directly. This will allow the creation of custom buttons directly (without workaround).

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Add the option to inherit from BaseButton when creating a script so users can create custom buttons.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Yes, you can modify the created script.

Is there a reason why this should be core and not an add-on in the asset library?

Yes, I think it is a limitation saying "you shouldn't do that".

@AThousandShips
Copy link
Member

Base button doesn't contain much of the logic required

You are not providing any reasons for being able to extend this, please fill in the form properly, all entries must be filled in:

Describe the feature / enhancement and how it helps to overcome the problem or limitation

This one should be filled in with what you need, not what to do

@Stronkkey
Copy link

@AThousandShips I think they mean that you cannot pick abstract classes to inherit from in the script creation wizard.
abstract

@AThousandShips
Copy link
Member

Yes, that's by design, you're not supposed to be able to extend these classes, that's not a bug, BaseButton is not a complete class and doesn't work on its own

@acgc99
Copy link
Author

acgc99 commented Oct 13, 2023

Therefore, things like extends BaseButton should be forbidden. Currently I'm using it without any problem. I add child nodes to it with mouse_filter = Control.MOUSE_FILTER_IGNORE to avoid problems.

@AThousandShips
Copy link
Member

See the discussion in #5641

@acgc99
Copy link
Author

acgc99 commented Oct 13, 2023

Is there any reason why I shouldn't use it specifically? For example, this is WIconButton structure (a button that is represented by an texture (only one texture, not like TextureButton)):

  • BaseButton
    • TextureRect

And it works as I expect. I think that that is better than:

  • Control
    • Button

which I would use to avoid exposing properties like Button.text on the inspector if BaseButton is forbidden.

This is another example of a complex custom button (WCard) that inherits from BaseButton:

image

@AThousandShips , how I am supposed to create custom buttons if I can't use BaseButton?

@AThousandShips
Copy link
Member

AThousandShips commented Oct 14, 2023

As far as I recall generally the BaseButton class is meant as an abstract base which doesn't handle the main behaviour, but I might be wrong, but generally the current implementation doesn't handle abstract classes completely so there's limitations to how it works, that's why it's hidden

I asked from the start why you needed this, and that this information should have been added to the proposal as that's what the instructions say, that's exactly why I asked...

Also please do not tag people when they don't respond immediately

@acgc99
Copy link
Author

acgc99 commented Oct 14, 2023

@AThousandShips sorry... I editted the issue.

@acgc99 acgc99 changed the title Allow inherit from BaseButton when creating new script Allow inherit from BaseButton when creating new script to create custom buttons Oct 14, 2023
@gregcsokas
Copy link

gregcsokas commented Oct 14, 2023

But with a script, you can create any kind of button.

Like here
https://github.com/gregcsokas/godot-ui-components/blob/main/templates/text_button/text_button.gd

Unfortunately, it's laggy as hell

UPDATE:
I tested it again and it works perfectly

@kleonc
Copy link
Member

kleonc commented Oct 14, 2023

This looks like a bug to me. Since godotengine/godot#58972 there's a distinction in binding between "abstract" and "virtual" classes. Quote:

  • Added a new "virtual" category for classes, they can't be instantiated from the editor, but can be inherited from script and extensions (GDREGISTER_VIRTUAL_CLASS).

If "virtual" classes (like BaseButton) are said to be extendable from script then I see no reason to disallow picking them as a base class when creating a new script from the FileSystem dock.

In case of adding to the scene tree a scriptless instance of a "virtual" class within the Scene dock I'm not sure why would it need to be forbidden. But even if it's forbidden for some sensible reason note that it's easily workaroundable, example:

class_name Test
extends BaseButton
  1. Empty scene -> Create root node -> Other node -> Test.
    PGkua3jrDj

  2. Detach script, you have BaseButton scene with no script.
    g1e19zlR1i

  3. Run the scene. No explosion. 🤔

Not sure if e.g. detaching a script from a "virtual" class should be forbidden or what. For sure there are many inconsistencies in the logic of handling such classes.


Also note that currently you can manually type in BaseButton etc. as the base class:
Godot_v4 2-beta1_win64_o4Nwm63LKh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants