Skip to content
Snippets Groups Projects
Verified Commit 96e8ef33 authored by Tóth Miklós Tibor's avatar Tóth Miklós Tibor :shrug:
Browse files

bindings

parent 0cf3dca0
No related branches found
No related tags found
No related merge requests found
......@@ -7,3 +7,5 @@ projlab.fls
projlab.out
projlab.synctex(busy)
projlab.toc
tmp
flap.log
\ No newline at end of file
package projlab;
import javafx.application.Platform;
import javafx.beans.binding.DoubleBinding;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.Button;
......@@ -20,6 +23,7 @@ import java.util.Map;
*/
@Docs(changed = true)
public class MainPanel extends AnchorPane {
/**
* A meglátogatható objektumok, amelyek gombként jelennek meg.
*/
......@@ -64,7 +68,7 @@ public class MainPanel extends AnchorPane {
/**
* Legenerált aszteroidák száma.
*/
private final int astAmount = 30;
private final int astAmount = 25;
/**
* Telepes, amit irányítani lehet.
......@@ -120,16 +124,20 @@ public class MainPanel extends AnchorPane {
var ast = new Asteroid(0, 10, mat);
Game.addAsteroid(ast);
ast.addObserver(astObs);
}
var asts = Game.getAsteroids();
for(int i = 0; i < astAmount; i++){
var ast = asts.get(i);
var neighbour = Rand.newListElement(asts);
ast.addNeighbour(neighbour);
neighbour.addNeighbour(ast);
if (i != 0) {
var nei = Rand.newListElement(Game.getAsteroids());
ast.addNeighbour(nei);
nei.addNeighbour(ast);
}
}
}
private static final int btWidth = 150;
private static final int btHeight = 90;
public void arrangeAsteroids() {
var asts = Game.getAsteroids();
int maxIndex = 0;
for(int i = 1; i < astAmount; i++){
var astMax = asts.get(maxIndex);
......@@ -139,49 +147,55 @@ public class MainPanel extends AnchorPane {
}
}
// create base asteroid
//var mat = Rand.newMaterial();
//var base = new Asteroid(0, 10, mat);
var base = asts.get(maxIndex);
//Game.addAsteroid(base);
//base.addObserver(astObs);
var bt = new Button();
var hand = new VisitableClickedHandler(base);
bt.setOnMouseClicked(hand);
//Coordinates location = getLocation(base);
Coordinates location = new Coordinates(getWidth()/2,getHeight()/2);
this.add(bt, location.x, location.y);
var middleX = widthProperty().divide(2);
var btXProp = middleX.subtract(bt.widthProperty().divide(2));
bt.layoutXProperty().bind(btXProp);
var middleY = heightProperty().divide(2);
var btYProp = middleY.subtract(bt.heightProperty().divide(2));
bt.layoutYProperty().bind(btYProp);
bt.setManaged(false);
bt.resize(btWidth, btHeight);
getChildren().add(bt);
visitables.put(base, bt);
setButtonText(base);
// create asteroids
double xdistance = 700;
double ydistance = 400;
var xdistance = widthProperty().subtract(bt.widthProperty()).divide(2);
var ydistance = heightProperty().subtract(bt.heightProperty()).divide(2);
for (int i = 0; i < astAmount; i++) {
if(i != maxIndex) {
//mat = Rand.newMaterial();
//var ast = new Asteroid(0, 10, mat);
var ast = asts.get(i);
//var asts = Game.getAsteroids();
//var neighbour = Rand.newListElement(asts);
//ast.addNeighbour(neighbour);
//neighbour.addNeighbour(ast);
//Game.addAsteroid(ast);
//ast.addObserver(astObs);
bt = new Button();
hand = new VisitableClickedHandler(ast);
bt.setOnMouseClicked(hand);
//location = getLocation(ast);
//this.add(bt, location.x, location.y);
if(i < maxIndex){
this.add(bt, location.x + xdistance * Math.cos(((360.0 / (astAmount -1)) * i) * Math.PI / 180), location.y + ydistance * Math.sin(((360.0 / (astAmount -1.0)) * i) * Math.PI / 180));
var ind = i;
if(i > maxIndex){
ind = i-1;
}
else{
this.add(bt, location.x + xdistance * Math.cos(((360.0 / (astAmount -1)) * (i-1)) * Math.PI / 180), location.y + ydistance * Math.sin(((360.0 / (astAmount -1.0)) * (i-1)) * Math.PI / 180));
DoubleBinding xOffset = xdistance.multiply(Math.cos(((360.0 / (astAmount -1)) * ind) * Math.PI / 180));
DoubleBinding yOffset = ydistance.multiply(Math.sin(((360.0 / (astAmount -1.0)) * ind) * Math.PI / 180));
if (ind % 2 == 0) {
xOffset = xOffset.divide(1.4);
yOffset = yOffset.divide(1.4);
}
bt.layoutXProperty().bind(middleX.add(xOffset).subtract(bt.widthProperty().divide(2)));
bt.layoutYProperty().bind(middleY.add(yOffset).subtract(bt.heightProperty().divide(2)));
bt.setManaged(false);
bt.resize(btWidth, btHeight);
visitables.put(ast, bt);
setButtonText(ast);
getChildren().add(bt);
}
}
......@@ -193,6 +207,7 @@ public class MainPanel extends AnchorPane {
*/
public void init() {
initAsteroids();
arrangeAsteroids();
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment