|
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
|
|
from dataclasses import dataclass |
|
|
|
|
import pygame |
|
|
|
|
|
|
|
|
|
from config import HEIGHT, WIDTH, CHAT_SELECTOR_WIDTH |
|
|
|
|
from config import HEIGHT, WIDTH, CHAT_SELECTOR_WIDTH, DARKER_BLUE, CHAT_PREVIEW_HEIGHT, BLUE, WHITE, font, DARK_BLUE |
|
|
|
|
import degeon_core as dc |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -14,22 +14,50 @@ class ActiveChat:
|
|
|
|
|
|
|
|
|
|
Attributes: |
|
|
|
|
:param chat (dc.Chat): the chat (Rust Chat type) |
|
|
|
|
:param height (int): the height of the active chat widget |
|
|
|
|
:param width (int): its width |
|
|
|
|
:param delta_x (int): distance from the left edge of the application to the left edge of the screen |
|
|
|
|
:param header_height (int): height of the header (the title) |
|
|
|
|
""" |
|
|
|
|
chat: dc.Chat |
|
|
|
|
height: int = HEIGHT |
|
|
|
|
width: int = WIDTH - CHAT_SELECTOR_WIDTH |
|
|
|
|
width: int = WIDTH - CHAT_SELECTOR_WIDTH - 10 |
|
|
|
|
delta_x: int = CHAT_SELECTOR_WIDTH + 10 |
|
|
|
|
header_height: int = int(CHAT_PREVIEW_HEIGHT * 1.5) |
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
|
def new(cls, chat: 'dc.Chat', **kwargs) -> ActiveChat: |
|
|
|
|
def new(cls, chat: dc.Chat, **kwargs) -> ActiveChat: |
|
|
|
|
""" |
|
|
|
|
Create a new `Chat` from a rust Chat object |
|
|
|
|
:param chat: rusty chat |
|
|
|
|
:param kwargs: optional other paraeters |
|
|
|
|
:return: the `Chat` |
|
|
|
|
""" |
|
|
|
|
return cls(chat=chat, **kwargs) |
|
|
|
|
|
|
|
|
|
def get_header(self) -> pygame.Surface: |
|
|
|
|
""" |
|
|
|
|
Render a pygame surface with the header. |
|
|
|
|
The header is (for now) just a name of the user written on a background |
|
|
|
|
|
|
|
|
|
:return: the header |
|
|
|
|
""" |
|
|
|
|
surface: pygame.Surface = pygame.Surface((self.width, self.header_height)) |
|
|
|
|
surface.fill(DARK_BLUE) |
|
|
|
|
name_surface: pygame.Surface = font.render(self.chat.profile.name, True, WHITE) |
|
|
|
|
surface.blit(name_surface, (20, 20)) |
|
|
|
|
return surface |
|
|
|
|
|
|
|
|
|
def render(self) -> pygame.Surface: |
|
|
|
|
""" |
|
|
|
|
Creates a pygame surface and draws the chat on it |
|
|
|
|
:return: the surface with the chat on it |
|
|
|
|
""" |
|
|
|
|
surface: pygame.Surface = pygame.Surface((self.width, self.height)) |
|
|
|
|
surface.fill(DARKER_BLUE) |
|
|
|
|
|
|
|
|
|
header = self.get_header() |
|
|
|
|
surface.blit(header, (0, 10)) |
|
|
|
|
return surface |
|
|
|
|
|
|
|
|
|
def process_event(self, event: pygame.event.Event): |
|
|
|
|