godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.23k stars 21.22k forks source link

Strange Window Behavoir C# #75495

Open silenuz opened 1 year ago

silenuz commented 1 year ago

Godot version

v4.0.stable.mono.official [92bee43ad]

System information

Linux Opensuse Leap

Issue description

So I finally figured out all the things I need to interact with the editor, and have finally started to create a plugin, however I can't get a window to show properly.

I created a window entirely in code. I then created an object that inherits from Popup menu and was going to use it to to launch the window. However upon launch the window content is entirely black.

I also had a test item in the tool menu so I tried launching it from there, and it worked fine. To help clarify this is what I mean:

Screenshot_2023-03-30_11-39-17

When I click the Test item it works, when I click the sub menu item Generate Script it appears entirely black.

In the next image the window launched from Test is on the left, and the window from Generate Script is on the right.

Screenshot_2023-03-30_11-37-39

Not sure if this is a bug or I am just missing something.

Steps to reproduce

Create a tool sub menu item and launch a window from it.

Minimal reproduction project

Sharpener.zip

Calinou commented 1 year ago

Please create a minimal reproduction project in GDScript instead of C# for two reasons:

silenuz commented 1 year ago

I don't know how to do it in GD Script.

But it is the same object being displayed each time, instantiated the same way.

The only difference is that in one case the dialog is a child of the plugin object and in the other case the dialog is a child of the popup menu. Note

_theme

Is the value from GetEditorInterface().GetBaseControl().Theme

PopupMenu code: private CreateObjectDialog newScriptDialog;

 newScriptDialog = new CreateObjectDialog(_theme);
 AddChild(newScriptDialog);
 newScriptDialog.Show();

Plugin Code:


CreateObjectDialog dialog = new CreateObjectDialog(GetEditorInterface().GetBaseControl().Theme);
AddChild(dialog);
dialog.Show();

I tried adding the popup menu as a child of the plugin but that was not possible to do.

I ended up working around it by passing an instance of the plugin to the popup menu, and have the popup menu add it as a child of the plugin, but as the popup menu itself is a property of the plugin I'm not a big fan of the current design.

silenuz commented 1 year ago

So I just tried with an instantiated scene and it does the same thing. In the following screenshot you can see the scene layout in the dock, the preview in the 2D viewer, the window when clicked from the menu item and the window when it's a child of the Popup menu.

Screenshot_2023-04-01_14-48-58

Attached is the project using the instantiated scene. test.zip

Update: Not sure if it's bug or I'm just trying to do something I shouldn't, but I can tell you why it happens.

It's because the popup menu it belongs to is hidden. If I add: HideOnItemSelection = false;

The content of the window displays only the menu is on top of it:

Screenshot_2023-04-01_15-50-31

If I have the window ignore it's Close Request then when I click in the editor area, and the menu closes, the window content disappears.

silenuz commented 1 year ago

Had some time to look further into things and attached is a simple project that demonstrates things with almost no code.

The project consists of three scenes with root node types of MenuBar, PopupMenu, and Window.

The Popup menu scene has window scene attached, the menu bar scene has the popup scene attached to it.

The only 'script' is attached to the popup, and the entire code follows:

public partial class Pmenu : PopupMenu
{
    private Window testDialog;

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        testDialog = (Window) GetNode("TestDialog");
        IdPressed += OnPressed;
        testDialog.CloseRequested += OnWindowCloseRequest;
    }

    private void OnWindowCloseRequest()
    {
        testDialog.Hide();
    }

    private void OnPressed(long id)
    {
        testDialog.Show();
    }

    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(double delta)
    {
    }
}

As can be seen it is bare bones, just two signals attached and handled.

So when I run this with project settings defaults I get this:

embed-on

So I must admit at this point I was wondering if there was a problem with my original code, because the window appears fine, only it's embedded so it it ignores the initial position property, so easy enough to fix go into advanced settings and uncheck embed windows. And you then get this:

embed-off

You'll find the project from the screenshots below.

plugintest.zip

silenuz commented 1 year ago

Found an even easier way to duplicate, and it's definitely related to visibility of the menu when embed sub windows is set to false.

Attached is a project consisting of two scenes. No code or scripts. If I toggle visibility of the popup in the Godot editor, the window content will vary with it. For example with pop up visible:

Screenshot_2023-04-02_10-07-28

If I then set the popup to be hidden then when the scene is run it looks like this: Screenshot_2023-04-02_10-08-15

popupscene.zip