Add method addingLines to UiConsole and fix writing on console
This commit is contained in:
parent
41b7cd2a3f
commit
bf166232f3
@ -16,20 +16,51 @@ class UiConsole(UiElement):
|
||||
self.image = pygame.Surface((rect.width, rect.height))
|
||||
self.image.fill(bgColor)
|
||||
|
||||
self.consoleLines = ["Hello from console!"]
|
||||
self.linesCount = 1
|
||||
self.consoleWidth = self.image.get_width()
|
||||
self.linesImagesCount = 0
|
||||
|
||||
self.consoleLines = []
|
||||
self.linesCount = 0
|
||||
|
||||
self.linesImages = []
|
||||
self.linesImages.append(font.render(self.consoleLines[0], False, textColor))
|
||||
self.lineHeight = self.linesImages[0].get_height()
|
||||
self.lineHeight = font.render("sampleText", False, textColor) .get_height()
|
||||
|
||||
self.maxLines = int(self.image.get_height() / self.lineHeight)
|
||||
|
||||
self.addLinesToConsole(["Hello from console!"])
|
||||
self.writeConsoleLines()
|
||||
|
||||
self.__writeConsoleLines__()
|
||||
|
||||
def __writeConsoleLines__(self, startingLineInd=0):
|
||||
def writeConsoleLines(self, startingLineInd=0):
|
||||
self.image.fill(self.bgColor)
|
||||
writtenLines = 0
|
||||
for i in range(startingLineInd, min(self.maxLines + startingLineInd, self.linesCount)):
|
||||
self.image.blit(self.linesImages[i], (writtenLines*self.lineHeight, 0))
|
||||
for i in range(startingLineInd, min(self.maxLines + startingLineInd, self.linesImagesCount)):
|
||||
self.image.blit(self.linesImages[i], (0, writtenLines * self.lineHeight))
|
||||
writtenLines += 1
|
||||
|
||||
def addLinesToConsole(self, linesToAdd):
|
||||
for line in linesToAdd:
|
||||
self.consoleLines.append(line)
|
||||
self.linesCount += 1
|
||||
|
||||
row = pygame.Surface((self.consoleWidth, self.lineHeight))
|
||||
row.fill(self.bgColor)
|
||||
|
||||
howMuchRowIsFilled = 0
|
||||
words = line.split(' ')
|
||||
for word in words:
|
||||
wordImage = self.font.render(' ' + word, False, self.textColor)
|
||||
if howMuchRowIsFilled + wordImage.get_width() <= self.consoleWidth:
|
||||
row.blit(wordImage, (howMuchRowIsFilled, 0))
|
||||
howMuchRowIsFilled += wordImage.get_width()
|
||||
else:
|
||||
self.linesImages.append(row)
|
||||
self.linesImagesCount += 1
|
||||
row = pygame.Surface((self.consoleWidth, self.lineHeight))
|
||||
row.fill(self.bgColor)
|
||||
howMuchRowIsFilled = 0
|
||||
|
||||
row.blit(wordImage, (howMuchRowIsFilled, 0))
|
||||
howMuchRowIsFilled += wordImage.get_width()
|
||||
|
||||
self.linesImages.append(row)
|
||||
self.linesImagesCount += 1
|
||||
|
Loading…
Reference in New Issue
Block a user