@@ -21,20 +21,39 @@ const MAX_SIZE = 128
2121var _index = LEVELS .find (GlobalScene .get_param ("level" ))
2222var _level : ComparisonSort
2323var _size = GlobalScene .get_param ("size" , ArrayModel .DEFAULT_SIZE )
24+ var _data_type = ArrayModel .DATA_TYPES .RANDOM_UNIQUE
2425
2526func _ready ():
27+ var types = $ Level/Right/Display/TypesContainer/Types
28+ for type in ArrayModel .DATA_TYPES :
29+ var button = Button .new ()
30+ button .text = type .replace ("_" , " " )
31+ button .connect ("pressed" , self , "_on_Button_pressed" , [type ])
32+ types .add_child (button )
33+ var top = types .get_child (0 )
34+ var bottom = types .get_child (types .get_child_count () - 1 )
35+ top .focus_neighbour_top = bottom .get_path ()
36+ bottom .focus_neighbour_bottom = top .get_path ()
37+ _reload ()
38+
39+ func _reload ():
40+ $ NamesContainer/Names/Current .grab_focus ()
2641 if _index == - 1 :
2742 _index = 0
28- _level = LEVELS [_index ].new (ArrayModel .new (_size ))
43+ _level = LEVELS [_index ].new (ArrayModel .new (_size , _data_type ))
2944 _level .connect ("done" , self , "_on_ComparisonSort_done" )
45+ _load_scores (_level )
46+ # Load level information
3047 $ NamesContainer/Names/Current .text = _level .NAME
31- for child in $ Level/Right/Display .get_children ():
32- child .queue_free ()
33- $ Level/Right/Display .add_child (ArrayView .new (_level ))
34- $ Timer .start ()
3548 $ Level/Left/Code .text = _level .DESCRIPTION
3649 $ Level/Right/Info/ControlsContainer/Controls .text = _level .CONTROLS
37- _load_scores (_level )
50+ var view = $ Level/Right/Display/ArrayView
51+ $ Level/Right/Display .remove_child (view )
52+ view .queue_free ()
53+ view = ArrayView .new (_level )
54+ view .name = "ArrayView"
55+ $ Level/Right/Display .add_child (view )
56+ $ Timer .start ()
3857
3958func _load_scores (level ):
4059 var data = $ Level/Right/Info/ScoresContainer/Scores/Data
@@ -52,7 +71,7 @@ func _switch_level(index):
5271 _index = 0
5372 else :
5473 _index = index
55- _ready ()
74+ _reload ()
5675
5776func _input (event ):
5877 if event .is_action_pressed ("ui_cancel" ):
@@ -63,23 +82,38 @@ func _input(event):
6382 _switch_level (_index + 1 )
6483 if event .is_action_pressed ("bigger" ):
6584 _size = min (_size * 2 , MAX_SIZE )
66- _ready ()
85+ _reload ()
6786 if event .is_action_pressed ("smaller" ):
6887 _size = max (_size / 2 , MIN_SIZE )
69- _ready ()
88+ _reload ()
7089 if event .is_action_pressed ("faster" ):
7190 $ Timer .wait_time = max ($ Timer .wait_time / 2 , MIN_WAIT )
7291 if event .is_action_pressed ("slower" ):
7392 $ Timer .wait_time = min ($ Timer .wait_time * 2 , MAX_WAIT )
74- if event .is_action_pressed ("ui_accept" ):
75- GlobalScene .change_scene ("res://scenes/play.tscn" ,
76- {"level" : LEVELS [_index ], "size" : _size })
93+ if event .is_action_pressed ("change_data" ):
94+ AudioServer .set_bus_mute (AudioServer .get_bus_index ("Master" ), true )
95+ $ Level/Right/Display/ArrayView .hide ()
96+ $ Level/Right/Display/TypesContainer .show ()
97+ $ Timer .stop ()
98+ $ Level/Right/Display/TypesContainer/Types .get_child (0 ).grab_focus ()
7799
78100func _on_ComparisonSort_done ():
79101 $ Timer .stop ()
80102 yield (get_tree ().create_timer (1 ), "timeout" )
81103 if _level .array .is_sorted ():
82- _ready ()
104+ _reload ()
83105
84106func _on_Timer_timeout ():
85107 _level .next (null )
108+
109+ func _on_Current_pressed ():
110+ GlobalScene .change_scene ("res://scenes/play.tscn" ,
111+ {"level" : LEVELS [_index ], "size" : _size })
112+
113+ func _on_Button_pressed (data_type ):
114+ AudioServer .set_bus_mute (AudioServer .get_bus_index ("Master" ), false )
115+ $ Level/Right/Display/TypesContainer .hide ()
116+ $ Level/Right/Display/ArrayView .show ()
117+ $ Timer .start ()
118+ _data_type = ArrayModel .DATA_TYPES [data_type ]
119+ _reload ()
0 commit comments