refactor dialogue handling for various game entities
This commit is contained in:
@@ -294,6 +294,19 @@ public class UI {
|
||||
x += panel.tileSize;
|
||||
y += panel.tileSize;
|
||||
|
||||
if(tradingNPC.dialogue[tradingNPC.dialogueSet][tradingNPC.dialogueIndex] != null) {
|
||||
currentDialogue = tradingNPC.dialogue[tradingNPC.dialogueSet][tradingNPC.dialogueIndex];
|
||||
if(panel.keyH.spacePressed) {
|
||||
if(panel.gameState == GameState.DIALOGUE) {
|
||||
tradingNPC.dialogueIndex++;
|
||||
panel.keyH.spacePressed = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tradingNPC.dialogueIndex = 0;
|
||||
if(panel.gameState == GameState.DIALOGUE) panel.gameState = GameState.PLAY;
|
||||
}
|
||||
|
||||
for(String line : currentDialogue.split("\n")) {
|
||||
graphics2d.drawString(line, x, y);
|
||||
y += 40;
|
||||
@@ -419,6 +432,7 @@ public class UI {
|
||||
|
||||
// TRADING
|
||||
private void tradeSelect() {
|
||||
tradingNPC.dialogueSet = 0;
|
||||
drawDialogueScreen();
|
||||
|
||||
int x = panel.tileSize*15;
|
||||
@@ -449,9 +463,8 @@ public class UI {
|
||||
graphics2d.drawString(">", x-panel.tileSize/2, y);
|
||||
if(panel.keyH.spacePressed) {
|
||||
commandNum = 0;
|
||||
tradingNPC.startDialogue(tradingNPC,1);
|
||||
tradeState = TradeState.SELECT;
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
currentDialogue = "Come again, hehe!";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -488,9 +501,7 @@ public class UI {
|
||||
if(!panel.keyH.spacePressed) return;
|
||||
if(tradingNPC.inventory.get(itemIndex).price > panel.player.coins) {
|
||||
tradeState = TradeState.SELECT;
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
currentDialogue = "You need more coins to buy that!";
|
||||
drawDialogueScreen();
|
||||
tradingNPC.startDialogue(tradingNPC,2);
|
||||
return;
|
||||
}
|
||||
if(panel.player.canObtainItem(tradingNPC.inventory.get(itemIndex))) {
|
||||
@@ -498,9 +509,7 @@ public class UI {
|
||||
return;
|
||||
}
|
||||
tradeState = TradeState.SELECT;
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
currentDialogue = "Your inventory is full!";
|
||||
drawDialogueScreen();
|
||||
tradingNPC.startDialogue(tradingNPC,3);
|
||||
}
|
||||
}
|
||||
private void tradeSell() {
|
||||
@@ -537,8 +546,7 @@ public class UI {
|
||||
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!";
|
||||
tradingNPC.startDialogue(tradingNPC,4);
|
||||
return;
|
||||
}
|
||||
if(panel.player.inventory.get(itemIndex).amt <= 1) panel.player.inventory.remove(itemIndex);
|
||||
|
||||
Reference in New Issue
Block a user