Hi guys!
I have an issue with making nifty panel changing. I have 3 general panels.
1 panel - game name
2 panel - buttons (start, load, save, options…)
3 panel - contains a child panel with changed content (content of load button, content of save button, content of options button…)
I don’t know how to make the Changed panel to change the content. Can you give me an advice?
I make my gui with XML.
Screen:
Use different panels for the changed panels and just make them visible or not depending on the button.
I use Nifty like this:
XML to define regions (think render queue buckets)… all take up the full screen but are used for different purposes.
I create everything like so:
[java]public guiActionBarButton(Main app, cScreenHUD hud, Nifty nifty, Screen screen, Element element, Element winLayer,
String Id, String function, int barIndex, int buttonIndex, int x, int y) {
this.app = app;
this.hud = hud;
this.nifty = nifty;
this.screen = screen;
this.element = element;
this.winLayer = winLayer;
this.Id = Id;
this.barIndex = barIndex;
this.buttonIndex = buttonIndex;
PanelCreator bPanel = new PanelCreator();
bPanel.setId(Id + “Panel”);
bPanel.setName(Id + “Panel”);
bPanel.setX(String.valueOf(x) + “px”);
bPanel.setY(“4px”);
bPanel.setWidth(“40px”);
bPanel.setHeight(“40px”);
bPanel.setFocusable(“false”);
bPanel.setVisible(“true”);
bPanel.setChildLayout(“absolute”);
bPanel.setPaddingBottom(“0px”);
bPanel.setPaddingTop(“0px”);
bPanel.setPaddingLeft(“0px”);
bPanel.setPaddingRight(“0px”);
bPanel.setVisibleToMouse(“false”);
bPanel.setStyle(“ab-button-blank”);
bPanel.create(nifty, screen, winLayer);
buttonPanel = element.findElementByName(Id + “Panel”);
ButtonBuilder btn = new ButtonBuilder(Id);
btn.id(Id);
btn.x(“0px”);
btn.y(“0px”);
btn.width(“40px”);
btn.height(“40px”);
btn.paddingBottom(“0px”);
btn.paddingTop(“0px”);
btn.paddingLeft(“0px”);
btn.paddingRight(“0px”);
btn.interactOnClick(“startASTimer(” + String.valueOf(buttonIndex) + “,” + String.valueOf(barIndex) + “)”);
btn.interactOnRelease(function + “(” + String.valueOf(barIndex) + “,” + String.valueOf(buttonIndex) + “)”);
btn.focusable(false);
btn.visibleToMouse(false);
btn.style(“ab-button-blank”);
btn.label("");
btn.build(nifty, screen, buttonPanel);
button = screen.findNiftyControl(Id, Button.class);
elButton = screen.findElementByName(Id);
PanelCreator buttonReset = new PanelCreator();
buttonReset.setId(Id + “Reset”);
buttonReset.setName(Id + “Reset”);
buttonReset.setX(“0px”);
buttonReset.setY(“0px”);
buttonReset.setWidth(“40px”);
buttonReset.setHeight(“40px”);
buttonReset.setFocusable(“false”);
buttonReset.setVisible(“true”);
buttonReset.setChildLayout(“vertical”);
buttonReset.setPaddingBottom(“0px”);
buttonReset.setPaddingTop(“0px”);
buttonReset.setPaddingLeft(“0px”);
buttonReset.setPaddingRight(“0px”);
buttonReset.setVisibleToMouse(“false”);
buttonReset.setStyle(“ab-button-reset”);
buttonReset.create(nifty, screen, buttonPanel); // << writes content into the layer I specify
winElReset = element.findElementByName(Id + “Reset”);
winElReset.setVisible(false);
}[/java]
When I need to remove something: (bPanel was drawn into an existing panel (winLayer) and the element reference was stored in buttonPanel.
[java]buttonPanel.markForRemoval();[/java]
To repopulate… just create the elements you need and place them in the layer you removed the old content from:
[java]bPanel.create(nifty, screen, winLayer);[/java]
Guess I should also say, I don’t always remove/replace content… I reuse existing content layers and replace text inside them… create new ones only when I have to… and remove them only if necessary.
For instance I have classes that manage specific types of items. Inventory bags can have any number of slots… I’ll reuse an existing bag with six slots if it isn’t currently display and repopulate the window with the items from the bag that was just opened. However, if they open up a second six slot bag and a window doesn’t exist for it, I’ll create a new one.
The nicest part of this is, I was able to create an entire foundation class structure I build everything off of, which allows me to create windows that are resizable, movable, have right-click context menus, etc, etc. So building new elements for my GUI is very easy. However, I used some serious hackery to get all this crap to work… it’s not pretty, but was necessary for the game I’m working on.
There is a section in the nifty bible on how to change the text in a panel…
@zarch said:
There is a section in the nifty bible on how to change the text in a panel...
Yeah... but content != text
But by extension it is - once you have the panel and no how to modify it then you can extrapolate that to adding/removing panels - changing images, etc.
@zarch said:
But by extension it is - once you have the panel and no how to modify it then you can extrapolate that to adding/removing panels - changing images, etc.
True... but not everyone will read that and see everything it might lead to. I found the nifty bible pretty much useless and it covers much of nothing past XML usage and some controller concepts. I was hoping for a little more focus on the "I don't want to use XML to define shit" approach. :)
@mifth : The layout is look exactly like my Settings screen. Just define the layout and basic element place holder in XML, and then show/hide the “tabs” by element.setVisible(). Will work fine!