Hi,
I'm trying to use GBUI for a test game and I'm having some troubles to put it in a game state. I'll add my game state code and I'd be very thankful with anyone can tell what I'm missing.
BTW: BuiSystem.init(new PolledRootNode(Timer.getTimer(), input), "atechnique/gbui/style2.bss"); is giving mw hard time… I tried to put in almost every folder related to my project (NetBeans 6.5) and I still get a run-time exception. If I use BuiSystem.init(), I don't get the exception, but nothing is shown. Actually I don't get any GUI stuff shown either way.
Thanks a lot,
Dirso.
The exception code:
java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
at com.jmex.bui.bss.BStyleSheetUtil.getStyleSheet(BStyleSheetUtil.java:134)
at com.jmex.bui.bss.BStyleSheetUtil.getStyleSheet(BStyleSheetUtil.java:38)
at com.jmex.bui.BuiSystem.init(BuiSystem.java:94)
at com.jmex.bui.BuiSystem.init(BuiSystem.java:81)
at superpong3d.MyBasicGameState.<clinit>(MyBasicGameState.java:60)
at superpong3d.Main.main(Main.java:36)
java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
at com.jmex.bui.bss.BStyleSheetUtil.getStyleSheet(BStyleSheetUtil.java:134)
at com.jmex.bui.bss.BStyleSheetUtil.getStyleSheet(BStyleSheetUtil.java:38)
at com.jmex.bui.BuiSystem.init(BuiSystem.java:136)
at com.jmex.bui.BuiSystem.init(BuiSystem.java:94)
at com.jmex.bui.BuiSystem.init(BuiSystem.java:81)
at superpong3d.MyBasicGameState.<clinit>(MyBasicGameState.java:60)
at superpong3d.Main.main(Main.java:36)
MyBasicGameState:
public class MyBasicGameState extends GameState {
/** The root of this GameStates scenegraph. */
protected Node rootNode;
static protected InputHandler input;
static protected MouseInput mouse;
// Unless we find a reason to have one of these for each sub-class, let's just share static instances
protected static DisplaySystem display;
protected BWindow _window;
protected boolean manualActivation = false;
static {
display = DisplaySystem.getDisplaySystem();
input = new InputHandler();
mouse = MouseInput.get();
BuiSystem.init(new PolledRootNode(Timer.getTimer(), input), "atechnique/gbui/style2.bss");
}
/**
*
* @param name The name of this GameState.
*/
public MyBasicGameState(String name) {
this.name = name;
rootNode = new Node(name + ": RootNode");
ZBufferState buf = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
buf.setEnabled(true);
buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
rootNode.setRenderState(buf);
// call virtual methods
//
initKeyBindings();
// create scene
initScene();
}
/**
* Updates the rootNode.
*
* @see GameState#update(float)
*/
public void update(float tpf) {
rootNode.updateGeometricState(tpf, true);
// test the input
input.update(tpf);
}
/**
* Draws the rootNode.
*
* @see GameState#render(float)
*/
public void render(float tpf) {
DisplaySystem.getDisplaySystem().getRenderer().draw(rootNode);
}
/**
* Empty.
*
* @see GameState#cleanup()
*/
public void cleanup() {
//do nothing
}
public Node getRootNode() {
return rootNode;
}
protected void initScene()
{
// do nothing again
}
/**
*
*/
protected void initKeyBindings()
{
// do nothing, derivated class responsability
}
public void halt(){
Main.halt();
}
public void setCursorVisible(boolean v){
mouse.setCursorVisible(v);
if(v)
mouse.setCursorPosition(display.getWidth()/2, display.getHeight()/2);
}
public void activate(){
doActivation(true);
}
public void deactivate(){
doActivation(false);
}
public void doActivation(boolean activate){
if(isActive()==activate)return;
manualActivation = activate;
super.setActive(activate);
if(activate)buildGUI();
else cleanupGUI();
}
protected void buildGUI(){
// Display the GBUI portion
rootNode.attachChild(BuiSystem.getRootNode());
rootNode.updateRenderState();
GameTaskQueueManager.getManager().update(new Callable<Object>() {
public Object call() throws Exception {
BuiSystem.addWindow(_window);
return null;
}
});
}
protected void cleanupGUI(){
if (_window.getRootNode() != null) {
_window.dismiss();
}
rootNode.detachChild(BuiSystem.getRootNode());
}
public static void changeGameState(String gsName){
GameStateManager.getInstance().deactivateAllChildren();
((MyBasicGameState)GameStateManager.getInstance().getChild(gsName)).activate();
}
}
MainMenuGameState:
public class MainMenuGameState extends MenuGameState {
private BButton _btnCancel;
private BButton _btnOk;
/**
*
*/
public MainMenuGameState(){
super("MainMenu");
}
/**
* update the Inputhandler.
*/
@Override
public void update(float tpf) {
super.update(tpf);
if(KeyBindingManager.getKeyBindingManager().isValidCommand("exit", false)){
halt();
}
}
@Override
public void cleanup() {
}
/**
*
*/
@Override
public void initKeyBindings()
{
KeyBindingManager.getKeyBindingManager().set("exit",
KeyInput.KEY_ESCAPE);
}
@Override
protected void buildGUI(){
super.buildGUI();
// create the main window
setCursorVisible(true);
_window = new BWindow(BuiSystem.getStyle(), new AbsoluteLayout());
_window.setSize(400, 300);
int buttonWidth = _window.getWidth() / 4;
int buttonHeight = 32;
// Cancel button
_btnCancel = new BButton("Cancel");
_btnCancel.setPreferredSize(buttonWidth, buttonHeight);
_window.add(_btnCancel, new Point(10, 20));
// OK button
_btnOk = new BButton("OK");
_btnOk.setPreferredSize(buttonWidth, buttonHeight);
_window.add(_btnOk, new Point(_window.getWidth() - 10 - buttonWidth, 20));
_window.center();
}
@Override
protected void cleanupGUI(){
super.cleanupGUI();
}
}