added stackable functionality to items and improved inventory management

This commit is contained in:
2025-12-13 12:13:01 +01:00
parent b380e218f6
commit 97da3982d1
9 changed files with 99 additions and 26 deletions

View File

@@ -199,6 +199,24 @@ public class UI {
graphics2d.fillRoundRect(slotX, slotY, panel.tileSize, panel.tileSize, 10, 10);
}
graphics2d.drawImage(entity.inventory.get(i).down1, slotX, slotY, null);
// AMOUNT
if(entity == panel.player && entity.inventory.get(i).amt > 1) {
graphics2d.setFont(graphics2d.getFont().deriveFont(32F));
int amtX;
int amtY;
String amtS = String.valueOf(entity.inventory.get(i).amt);
amtX = getAlignedToRightX(amtS, slotX+44);
amtY = slotY + panel.tileSize;
// SHADOW
graphics2d.setColor(new Color(60, 60, 60));
graphics2d.drawString(amtS, amtX, amtY);
// NUMBER
graphics2d.setColor(Color.white);
graphics2d.drawString(amtS, amtX-3, amtY-3);
}
slotX += slotSize;
if (i == 4 || i == 9 || i == 14) {
slotX = slotXStart;
@@ -450,15 +468,14 @@ public class UI {
drawDialogueScreen();
return;
}
if(panel.player.inventory.size() == panel.player.maxInvSize) {
tradeState = TradeState.SELECT;
panel.gameState = GameState.DIALOGUE;
currentDialogue = "Your inventory is full!";
drawDialogueScreen();
if(panel.player.canObtainItem(tradingNPC.inventory.get(itemIndex))) {
panel.player.coins -= tradingNPC.inventory.get(itemIndex).price;
return;
}
panel.player.coins -= tradingNPC.inventory.get(itemIndex).price;
panel.player.inventory.add(tradingNPC.inventory.get(itemIndex));
tradeState = TradeState.SELECT;
panel.gameState = GameState.DIALOGUE;
currentDialogue = "Your inventory is full!";
drawDialogueScreen();
}
}
private void tradeSell() {
@@ -499,7 +516,8 @@ public class UI {
currentDialogue = "You cannot sell an equipped item!";
return;
}
panel.player.inventory.remove(itemIndex);
if(panel.player.inventory.get(itemIndex).amt <= 1) panel.player.inventory.remove(itemIndex);
else panel.player.inventory.get(itemIndex).amt--;
panel.player.coins += Integer.parseInt(price);
}
}