@@ -10,32 +10,44 @@ const LEVELS = [
1010const MIN_WAIT = 1.0 / 32 # Should be greater than maximum frame time
1111const MAX_WAIT = 4
1212const MIN_SIZE = 8
13- const MAX_SIZE = 128
13+ const MAX_SIZE = 256
1414
1515var _level = LEVELS [0 ].new (ArrayModel .new (
1616 GlobalScene .get_param ("size" , ArrayModel .DEFAULT_SIZE )))
1717
1818func _ready ():
19+ var buttons = $ LevelsBorder/Levels/LevelsContainer/Buttons
1920 for level in LEVELS :
2021 var button = Button .new ()
2122 button .text = level .NAME
2223 button .align = Button .ALIGN_LEFT
2324 button .connect ("focus_entered" , self , "_on_Button_focus_entered" )
2425 button .connect ("pressed" , self , "_on_Button_pressed" , [level ])
25- $ LevelsBorder/Levels .add_child (button )
26- # Autofocus last played level
27- if GlobalScene .get_param ("level" ) == level :
26+ buttons .add_child (button )
27+ var score = Label .new ()
28+ score .align = Label .ALIGN_RIGHT
29+ $ LevelsBorder/Levels/LevelsContainer/Scores .add_child (score )
30+ # Autofocus last played level
31+ for button in buttons .get_children ():
32+ if button .text == _level .NAME :
2833 button .grab_focus ()
29- var top_button = $ LevelsBorder/Levels .get_children ()[0 ]
30- var bottom_button = $ LevelsBorder/Levels .get_children ()[- 1 ]
34+ var top_button = buttons .get_children ()[0 ]
35+ var bottom_button = buttons .get_children ()[- 1 ]
3136 # Allow looping from ends of list
3237 top_button .focus_neighbour_top = bottom_button .get_path ()
3338 bottom_button .focus_neighbour_bottom = top_button .get_path ()
34- # If no last played level, autofocus first level
35- if GlobalScene .get_param ("level" ) == null :
36- top_button .grab_focus ()
3739
3840func _on_Button_focus_entered (size = _level .array .size ):
41+ # Update high scores
42+ var buttons = $ LevelsBorder/Levels/LevelsContainer/Buttons
43+ var scores = $ LevelsBorder/Levels/LevelsContainer/Scores
44+ var save = GlobalScene .read_save ()
45+ for i in range (LEVELS .size ()):
46+ var name = buttons .get_child (i ).text
47+ if name in save and str (size ) in save [name ]:
48+ scores .get_child (i ).text = "%.3f " % save [name ][str (size )]
49+ else :
50+ scores .get_child (i ).text = "INF"
3951 # Pause a bit to show completely sorted array
4052 if _level .array .is_sorted ():
4153 $ Timer .stop ()
0 commit comments