I have had a problem for some time now where I couldn’t get my tags to respond to any clicks.
Recently, I’ve figured out that it’s because for some reason, Nifty GUI forgets about/eliminates all of the xml that passes the subsequent tag. This is inoppurtune considering the deadline for IndieCade is two days from now.
For example, here’s my xml file (notice the position of the tag):
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd">
<!-- +++++++++++++++++++++++++++++++++++++++ -->
<!-- start screen -->
<!-- +++++++++++++++++++++++++++++++++++++++ -->
<screen id="start" controller="Game.Screens.ScenariosScreen">
<layer id="BackgroundLayer" childLayout="center">
<panel id="Background" height="100%" width="100%" childLayout="center">
<image id="ScenarioBackground" filename="Textures/Backgrounds/PregameBackground.png" width="100%" height="100%"></image>
</panel>
</layer>
<layer id="Layer1" childLayout="center">
<!--Other on screen elements-->
<panel id="OtherElements" childLayout="absolute">
<text id="Description" font="Interface/Fonts/DifficultyMenu/STechMono14px.fnt" text="test"></text>
</panel>
<!--Scenarios-->
<panel id="icons" childLayout="absolute" visibleToMouse="true">
<text id="Realism" font="Interface/Fonts/DifficultyMenu/STechMono24px.fnt" text="Realism"></text>
<text id="Surveillance" font="Interface/Fonts/DifficultyMenu/STechMono24px.fnt" text="Surveillance"></text>
<text id="Knowledge" font="Interface/Fonts/DifficultyMenu/STechMono24px.fnt" text="Knowledge"></text>
<text id="Privilege" font="Interface/Fonts/DifficultyMenu/STechMono24px.fnt" text="Privilege"></text>
<text id="Supervision" font="Interface/Fonts/DifficultyMenu/STechMono24px.fnt" text="Supervision"></text>
<text id="Inconvenience" font="Interface/Fonts/DifficultyMenu/STechMono24px.fnt" text="Inconvinience"></text>
<interface onClick="onClick()"/>
<text id="Rivalry" font="Interface/Fonts/DifficultyMenu/STechMono24px.fnt" text="Rivalry"></text>
</panel>
</layer>
</screen>
</nifty>
In this scenario, calling screen.findElementByName(“Rivalry”) in the controller will return Null, while the other elements will remain. If I move the interface element way up here:
<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd">
<!-- +++++++++++++++++++++++++++++++++++++++ -->
<!-- start screen -->
<!-- +++++++++++++++++++++++++++++++++++++++ -->
<screen id="start" controller="Game.Screens.ScenariosScreen">
<layer id="BackgroundLayer" childLayout="center">
<panel id="Background" height="100%" width="100%" childLayout="center">
<image id="ScenarioBackground" filename="Textures/Backgrounds/PregameBackground.png" width="100%" height="100%"></image>
<interface onClick="onClick()"/>
</panel>
</layer>
<layer id="Layer1" childLayout="center">
<!--Other on screen elements-->
<panel id="OtherElements" childLayout="absolute">
<text id="Description" font="Interface/Fonts/DifficultyMenu/STechMono14px.fnt" text="test"></text>
</panel>
<!--Scenarios-->
<panel id="icons" childLayout="absolute" visibleToMouse="true">
<text id="Realism" font="Interface/Fonts/DifficultyMenu/STechMono24px.fnt" text="Realism"></text>
<text id="Surveillance" font="Interface/Fonts/DifficultyMenu/STechMono24px.fnt" text="Surveillance"></text>
<text id="Knowledge" font="Interface/Fonts/DifficultyMenu/STechMono24px.fnt" text="Knowledge"></text>
<text id="Privilege" font="Interface/Fonts/DifficultyMenu/STechMono24px.fnt" text="Privilege"></text>
<text id="Supervision" font="Interface/Fonts/DifficultyMenu/STechMono24px.fnt" text="Supervision"></text>
<text id="Inconvenience" font="Interface/Fonts/DifficultyMenu/STechMono24px.fnt" text="Inconvinience"></text>
<text id="Rivalry" font="Interface/Fonts/DifficultyMenu/STechMono24px.fnt" text="Rivalry"></text>
</panel>
</layer>
</screen>
</nifty>
The entire layer below the background (Layer1) won’t exist when I check the screen during a breakpoint.
Is there something I’m doing wrong? What’s going on with Nifty?