-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextBoxForMultiplayer.py
More file actions
26 lines (24 loc) · 978 Bytes
/
TextBoxForMultiplayer.py
File metadata and controls
26 lines (24 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from Constants import BLACK,WHITE
from TextBoxBase import TextBoxBase
import pygame
class TextBoxForMultiplayer(TextBoxBase):
def __init__(self, x, y, width, height,user):
super().__init__(x,y,width,height)
self.user=user
def handle_event(self, event):
if event.type == pygame.MOUSEBUTTONDOWN:
if self.rect.collidepoint(event.pos):
self.active = not self.active
else:
self.active = False
self.color = WHITE if self.active else BLACK
if event.type == pygame.KEYDOWN:
if self.active:
if event.key == pygame.K_RETURN:
self.user.name=self.text
self.text = ''
elif event.key == pygame.K_BACKSPACE:
self.text = self.text[:-1]
else:
self.text += event.unicode
self.txt_surface = self.font.render(self.text, True, BLACK)