|
|
|
@ -5,7 +5,7 @@ from dataclasses import dataclass, field
|
|
|
|
|
|
|
|
|
|
import pygame |
|
|
|
|
|
|
|
|
|
from config import WIDTH, HEIGHT, DARK_BLUE, WHITE, GREY, BLUE, font |
|
|
|
|
from config import CHAT_SELECTOR_WIDTH, HEIGHT, DARK_BLUE, WHITE, GREY, BLUE, font, CHAT_PREVIEW_HEIGHT, MEDIUM_BLUE |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass |
|
|
|
@ -23,27 +23,28 @@ class ChatSelector:
|
|
|
|
|
chat_height (int): height of one chat |
|
|
|
|
""" |
|
|
|
|
chats: typing.List['dc.Chat'] = field(default_factory=list) |
|
|
|
|
active_chat: int = 0 |
|
|
|
|
active_chat: int = -1 |
|
|
|
|
hovered_chat: typing.Optional[int] = None |
|
|
|
|
width: int = WIDTH // 3 |
|
|
|
|
width: int = CHAT_SELECTOR_WIDTH |
|
|
|
|
height: int = HEIGHT |
|
|
|
|
chat_height: int = HEIGHT // 4 |
|
|
|
|
chat_height: int = CHAT_PREVIEW_HEIGHT |
|
|
|
|
|
|
|
|
|
def render(self) -> pygame.Surface: |
|
|
|
|
""" |
|
|
|
|
Creates a pygame surface and draws the list of chats on it |
|
|
|
|
:return: the surface with the chat selector |
|
|
|
|
""" |
|
|
|
|
surface: pygame.Surface = pygame.Surface((self.width, self.chat_height * len(self.chats))) |
|
|
|
|
surface: pygame.Surface = pygame.Surface((self.width, self.height)) |
|
|
|
|
surface.fill(GREY) |
|
|
|
|
for i, chat in enumerate(self.chats): |
|
|
|
|
bg_color, text_color = DARK_BLUE, WHITE |
|
|
|
|
if i == self.hovered_chat: |
|
|
|
|
bg_color = GREY |
|
|
|
|
bg_color = MEDIUM_BLUE |
|
|
|
|
if i == self.active_chat: |
|
|
|
|
bg_color = BLUE |
|
|
|
|
title_surface: pygame.Surface = font.render(chat.profile.name, True, text_color) |
|
|
|
|
pygame.draw.rect(surface, bg_color, (0, i * self.chat_height + 1, self.width, self.chat_height - 2)) |
|
|
|
|
surface.blit(title_surface, (i * self.chat_height + 10)) |
|
|
|
|
pygame.draw.rect(surface, bg_color, (3, i * self.chat_height + 1, self.width - 6, self.chat_height - 2)) |
|
|
|
|
surface.blit(title_surface, (7, i * self.chat_height + 10)) |
|
|
|
|
return surface |
|
|
|
|
|
|
|
|
|
def process_event(self, event: pygame.event.Event): |
|
|
|
|