6
6
7
7
import pygame
8
8
9
- from ..constants import BKG_COLOR , CIRCLE_XY , FRG_COLOR , HALF_RES , INTERNAL_RES , GameStateID
10
- from .renderer import Button , TextRender
9
+ from ..constants import BKG_COLOR , CIRCLE_XY , FRG_COLOR , HALF_RES , INTERNAL_RES , Difficulty , GameStateID
10
+ from .renderer import Button , TextInput , TextRender
11
11
from .state import State
12
12
13
13
@@ -19,6 +19,9 @@ def __init__(self, game) -> None:
19
19
self .font : pygame .font .Font = game .font_sm
20
20
super ().__init__ (game )
21
21
22
+ self ._cmdr_name = "Jameson"
23
+ self ._cmdr_input = TextInput (55 , 20 , 80 , self .font )
24
+ self .sprite_group = pygame .sprite .Group (self ._cmdr_input )
22
25
self ._curr_difficulty = 2
23
26
self ._curr_points = 16
24
27
self ._curr_pilot = 1
@@ -68,6 +71,25 @@ def handle_events(self, event: pygame.event) -> None:
68
71
self .game .current_state = GameStateID .SPLASH
69
72
if event .key == pygame .K_RETURN :
70
73
self .game .current_state = GameStateID .SYSTEM_INFO
74
+ if event .type == pygame .MOUSEBUTTONDOWN and event .button == 1 :
75
+ for index , button in enumerate (self ._buttons ):
76
+ if button .is_clicked (event .pos ) and index < 2 :
77
+ if button .text == "+" :
78
+ self ._curr_difficulty += 1
79
+ elif button .text == "-" :
80
+ self ._curr_difficulty -= 1
81
+ else :
82
+ raise ValueError (f"Invalid button text! Expected '+' or '-' but got { button .text } " )
83
+ elif button .is_clicked (event .pos ) and index >= 2 :
84
+ if button .text == "+" :
85
+ self ._curr_points -= 1
86
+ self ._curr_values [index // 2 ] += 1
87
+ elif button .text == "-" :
88
+ self ._curr_points += 1
89
+ self ._curr_values [index // 2 ] -= 1
90
+ else :
91
+ raise ValueError (f"Invalid button text! Expected '+' or '-' but got { button .text } " )
92
+ self .sprite_group .update (event )
71
93
72
94
def update (self , actions ) -> None :
73
95
pass
@@ -114,6 +136,9 @@ def render(self, canvas: pygame.Surface) -> pygame.Surface:
114
136
button .draw (canvas )
115
137
116
138
# Draw the current values
139
+ self .sprite_group .draw (canvas )
140
+ difficulty_text = TextRender (Difficulty .name (self ._curr_difficulty ), (HALF_RES , 40 ), self .font )
141
+ difficulty_text .draw (canvas )
117
142
for idx , value in enumerate (self ._curr_values ):
118
143
value_text = TextRender (str (value ), (HALF_RES , 65 + (idx * 14 )), self .font )
119
144
value_text .draw (canvas )
0 commit comments