From 0add2066e2c1af94dcd53a7a730106eb98f29101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sun, 5 Apr 2020 23:57:28 +0200 Subject: [PATCH 1/3] Add method updating text in UiText --- src/ui/UiText.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ui/UiText.py b/src/ui/UiText.py index a6beb6a..676faf7 100644 --- a/src/ui/UiText.py +++ b/src/ui/UiText.py @@ -24,3 +24,11 @@ class UiText(UiElement): self.image.fill(backgroundColor) wordImage = self.font.render(text, antialias, textColor) self.image.blit(wordImage, (0, 0)) + + def changeText(self, newText): + self.text = newText + + if self.backgroundColor is not None: + self.image.fill(self.backgroundColor) + wordImage = self.font.render(self.text, self.antialias, self.textColor) + self.image.blit(wordImage, (0, 0)) From 4985794b446acb1454cc29cd4f8fe4b9b95e5221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sun, 5 Apr 2020 23:57:53 +0200 Subject: [PATCH 2/3] Add updating time in top left corner --- src/game/EventManager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/game/EventManager.py b/src/game/EventManager.py index 7ee55b6..3960521 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -21,6 +21,8 @@ class EventManager: def handleEvents(self): pygame.event.pump() + self.game.screen.ui.timerTextView.changeText(self.game.ingameTimer.getPrettyTime()) + keys = pygame.key.get_pressed() for event in pygame.event.get(): if event.type == pygame.QUIT: From 932073d72a4de51569c0fc478f0cbad8818c40c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sun, 5 Apr 2020 23:58:45 +0200 Subject: [PATCH 3/3] Reformat file Ui.py --- src/ui/Ui.py | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/ui/Ui.py b/src/ui/Ui.py index a68b3bf..394c2e8 100644 --- a/src/ui/Ui.py +++ b/src/ui/Ui.py @@ -26,26 +26,37 @@ class Ui(): self.timerTextView = UiText(pygame.Rect(0, 0, leftUiWidth, self.barHeight), font=self.font, text=timer.getPrettyTime(), textColor=Colors.WHITE.value, backgroundColor=Colors.GRAY.value) - self.isDayTextView = UiText(pygame.Rect(0, self.timerTextView.rect.y + self.barHeight, leftUiWidth, self.barHeight), text="Day", - font=self.font, backgroundColor=Colors.GRAY.value, textColor=Colors.WHITE.value) + self.isDayTextView = UiText( + pygame.Rect(0, self.timerTextView.rect.y + self.barHeight, leftUiWidth, self.barHeight), text="Day", + font=self.font, backgroundColor=Colors.GRAY.value, textColor=Colors.WHITE.value) self.healthTextView = UiText(pygame.Rect(0, 0, rightUiWidth, self.barHeight), text="Health points", font=self.font, textColor=Colors.WHITE.value) - self.healthBar = UiBar(pygame.Rect(0, self.healthTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight)) + self.healthBar = UiBar( + pygame.Rect(0, self.healthTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight)) - self.hungerTextView = UiText(pygame.Rect(0, self.healthBar.rect.y + self.barHeight, rightUiWidth, self.barHeight), - text="Hunger", font=self.font, textColor=Colors.WHITE.value) - self.hungerBar = UiBar(pygame.Rect(0, self.hungerTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight), initialFilledPercent=0, - filledBarColor=Colors.YELLOW.value) + self.hungerTextView = UiText( + pygame.Rect(0, self.healthBar.rect.y + self.barHeight, rightUiWidth, self.barHeight), + text="Hunger", font=self.font, textColor=Colors.WHITE.value) + self.hungerBar = UiBar( + pygame.Rect(0, self.hungerTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight), + initialFilledPercent=0, + filledBarColor=Colors.YELLOW.value) - self.staminaTextView = UiText(pygame.Rect(0, self.hungerBar.rect.y + self.barHeight, rightUiWidth, self.barHeight), text="Stamina", - font=self.font, textColor=Colors.WHITE.value) - self.staminaBar = UiBar(pygame.Rect(0, self.staminaTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight), filledBarColor=Colors.GREEN.value) + self.staminaTextView = UiText( + pygame.Rect(0, self.hungerBar.rect.y + self.barHeight, rightUiWidth, self.barHeight), text="Stamina", + font=self.font, textColor=Colors.WHITE.value) + self.staminaBar = UiBar( + pygame.Rect(0, self.staminaTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight), + filledBarColor=Colors.GREEN.value) - self.thirstTextView = UiText(pygame.Rect(0, self.staminaBar.rect.y + self.barHeight, rightUiWidth, self.barHeight), text="Thirst", - font=self.font, textColor=Colors.WHITE.value) - self.thirstBar = UiBar(pygame.Rect(0, self.thirstTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight), initialFilledPercent=0, - filledBarColor=Colors.BLUE.value) + self.thirstTextView = UiText( + pygame.Rect(0, self.staminaBar.rect.y + self.barHeight, rightUiWidth, self.barHeight), text="Thirst", + font=self.font, textColor=Colors.WHITE.value) + self.thirstBar = UiBar( + pygame.Rect(0, self.thirstTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight), + initialFilledPercent=0, + filledBarColor=Colors.BLUE.value) self.console = UiConsole(pygame.Rect(0, self.timerTextView.rect.h + self.isDayTextView.rect.h, leftUiWidth, screenHeight - self.timerTextView.rect.h - self.isDayTextView.rect.h), @@ -61,8 +72,6 @@ class Ui(): pass - - class Colors(Enum): RED = (255, 0, 0) GREEN = (0, 255, 0)