Nifty-Gui font issue - SOLVED

So, I am adding elements dynamically to the screen.
When I do so, I have the font set to a 7pt font and it all renders fine.
When clicking on the element, I have it hide that element and build a new element (a focus element, so you can actually read the text.) when doing so, it an all elements created on that screen change to the new focus element’s text size.

I’ve tested with using the java builders, as well as setting everything up in XML, and even creating two separate styles for the two elements. I keep running into the same issue, after it renders the new element…

Anyone run into this before?

1 Like

Without you posting your code for what you are doing its hard to offer any help. I’ve never seen this happen before and I have some pretty extensive experience working with nifty.

1 Like

Fair point.
I’m pulling out just the bit that’s having issues.
Posting it back in a second.

1 Like

Below is a quick mock up of the code.

private void addCardToPanel(Card card) {

	String id = Integer.toString(card.inGameID);
	CardObject thisCard = new CardObject(card,id);
	cardObjectMap.put(id, thisCard);
	new PanelBuilder(id) {
		{
			childLayoutAbsoluteInside();
		
			width(Integer.toString(75));
			height(Integer.toString(100));
			
			interactOnClick("clicked(" + id +")");

			
			backgroundImage(backgroundImage);
			control(new LabelBuilder("Label" + id, labelString){{
				
				font("typefaces/verdana-7pt.fnt");
				x("7");
				//y("0");
				height("10");
				width("60");
				color("#000000");
			
			}});
			
		}
	});
			
}

public void clicked(String id) {
Element e = nifty.getCurrentScreen().findElementByID(id);
createFocus(e);
}
public void createFocus(Element e) {
e.hide();

	new PanelBuilder("focus" + e.getID() {
		{
			x(Integer.toString(e.getX()-50));
			y(Integer.toString(e.getY()-75));

			width(Integer.toString(200));
			height(Integer.toString(200));
			
			backgroundImage(backgroundImage);
			
			control(new LabelBuilder("labelFocusLabel" + e.getID(), labelEString){{
				
				font("verdana-12pt.fnt");
				x("10");
				color("#000000");
			
			}});
		}
	});

}

1 Like

I’m assuming you’ve removed code, because currently those builders don’t actually build any elements. I would attempt to build a simple stand alone example that demonstrates the problem. Given the code that you’ve posted, my working assumption is still that the bug is somewhere in the code we don’t see.

1 Like

I removed a ton of the other controls.
And the only things else I removed was this:

.build(nifty, nifty.getCurrentScreen(), nifty.getCurrentScreen().findElementById(“handPanel”));
and .build(nifty, nifty.getCurrentScreen(), nifty.getCurrentScreen().findElementById(“handFocusPanel”));

the add Card to panel is called when it receives a card is runs it with the build, that puts it in hand panel.
When you click it, it creates the element then builds it into the handFocusPanel.

I’ll work on creating a small mock up, but I am now, re-vamping the entire process to see if it is a bug somewhere that I’ve created…

1 Like

Update still an issue.
I’ve noticed this:

When you click on the card you want the focus on:
Aug 07, 2017 3:37:46 PM de.lessvoid.nifty.render.batch.BatchRenderImage uploadImageToAtlas
INFO: Image [typefaces/verdana-7pt.png] uploaded to atlas (atlas texture id: 1).
Aug 07, 2017 3:37:48 PM de.lessvoid.nifty.render.batch.BatchRenderImage uploadImageToAtlas
INFO: Image [typefaces/verdana-12pt.png] uploaded to atlas (atlas texture id: 1).

So it looks like the font is being replaced in the BatchRenderImage.

I’ve also got a better explanation of what I am doing:

the addCardToScreen is called by the main method when it receives a card.

public addCardToScreen() {
newCollapsedCard().build(nifty, nifty.getCurrentScreen(), nifty.getCurrentScreen().findElementById(“handPanel”));
}

private PanelBuilder newCollapsedCard() {
	String id = this.niftyID;
	PanelBuilder pb = new PanelBuilder(id) {
		{
			childLayoutAbsoluteInside();
			width(Integer.toString(75));
			height(Integer.toString(100));
			
			interactOnClick("clicked(" + id +")");
			String font = "typefaces/verdana-7pt.fnt";
			
			backgroundImage(backgroundImage);
			String cardNameString = card.cardName.trim();
			
			control(new LabelBuilder("NameLabel" + id, NameString){{
				
				font(font);
				x("7");
				height("10");
				width("60");
				color("#000000");
			
			}});
		}
	};
	return pb;
}

private PanelBuilder newFullCard() {
	Element e = nifty.getCurrentScreen().findElementById(getNiftyID());
	PanelBuilder pb = 
	new PanelBuilder("card-focus" + this.niftyID) {
		{
			x(Integer.toString(e.getX()-50));
			y(Integer.toString(e.getY()-75));
			childLayoutAbsoluteInside();
			
			width(Integer.toString(200));
			height(Integer.toString(200));
			
			interactOnClick("clickedFocusCard(card-focus" + getNiftyID() +")");
			String focusFont = "typefaces/verdana-12pt.fnt";
			backgroundImage(backgroundImage);
			String cardNameString = getCard().cardName.trim();
			control(new LabelBuilder("cardNameFocusLabel" + getNiftyID(), cardNameString){{
				
				font(focusFont);
				x("10");
				color("#000000");
			
			}});
		}
	};
	return pb;
}

public void clicked(String id) {
	lastClick = id;
	newCollapsedCard().build(nifty, nifty.getCurrentScreen(), nifty.getCurrentScreen().findElementById("cardFocusPanel"));
	Element e = nifty.getCurrentScreen().findElementById(id);
    e.hide();
}
  
public void clickedFocusCard(String id) {
	nifty.getCurrentScreen().findElementById(id).hide();
	Element e = nifty.getCurrentScreen().findElementById(lastClick);
	e.show();
}
1 Like

CLOSE this.

Was not a bug in my code.
Was how the BatchRenderer Works…
if the Font’s have the same info face name then it will assume both fonts are the exact same no matter size.

2 Likes

Post the header of both of your font files. I think you have something misconfigured.

EDIT: you beat me to it

Thanks for your time.