|
|
@@ -171,7 +171,7 @@ public class GameController implements Observer {
|
|
|
var label = item.getName();
|
|
|
var buttonData = new ButtonData("useitem", item.getName());
|
|
|
|
|
|
- var button = createActionButton(label, buttonData);
|
|
|
+ var button = createInventoryButton(label, buttonData, item.getIconImagePath().orElse(null));
|
|
|
button.getStyleClass().add("inventory-item");
|
|
|
|
|
|
newItems.add(button);
|
|
|
@@ -180,7 +180,7 @@ public class GameController implements Observer {
|
|
|
if (Session.getGame().getInventory().getWeapon().isPresent()) {
|
|
|
var weapon = Session.getGame().getInventory().getWeapon().get();
|
|
|
|
|
|
- var button = createActionButton(weapon.getName(), new ButtonData(""));
|
|
|
+ var button = createInventoryButton(weapon.getName(), new ButtonData(""), weapon.getIconImagePath().orElse(null));
|
|
|
button.getStyleClass().add("inventory-item");
|
|
|
button.getStyleClass().add("weapon");
|
|
|
button.setDisable(true);
|
|
|
@@ -191,20 +191,28 @@ public class GameController implements Observer {
|
|
|
inventoryContainer.getChildren().addAll(newItems);
|
|
|
}
|
|
|
|
|
|
- private void renderMapImage() {
|
|
|
- var room = Session.getGame().getCurrentRoom();
|
|
|
+ private void finishGame() {
|
|
|
+ inputButtonContainer.getChildren().clear();
|
|
|
+ inventoryContainer.getChildren().clear();
|
|
|
|
|
|
- if (room.getMapImagePath().isEmpty()) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ Output.printLine();
|
|
|
+ Output.printLine();
|
|
|
+ Output.print(Session.getGame().getEpilogue());
|
|
|
+ }
|
|
|
|
|
|
- var imageResource = Objects.requireNonNull(getClass().getResource(room.getMapImagePath().get())).toExternalForm();
|
|
|
- var image = new Image(imageResource);
|
|
|
+ private void renderMapImage() {
|
|
|
+ var room = Session.getGame().getCurrentRoom();
|
|
|
|
|
|
- mapContainer.setImage(image);
|
|
|
+ if (room.getMapImagePath().isEmpty()) {
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- private Button createActionButton(String label, ButtonData buttonData) {
|
|
|
+ var image = loadImage(room.getMapImagePath().get());
|
|
|
+
|
|
|
+ mapContainer.setImage(image);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Button createActionButton(String label, ButtonData buttonData) {
|
|
|
Button actionButton = new Button(label);
|
|
|
|
|
|
actionButton.setUserData(buttonData);
|
|
|
@@ -214,12 +222,30 @@ public class GameController implements Observer {
|
|
|
return actionButton;
|
|
|
}
|
|
|
|
|
|
- private void finishGame() {
|
|
|
- inputButtonContainer.getChildren().clear();
|
|
|
- inventoryContainer.getChildren().clear();
|
|
|
+ private Button createInventoryButton(String label, ButtonData buttonData, String imagePath) {
|
|
|
+ Button inventoryButton = new Button(label);
|
|
|
|
|
|
- Output.printLine();
|
|
|
- Output.printLine();
|
|
|
- Output.print(Session.getGame().getEpilogue());
|
|
|
+ inventoryButton.setUserData(buttonData);
|
|
|
+ inventoryButton.setOnAction(this::exectuteAction);
|
|
|
+ inventoryButton.setMaxWidth(Double.MAX_VALUE);
|
|
|
+
|
|
|
+ if (imagePath != null) {
|
|
|
+ var image = loadImage(imagePath);
|
|
|
+
|
|
|
+ ImageView icon = new ImageView(image);
|
|
|
+
|
|
|
+ icon.setFitWidth(24);
|
|
|
+ icon.setFitHeight(24);
|
|
|
+ icon.setPreserveRatio(true);
|
|
|
+
|
|
|
+ inventoryButton.setGraphic(icon);
|
|
|
+ }
|
|
|
+
|
|
|
+ return inventoryButton;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Image loadImage(String imagePath) {
|
|
|
+ var imageResource = Objects.requireNonNull(getClass().getResource(imagePath)).toExternalForm();
|
|
|
+ return new Image(imageResource);
|
|
|
}
|
|
|
}
|