Hi davedes, thanks for taking the time!
This is really weird, i've pulled two versions from my SVN and kind of "narrowed" the issue.
The problem lies here :
This is my "menuview" :
Code:
public class TeamView extends BasicGameState implements ComponentListener {
...
@Override
public void enter(GameContainer container, StateBasedGame game)
throws SlickException {
...
/*
buttons.add(new MenuButton(container,this,475,300,150,30,"test","test"));
buttons.add(new MenuButton(container,this,320,340,150,30,"test2","test2"));
buttons.add(new MenuButton(container,this,630,340,150,30,"test3","test3"));
*/
}
...
}
This is the "MenuButton" :
Code:
package com.projectx.view.components;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.gui.ComponentListener;
import org.newdawn.slick.gui.GUIContext;
import com.projectx.view.Resources;
public class MenuButton extends BaseComponent {
private static final Color transparentwhite = new Color(1,1,1,1);
private String text;
private String smalltext;
public MenuButton(GUIContext container, ComponentListener listener, int x, int y, int width, int height, String text, String smalltext) {
super(container, listener, x, y, width, height);
this.text = text;
this.smalltext = smalltext;
visible = true;
}
@Override
public void render(GUIContext gc, Graphics gr) throws SlickException {
gr.setLineWidth(1);
if (over){
gr.drawGradientLine(x, y, Color.white, x-8, y, transparentwhite);
gr.drawGradientLine(x, y, Color.white, x+80, y, transparentwhite);
gr.drawGradientLine(x, y, Color.white, x, y-8, transparentwhite);
gr.drawGradientLine(x, y, Color.white, x, y+8, transparentwhite);
gr.drawGradientLine(x+width, y+height, Color.white, x+width-80, y+height, transparentwhite);
gr.drawGradientLine(x+width, y+height, Color.white, x+width+8, y+height, transparentwhite);
gr.drawGradientLine(x+width, y+height, Color.white, x+width, y+height-8, transparentwhite);
gr.drawGradientLine(x+width, y+height, Color.white, x+width, y+height+8, transparentwhite);
}
Resources.fontMicro.drawString(x+width/2-Resources.fontMicro.getWidth(smalltext)/2, y+2, smalltext);
Resources.font.drawString(x+width/2-Resources.font.getWidth(text)/2, y+10, text);
}
}
The BaseComponent is a small add up to the abstractcomponent :
Code:
package com.projectx.view.components;
import org.newdawn.slick.gui.AbstractComponent;
import org.newdawn.slick.gui.ComponentListener;
import org.newdawn.slick.gui.GUIContext;
public abstract class BaseComponent extends AbstractComponent {
protected int x, y, height, width;
protected boolean over;
protected boolean visible = false;
public BaseComponent(GUIContext container, ComponentListener listener, int x, int y, int width, int height) {
super(container);
this.x = x;
this.y = y;
this.height = height;
this.width = width;
if (listener != null){
addListener(listener);
}
}
@Override
public int getHeight() {
return height;
}
@Override
public int getWidth() {
return width;
}
@Override
public int getX() {
return x;
}
@Override
public int getY() {
return y;
}
@Override
public void setLocation(int X, int Y) {
this.x = X;
this.y = Y;
}
@Override
public void mouseReleased(int button, int x, int y) {
if (listeners.size() > 0 && visible && x > this.x && x < (this.x + this.width)
&& y > this.y && y < (this.y + this.height)){
notifyListeners();
consumeEvent();
}
}
@Override
public void mouseMoved(int oldx, int oldy, int newx, int newy) {
if (newx > this.x && newx < (this.x + this.width)
&& newy > this.y && newy < (this.y + this.height)){
over = true;
}
else{
over = false;
}
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
}
If i uncomment the three lines creating the buttons (not even actually rendering them in the view) when i go to my gamestate, when i click, it goes in the
mouseReleased method of the BaseComponent of the MenuButton (or even sometimes some other components of the menu, which are never added nor rendered into the gameview), since the test is ok the menuview is notified, and the event consumed, and my game is not working anymore

.
Since the GameContainer is shared between the states, maybe there's something there?
Also, i don't get why the mousereleased function is called on every component everytime, why is the event not bound to the actual size and placement of the component?
This is really a bumer for me, hope you can help me out, if you need more information, feel free to tell me. I know i can workaround this, but it's just plain weird...
(Also i tried pulling the last development version you guys are working on, and apparently, same problem)