Add scroll up and down method in UiConsole class
This commit is contained in:
parent
76de35bc3d
commit
b15382d9bc
@ -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) + ":"])
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user