@@ -21,18 +21,17 @@ def render(self, *args, **kwargs):
2121 if new_date != self ._date :
2222 self .image .fill ((0 , 0 , 0 ))
2323 pygame .draw .line (self .image , (95 , 255 , 177 ), (5 , 15 ), (5 , 35 ), 2 )
24- pygame .draw .line (self .image , (95 , 255 , 177 ), (5 , 15 ), (config .WIDTH - 124 , 15 ), 2 )
25- pygame .draw .line (self .image , (95 , 255 , 177 ), (config .WIDTH - 124 , 15 ), (config .WIDTH - 124 , 35 ), 2 )
26- pygame .draw .line (self .image , (95 , 255 , 177 ), (config .WIDTH - 120 , 15 ), (config .WIDTH - 13 , 15 ), 2 )
24+ pygame .draw .line (self .image , (95 , 255 , 177 ), (5 , 15 ), (config .WIDTH - 154 , 15 ), 2 )
25+ pygame .draw .line (self .image , (95 , 255 , 177 ), (config .WIDTH - 154 , 15 ), (config .WIDTH - 154 , 35 ), 2 )
26+ pygame .draw .line (self .image , (95 , 255 , 177 ), (config .WIDTH - 148 , 15 ), (config .WIDTH - 13 , 15 ), 2 )
2727 pygame .draw .line (self .image , (95 , 255 , 177 ), (config .WIDTH - 13 , 15 ), (config .WIDTH - 13 , 35 ), 2 )
2828
29- basicFont = pygame .font .SysFont (None , 17 )
30- text = basicFont .render (" %s " % self .headline , True , (105 , 251 , 187 ), (0 , 0 , 0 ))
29+ text = config .FONTS [14 ].render (" %s " % self .headline , True , (105 , 251 , 187 ), (0 , 0 , 0 ))
3130 self .image .blit (text , (26 , 8 ))
32- text = basicFont .render (self .title , True , (95 , 255 , 177 ), (0 , 0 , 0 ))
33- self .image .blit (text , ((config .WIDTH - 124 ) - text .get_width () - 10 , 19 ))
34- text = basicFont .render (self ._date , True , (95 , 255 , 177 ), (0 , 0 , 0 ))
35- self .image .blit (text , ((config .WIDTH - 111 ), 19 ))
31+ text = config . FONTS [ 14 ] .render (self .title , True , (95 , 255 , 177 ), (0 , 0 , 0 ))
32+ self .image .blit (text , ((config .WIDTH - 154 ) - text .get_width () - 10 , 19 ))
33+ text = config . FONTS [ 14 ] .render (self ._date , True , (95 , 255 , 177 ), (0 , 0 , 0 ))
34+ self .image .blit (text , ((config .WIDTH - 141 ), 19 ))
3635 self ._date = new_date
3736
3837 super (Header , self ).update (* args , ** kwargs )
@@ -57,11 +56,15 @@ def select(self, module):
5756 pygame .draw .line (self .image , (95 , 255 , 177 ), (5 , 20 ), (config .WIDTH - 13 , 20 ), 2 )
5857 pygame .draw .line (self .image , (95 , 255 , 177 ), (config .WIDTH - 13 , 2 ), (config .WIDTH - 13 , 20 ), 2 )
5958
60- offset = 50
59+ offset = 20
6160 for m in self .menu :
62- basicFont = pygame .font .SysFont (None , 16 )
63- text = basicFont .render (" %s " % m , True , (105 , 255 , 187 ), (0 , 0 , 0 ))
64- text_width = text .get_size ()[0 ]
61+ padding = 1
62+ text_width = 0
63+ while text_width < 54 :
64+ spaces = " " .join ([" " for x in range (padding )])
65+ text = config .FONTS [12 ].render ("%s%s%s" % (spaces , m , spaces ), True , (105 , 255 , 187 ), (0 , 0 , 0 ))
66+ text_width = text .get_size ()[0 ]
67+ padding += 1
6568 #print(m+" : "+str(text.get_size()))
6669 if m == self .selected :
6770 pygame .draw .rect (self .image , (95 , 255 , 177 ), (offset - 2 , 6 , (text_width + 3 ), 26 ), 2 )
@@ -70,6 +73,48 @@ def select(self, module):
7073 offset = offset + 120 + (text_width - 100 )
7174
7275
76+ class Menu (game .Entity ):
77+
78+ def __init__ (self , width , items = [], callbacks = [], selected = 0 ):
79+ super (Menu , self ).__init__ ((width , config .HEIGHT - 80 ))
80+ self .items = items
81+ self .callbacks = callbacks
82+ self .selected = 0
83+ self .select (selected )
84+
85+ if config .SOUND_ENABLED :
86+ self .dial_move_sfx = pygame .mixer .Sound ('sounds/dial_move.ogg' )
87+
88+ def select (self , item ):
89+ self .selected = item
90+ self .redraw ()
91+ if len (self .callbacks ) > item and self .callbacks [item ]:
92+ self .callbacks [item ]()
93+
94+ def handle_action (self , action ):
95+ if action == "dial_up" :
96+ if self .selected > 0 :
97+ if config .SOUND_ENABLED :
98+ self .dial_move_sfx .play ()
99+ self .select (self .selected - 1 )
100+ if action == "dial_down" :
101+ if self .selected < len (self .items ) - 1 :
102+ if config .SOUND_ENABLED :
103+ self .dial_move_sfx .play ()
104+ self .select (self .selected + 1 )
105+
106+ def redraw (self ):
107+ self .image .fill ((0 , 0 , 0 ))
108+ offset = 5
109+ for i in range (len (self .items )):
110+ text = config .FONTS [14 ].render (" %s " % self .items [i ], True , (105 , 255 , 187 ), (0 , 0 , 0 ))
111+ if i == self .selected :
112+ selected_rect = (5 , offset - 2 , text .get_size ()[0 ] + 6 , text .get_size ()[1 ] + 3 )
113+ pygame .draw .rect (self .image , (95 , 255 , 177 ), selected_rect , 2 )
114+ self .image .blit (text , (10 , offset ))
115+ offset += text .get_size ()[1 ] + 6
116+
117+
73118class Scanlines (game .Entity ):
74119
75120 def __init__ (self , width , height , gap , speed , colours , full_push = False ):
0 commit comments