Create a property window - advice needed

I am creating a properties window for the 3d objects in a sandbox editor. The objects can have different properties, so depending on the type of object, a different property window would be shown. The ui is created in nifty.

My basic approach would be:

  • top level component is window with scrollcomponent inside.
  • a panel with the properties of each object type will be created at startup.
  • each property will be visualized with custom controls that I made. (panel with horizontal orientation)
  • if an object is selected the appropriate panel will be added to the scroll-able component.

Do you think this is a good approach with the nifty gui? Anybody have a better idea? The thing I worry about the most is the behavior of the scroll component.

I had real trouble getting the nifty scroll pane to work, in the end I made my own. It’s easy enough to make one though.

Your general approach seems fine.

1 Like

Thanks Zarch.

The principle works, I didn’t have too much trouble with the scroll panel. I followed the advice to update the scrollpanel element like this :

Element scrollPanel = this.currentScreen.findElementByName(“scrollPropertiesPanel”);
if (scrollPanel != null) {
System.out.println(“Layouting scrollpanel”);
scrollPanel.getNiftyControl(ScrollPanel.class).setUp(0, 5, 0, 50, AutoScroll.OFF);

What didn’t work was reusing a property panel for a given object type. I have to recreate the property panel every time I use it. I use markForRemoval to remove a panel from the scroll panel and that seems to change some state in the panel that makes it difficult later on to add it again.

Maybe somebody has an idea how to make reuse of Element objects possible?

I’ve never re-used them, I just remove and add new. Seems to work fine that way.

1 Like
@zarch said: I've never re-used them, I just remove and add new. Seems to work fine that way.

It basically works, the only remaining problem now is that I still receive events from the discarded elements.

You still receive events for nifty elements that have been removed from the screen? :o

I’ve never (ever) seen that happen but it sounds like a bug…

The bug will probably be on my part :wink:

I subscribe to all the slider events in my controller, and check if the id matches the id of
the specific slider in this controller. Probably should change that to listen
to one specific slider in my controller, still trying to find out how to do that.

@NiftyEventSubscriber(pattern = “.*#slider”)
public void sliderValueChanged(String id, SliderChangedEvent event) {
if (id.equals(sliderElement.getId())) {
TextRenderer textRenderer = textElement.getRenderer(TextRenderer.class);