Add scroll up and down method in UiConsole class

This commit is contained in:
Michał Czekański 2020-05-15 01:44:32 +02:00 committed by Marcin Kostrzewski
parent 76de35bc3d
commit b15382d9bc
2 changed files with 19 additions and 5 deletions

View File

@ -91,9 +91,9 @@ class Ui():
if event.type == pygame.MOUSEBUTTONDOWN: if event.type == pygame.MOUSEBUTTONDOWN:
console = self.console console = self.console
if event.button == 4: if event.button == 4:
console.writeConsoleLines(console.topWrittenLineInd + 1) console.scrollDown()
elif event.button == 5: elif event.button == 5:
console.writeConsoleLines(console.topWrittenLineInd - 1) console.scrollUp()
def updateOnPlayerPickup(self, playerStats, pickedObject): def updateOnPlayerPickup(self, playerStats, pickedObject):
self.console.addLinesToConsoleAndScrollToDisplayThem([self.timer.getPrettyTime() + " - Picked object " + str(pickedObject.id) + ":"]) self.console.addLinesToConsoleAndScrollToDisplayThem([self.timer.getPrettyTime() + " - Picked object " + str(pickedObject.id) + ":"])

View File

@ -69,7 +69,7 @@ class UiConsole(UiElement):
self.maxLines = int(self.image.get_height() / self.lineHeight) self.maxLines = int(self.image.get_height() / self.lineHeight)
self.addLinesToConsole(["Hello from console!"]) self.addLinesToConsole(["Hello from console!"])
self.writeConsoleLines() self.__writeConsoleLines__()
def update(self, *args): def update(self, *args):
""" """
@ -89,7 +89,21 @@ class UiConsole(UiElement):
""" """
self.addLinesToConsoleAndScrollToDisplayThem([inp]) 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. Displays lines stored in console's list of lines, starting from line with given index.
@ -152,4 +166,4 @@ class UiConsole(UiElement):
ind = 0 ind = 0
if self.linesImagesCount > self.maxLines: if self.linesImagesCount > self.maxLines:
ind = self.linesImagesCount - self.maxLines ind = self.linesImagesCount - self.maxLines
self.writeConsoleLines(ind) self.__writeConsoleLines__(ind)