From 3ff1b1b7bc37f0572e97aadf2443a1d417a49836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sat, 4 Apr 2020 19:24:04 +0200 Subject: [PATCH] Add method writing lines on UiConsole --- src/ui/UiConsole.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ui/UiConsole.py b/src/ui/UiConsole.py index afca695..557060c 100644 --- a/src/ui/UiConsole.py +++ b/src/ui/UiConsole.py @@ -4,9 +4,32 @@ from src.ui.UiElement import UiElement class UiConsole(UiElement): - def __init__(self, rect: pygame.Rect, bgColor=(125, 125, 125)): + def __init__(self, rect: pygame.Rect, bgColor=(125, 125, 125), textColor=(255, 255, 255), font=None): super().__init__(rect) + self.textColor = textColor + + if font is None: + font = pygame.font.Font(None, 25) + self.font = font self.bgColor = bgColor self.image = pygame.Surface((rect.width, rect.height)) self.image.fill(bgColor) + + self.consoleLines = ["Hello from console!"] + self.linesCount = 1 + self.linesImages = [] + self.linesImages.append(font.render(self.consoleLines[0], False, textColor)) + self.lineHeight = self.linesImages[0].get_height() + + self.maxLines = int(self.image.get_height() / self.lineHeight) + + + self.__writeConsoleLines__() + + 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)) + writtenLines += 1