Răsfoiți Sursa

Added inventory item icons

Ondřej Schlaichert 8 luni în urmă
părinte
comite
46aff24f28

+ 43 - 17
src/main/java/eu/oschl/gui/GameController.java

@@ -171,7 +171,7 @@ public class GameController implements Observer {
             var label = item.getName();
             var label = item.getName();
             var buttonData = new ButtonData("useitem", 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");
             button.getStyleClass().add("inventory-item");
 
 
             newItems.add(button);
             newItems.add(button);
@@ -180,7 +180,7 @@ public class GameController implements Observer {
         if (Session.getGame().getInventory().getWeapon().isPresent()) {
         if (Session.getGame().getInventory().getWeapon().isPresent()) {
             var weapon = Session.getGame().getInventory().getWeapon().get();
             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("inventory-item");
             button.getStyleClass().add("weapon");
             button.getStyleClass().add("weapon");
             button.setDisable(true);
             button.setDisable(true);
@@ -191,20 +191,28 @@ public class GameController implements Observer {
         inventoryContainer.getChildren().addAll(newItems);
         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);
         Button actionButton = new Button(label);
 
 
         actionButton.setUserData(buttonData);
         actionButton.setUserData(buttonData);
@@ -214,12 +222,30 @@ public class GameController implements Observer {
         return actionButton;
         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);
     }
     }
 }
 }

+ 14 - 7
src/main/java/eu/oschl/schmorn/Setup.java

@@ -295,7 +295,8 @@ class Setup {
                 "ratsword",
                 "ratsword",
                 "a steel sword, expertly crafted by the Swordsmith Rat",
                 "a steel sword, expertly crafted by the Swordsmith Rat",
                 "Schmorn attacks with the ratsword.",
                 "Schmorn attacks with the ratsword.",
-                10
+                10,
+                "images/items/ratsword.png"
         );
         );
         swordsmithRatsLair.addObject(sword);
         swordsmithRatsLair.addObject(sword);
 
 
@@ -304,7 +305,8 @@ class Setup {
                 "a huge, menacing key, made out of black iron",
                 "a huge, menacing key, made out of black iron",
                 "Schmorn used the key to unlock the dark passage.",
                 "Schmorn used the key to unlock the dark passage.",
                 new Room[]{crossroads},
                 new Room[]{crossroads},
-                crossroadsDarkEntrancePassageBlockage
+                crossroadsDarkEntrancePassageBlockage,
+                "images/items/dark_key.png"
         );
         );
         guardRoom.addObject(darkKey);
         guardRoom.addObject(darkKey);
 
 
@@ -313,7 +315,8 @@ class Setup {
                 "a small, golden, delicate key",
                 "a small, golden, delicate key",
                 "Schmorn used the key to unlock the kitchen door.",
                 "Schmorn used the key to unlock the kitchen door.",
                 new Room[]{crossroads},
                 new Room[]{crossroads},
-                crossroadsRoyalKitchensEntrancePassageBlockage
+                crossroadsRoyalKitchensEntrancePassageBlockage,
+                "images/items/kitchen_key.png"
         );
         );
         shadowChamber.addObject(kitchenKey);
         shadowChamber.addObject(kitchenKey);
 
 
@@ -322,7 +325,8 @@ class Setup {
                 "a mysteriously shaped stone that is so cold it hurts to touch",
                 "a mysteriously shaped stone that is so cold it hurts to touch",
                 "Schmorn inserted the stone into the lift panel.",
                 "Schmorn inserted the stone into the lift panel.",
                 new Room[]{crossroads},
                 new Room[]{crossroads},
-                crossroadsDungeonExitPassageBlockage
+                crossroadsDungeonExitPassageBlockage,
+                "images/items/frozen_stone.png"
         );
         );
         prisonsEnd.addObject(frozenStone);
         prisonsEnd.addObject(frozenStone);
 
 
@@ -331,7 +335,8 @@ class Setup {
                 "a blood-red stone, always wet with fresh blood, which cannot be washed off",
                 "a blood-red stone, always wet with fresh blood, which cannot be washed off",
                 "Schmorn inserted the stone into the lift panel.",
                 "Schmorn inserted the stone into the lift panel.",
                 new Room[]{crossroads},
                 new Room[]{crossroads},
-                crossroadsDungeonExitPassageBlockage
+                crossroadsDungeonExitPassageBlockage,
+                "images/items/blood_stone.png"
         );
         );
         pathwaysEnd.addObject(bloodStone);
         pathwaysEnd.addObject(bloodStone);
 
 
@@ -340,7 +345,8 @@ class Setup {
                 "a mysteriously shaped stone that is so hot it's almost impossible to carry",
                 "a mysteriously shaped stone that is so hot it's almost impossible to carry",
                 "Schmorn inserted the stone into the lift panel.",
                 "Schmorn inserted the stone into the lift panel.",
                 new Room[]{crossroads},
                 new Room[]{crossroads},
-                crossroadsDungeonExitPassageBlockage
+                crossroadsDungeonExitPassageBlockage,
+                "images/items/fire_stone.png"
         );
         );
         kitchensEnd.addObject(fireStone);
         kitchensEnd.addObject(fireStone);
 
 
@@ -348,7 +354,8 @@ class Setup {
                 "unbreakable ladle",
                 "unbreakable ladle",
                 "a mighty weapon, the most prized possession of the Head Chef, stronger than any sword",
                 "a mighty weapon, the most prized possession of the Head Chef, stronger than any sword",
                 "Schmorn performs a powerful attack with the mighy Unbreakable Ladle.",
                 "Schmorn performs a powerful attack with the mighy Unbreakable Ladle.",
-                20
+                20,
+                "images/items/unbreakable_ladle.png"
         );
         );
         royalKitchensEntrance.addObject(unbreakableLadle);
         royalKitchensEntrance.addObject(unbreakableLadle);
 
 

+ 7 - 0
src/main/java/eu/oschl/textadventure/objects/InventoryItem.java

@@ -15,6 +15,13 @@ public class InventoryItem extends PickableObject {
     private final Room[] canBeUsedIn;
     private final Room[] canBeUsedIn;
     private final Blockage interactsWith;
     private final Blockage interactsWith;
 
 
+    public InventoryItem(String name, String description, String useText, Room[] canBeUsedIn, Blockage interactsWith, String iconImagePath) {
+        super(name, description, iconImagePath);
+        this.useText = useText;
+        this.canBeUsedIn = canBeUsedIn;
+        this.interactsWith = interactsWith;
+    }
+
     public InventoryItem(String name, String description, String useText, Room[] canBeUsedIn, Blockage interactsWith) {
     public InventoryItem(String name, String description, String useText, Room[] canBeUsedIn, Blockage interactsWith) {
         super(name, description);
         super(name, description);
         this.useText = useText;
         this.useText = useText;

+ 16 - 0
src/main/java/eu/oschl/textadventure/objects/PickableObject.java

@@ -1,5 +1,7 @@
 package eu.oschl.textadventure.objects;
 package eu.oschl.textadventure.objects;
 
 
+import java.util.Optional;
+
 /**
 /**
  * Represents an object in the game that can be picked up by the player.
  * Represents an object in the game that can be picked up by the player.
  * This class serves as a base for all pickable objects, providing common properties and methods.
  * This class serves as a base for all pickable objects, providing common properties and methods.
@@ -7,8 +9,22 @@ package eu.oschl.textadventure.objects;
  * @author Ondřej Schlaichert
  * @author Ondřej Schlaichert
  */
  */
 public abstract class PickableObject extends GameObject {
 public abstract class PickableObject extends GameObject {
+    private final String iconImagePath;
+
+    public PickableObject(String name, String description, String iconImagePath) {
+        super(name, description);
+
+        this.iconImagePath = iconImagePath;
+    }
+
     public PickableObject(String name, String description) {
     public PickableObject(String name, String description) {
         super(name, description);
         super(name, description);
+
+        this.iconImagePath = null;
+    }
+
+    public Optional<String> getIconImagePath() {
+        return Optional.ofNullable(iconImagePath);
     }
     }
 
 
     /**
     /**

+ 6 - 0
src/main/java/eu/oschl/textadventure/objects/Weapon.java

@@ -9,6 +9,12 @@ public class Weapon extends PickableObject {
     public final String attackText;
     public final String attackText;
     public final int damage;
     public final int damage;
 
 
+    public Weapon(String name, String description, String attackText, int damage, String iconImagePath) {
+        super(name, description, iconImagePath);
+        this.attackText = attackText;
+        this.damage = damage;
+    }
+
     public Weapon(String name, String description, String attackText, int damage) {
     public Weapon(String name, String description, String attackText, int damage) {
         super(name, description);
         super(name, description);
         this.attackText = attackText;
         this.attackText = attackText;

BIN
src/main/resources/eu/oschl/gui/images/items/blood_stone.png


BIN
src/main/resources/eu/oschl/gui/images/items/dark_key.png


BIN
src/main/resources/eu/oschl/gui/images/items/fire_stone.png


BIN
src/main/resources/eu/oschl/gui/images/items/frozen_stone.png


BIN
src/main/resources/eu/oschl/gui/images/items/kitchen_key.png


BIN
src/main/resources/eu/oschl/gui/images/items/ratsword.png


BIN
src/main/resources/eu/oschl/gui/images/items/unbreakable_ladle.png