Remove unnecessary field in UiBar class
This commit is contained in:
parent
9d1ecf5d90
commit
08643c7083
@ -6,12 +6,11 @@ from src.ui.UiElement import UiElement
|
|||||||
|
|
||||||
|
|
||||||
class UiBar(UiElement):
|
class UiBar(UiElement):
|
||||||
value: int
|
|
||||||
filledBarColor: Tuple[int, int, int]
|
filledBarColor: Tuple[int, int, int]
|
||||||
outlineThickness: int
|
outlineThickness: int
|
||||||
outlineColor: Tuple[int, int, int]
|
outlineColor: Tuple[int, int, int]
|
||||||
emptyBarColor: Tuple[int, int, int]
|
emptyBarColor: Tuple[int, int, int]
|
||||||
filledPercent: float
|
filledPercent: int
|
||||||
|
|
||||||
def __init__(self, rect: pygame.Rect, initialFilledPercent: int = 100,
|
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),
|
filledBarColor: Tuple[int, int, int] = (255, 0, 0), emptyBarColor: Tuple[int, int, int] = (0, 0, 0),
|
||||||
@ -26,23 +25,29 @@ class UiBar(UiElement):
|
|||||||
:param outlineThickness:
|
:param outlineThickness:
|
||||||
"""
|
"""
|
||||||
super().__init__(rect)
|
super().__init__(rect)
|
||||||
self.filledPercent = initialFilledPercent / 100
|
|
||||||
|
# Make sure that filled percent is between 0 and 100
|
||||||
|
if initialFilledPercent < 0:
|
||||||
|
initialFilledPercent = 0
|
||||||
|
elif initialFilledPercent > 100:
|
||||||
|
initialFilledPercent = 100
|
||||||
|
self.filledPercent = initialFilledPercent
|
||||||
|
|
||||||
self.emptyBarColor = emptyBarColor
|
self.emptyBarColor = emptyBarColor
|
||||||
self.barColor = filledBarColor
|
self.barColor = filledBarColor
|
||||||
self.outlineColor = outlineColor
|
self.outlineColor = outlineColor
|
||||||
self.outlineThickness = outlineThickness
|
self.outlineThickness = outlineThickness
|
||||||
self.filledBarColor = filledBarColor
|
self.filledBarColor = filledBarColor
|
||||||
self.value = initialFilledPercent
|
|
||||||
|
|
||||||
self.__genBar__()
|
self.__genBar__()
|
||||||
|
|
||||||
def __genBar__(self):
|
def __genBar__(self):
|
||||||
"""
|
"""
|
||||||
Generates bar image.
|
Generates bar image based on filled percent field.
|
||||||
"""
|
"""
|
||||||
self.image = pygame.Surface((self.rect.width, self.rect.height))
|
self.image = pygame.Surface((self.rect.width, self.rect.height))
|
||||||
filledPartRect = pygame.rect.Rect(self.outlineThickness / 2, self.outlineThickness / 2,
|
filledPartRect = pygame.rect.Rect(self.outlineThickness / 2, self.outlineThickness / 2,
|
||||||
(self.rect.width - self.outlineThickness) * self.filledPercent,
|
(self.rect.width - self.outlineThickness) * (self.filledPercent / 100),
|
||||||
self.rect.height - self.outlineThickness)
|
self.rect.height - self.outlineThickness)
|
||||||
self.image.fill(self.filledBarColor, filledPartRect)
|
self.image.fill(self.filledBarColor, filledPartRect)
|
||||||
pygame.draw.rect(self.image, self.outlineColor, pygame.rect.Rect(0, 0, self.rect.width, self.rect.height),
|
pygame.draw.rect(self.image, self.outlineColor, pygame.rect.Rect(0, 0, self.rect.width, self.rect.height),
|
||||||
@ -53,6 +58,5 @@ class UiBar(UiElement):
|
|||||||
Updates how much bar is filled
|
Updates how much bar is filled
|
||||||
:param filledPercent: Value between 0 and 100
|
:param filledPercent: Value between 0 and 100
|
||||||
"""
|
"""
|
||||||
self.filledPercent = filledPercent / 100
|
self.filledPercent = filledPercent
|
||||||
self.value = filledPercent
|
|
||||||
self.__genBar__()
|
self.__genBar__()
|
||||||
|
Loading…
Reference in New Issue
Block a user