|
|
@@ -1,23 +1,23 @@
|
|
|
package view;
|
|
|
|
|
|
import model.Inventory;
|
|
|
+import util.TextUtil;
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
public class InventoryView {
|
|
|
private GamePanel gp;
|
|
|
private int inventoryHeight, inventoryWidth, inventoryY, inventoryX;
|
|
|
-
|
|
|
-
|
|
|
+ int overlayX = 20;
|
|
|
+ int overlayY = 20;
|
|
|
+ int slotSize = 48;
|
|
|
+ int slotSpacing = 8;
|
|
|
+ int slotCount = 0;
|
|
|
public InventoryView(GamePanel gamePanel){
|
|
|
this.gp = gamePanel;
|
|
|
}
|
|
|
public void drawInventoryOverlay(Graphics2D g2) {
|
|
|
- int overlayX = 20;
|
|
|
- int overlayY = 20;
|
|
|
- int slotSize = 48;
|
|
|
- int slotSpacing = 8;
|
|
|
- int slotCount = gp.inventory.getUniqueItemsCount(); // Change as needed
|
|
|
+ slotCount = gp.inventory.getUniqueItemsCount();
|
|
|
|
|
|
int overlayWidth = slotSize + 2* slotSpacing;
|
|
|
int overlayHeight = (slotSize + slotSpacing) * slotCount + slotSpacing;
|
|
|
@@ -27,21 +27,41 @@ public class InventoryView {
|
|
|
g2.fillRoundRect(overlayX, overlayY, overlayWidth, overlayHeight, 15, 15);
|
|
|
|
|
|
// Draw slots
|
|
|
- g2.setColor(Color.LIGHT_GRAY);
|
|
|
for (int i = 0; i < slotCount; i++) {
|
|
|
-
|
|
|
+ if(gp.inventory.getItemList().get(i).isSelected()){
|
|
|
+ g2.setColor(Color.CYAN);
|
|
|
+ }else{
|
|
|
+ g2.setColor(Color.LIGHT_GRAY);
|
|
|
+ }
|
|
|
int x = overlayX + slotSpacing;
|
|
|
int y = overlayY + slotSpacing + i * (slotSize + slotSpacing);
|
|
|
g2.fillRoundRect(x, y, slotSize, slotSize, 10, 10);
|
|
|
|
|
|
- // Optional: draw slot index or placeholder icon
|
|
|
g2.setColor(Color.DARK_GRAY);
|
|
|
- g2.setFont(new Font("Arial", Font.PLAIN, 14));
|
|
|
- g2.drawString("Slot " + (i + 1), x + 5, y + slotSize / 2 + 5);
|
|
|
+
|
|
|
+ String itemName = gp.inventory.getItemList().get(i).getItemName().toString();
|
|
|
+
|
|
|
+ TextUtil.setFontAppropriateToSize(itemName, slotSize - slotSpacing/2, g2);
|
|
|
+
|
|
|
+ g2.drawString(itemName, x + slotSpacing/4, y + slotSize / 2 + 5);
|
|
|
+ g2.drawString( "" + gp.inventory.getItemList().get(i).getCount() , x + slotSize - slotSize/5, y + slotSize -2);
|
|
|
|
|
|
g2.setColor(Color.LIGHT_GRAY); // reset color for next slot
|
|
|
}
|
|
|
}
|
|
|
+ public int getClickedInventorySlot(int mouseX, int mouseY) {
|
|
|
+ for (int i = 0; i < slotCount; i++) {
|
|
|
+ int x = overlayX + slotSpacing;
|
|
|
+ int y = overlayY + slotSpacing + i * (slotSize + slotSpacing);
|
|
|
+ int width = slotSize;
|
|
|
+ int height = slotSize;
|
|
|
+
|
|
|
+ if (mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height) {
|
|
|
+ return i; // Slot i was clicked
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return -1; // No slot was clicked
|
|
|
+ }
|
|
|
public int getInventoryHeight() {
|
|
|
return inventoryHeight;
|
|
|
}
|