From 178115cc4d7fba01914c2be2cd7c6bc2f6ddf5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Mon, 6 Apr 2020 13:20:04 +0200 Subject: [PATCH] Add method updating console on player interaction in Ui and fix bar updating --- src/ui/Ui.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/ui/Ui.py b/src/ui/Ui.py index 7d9f6dd..f75b6b8 100644 --- a/src/ui/Ui.py +++ b/src/ui/Ui.py @@ -62,23 +62,17 @@ class Ui(): screenHeight - self.timerTextView.rect.h - self.isDayTextView.rect.h), font=self.font) - def updateBasedOnPlayerStats(self, statistics: Statistics): - consoleLines = [] - - self.healthBar.updateFill(statistics.hp) - consoleLines.append("Health: " + str(statistics.hp)) - - self.hungerBar.updateFill(statistics.hunger) - consoleLines.append("Hunger: " + str(statistics.hunger)) - - self.staminaBar.updateFill(statistics.stamina) - consoleLines.append("Stamina: " + str(statistics.stamina)) - - self.thirstBar.updateFill(statistics.thirst) - consoleLines.append("Thirst: " + str(statistics.thirst)) - + def updateConsoleBasedOnPlayerStats(self, statistics: Statistics): + consoleLines = ["Health: " + str(statistics.hp), "Hunger: " + str(statistics.hunger), + "Stamina: " + str(statistics.stamina), "Thirst: " + str(statistics.thirst)] self.console.addLinesToConsoleAndScrollToDisplayThem(consoleLines) + def updateBarsBasedOnPlayerStats(self, statistics: Statistics): + self.healthBar.updateFill(statistics.hp) + self.hungerBar.updateFill(statistics.hunger) + self.staminaBar.updateFill(statistics.stamina) + self.thirstBar.updateFill(statistics.thirst) + def updateBasedOnPygameEvent(self, event: pygame.event): if event.type == pygame.MOUSEBUTTONDOWN: console = self.console @@ -89,7 +83,11 @@ class Ui(): def updateOnPlayerPickup(self, playerStats, pickedObject): self.console.addLinesToConsoleAndScrollToDisplayThem([self.timer.getPrettyTime() + " - Picked object " + str(pickedObject.id) + ":"]) - self.updateBasedOnPlayerStats(playerStats) + self.updateConsoleBasedOnPlayerStats(playerStats) + + def updateOnPlayerInteraction(self, playerStats, interactedObject): + self.console.addLinesToConsoleAndScrollToDisplayThem([self.timer.getPrettyTime() + " - Player interacted with " + str(interactedObject.id) + ":"]) + self.updateConsoleBasedOnPlayerStats(playerStats) def updateTime(self): self.timerTextView.changeText(self.timer.getPrettyTime())