diff --git a/docs/.gitignore b/docs/.gitignore index 1f273defd44095ddb160924d8c179257b9b48e32..d708c3917eb1111b99934c1ef1eac4a815068db3 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -6,4 +6,6 @@ projlab.fdb_latexmk projlab.fls projlab.out projlab.synctex(busy) -projlab.toc \ No newline at end of file +projlab.toc +tmp +flap.log \ No newline at end of file diff --git a/src/projlab/MainPanel.java b/src/projlab/MainPanel.java index 4ce3a7f2f8343430217f27a94492b5568290f270..fd50ae1ea82b81ca8496621d8ac8d2edbd8f6a68 100644 --- a/src/projlab/MainPanel.java +++ b/src/projlab/MainPanel.java @@ -1,6 +1,9 @@ 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(); } /**