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
311 stars 23 forks source link

Can't figure out how to get IInterface #46

Open crabmiau opened 1 week ago

crabmiau commented 1 week ago

I'm trying to get the position of the watermark but it requires IInterface, I cant figure out where I can get it

lukflug commented 1 week ago

The instance you used to create the ClickGUI or HUD. If you're using the PanelStudio-MC support library, that's typically an instance of GUIInterface (a sublcass of MinecraftGUI). In the example mod, you can obtain it via the ClickGUI.getInterface() method.

crabmiau commented 1 week ago

I can't get it from another class since it has protected access

crabmiau commented 1 week ago

i figured it out but Point cfgvar5 = WatermarkModule.getComponent().getPosition(gui.getInterface()); returns java.awt.Point[x=1,y=1] even if its not at 1,1

lukflug commented 1 week ago

If it's the WatermarkModule from the example mod, this shouldn't be the case. I can't tell what is causing it without looking at the code tho. If you're looking to save the positions of the panels in a config file, there's an interface for that. Implement the interface IConfigList, which models the config as a bunch of items representing panels (each represented with IPanelConfig) that have a title (which identifies the panel) and position, and a boolean state, (usually whether the panel is open or closed). The methods you implement for those interfaces basically save/load the values to/from the config file. To load/save the config you called gui.loadConfig or gui.saveConfig with your IConfigList implementation.

lukflug commented 1 week ago

Also worth noting is that the position you get via getPosition is the top left corner of the component you're rendering to the HUD. This is not necessarily the one that is saved in the config file. For example, ListComponent, which WatermarkModule is based on, will store the x coordinate of the right edge, if it is configured to align to the right instead of the left.

crabmiau commented 1 week ago

If it's the WatermarkModule from the example mod, this shouldn't be the case. I can't tell what is causing it without looking at the code tho. If you're looking to save the positions of the panels in a config file, there's an interface for that. Implement the interface IConfigList, which models the config as a bunch of items representing panels (each represented with IPanelConfig) that have a title (which identifies the panel) and position, and a boolean state, (usually whether the panel is open or closed). The methods you implement for those interfaces basically save/load the values to/from the config file. To load/save the config you called gui.loadConfig or gui.saveConfig with your IConfigList implementation.

I tried to do it but it seems its not well documented and I don't exactly know how to use it

lukflug commented 1 week ago

Here's an example: https://github.com/IUDevman/gamesense-client/blob/master/src/main/java/com/gamesense/client/clickgui/GuiConfig.java

crabmiau commented 1 week ago

Are there any more simple examples?

lukflug commented 1 week ago

I don't see how this could get much simpler. Most of the code is related to JSON loading/saving, which will have to be replaced by your own specific loading/saving code anyways.

crabmiau commented 1 week ago

and the example also seems old

lukflug commented 1 week ago

Whoops, I linked the wrong branch: https://github.com/IUDevman/gamesense-client/blob/d2.3.1/src/main/java/com/gamesense/client/clickgui/GuiConfig.java At any rate, the interface haven't changed since then, so it shouldn't matter that much.