[SOLVED] Nifty can't load controls!

Hi guys! I have been learning Nifty GUI so far, and it’s really giving me more problems than I expected.

Firstly, I draw a simple menu using the jME editor (because if I try to type in the xml, the IDE simply edits the file without even asking). If I try to view it in the Visual tab, it looks normal. However, when I try to load it in the game, I get these errors (not exceptions):

fev 16, 2016 6:36:51 PM de.lessvoid.nifty.loaderv2.types.ScreenType create
WARNING: Missing ScreenController for screen [start] using DefaultScreenController() instead but this might not be what you want.
fev 16, 2016 6:36:51 PM de.lessvoid.nifty.loaderv2.types.ControlType internalApplyControl
WARNING: controlDefinition [label] missing.
fev 16, 2016 6:36:51 PM de.lessvoid.nifty.loaderv2.types.ControlType internalApplyControl
WARNING: controlDefinition [button] missing.
fev 16, 2016 6:36:51 PM de.lessvoid.nifty.loaderv2.types.ControlType internalApplyControl
WARNING: controlDefinition [button] missing.
fev 16, 2016 6:36:51 PM de.lessvoid.nifty.loaderv2.types.ControlType internalApplyControl
WARNING: controlDefinition [button] missing.
fev 16, 2016 6:36:51 PM de.lessvoid.nifty.loaderv2.types.ControlType internalApplyControl
WARNING: controlDefinition [button] missing.
fev 16, 2016 6:36:51 PM de.lessvoid.nifty.loaderv2.types.ControlType internalApplyControl
WARNING: controlDefinition [label] missing.

I also validated the xml and it doesn’t throw errors.

I also need to ask: is Nifty dead? Because I’m simply getting too much trouble to use it! The wiki they have on Github is poor, and for me, I always get problems to build a simple GUI.

Thanks,
Ev1lbl0w

Can you post the xml please?

Nifty is still actively developed and works fine. They are currently working towards a complete rewrite I believe. The nifty editor in the sdk may not work properly… I’ve never used it and define everything in xml or java by hand. You need to post the xml output you are trying to load. The xml is probably valid, but you are probably missing the includes for the default control definitions.

Thanks for the replies @Smire and @glh3586!

As requested, here is the xml I’m loading:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<nifty xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://nifty-gui.lessvoid.com/nifty-gui" xsi:schemaLocation="https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd">
    <screen id="start">
        <layer id="gui" childLayout="vertical">
            <panel id="title" childLayout="center" backgroundColor="#500a" width="100%" style="" height="20%">
                <control name="label" id="titleLabel" width="100%" style="" text="Strategy" font="Interface/Fonts/Title.fnt" height="100%"/>
            </panel>
            <panel id="play" childLayout="center" backgroundColor="#050a" width="100%" style="" height="50%">
                <control name="button" id="playButton" childLayout="center" style="nifty-button" valign="center" label="Jogar" height="23"/>
            </panel>
            <panel id="others" childLayout="horizontal" backgroundColor="#005a" width="100%" style="" height="20%">
                <panel id="emptySpace1" childLayout="center" width="20%" style="" height="100%"/>
                <panel id="help" childLayout="center" width="20%" style="" height="100%">
                    <control name="button" id="helpButton" childLayout="center" label="Ajuda"/>
                </panel>
                <panel id="options" childLayout="center" width="20%" style="" height="100%">
                    <control name="button" id="optionsButton" childLayout="center" label="Opções"/>
                </panel>
                <panel id="exit" childLayout="center" width="20%" style="" height="100%">
                    <control name="button" id="exitButton" childLayout="center" label="Sair"/>
                </panel>
                <panel id="emptySpace2" childLayout="center" width="20%" style="" height="100%"/>
            </panel>
            <panel id="copyright" childLayout="center" backgroundColor="#555a" width="100%" style="" height="10%">
                <control name="label" id="copyrightLabel" width="100%" style="" text="Copyright 2015 GODE. GODE provides software only. Use of GODE's software is subject to our Terms of Services and Privacy Policy." wrap="true" font="aurulent-sans-16.fnt" height="100%"/>
            </panel>
        </layer>
    </screen>
</nifty>

This is the visual I get from the Visual tab:

@glh3586 I would also define everything by hand, but the IDE simply edits everything I wirte without warning. It’s really annoying. Are you also having this problem? I’m using the new 3.1 SDK.

I also tried to create a new .xml file and paste the code of the gui. Still doesn’t work.

And BTW, any chance I can re-center the words from the buttons? Because the control is placing the bottom of the word as center.

If that is the only file you are loading then you aren’t actually loading the default nifty controls. You need the following under the nifty tag. You can do it in that file or put it in a different xml file that you load first.

<useControls filename="nifty-default-controls.xml" />
<useStyles filename="nifty-default-styles.xml" />

Also don’t forget that you need a controller class if you want the buttons to do anything:

<screen id="screen" controller="test.package.customController">

The controller class implements screenController and you can add methods that can be called by the nifty buttons.

1 Like

Thanks guys! It’s working now. I just have a last question. Which of this approaches is the best one?

  • Create a single gui.xml with all the screens
  • Create various xml’s for every screen (eg: menu.xml, ingame.xml, pause.xml)

I would let it depend on how good you keep an overview on them, maybe have long XMLs in a seperate file. I don’t know if it has any impact on the performance though.

I started with one xml file and I’ve slowly moved to separating them out. It hasn’t impacted load time and cognitively I’ve found it easier. Especially after a year when you don’t remember what you wrote in the first place.

Ok thanks for the huge help guys!