From 04898fc27b68fb5950ed1a4d076e808f928cf932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Mon, 6 Apr 2020 00:45:52 +0200 Subject: [PATCH] Fix console scrolling --- src/ui/Ui.py | 10 ++++++++-- src/ui/UiConsole.py | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ui/Ui.py b/src/ui/Ui.py index 7c50c6f..98d26ee 100644 --- a/src/ui/Ui.py +++ b/src/ui/Ui.py @@ -80,10 +80,16 @@ class Ui(): self.thirstBar.updateFill(statistics.thirst) consoleLines.append("Stamina: " + str(statistics.thirst)) - self.console.addLinesToConsoleAndScrollToDisplayThem(consoleLines) + if len(consoleLines) > 0: + self.console.addLinesToConsoleAndScrollToDisplayThem(consoleLines) def updateBasedOnPygameEvent(self, event: pygame.event): - pass + if event.type == pygame.MOUSEBUTTONDOWN: + console = self.console + if event.button == 4: + console.writeConsoleLines(console.topWrittenLineInd + 1) + elif event.button == 5: + console.writeConsoleLines(console.topWrittenLineInd - 1) class Colors(Enum): diff --git a/src/ui/UiConsole.py b/src/ui/UiConsole.py index 1c57793..d1afc11 100644 --- a/src/ui/UiConsole.py +++ b/src/ui/UiConsole.py @@ -35,8 +35,8 @@ class UiConsole(UiElement): self.image.fill(self.bgColor) if startingLineInd < 0: startingLineInd = 0 - elif startingLineInd > self.linesImagesCount: - startingLineInd = self.linesImagesCount + elif startingLineInd >= self.linesImagesCount: + startingLineInd = self.linesImagesCount - 1 self.topWrittenLineInd = startingLineInd writtenLines = 0 for i in range(startingLineInd, min(self.maxLines + startingLineInd, self.linesImagesCount)):