diff --git a/src/de/miaurizius/jgame2d/core/UI.java b/src/de/miaurizius/jgame2d/core/UI.java index aa8012a..c3d906a 100644 --- a/src/de/miaurizius/jgame2d/core/UI.java +++ b/src/de/miaurizius/jgame2d/core/UI.java @@ -462,7 +462,46 @@ public class UI { } } private void tradeSell() { + drawInventory(panel.player, true); + int x, y, width, height; + // HINT WINDOW + x = panel.tileSize*2; + y = panel.tileSize*9; + width = panel.tileSize*6; + height = panel.tileSize*2; + drawSubWindow(x, y, width, height); + graphics2d.drawString("[ESC] Back", x+panel.tileSize, y+60); + + // PLAYER COINS + x = panel.tileSize*12; + drawSubWindow(x, y, width, height); + graphics2d.drawString("Your Coins: " + panel.player.coins, x+panel.tileSize, y+60); + + // PRICE WINDOW + int itemIndex = getItemIndex(playerSlotCol, playerSlotRow); + if(itemIndex < panel.player.inventory.size()) { + x = (int)(panel.tileSize*15.5); + y = (int)(panel.tileSize*5.5); + width = (int)(panel.tileSize*2.5); + height = panel.tileSize; + drawSubWindow(x, y, width, height); + graphics2d.drawImage(coin, x+10, y+8, 32, 32, null); + String price = String.valueOf(panel.player.inventory.get(itemIndex).price/2); + graphics2d.drawString(price, getAlignedToRightX(price, panel.tileSize*18-20), y+34); + + // SELL + if(!panel.keyH.spacePressed) return; + if(panel.player.inventory.get(itemIndex) == panel.player.currentWeapon || panel.player.inventory.get(itemIndex) == panel.player.currentShield) { + commandNum = 0; + tradeState = TradeState.SELECT; + panel.gameState = GameState.DIALOGUE; + currentDialogue = "You cannot sell an equipped item!"; + return; + } + panel.player.inventory.remove(itemIndex); + panel.player.coins += Integer.parseInt(price); + } } // UTILITY diff --git a/src/de/miaurizius/jgame2d/core/handlers/KeyHandler.java b/src/de/miaurizius/jgame2d/core/handlers/KeyHandler.java index f15d7cc..2b6bd43 100644 --- a/src/de/miaurizius/jgame2d/core/handlers/KeyHandler.java +++ b/src/de/miaurizius/jgame2d/core/handlers/KeyHandler.java @@ -176,6 +176,10 @@ public class KeyHandler implements KeyListener { npcInventory(code); if(code == KeyEvent.VK_ESCAPE) panel.ui.tradeState = UI.TradeState.SELECT; } + if(panel.ui.tradeState == UI.TradeState.SELL) { + playerInventory(code); + if(code == KeyEvent.VK_ESCAPE) panel.ui.tradeState = UI.TradeState.SELECT; + } } // UTILITY