From b15382d9bccba48da62319009ce4f0226703c6e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Fri, 15 May 2020 01:44:32 +0200 Subject: [PATCH] Add scroll up and down method in UiConsole class --- src/ui/Ui.py | 4 ++-- src/ui/UiConsole.py | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/ui/Ui.py b/src/ui/Ui.py index f232cce..19a2531 100644 --- a/src/ui/Ui.py +++ b/src/ui/Ui.py @@ -91,9 +91,9 @@ class Ui(): if event.type == pygame.MOUSEBUTTONDOWN: console = self.console if event.button == 4: - console.writeConsoleLines(console.topWrittenLineInd + 1) + console.scrollDown() elif event.button == 5: - console.writeConsoleLines(console.topWrittenLineInd - 1) + console.scrollUp() def updateOnPlayerPickup(self, playerStats, pickedObject): self.console.addLinesToConsoleAndScrollToDisplayThem([self.timer.getPrettyTime() + " - Picked object " + str(pickedObject.id) + ":"]) diff --git a/src/ui/UiConsole.py b/src/ui/UiConsole.py index f56d575..107e4d0 100644 --- a/src/ui/UiConsole.py +++ b/src/ui/UiConsole.py @@ -69,7 +69,7 @@ class UiConsole(UiElement): self.maxLines = int(self.image.get_height() / self.lineHeight) self.addLinesToConsole(["Hello from console!"]) - self.writeConsoleLines() + self.__writeConsoleLines__() def update(self, *args): """ @@ -89,7 +89,21 @@ class UiConsole(UiElement): """ self.addLinesToConsoleAndScrollToDisplayThem([inp]) - def writeConsoleLines(self, startingLineInd: int = 0): + def scrollUp(self): + """ + Scrolls one line up. + + """ + self.__writeConsoleLines__(self.topWrittenLineInd - 1) + + def scrollDown(self): + """ + Scrolls one line down. + + """ + self.__writeConsoleLines__(self.topWrittenLineInd + 1) + + def __writeConsoleLines__(self, startingLineInd: int = 0): """ Displays lines stored in console's list of lines, starting from line with given index. @@ -152,4 +166,4 @@ class UiConsole(UiElement): ind = 0 if self.linesImagesCount > self.maxLines: ind = self.linesImagesCount - self.maxLines - self.writeConsoleLines(ind) + self.__writeConsoleLines__(ind)