mirror of
https://github.com/Stefan-5422/School-Programming-Projekt-022022.git
synced 2026-09-04 08:56:01 +02:00
Add build ui;
Fixed naming mistake in MainController
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
package com.yes.yes;
|
package com.yes.yes;
|
||||||
|
|
||||||
import com.yes.yes.managers.GameManager;
|
import com.yes.yes.managers.*;
|
||||||
import com.yes.yes.managers.PlayerManager;
|
|
||||||
import com.yes.yes.utils.Coordinate;
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
@@ -14,11 +12,14 @@ public class MainController {
|
|||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
GameManager gameManager = new GameManager(root);
|
GameManager gameManager = new GameManager(root);
|
||||||
gameManager.setup();
|
gameManager.initialize();
|
||||||
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
PlayerManager playerManager = new PlayerManager(gameManager.getWorld());
|
UiManager uiManager = new UiManager(root);
|
||||||
playerManager.setup();
|
uiManager.initialize();
|
||||||
|
|
||||||
|
PlayerManager playerManager = new PlayerManager(gameManager.getWorld(), uiManager.getBuildBox());
|
||||||
|
playerManager.initialize();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ public class UiManager {
|
|||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
buildBox = new BuildBox();
|
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;
|
package com.yes.yes.ui;
|
||||||
|
|
||||||
|
import com.yes.yes.utils.EntityRegistry;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.scene.control.ScrollPane;
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
|
|
||||||
public class BuildBox
|
import java.util.function.Function;
|
||||||
extends javafx.scene.Group {
|
|
||||||
|
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() {
|
public BuildBox() {
|
||||||
ScrollPane pane = new ScrollPane();
|
ScrollPane pane = new ScrollPane();
|
||||||
HBox hbox = new HBox();
|
HBox hbox = new HBox();
|
||||||
@@ -17,14 +28,14 @@ public class BuildBox
|
|||||||
|
|
||||||
this.getChildren().add(pane);
|
this.getChildren().add(pane);
|
||||||
|
|
||||||
Platform.runLater(() ->
|
this.setViewOrder(-1);
|
||||||
{
|
|
||||||
pane.prefWidthProperty()
|
Platform.runLater(() -> pane.prefWidthProperty().bind(this.getScene().getWindow().widthProperty()));
|
||||||
.bind(this.getScene()
|
|
||||||
.getWindow()
|
EntityRegistry.getKeys().forEach(e -> hbox.getChildren().add(new BuildItem(e, changeItem)));
|
||||||
.widthProperty());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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