lukflug / PanelStudio

An extensible and customizable GUI API/library to create ClickGUIs, HUDEditors and TabGUIs designed for use in Minecraft utility mods.
https://lukflug.github.io/panelstudio.html
MIT License
309 stars 23 forks source link

GUI opens, but wont respond to any mouse events #12

Closed ghost closed 3 years ago

ghost commented 3 years ago

image This is how it looks, but i cannot interact with it in any way. No dragging, no clicking, no expanding etc.

lukflug commented 3 years ago

Could you describe your problem more precisely?

ghost commented 3 years ago

Version i am using is 1.16.5, I just followed the general instructions in the readme. this is the whole gui class:

package me.constantindev.ccl.gui;

import com.lukflug.panelstudio.CollapsibleContainer;
import com.lukflug.panelstudio.DraggableContainer;
import com.lukflug.panelstudio.SettingsAnimation;
import com.lukflug.panelstudio.mc16.MinecraftGUI;
import com.lukflug.panelstudio.settings.SimpleToggleable;
import com.lukflug.panelstudio.theme.ColorScheme;
import com.lukflug.panelstudio.theme.GameSenseTheme;
import com.lukflug.panelstudio.theme.Theme;
import me.constantindev.ccl.etc.MType;
import me.constantindev.ccl.etc.base.Module;
import me.constantindev.ccl.etc.config.ClientConfig;
import me.constantindev.ccl.etc.reg.ModuleRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.MatrixStack;

import java.awt.*;

public class ClickGUI extends MinecraftGUI {
    private final GUIInterface guiInterface;
    private final Theme theme;
    private final com.lukflug.panelstudio.ClickGUI gui;

    public ClickGUI() {
        guiInterface = new GUIInterface(true) {
            @Override
            protected String getResourcePrefix() {
                return "ccl:gui/";
            }

            @Override
            public void drawString(Point pos, String s, Color c) {
                end();
                MinecraftClient.getInstance().textRenderer.draw(new MatrixStack(), s, pos.x, pos.y, c.getRGB());
                begin();
            }

            @Override
            public int getFontWidth(String s) {
                return MinecraftClient.getInstance().textRenderer.getWidth(s);
            }

            @Override
            public int getFontHeight() {
                return MinecraftClient.getInstance().textRenderer.fontHeight;
            }
        };
        theme = new GameSenseTheme(new ColorScheme() {
            @Override
            public Color getActiveColor() {
                return new Color(20, 255, 255);
            }

            @Override
            public Color getInactiveColor() {
                return new Color(20, 50, 255);
            }

            @Override
            public Color getBackgroundColor() {
                return new Color(40, 40, 40);
            }

            @Override
            public Color getOutlineColor() {
                return new Color(100, 100, 100);
            }

            @Override
            public Color getFontColor() {
                return new Color(255, 40, 40);
            }

            @Override
            public int getOpacity() {
                return 255;
            }
        }, height, 2, 2);
        gui = new com.lukflug.panelstudio.ClickGUI(guiInterface, null);
        for (MType type : MType.ALL) {
            com.lukflug.panelstudio.DraggableContainer container = new DraggableContainer(type.toString(), null, theme.getContainerRenderer(), new SimpleToggleable(true), new SettingsAnimation(ClientConfig.animSpeed), new SimpleToggleable(true), new Point(50, 50), width);
            gui.addComponent(container);
            for (Module m : ModuleRegistry.getAll()) {
                if (m.type != type) continue;
                CollapsibleContainer mc = new CollapsibleContainer(m.name, null, theme.getContainerRenderer(), new SimpleToggleable(false), new SettingsAnimation(ClientConfig.animSpeed), m.isOn);
                container.addComponent(mc);
            }
        }
    }

    @Override
    protected com.lukflug.panelstudio.ClickGUI getGUI() {
        return gui;
    }

    @Override
    protected GUIInterface getInterface() {
        return guiInterface;
    }

    @Override
    protected int getScrollSpeed() {
        return 1;
    }
}

I can imagine some of the values I return like the scroll speed to affect this, since I did not have any true references for these.

ghost commented 3 years ago

Closed by accident, ouch

lukflug commented 3 years ago

How do you open the GUI, do you call the MinecraftClient.getInstance().openScreen() method?

ghost commented 3 years ago

Yes,

if (ModuleRegistry.getByName("clickgui").isOn.isOn()) {
            ModuleRegistry.getByName("clickgui").isOn.setState(false);
            MinecraftClient.getInstance().openScreen(new ClickGUI());
        }
lukflug commented 3 years ago

This is probably not related to the problem, but you should instantiate ClickGUI only once and not every time you open it.

Could you add following to the ClickGUI class and tell me if this print statement shows up when you click, to troubleshoot it?

@Override
public boolean mouseClicked(double mouseX, double mouseY, int clickedButton) {
    // <insert print statement here>
    return super.mouseClicked(mouseX,mousY,clickedButton)
}
ghost commented 3 years ago

image it definitely does receive the events

lukflug commented 3 years ago

Ah, ok I just noticed the problem: }, height, 2, 2); The height field is inherited from a superclass and is actually zero. Replace height in this line by a number like 12.

ghost commented 3 years ago

still, nothing

lukflug commented 3 years ago

Could you replace this: new DraggableContainer(type.toString(), null, theme.getContainerRenderer(), new SimpleToggleable(true), new SettingsAnimation(ClientConfig.animSpeed), new SimpleToggleable(true), new Point(50, 50), width); by this:

new DraggableContainer(type.toString(), null, theme.getContainerRenderer(), new SimpleToggleable(true), new SettingsAnimation(ClientConfig.animSpeed), new SimpleToggleable(true), new Point(50, 50), width) {
    @Override
    public void render (Context context) {
        super.render(context);
        System.out.println(context.getHeight());
    }
}
ghost commented 3 years ago

I may have found the issue, lets see if this works

ghost commented 3 years ago

I found the issue. width is inherited from a superclass aswell and is also 0. Causes the hitbox to be 0 px wide

ghost commented 3 years ago

Next issue: the categories can somehow be toggled and wont really expand anywhere

ghost commented 3 years ago

Fixed it, all good now