From 9d1ecf5d9052499da1cb6e500ab6e60d4aa98b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Thu, 14 May 2020 21:10:51 +0200 Subject: [PATCH] Add comments in UiBar.py --- src/ui/UiBar.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/ui/UiBar.py b/src/ui/UiBar.py index 8475395..8b61cd2 100644 --- a/src/ui/UiBar.py +++ b/src/ui/UiBar.py @@ -1,11 +1,30 @@ +from typing import Tuple + import pygame from src.ui.UiElement import UiElement class UiBar(UiElement): - def __init__(self, rect: pygame.Rect, initialFilledPercent=100, filledBarColor=(255, 0, 0), emptyBarColor=(0, 0, 0), - outlineColor=(75, 75, 75), outlineThickness=10): + value: int + filledBarColor: Tuple[int, int, int] + outlineThickness: int + outlineColor: Tuple[int, int, int] + emptyBarColor: Tuple[int, int, int] + filledPercent: float + + def __init__(self, rect: pygame.Rect, initialFilledPercent: int = 100, + filledBarColor: Tuple[int, int, int] = (255, 0, 0), emptyBarColor: Tuple[int, int, int] = (0, 0, 0), + outlineColor: Tuple[int, int, int] = (75, 75, 75), outlineThickness: int = 10): + """ + Creates UiBar object + :param rect: + :param initialFilledPercent: How much bar is filled at the beginning. Number between 0 and 100 + :param filledBarColor: Color of the filled part of the bar. + :param emptyBarColor: Color of the empty part of the bar. + :param outlineColor: Color of the bar outline. + :param outlineThickness: + """ super().__init__(rect) self.filledPercent = initialFilledPercent / 100 self.emptyBarColor = emptyBarColor @@ -18,6 +37,9 @@ class UiBar(UiElement): self.__genBar__() def __genBar__(self): + """ + Generates bar image. + """ self.image = pygame.Surface((self.rect.width, self.rect.height)) filledPartRect = pygame.rect.Rect(self.outlineThickness / 2, self.outlineThickness / 2, (self.rect.width - self.outlineThickness) * self.filledPercent, @@ -26,7 +48,11 @@ class UiBar(UiElement): pygame.draw.rect(self.image, self.outlineColor, pygame.rect.Rect(0, 0, self.rect.width, self.rect.height), self.outlineThickness) - def updateFill(self, filledPercent): + def updateFill(self, filledPercent: int): + """ + Updates how much bar is filled + :param filledPercent: Value between 0 and 100 + """ self.filledPercent = filledPercent / 100 self.value = filledPercent self.__genBar__()