Nifty gui and SimpleUpdate

thanks a lot ! I couldn’t find the sources :’(

I downloaded the sources and found the MenuItemControl , i copyed it and replaced the controller :

controller="de.lessvoid.nifty.controls.MenuItemControl " to controller =“myproject.MenuItemControl”



It’s working with de.lessvoid.nifty.controls.MenuItemControl but not with the one i copied , how can i see the code of de.lessvoid.nifty.controls.MenuItemControl ? It seems the sources i downloaded from nehon’s link is quite different …



Here’s is the code i copyed :



[java]







import java.util.Properties;



import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.elements.ControllerEventListener;

import de.lessvoid.nifty.elements.Element;

import de.lessvoid.nifty.input.NiftyInputEvent;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.xml.xpp3.Attributes;



public class MenuItemControl extends FocusHandlers implements Controller {

private Screen screen;

private Element element;

private FocusHandler focusHandler;



public void bind(

final Nifty nifty,

final Screen screenParam,

final Element newElement,

final Properties properties,

final ControllerEventListener newListener,

final Attributes controlDefinitionAttributes) {

element = newElement;

screen = screenParam;

}



public void onStartScreen() {

focusHandler = screen.getFocusHandler();

}



public boolean inputEvent(final NiftyInputEvent inputEvent) {

if (inputEvent == NiftyInputEvent.NextInputElement) {

if (focusHandler != null) {

Element nextElement = focusHandler.getNext(element);

nextElement.setFocus();

return true;

}

} else if (inputEvent == NiftyInputEvent.PrevInputElement) {

if (focusHandler != null) {

Element prevElement = focusHandler.getPrev(element);

prevElement.setFocus();

return true;

}

} else if (inputEvent == NiftyInputEvent.MoveCursorDown) {

if (focusHandler != null) {

Element nextElement = focusHandler.getNext(element);

if (nextElement.getParent().equals(element.getParent())) {

nextElement.setFocus();

return true;

}

}

} else if (inputEvent == NiftyInputEvent.MoveCursorUp) {

if (focusHandler != null) {

Element prevElement = focusHandler.getPrev(element);

if (prevElement.getParent().equals(element.getParent())) {

prevElement.setFocus();

return true;

}

}

} else if (inputEvent == NiftyInputEvent.Activate) {

element.onClick();

return true;

}

return false;

}



public void onFocus(final boolean getFocus) {

}

}



[/java]



for some reason focushandler was missing in the import by the way



Thanks in advance

i think maybe only void can answer , if you come here please answer it’ll help me a lot

I’d be happy to help if I’d understand or see the question :slight_smile:



You’re trying to find the right sources? Then what version of Nifty do you use? The official version bundled with JME should be Nifty 1.2 and for this the link of nehon should be fine. If not then you can browse the source online too http://nifty-gui.svn.sourceforge.net/viewvc/nifty-gui/.



Where’s the exact problem again? :slight_smile:

oh void ! my king !



The problem here is that i have an xml building a menu that i can browse with arrows thanks to the default controller



http://pastebin.com/JbxzFGHr



As you can see when i summon the menuitemcontrol from your library everything is working , but since i can’t access to that file i can’t customize my actions

So i tried to dl the nifty 1.2 sources and found that file the problem is that when i put that file ( i copied the source upside ) arrows are not longer working to browse the menu. I understand verywell the code of menuitemcontroll and i really don’t know why isn’t it working , so de.lessvoid.nifty.controls.MenuItemControl is different from menuitemcontrol i download , you are the only one here to tell me what’s wrong… or how i can access to the original file thanks !

The history of that file is online available. You can browse it here: de.lessvoid.nifty.controls.MenuItemControl.java as well as de.lessvoid.nifty.input.mapping.MenuInputMapping.java Does that help?



I’m still a bit confused on what you’re trying to do exactly to be honest :frowning:

Hi master void and thanks for your answers ,



I browsed the menuitemcontrol code you linked to me ( menuinputmapping works perfectly ) and i have some questions :



1.How do you i use the AbstractController ? it seems that i have to import net.java.games.input.AbstractController; i’m not sure that’s right… ( i was using Controller on the other example not AbstractController , what are the differences ? )

2. I have FocusHandler can’t resolved a type , is that because it was on the package and since i use another package it doesn’t recognized it anymore ? i tried to import de.lessvoid.nifty.controls.FocusHandler;

3. I really have an issue with the onFocus method here :



[java]

@Override

public void onFocus(final boolean getFocus) {

super.onFocus(getFocus);

}

[/java]



It seems that onFocus is not an argument for super ( on eclipse it doesn’t propose me ) , anyway i have this error :



[java]

The method onFocus(boolean) of type MenuItemControl must override or implement a supertype method MenuItemControl.java

[/java]



Thanks for help

  1. That’s definitely the wrong class! :smiley: The AbstractController is pretty new and was contributed by a nifty user. In it’s current form it allows to register a listener that calls you back when a control gets the focus. This requires Nifty 1.3 and is considered an unstable API right now. I’m pretty sure it will change before 1.3 will be released. So I wouldn’t rely on it right now.


  2. The link I’ve posted contains the complete history of the files over all previous Nifty releases. So if you are looking for a specific version you’ll need to start your search with the version of Nifty that you’re currently using. So this might be a bit irritating :slight_smile:


  3. Yes, onFocus() has now been changed and implemented in the AbstractController and in this process every class that “extends AbstractController” does indeed @Override that method.



    You can’t mix the latest revision of the links I’ve posted with old Nifty version. If you want to use the latest version, you’ll need the whole 1.3-SNAPSHOT of Nifty which you currently only get by getting the source of Nifty (with svn) and build it on your own. Nightly builds are currently not available because I’ve not yet setup hudson again. Hudson was running on a hard drive that crashed a couple of weeks ago :confused:



    So here are your options:


  4. Get Nifty 1.3 from SVN and build it on your own.
  5. Find out the version of Nifty that you’re using to find the appropriate Version of the source.
1 Like

Thanks for the answer ,



I’m using Nifty 1.2 i’m pretty sure of it , and i need to find the source of menuitemcontrol related to the 1.2 version , do you have a link to propose ? thanks in advance

OK, you can find all previous versions as Tags in the SVN:



http://nifty-gui.svn.sourceforge.net/viewvc/nifty-gui/nifty/tags/



The Nifty 1.2 MenuItemControl is therefore here:



http://nifty-gui.svn.sourceforge.net/viewvc/nifty-gui/nifty/tags/nifty-1.2/src/main/java/de/lessvoid/nifty/controls/MenuItemControl.java?revision=935&view=markup

thanks a lot void , but still doesn’t work , when i put the controller as de.lessvoid.nifty.controls.MenuItemControl it’s working but when i just copy the code of the 1.2 version and i handle on my xml the controller to Myproject.MenuItemControl i can’t browse the items of my menu … i’m getting mad … and by the way i just had to add import de.lessvoid.nifty.controls.FocusHandler; or FocusHandler couldn’t resolved a type…

FocusHandler is in the same package as MenuItemControl so for the original class it’s not a problem because the FocusHandler is really in the same package and does not need a separate import.



If you copy the MenuItemControl to some other package you’ll need to add the FocusHandler import manually.



Can you verify that the inputEvent() method of your own MenuItemControl is called correctly? debugger or System.out.println() or something?



If you’re using your own control then you might need to set the InputMapping too. The idea is to have the InputMapping translates the physical keyboard events to the “logical” NiftyInputEvent so that the inputEvent() method can handle different input devices later. If you would later use a game pad there might be special keys that some special Game Pad InputMapping might map to NiftyInputEvent.MoveCursorUp and so on. So you could use the L1 and R1 buttons on your PS3 game pad to switch menu items.



That was the idea behind that maybe somewhat strange seperation. It’s like so:



physical input event of “some” input device → InputMapping → NiftyInputEvent



By seperating both things you could easily reuse the Controller code which only depends on the logical view (NiftyEvent) and just add a different input mapping later.



Here is an example as used in the intro.xml of the nifty-examples project:



[xml]<style id=“menu-item” base=“menu-font”>

<attributes align=“left” textHAlign=“left” color="#cccf" width=“100%”

focusable=“true”

controller=“de.lessvoid.nifty.controls.MenuItemControl”

inputMapping=“de.lessvoid.nifty.input.mapping.MenuInputMapping” />





<!-- usage →

<label id=“helloWorld” text=“Hello World” style=“menu-item”>[/xml]



This will on the fly make the label to a control that uses the MenuInputMapping of events and the MenuItemControl to switch menu items.



You should be able to apply this the same to a customControlDefinition of your own control. It’s the same mechanism really.

[java]

public boolean inputEvent(final NiftyInputEvent inputEvent) {

System.out.println(“test”);

if (inputEvent == NiftyInputEvent.NextInputElement) {

System.out.println(“test”);

if (focusHandler != null) {

System.out.println(“test”);

Element nextElement = focusHandler.getNext(element);

nextElement.setFocus();

return true;

}

etc…

[/java]



nothing is happening so i guess it’s not called correctly



Here’s the part of my XML :

[xml]

<attributes align=“right” textHAlign=“center” color="#cccf" width=“100%”

font=“aurulent-sans-17.fnt”

focusable=“true”

controller=“Myproject.MenuItemControl” <=== If i replace this to "de.lessvoid.nifty.controls.MenuItemControl it’s working …

inputMapping=“Myproject.MenuInputMapping” />

[/xml]





So now , we know that inputevent() method is not called what did i do wrong ? and why de.lessvoid.nifty.controls.MenuItemControl is working ?



BTW i did a inputmapping and it’s working with the menuitemcontrol source …

can you post Myproject.MenuInputMapping too?

well, anything odd in the console log? like exceptions or something?



maybe set the loglevel of nifty higher. you can use this to change this (call it somewhere in the beginning before calling any nifty stuff):



[java]Logger.getLogger("de.lessvoid.nifty").setLevel(Level.ALL);[/java]

and can I see the complete Myproject.MenuItemControl too? :slight_smile: Sorry, just want to gather as many data as possible … not sure what’s wrong (yet)

damn my pc is off it’s 1.AM in france , i wish so hard to give you all of this , but i’m not on the computer now and i have to sleep because i get up for work tomorow , i’ll post you everything tomorow . Thank you void , thank you very much about carring to my problem i’m touched !

it’s 1 am here too, don’t worry … actually I’m glad that I can go to bed now too :smiley: also need to work tommorow :confused:

Problem Solved ! I didn’t implements the right controller … that was a very stupid mistake by me i’m sorry a lot of error are caused by mistake , anyway i would never seen it if you didn’t tell me to check the log about Errors , i have an " Attention it doesn’t implement the right thing "



Thanks a lot Void ! ( and everyone else )

Sorry to bother again but i have another little problem that i’m sure you have the answer :smiley: , i have this



[xml]

<panel id=“huhu-2” childLayout=“vertical” width=“100%”>

<label id=“Attack” text=“Attack” style=“menu-item” >

</label>

<label id=“Shi” text=“Shi” style=“menu-item” >

</label>

<label id=“Combos” text=“Combos” style=“menu-item” >

</label>

<label id=“Items” text=“Items” style=“menu-item” >

</label>

</panel>

[/xml]



And that :



[java]

else if (inputEvent == NiftyInputEvent.Activate) {

System.out.println("Test ");

element.onClick();

return true;

[/java]



I would like to do something like this (pseudo code here ):





[java]

else if (inputEvent == NiftyInputEvent.Activate ) {



if (element.name=“Attack”){

Object.MyAttackFunction

}elseif(element.name=“Items”){

Object.MyItemFunction}

etc…

element.onClick();

return true;

[/java]



How do i link Labels id names to my program in Java ? Thanks a lot in advance !