Fix console scrolling

This commit is contained in:
Michał Czekański 2020-04-06 00:45:52 +02:00
parent 53417ecab9
commit 04898fc27b
2 changed files with 10 additions and 4 deletions

View File

@ -80,10 +80,16 @@ class Ui():
self.thirstBar.updateFill(statistics.thirst)
consoleLines.append("Stamina: " + str(statistics.thirst))
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):

View File

@ -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)):