mirror of
https://github.com/Stefan-5422/School-Programming-Projekt-022022.git
synced 2026-09-04 00:46:01 +02:00
Add build ui;
Fixed naming mistake in MainController
This commit is contained in:
@@ -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();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String, Void> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String,Void> 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user