mirror of
https://github.com/kristoferssolo/2048.git
synced 2025-10-21 15:20:35 +00:00
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
from abc import ABC, ABCMeta, abstractmethod
|
|
from typing import Optional
|
|
|
|
import pygame
|
|
from loguru import logger
|
|
|
|
from py2048 import Config
|
|
from py2048.utils import Position, Size
|
|
|
|
|
|
class UIElement(ABC, metaclass=ABCMeta):
|
|
def __init__(
|
|
self,
|
|
/,
|
|
*,
|
|
position: Position,
|
|
bg_color: str,
|
|
font_color: str,
|
|
size: Size = Size(50, 50),
|
|
text: str = "",
|
|
border_radius: int = 0,
|
|
border_width: int = 0,
|
|
):
|
|
super().__init__()
|
|
self.text = text
|
|
self.size = size
|
|
self.bg_color = bg_color
|
|
self.font_color = font_color
|
|
self.border_radius = border_radius
|
|
self.border_width = border_width
|
|
self.position = position
|
|
self.x, self.y = self.position
|
|
self.font = pygame.font.SysFont(Config.FONT.family, Config.FONT.size)
|
|
|
|
@abstractmethod
|
|
def draw(self, surface: pygame.Surface) -> None:
|
|
"""Draw the element on the given surface."""
|
|
|
|
@abstractmethod
|
|
def _draw_background(self, surface: pygame.Surface) -> None:
|
|
"""Draw a background for the given surface."""
|
|
|
|
@abstractmethod
|
|
def _draw_text(self) -> None:
|
|
"""Draw the text of the element."""
|
|
|
|
@abstractmethod
|
|
def _create_surface(self) -> pygame.Surface:
|
|
"""Create a surface for the element."""
|