Skip to content

Commit

Permalink
add 1.12
Browse files Browse the repository at this point in the history
add config
  • Loading branch information
Leg0shii committed Apr 29, 2023
1 parent d605ad6 commit 31084e7
Show file tree
Hide file tree
Showing 75 changed files with 2,373 additions and 444 deletions.
53 changes: 41 additions & 12 deletions src/main/java/de/legoshi/parkourcalculator/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package de.legoshi.parkourcalculator;

import de.legoshi.parkourcalculator.gui.BlockGUI;
import de.legoshi.parkourcalculator.gui.MenuGUI;
import de.legoshi.parkourcalculator.gui.debug.menu.ScreenSettings;
import de.legoshi.parkourcalculator.gui.menu.ConfigGUI;
import de.legoshi.parkourcalculator.gui.menu.ConfigProperties;
import de.legoshi.parkourcalculator.gui.menu.MenuGUI;
import de.legoshi.parkourcalculator.gui.debug.CoordinateScreen;
import de.legoshi.parkourcalculator.gui.InputTickGUI;
import de.legoshi.parkourcalculator.gui.MinecraftGUI;
Expand All @@ -13,10 +16,7 @@
import de.legoshi.parkourcalculator.simulation.Parkour_1_12;
import de.legoshi.parkourcalculator.simulation.Parkour_1_8;
import de.legoshi.parkourcalculator.util.PositionVisualizer;
import de.legoshi.parkourcalculator.simulation.environment.blockmanager.BlockManager_1_8;
import de.legoshi.parkourcalculator.simulation.movement.Movement_1_8;
import de.legoshi.parkourcalculator.simulation.tick.InputTickManager;
import de.legoshi.parkourcalculator.util.ConfigReader;
import javafx.beans.binding.NumberBinding;
import javafx.geometry.Rectangle2D;
import javafx.scene.Group;
Expand All @@ -34,12 +34,11 @@ public class Application extends javafx.application.Application {
public Scene scene;
public BorderPane window;

public ConfigReader configReader;

public DebugUI debugUI;
public InputTickGUI inputTickGUI;
public BlockGUI blockGUI;
public MenuGUI menuGUI;
public ConfigGUI configGUI;
public MinecraftGUI minecraftGUI;
public SubScene minecraftSubScene;
public CoordinateScreen coordinateScreen;
Expand All @@ -64,10 +63,10 @@ public void start(Stage stage) {
this.scene = new Scene(window, 1400, 1000, true);
this.scene.getStylesheets().add(Application.class.getResource("darkmode.css").toExternalForm());

this.configReader = new ConfigReader();
this.configGUI = new ConfigGUI(this);

// different parkour versions
this.parkourVersion = ParkourVersion.valueOf(configReader.getProperty("parkourVersion"));
this.parkourVersion = configGUI.getConfigProperties().getVersion();
applyParkour(parkourVersion);

// load the input manager and the UI
Expand All @@ -80,7 +79,7 @@ public void start(Stage stage) {
this.positionVisualizer = new PositionVisualizer(pathGroup, currentParkour, inputTickManager);

// load and register block gui
this.blockGUI = new BlockGUI();
this.blockGUI = new BlockGUI(currentParkour);
this.window.setBottom(blockGUI);

// load the menu bar
Expand All @@ -89,6 +88,7 @@ public void start(Stage stage) {

// load coordinate-screen and the menu-accordion
this.informationScreen = new InformationScreen();
this.informationScreen.updateVersionLabel(parkourVersion.toString());
this.coordinateScreen = new CoordinateScreen(currentParkour);
this.menuScreen = new MenuScreen(this, getMenuOffset(scene));
this.debugUI = new DebugUI(informationScreen, coordinateScreen, menuScreen);
Expand All @@ -107,6 +107,8 @@ public void start(Stage stage) {
this.positionVisualizer.addObserver(coordinateScreen);
this.positionVisualizer.generatePlayerPath();

updateConfigValues(configGUI.getConfigProperties());

stage.setTitle(APP_NAME);
stage.setScene(scene);
stage.show();
Expand All @@ -125,15 +127,42 @@ public static void main(String[] args) {
launch();
}

public void updateConfigValues(ConfigProperties configProperties) {
ScreenSettings.precision = configProperties.getCoordinatePrecision();
minecraftGUI.getController().updateConfigValues(configProperties);
coordinateScreen.updateConfigValues();
minecraftGUI.updateConfigValues(configProperties);

ScreenSettings.getCoordinatePrecTF().setText(configProperties.getCoordinatePrecision() + "");
ScreenSettings.getPreviewBlockCB().setSelected(configProperties.isPreviewBlock());
ScreenSettings.getPathCollisionCB().setSelected(configProperties.isPathCollision());
ScreenSettings.getRealVelCB().setSelected(configProperties.isRealVelocity());

if (configProperties.isRealVelocity()) coordinateScreen.update();

ParkourVersion version = configProperties.getVersion();
menuScreen.versionSettings.getVersionComboBox().setValue(version.toString());
applyParkour(version);
}

public void applyParkour(ParkourVersion parkourVersion) {
switch (parkourVersion) {
case V_1_8 -> currentParkour = parkour_1_8 == null ? new Parkour_1_8() : parkour_1_8;
default -> currentParkour = parkour_1_12 == null ? new Parkour_1_12() : parkour_1_12;
case V_1_8 -> {
currentParkour = parkour_1_8 == null ? new Parkour_1_8() : parkour_1_8;
parkour_1_8 = (Parkour_1_8) currentParkour;
}
default -> {
currentParkour = parkour_1_12 == null ? new Parkour_1_12() : parkour_1_12;
parkour_1_12 = (Parkour_1_12) currentParkour;
}
}
if (positionVisualizer != null) this.positionVisualizer.apply(currentParkour);
if (coordinateScreen != null) this.coordinateScreen.apply(currentParkour);
if (menuScreen != null) this.menuScreen.apply(currentParkour);
if (menuGUI != null) this.menuGUI.apply(currentParkour);
if (blockGUI != null) this.blockGUI.apply(currentParkour);
if (minecraftGUI != null) this.minecraftGUI.apply(currentParkour);
if (positionVisualizer != null) this.positionVisualizer.apply(currentParkour);
if (informationScreen != null) informationScreen.updateVersionLabel(parkourVersion.toString());
this.parkourVersion = parkourVersion;
}

Expand Down
27 changes: 16 additions & 11 deletions src/main/java/de/legoshi/parkourcalculator/gui/BlockGUI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.legoshi.parkourcalculator.gui;

import de.legoshi.parkourcalculator.simulation.Parkour;
import de.legoshi.parkourcalculator.simulation.environment.blockmanager.BlockManager;
import de.legoshi.parkourcalculator.simulation.environment.blockmanager.BlockManager_1_8;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
Expand All @@ -14,25 +16,28 @@

public class BlockGUI extends ScrollPane {

private AnchorPane anchorPane;
private HBox hBox;

private BlockManager blockManager;
private final HBox hBox;
private StackPane selectedPane;

public BlockGUI() {
public BlockGUI(Parkour parkour) {
BorderPane.setAlignment(this, Pos.CENTER);
setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);

hBox = new HBox();
hBox.setAlignment(Pos.CENTER);
hBox.setSpacing(5.0);
hBox.setPadding(new Insets(8, 8, 20, 8));

anchorPane = new AnchorPane(hBox);
setContent(anchorPane);

setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
setContent(new AnchorPane(hBox));
apply(parkour);
}

public void apply(Parkour parkour) {
this.blockManager = parkour.getBlockManager();
hBox.getChildren().clear();
registerBlocks();
System.out.println("BlockGUI applied");
}

private void registerBlocks() {
Expand All @@ -44,7 +49,7 @@ private void registerBlocks() {
clickEffect.setColor(Color.GRAY);
clickEffect.setRadius(20.0);

BlockManager_1_8.registeredBlocks.forEach(block -> {
blockManager.registeredBlocks.forEach(block -> {
StackPane stackPane = new StackPane();
ImageView imageView = new ImageView(block.image);
stackPane.getChildren().add(imageView);
Expand All @@ -55,13 +60,13 @@ private void registerBlocks() {
selectedPane = stackPane;

stackPane.setEffect(clickEffect);
BlockManager_1_8.updateCurrentBlock(block);
blockManager.updateCurrentBlock(block);
});

stackPane.setOnMouseEntered(event -> stackPane.setEffect(hoverEffect));
stackPane.setOnMouseExited(event -> stackPane.setEffect(selectedPane == stackPane ? clickEffect : null));

if (BlockManager_1_8.currentBlock.getClass().getSimpleName().equals(block.getClass().getSimpleName())) {
if (blockManager.currentBlock.getClass().getSimpleName().equals(block.getClass().getSimpleName())) {
selectedPane = stackPane;
stackPane.setEffect(clickEffect);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

import java.util.ArrayList;

public class EditPlayerGUI extends GridPane {

private Stage stage;
Expand Down Expand Up @@ -112,15 +114,6 @@ private void registerBruteForceButton() {
int yLoc = Integer.parseInt(pos[1]);
int zLoc = Integer.parseInt(pos[2]);
ABlock aBlock = null;
for (ABlock block : BlockManager_1_8.aBlocks) {
for (AxisVecTuple axisVecTuple : block.getAxisVecTuples()) {
if (xLoc <= axisVecTuple.getBb().maxX && xLoc - 1 >= axisVecTuple.getBb().minX &&
yLoc <= axisVecTuple.getBb().maxY && yLoc - 1 >= axisVecTuple.getBb().minY &&
zLoc <= axisVecTuple.getBb().maxZ && zLoc - 1 >= axisVecTuple.getBb().minZ) {
aBlock = block;
}
}
}

if (aBlock == null) return;

Expand Down
88 changes: 58 additions & 30 deletions src/main/java/de/legoshi/parkourcalculator/gui/MinecraftGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@
import de.legoshi.parkourcalculator.Application;
import de.legoshi.parkourcalculator.gui.debug.InformationScreen;
import de.legoshi.parkourcalculator.gui.debug.menu.ScreenSettings;
import de.legoshi.parkourcalculator.gui.menu.ConfigProperties;
import de.legoshi.parkourcalculator.simulation.Parkour;
import de.legoshi.parkourcalculator.simulation.environment.BlockFactory;
import de.legoshi.parkourcalculator.simulation.environment.blockmanager.BlockManager_1_8;
import de.legoshi.parkourcalculator.simulation.environment.blockmanager.BlockManager;
import de.legoshi.parkourcalculator.simulation.environment.Facing;
import de.legoshi.parkourcalculator.simulation.environment.block.ABlock;
import de.legoshi.parkourcalculator.simulation.environment.block.Air;
import de.legoshi.parkourcalculator.simulation.environment.block.StandardBlock;
import de.legoshi.parkourcalculator.util.ConfigReader;
import de.legoshi.parkourcalculator.util.NumberHelper;
import de.legoshi.parkourcalculator.util.Vec3;
import de.legoshi.parkourcalculator.util.fxyz.AdvancedCamera;
import de.legoshi.parkourcalculator.util.fxyz.FPSController;
import javafx.geometry.Bounds;
import javafx.scene.*;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Box;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

Expand All @@ -33,44 +37,71 @@ public class MinecraftGUI extends Observable {

public static final Vec3 BLOCK_POSITION = new Vec3(1, 0, 0);

private final ConfigReader configReader;
private final ConfigProperties configProperties;
private final Application application;
private BlockManager blockManager;

private final BorderPane window;
private final SubScene subScene;
private final Group group;

private ArrayList<Box> previewBlockBoxes = new ArrayList<>();
private final ArrayList<Observer> observers = new ArrayList<>();
@Getter private FPSController controller;

private List<Box> previewBlockBoxes = new ArrayList<>();
private final List<Observer> observers = new ArrayList<>();

private MouseButton addBlock, destroyBlock;

public MinecraftGUI(Application application, Group group) {
this.application = application;
this.configReader = application.configReader;
this.configProperties = application.configGUI.getConfigProperties();
this.blockManager = application.currentParkour.getBlockManager();

this.group = group;
this.group.setDepthTest(DepthTest.ENABLE);

this.subScene = application.minecraftSubScene;
this.window = application.window;
BorderPane window = application.window;

this.subScene.heightProperty().bind(window.heightProperty().subtract(application.menuGUI.heightProperty()).subtract(application.blockGUI.heightProperty()));
this.subScene.widthProperty().bind(window.widthProperty().subtract(application.inputTickGUI.widthProperty()).subtract(application.coordinateScreen.widthProperty()));

addObserver(application.currentParkour.getBlockManager());
apply(application.currentParkour);
addObserver(application.coordinateScreen);
addObserver(application.positionVisualizer);
addObserver(application.informationScreen);

application.menuGUI.setMinecraftGUI(this);

application.minecraftSubScene.setOnMouseMoved(this::handleBackgroundMouseMove);

addStartingBlock();
registerCamera();
}

public void updateConfigValues(ConfigProperties configProperties) {
addBlock = MouseButton.valueOf(configProperties.getPlaceBlock());
destroyBlock = MouseButton.valueOf(configProperties.getDestroyBlock());
}

public void apply(Parkour parkour) {
group.getChildren().removeIf(node -> !(node instanceof Group));

observers.remove(blockManager);
this.observers.add(0, parkour.getBlockManager());

this.blockManager = parkour.getBlockManager();
this.previewBlockBoxes = new ArrayList<>();

if (blockManager.aBlocks.isEmpty()) {
addStartingBlock();
return;
}

List<ABlock> aBlocksCopy = new ArrayList<>(blockManager.aBlocks);
aBlocksCopy.forEach(this::addBlock);
blockManager.aBlocks = aBlocksCopy;
}

public void addStartingBlock() {
addBlock(new StandardBlock(BLOCK_POSITION));
addBlock(new StandardBlock(BLOCK_POSITION.copy()));
}

public void resetScreen() {
Expand All @@ -81,21 +112,18 @@ public void resetScreen() {
public void handleMouseClick(MouseEvent mouseEvent) {
if (!(mouseEvent.getTarget() instanceof Box)) return;
mouseEvent.consume();
switch (mouseEvent.getButton()) {
case PRIMARY -> {
Vec3 newBlockPos = getRoundedCoordinatesFromMouseEvent(mouseEvent);
if(newBlockPos != null) {
newBlockPos.x *= -1; // flipping the x axis ??
ABlock curBlock = BlockManager_1_8.getBlock(newBlockPos.x, newBlockPos.y, newBlockPos.z);
if (!(curBlock instanceof Air)) return;
}
ABlock newBlock = getNewBlockFromPos(mouseEvent);
if (newBlock != null) addBlock(newBlock);
}
case SECONDARY -> {
ABlock block = getExistingBlockFromPos(mouseEvent);
if (block != null) removeBlock(block);
if (mouseEvent.getButton().equals(addBlock)) {
Vec3 newBlockPos = getRoundedCoordinatesFromMouseEvent(mouseEvent);
if(newBlockPos != null) {
newBlockPos.x *= -1; // flipping the x axis
ABlock curBlock = blockManager.getBlock(newBlockPos.x, newBlockPos.y, newBlockPos.z);
if (!(curBlock instanceof Air)) return;
}
ABlock newBlock = getNewBlockFromPos(mouseEvent);
if (newBlock != null) addBlock(newBlock);
} else if(mouseEvent.getButton().equals(destroyBlock)) {
ABlock block = getExistingBlockFromPos(mouseEvent);
if (block != null) removeBlock(block);
}
}

Expand Down Expand Up @@ -178,11 +206,11 @@ private ABlock getNewBlockFromPos(MouseEvent mouseEvent) {
Vec3 vec3Rounded = getRoundedCoordinatesFromMouseEvent(mouseEvent);
if (vec3Rounded == null) return null;

return BlockFactory.createBlock(vec3Rounded, BlockManager_1_8.currentBlock.getClass().getSimpleName());
return BlockFactory.createBlock(vec3Rounded, blockManager.currentBlock.getClass().getSimpleName());
}

private ABlock getExistingBlockFromPos(MouseEvent mouseEvent) {
for (ABlock aBlock : BlockManager_1_8.aBlocks) {
for (ABlock aBlock : blockManager.aBlocks) {
Box box = (Box) mouseEvent.getTarget();
if (aBlock.getBoxesArrayList().contains(box)) {
return aBlock;
Expand Down Expand Up @@ -227,7 +255,7 @@ public void removeBlock(ABlock aBlock) {

private void registerCamera() {
AdvancedCamera camera = new AdvancedCamera();
FPSController controller = new FPSController(configReader);
this.controller = new FPSController(configProperties);
controller.setScene(application.scene);

camera.setController(controller);
Expand All @@ -247,7 +275,7 @@ private void registerCamera() {

public void clearScreen() {
group.getChildren().removeIf(node -> !(node instanceof Group)); // remove all blocks, keep path group
BlockManager_1_8.aBlocks = new ArrayList<>();
blockManager.aBlocks = new ArrayList<>();
}

public void addObserver(Observer observer) {
Expand Down
Loading

0 comments on commit 31084e7

Please sign in to comment.