feat(startscreen): change ui texts from german to english and fix button click event
This commit is contained in:
@@ -45,6 +45,8 @@ class Button:
|
|||||||
current_color = self.hover
|
current_color = self.hover
|
||||||
|
|
||||||
# check if left mouse button is pressed
|
# check if left mouse button is pressed
|
||||||
|
if pygame.mouse.get_pressed()[0] == 1:
|
||||||
|
self.clicked = True
|
||||||
if pygame.mouse.get_pressed()[0] == 0 and self.clicked:
|
if pygame.mouse.get_pressed()[0] == 0 and self.clicked:
|
||||||
self.clicked = False
|
self.clicked = False
|
||||||
action = True
|
action = True
|
||||||
|
|||||||
+49
-36
@@ -17,32 +17,72 @@ class Startscreen:
|
|||||||
self.button_hover_color = COLOR_BUTTON_HOVER
|
self.button_hover_color = COLOR_BUTTON_HOVER
|
||||||
|
|
||||||
self.player_name = ""
|
self.player_name = ""
|
||||||
|
self.wrong_name = False
|
||||||
|
|
||||||
self.button_start = Button("[ENTER] Immatrikulieren",
|
self.button_start = Button("[ENTER] Matriculate",
|
||||||
500,
|
500,
|
||||||
70,
|
70,
|
||||||
20,
|
20,
|
||||||
60,
|
100,
|
||||||
self.button_color,
|
self.button_color,
|
||||||
self.button_hover_color)
|
self.button_hover_color)
|
||||||
|
|
||||||
self.button_quit = Button("[ESC] Exmatrikulieren",
|
self.button_quit = Button("[ESC] Exmatriculate",
|
||||||
500,
|
500,
|
||||||
70,
|
70,
|
||||||
20,
|
20,
|
||||||
150,
|
190,
|
||||||
self.button_color,
|
self.button_color,
|
||||||
self.button_hover_color)
|
self.button_hover_color)
|
||||||
|
|
||||||
self.text_input_name = TextInput(400,
|
self.text_input_name = TextInput(400,
|
||||||
40,
|
40,
|
||||||
20,
|
20,
|
||||||
240)
|
310)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
# set background color
|
||||||
|
self.screen.fill(COLOR_STARTSCREEN_BACKGROUND)
|
||||||
|
|
||||||
|
# set title and intro/welcome message
|
||||||
|
title = self.font_title.render("SILENT FH", True, COLOR_STARTSCREEN_FONT_TITLE)
|
||||||
|
self.screen.blit(title, (10, 10))
|
||||||
|
message_1 = self.font_label.render("Welcome to Silent FH", True, COLOR_STARTSCREEN_FONT_LABEL)
|
||||||
|
message_2 = self.font_label.render("Study with purpose. Survive with Coffee.", True,
|
||||||
|
COLOR_STARTSCREEN_FONT_LABEL)
|
||||||
|
|
||||||
|
self.screen.blit(message_1, (10, 50))
|
||||||
|
self.screen.blit(message_2, (10, 70))
|
||||||
|
|
||||||
|
# draw buttons and get click state
|
||||||
|
button_start_pressed = self.button_start.draw(self.screen)
|
||||||
|
button_quit_pressed = self.button_quit.draw(self.screen)
|
||||||
|
|
||||||
|
# draw text input box
|
||||||
|
label_input = self.font_label.render("Enter your student name or ID:", True,
|
||||||
|
COLOR_STARTSCREEN_FONT_LABEL)
|
||||||
|
self.screen.blit(label_input, (10, 280))
|
||||||
|
self.text_input_name.draw(self.screen)
|
||||||
|
|
||||||
|
# prepare error message when no input was submitted
|
||||||
|
label_input_error = self.font_label.render("Student not found. Please enter valid name/id.", True,
|
||||||
|
(255, 0, 0))
|
||||||
|
|
||||||
# get all events
|
# get all events
|
||||||
events = pygame.event.get()
|
events = pygame.event.get()
|
||||||
|
|
||||||
|
# react on button clicks
|
||||||
|
if button_start_pressed:
|
||||||
|
self.player_name = self.text_input_name.get_text()
|
||||||
|
|
||||||
|
if self.player_name.strip() != "":
|
||||||
|
print("Spielername:", self.player_name)
|
||||||
|
return "game"
|
||||||
|
else:
|
||||||
|
self.wrong_name = True
|
||||||
|
if button_quit_pressed:
|
||||||
|
return "quit"
|
||||||
|
|
||||||
# check events
|
# check events
|
||||||
for event in events:
|
for event in events:
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
@@ -61,38 +101,11 @@ class Startscreen:
|
|||||||
if self.player_name.strip() != "":
|
if self.player_name.strip() != "":
|
||||||
print("Spielername:", self.player_name)
|
print("Spielername:", self.player_name)
|
||||||
return "game"
|
return "game"
|
||||||
|
else:
|
||||||
|
self.wrong_name = True
|
||||||
|
|
||||||
# set background color
|
if self.wrong_name:
|
||||||
self.screen.fill(COLOR_STARTSCREEN_BACKGROUND)
|
self.screen.blit(label_input_error, (10, 350))
|
||||||
|
|
||||||
# set title and intro/welcome message
|
|
||||||
title = self.font_title.render("SILENT FH", True, COLOR_STARTSCREEN_FONT_TITLE)
|
|
||||||
self.screen.blit(title, (10, 10))
|
|
||||||
message = self.font_label.render("Welcome to FH - Study with purpose", True, COLOR_STARTSCREEN_FONT_LABEL)
|
|
||||||
|
|
||||||
# draw buttons and get click state
|
|
||||||
button_start_pressed = self.button_start.draw(self.screen)
|
|
||||||
button_quit_pressed = self.button_quit.draw(self.screen)
|
|
||||||
|
|
||||||
# draw text input box
|
|
||||||
self.text_input_name.draw(self.screen)
|
|
||||||
|
|
||||||
# react on button clicks
|
|
||||||
if button_start_pressed:
|
|
||||||
return "game"
|
|
||||||
if button_quit_pressed:
|
|
||||||
return "quit"
|
|
||||||
|
|
||||||
# check key down events - exit/quit
|
|
||||||
for event in pygame.event.get():
|
|
||||||
if event.type == pygame.QUIT:
|
|
||||||
return "quit"
|
|
||||||
|
|
||||||
if event.type == pygame.KEYDOWN:
|
|
||||||
if event.key == pygame.K_RETURN:
|
|
||||||
return "game"
|
|
||||||
if event.key == pygame.K_ESCAPE:
|
|
||||||
return "quit"
|
|
||||||
|
|
||||||
return "startscreen"
|
return "startscreen"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user