Hi there,
I started with TWL today and I have to say: It is great. Until now, everything works fine. Much better than AWT and Swing.
But I got one problem now: I need different menus. For example there is the main menu, when the program starts.
If you click on a certain button in this menu, it has to disappear and another menu should appear. First I tried to make this second menu as a submenu of the first, but that did not work, because if you set the parent menu to invisible, then the child menu is as well invisible (which is pretty logically).
So I tried the following: I have one "root" widget. The both described menus are children of this root menu. Then it should be pretty simple to switch between the menus.
That worked so far: The menu shows up correctly when the program starts. But I cannot interact with any elements in this menu.
Not only, that nothing happens if I click on a button, the click is also even not recognized (as you can see because the button does not change it status for hovering etc.).
These are the functions I use to create both menus:
Code:
private void initGUI(){
initMainMenu();
root.add(mainMenu);
initStartGameMenu();
root.add(startGameMenu);
}
private void initStartGameMenu(){
startGameMenu = new Widget();
startGameMenu.setTheme("");
startGameMenu.setPosition(0, 0);
startGameMenu.setSize(root.getWidth(), root.getHeight());
//Button things go here.....
startGameMenu.add(backButton);
startGameMenu.setVisible(false);
}
private void initMainMenu(){
mainMenu = new Widget();
mainMenu.setTheme("");
mainMenu.setPosition(0, 0);
mainMenu.setSize(root.getWidth(), root.getHeight());
int posIndex = 0;
float posDistance = (float)solution.y / 4.0f - 20.0f;
//Button things....
startGameButton.addCallback(new Runnable() {
@Override
public void run() {
startGameMenu.setVisible(true);
mainMenu.setVisible(false);
}
});
//More button things....
endGameButton.addCallback(new Runnable() {
@Override
public void run() {
System.exit(0);
}
});
mainMenu.add(startGameButton);
mainMenu.add(endGameButton);
mainMenu.add(loadSettingButton);
}
And here my GUI is created (which is just the code from the TWL example):
Code:
@Override
public void init(GameContainer gameCon) throws SlickException {
root = new Widget();
root.setTheme("");
// save Slick's GL state while loading the theme
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
try {
lwjglRenderer = new LWJGLRenderer();
theme = ThemeManager.createThemeManager(
GameOfLife.class.getResource("simple.xml"), lwjglRenderer);
gui = new GUI(root, lwjglRenderer);
gui.applyTheme(theme);
} catch (LWJGLException e) {
e.printStackTrace();
} catch(IOException e){
e.printStackTrace();
} finally {
// restore Slick's GL state
GL11.glPopAttrib();
}
initGUI();
// connect input
twlInputAdapter = new TWLInputAdapter(gui, gameCon.getInput());
gameCon.getInput().addPrimaryListener(twlInputAdapter);
setGameTimer(new GameTimer());
gameCon.setShowFPS(false);
}
The menus are in the code like this:
Code:
private Widget root;
private Widget mainMenu;
private Widget startGameMenu;
Can anyone please help me?
I have no clue what actually the problem is. And sadly I cannot find any information about somethign like this.
Greetings,
M0rgenstern