diff --git a/src/main/java/com/yes/yes/MainController.java b/src/main/java/com/yes/yes/MainController.java index 20548b8..6e53d44 100644 --- a/src/main/java/com/yes/yes/MainController.java +++ b/src/main/java/com/yes/yes/MainController.java @@ -1,8 +1,6 @@ package com.yes.yes; -import com.yes.yes.managers.GameManager; -import com.yes.yes.managers.PlayerManager; -import com.yes.yes.utils.Coordinate; +import com.yes.yes.managers.*; import javafx.application.Platform; import javafx.fxml.FXML; import javafx.scene.layout.VBox; @@ -14,11 +12,14 @@ public class MainController { public void initialize() { GameManager gameManager = new GameManager(root); - gameManager.setup(); + gameManager.initialize(); Platform.runLater(() -> { - PlayerManager playerManager = new PlayerManager(gameManager.getWorld()); - playerManager.setup(); + UiManager uiManager = new UiManager(root); + uiManager.initialize(); + + PlayerManager playerManager = new PlayerManager(gameManager.getWorld(), uiManager.getBuildBox()); + playerManager.initialize(); }); } diff --git a/src/main/java/com/yes/yes/managers/UiManager.java b/src/main/java/com/yes/yes/managers/UiManager.java index 450ba13..5c4f09b 100644 --- a/src/main/java/com/yes/yes/managers/UiManager.java +++ b/src/main/java/com/yes/yes/managers/UiManager.java @@ -13,6 +13,10 @@ public class UiManager { public void initialize() { buildBox = new BuildBox(); - root.getChildren().add(0,buildBox); + root.getChildren().add(0, buildBox); + } + + public BuildBox getBuildBox() { + return buildBox; } } diff --git a/src/main/java/com/yes/yes/ui/BuildBox.java b/src/main/java/com/yes/yes/ui/BuildBox.java index 43fb374..26ff844 100644 --- a/src/main/java/com/yes/yes/ui/BuildBox.java +++ b/src/main/java/com/yes/yes/ui/BuildBox.java @@ -1,11 +1,22 @@ package com.yes.yes.ui; +import com.yes.yes.utils.EntityRegistry; import javafx.application.Platform; import javafx.scene.control.ScrollPane; import javafx.scene.layout.HBox; -public class BuildBox - extends javafx.scene.Group { +import java.util.function.Function; + +public class BuildBox extends javafx.scene.Group { + String selectedEntity; + + + Function changeItem = i -> { + System.out.println(i); + this.selectedEntity = i; + return null; + }; + public BuildBox() { ScrollPane pane = new ScrollPane(); HBox hbox = new HBox(); @@ -17,14 +28,14 @@ public class BuildBox this.getChildren().add(pane); - Platform.runLater(() -> - { - pane.prefWidthProperty() - .bind(this.getScene() - .getWindow() - .widthProperty()); - } - ); + this.setViewOrder(-1); + + Platform.runLater(() -> pane.prefWidthProperty().bind(this.getScene().getWindow().widthProperty())); + + EntityRegistry.getKeys().forEach(e -> hbox.getChildren().add(new BuildItem(e, changeItem))); } + public String getSelectedEntity() { + return selectedEntity; + } } diff --git a/src/main/java/com/yes/yes/ui/BuildItem.java b/src/main/java/com/yes/yes/ui/BuildItem.java new file mode 100644 index 0000000..cac851b --- /dev/null +++ b/src/main/java/com/yes/yes/ui/BuildItem.java @@ -0,0 +1,38 @@ +package com.yes.yes.ui; + +import com.yes.yes.utils.EntityRegistry; +import com.yes.yes.world.Chunk; +import javafx.scene.Node; +import javafx.scene.control.Button; + +import java.util.function.Function; + +public class BuildItem extends javafx.scene.layout.StackPane { + String display_name; + String name; + Class entity; + + public BuildItem(String name, Function onClick) { + super(); + + this.display_name = EntityRegistry.getEntity(name).getDisplayName(); + this.entity = EntityRegistry.getEntity(name).getEntity(); + this.name = name; + + this.prefWidth(Chunk.ENTITY_SIZE); + this.prefHeight(Chunk.ENTITY_SIZE+10); + + try { + this.getChildren().add((Node)entity.getConstructor().newInstance()); + } catch (Exception ignored){} + + Button button = new Button(); + + button.setStyle("-fx-background-color: null; -fx-border-color: null"); + button.setPrefSize(Chunk.ENTITY_SIZE,Chunk.ENTITY_SIZE); + button.setMinSize(Chunk.ENTITY_SIZE,Chunk.ENTITY_SIZE); + button.setOnAction((e)-> onClick.apply(this.name)); + + this.getChildren().add(button); + } +}