|
|
|
@ -4,6 +4,7 @@ import typing
|
|
|
|
|
from dataclasses import dataclass, field |
|
|
|
|
import pygame |
|
|
|
|
|
|
|
|
|
from button import Button |
|
|
|
|
from config import HEIGHT, WIDTH, CHAT_SELECTOR_WIDTH, DARKER_BLUE, CHAT_PREVIEW_HEIGHT, WHITE, font, DARK_BLUE, \ |
|
|
|
|
MESSAGE_HEIGHT |
|
|
|
|
import degeon_core as dc |
|
|
|
@ -26,6 +27,8 @@ class ActiveChat:
|
|
|
|
|
""" |
|
|
|
|
chat: dc.Chat |
|
|
|
|
input_field: TextField = field(default_factory=lambda: TextField()) |
|
|
|
|
send_button: Button = field(default_factory=lambda: Button(height=CHAT_PREVIEW_HEIGHT, width=100, text='Send', |
|
|
|
|
top_left=(WIDTH - 112, HEIGHT - 85))) |
|
|
|
|
height: int = HEIGHT |
|
|
|
|
width: int = WIDTH - CHAT_SELECTOR_WIDTH - 10 |
|
|
|
|
delta_x: int = CHAT_SELECTOR_WIDTH + 10 |
|
|
|
@ -83,6 +86,10 @@ class ActiveChat:
|
|
|
|
|
# Render message input |
|
|
|
|
input_field_surface: pygame.Surface = self.input_field.render() |
|
|
|
|
surface.blit(input_field_surface, (0, self.height - input_field_surface.get_height())) |
|
|
|
|
# Render sending button |
|
|
|
|
sending_button_surface: pygame.Surface = self.send_button.render() |
|
|
|
|
surface.blit(sending_button_surface, |
|
|
|
|
(self.send_button.top_left[0] - self.delta_x, self.send_button.top_left[1])) |
|
|
|
|
return surface |
|
|
|
|
|
|
|
|
|
def process_event(self, event: pygame.event.Event) -> typing.Optional[str]: |
|
|
|
@ -92,3 +99,5 @@ class ActiveChat:
|
|
|
|
|
:return: A message to send if there is one |
|
|
|
|
""" |
|
|
|
|
self.input_field.process_event(event) |
|
|
|
|
if self.send_button.process_event(event): |
|
|
|
|
return self.input_field.collect() |
|
|
|
|