From 65c9171428b50f55164ebf5050fc5325558c999c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sat, 4 Apr 2020 21:37:25 +0200 Subject: [PATCH] Fix writing console lines when line ind is too small or too big --- src/ui/UiConsole.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ui/UiConsole.py b/src/ui/UiConsole.py index 53591e5..8ce5d89 100644 --- a/src/ui/UiConsole.py +++ b/src/ui/UiConsole.py @@ -21,6 +21,7 @@ class UiConsole(UiElement): self.consoleLines = [] self.linesCount = 0 + self.topWrittenLineInd = 0 self.linesImages = [] self.lineHeight = font.render("sampleText", False, textColor) .get_height() @@ -32,6 +33,11 @@ class UiConsole(UiElement): def writeConsoleLines(self, startingLineInd=0): self.image.fill(self.bgColor) + if startingLineInd < 0: + startingLineInd = 0 + elif startingLineInd > self.linesImagesCount: + startingLineInd = self.linesImagesCount + self.topWrittenLineInd = startingLineInd writtenLines = 0 for i in range(startingLineInd, min(self.maxLines + startingLineInd, self.linesImagesCount)): self.image.blit(self.linesImages[i], (0, writtenLines * self.lineHeight))