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
1 merge request!114Tomi
Pipeline #7848 failed
Pipeline: tester

#7849

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