Browse Source

Rendering active chat in interface (header)

interface-2
Lev 3 years ago
parent
commit
67b8c7cfe5
  1. 34
      degeon_py/active_chat.py
  2. 1
      degeon_py/config.py
  3. 3
      degeon_py/degeon.py

34
degeon_py/active_chat.py

@ -3,7 +3,7 @@ from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
import pygame 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 import degeon_core as dc
@ -14,22 +14,50 @@ class ActiveChat:
Attributes: Attributes:
:param chat (dc.Chat): the chat (Rust Chat type) :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 chat: dc.Chat
height: int = HEIGHT 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 @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) 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: def render(self) -> pygame.Surface:
""" """
Creates a pygame surface and draws the chat on it Creates a pygame surface and draws the chat on it
:return: the surface with the chat on it :return: the surface with the chat on it
""" """
surface: pygame.Surface = pygame.Surface((self.width, self.height)) surface: pygame.Surface = pygame.Surface((self.width, self.height))
surface.fill(DARKER_BLUE)
header = self.get_header()
surface.blit(header, (0, 10))
return surface return surface
def process_event(self, event: pygame.event.Event): def process_event(self, event: pygame.event.Event):

1
degeon_py/config.py

@ -3,6 +3,7 @@ import pygame
pygame.init() pygame.init()
font = pygame.font.Font('CRC35.otf', 25) font = pygame.font.Font('CRC35.otf', 25)
font_large = pygame.font.Font('CRC35.otf', 35)
RED = 0xFF0000 RED = 0xFF0000
BLUE = 0x0000FF BLUE = 0x0000FF

3
degeon_py/degeon.py

@ -44,7 +44,8 @@ class Degeon:
chats_surface = self.chat_selector.render() chats_surface = self.chat_selector.render()
screen.blit(chats_surface, (0, 0)) screen.blit(chats_surface, (0, 0))
if self.active_chat is not None: if self.active_chat is not None:
pass active_chat_surface = self.active_chat.render()
screen.blit(active_chat_surface, (self.active_chat.delta_x, 0))
else: else:
text_surface: pygame.Surface = font.render('<- Select chat in the menu', True, WHITE) text_surface: pygame.Surface = font.render('<- Select chat in the menu', True, WHITE)
screen.blit(text_surface, screen.blit(text_surface,

Loading…
Cancel
Save