87 lines
1.8 KiB
Java
87 lines
1.8 KiB
Java
import javafx.scene.paint.Color;
|
|
import javafx.scene.shape.Circle;
|
|
import javafx.scene.shape.Shape;
|
|
import javafx.event.Event;
|
|
import javafx.event.EventHandler;
|
|
import javafx.scene.input.MouseEvent;
|
|
public class MuehleButton {
|
|
|
|
public Game game;
|
|
|
|
|
|
|
|
public double absoluteX;
|
|
public double absoluteY;
|
|
|
|
public Color color = Color.BLUE;
|
|
|
|
public double radius;
|
|
|
|
public Circle circle;
|
|
|
|
public int id;
|
|
|
|
public boolean isActive = true;
|
|
|
|
public boolean isDestroyed = false;
|
|
|
|
public MuehleButton(int id, double absX, double absY, Game game) {
|
|
this.id = id;
|
|
|
|
|
|
|
|
absoluteX = absX;
|
|
absoluteY = absY;
|
|
|
|
radius = 20;
|
|
this.color = color;
|
|
circle = new Circle(absoluteX, absoluteY, radius);
|
|
circle.setFill(this.color);
|
|
|
|
this.game = game;
|
|
|
|
circle.addEventHandler(MouseEvent.MOUSE_RELEASED, mouse_click_target);
|
|
|
|
setActive(true);
|
|
}
|
|
|
|
public Shape getShape() {
|
|
return circle;
|
|
|
|
}
|
|
public void setActive(boolean value) {
|
|
isActive = value;
|
|
if(value == true) {
|
|
circle.setFill(this.color);
|
|
}
|
|
else {
|
|
circle.setFill(Color.rgb(0,0,0,0));
|
|
//circle.setFill(Color.rgb(0,255,0));
|
|
}
|
|
}
|
|
public void destroy( ) {
|
|
isDestroyed = true;
|
|
circle.setFill(Color.rgb(0,0,0,0));
|
|
|
|
} // end of if-else
|
|
|
|
public void create() {
|
|
isDestroyed = false;
|
|
circle.setFill(this.color);
|
|
}
|
|
|
|
EventHandler<MouseEvent> mouse_click_target = new EventHandler<MouseEvent>() {
|
|
public void handle(MouseEvent event) {
|
|
if (isActive) {
|
|
MouseClick();
|
|
} // end of if
|
|
}
|
|
};
|
|
|
|
|
|
public void MouseClick() {
|
|
game.chip_button_clicked(this);
|
|
}
|
|
|
|
} // end of MuehleButton
|