@@ -4,8 +4,23 @@ extends MarginContainer
4
4
signal block_picked (block : Block )
5
5
6
6
const BlockCategory = preload ("res://addons/block_code/ui/picker/categories/block_category.gd" )
7
+ const BlockDefinition = preload ("res://addons/block_code/code_generation/block_definition.gd" )
7
8
const Util = preload ("res://addons/block_code/ui/util.gd" )
8
9
10
+ const CATEGORY_ORDER_OVERRIDE = {
11
+ "Lifecycle" :
12
+ [
13
+ "ready" ,
14
+ "process" ,
15
+ ],
16
+ "Logic | Conditionals" :
17
+ [
18
+ "if" ,
19
+ "else" ,
20
+ "else_if" ,
21
+ ]
22
+ }
23
+
9
24
var category : BlockCategory
10
25
11
26
@onready var _context := BlockEditorContext .get_default ()
@@ -20,11 +35,25 @@ func _ready():
20
35
if _context .block_script == null :
21
36
return
22
37
23
- for block_definition in _context .block_script .get_blocks_in_category (category ):
38
+ if category == null :
39
+ return
40
+
41
+ var category_order = CATEGORY_ORDER_OVERRIDE .get (category .name )
42
+ var block_definitions = _context .block_script .get_blocks_in_category (category )
43
+ if category_order :
44
+ block_definitions .sort_custom (_sort_blocks_by_list_order .bind (category_order ))
45
+
46
+ for block_definition in block_definitions :
24
47
var block : Block = _context .block_script .instantiate_block (block_definition )
25
48
26
49
block .color = category .color
27
50
block .can_delete = false
28
51
block .drag_started .connect (func (block : Block ): block_picked .emit (block ))
29
52
30
53
_blocks .add_child (block )
54
+
55
+
56
+ static func _sort_blocks_by_list_order (block_definition_a , block_definition_b , name_order : Array ) -> bool :
57
+ var a_order = name_order .find (block_definition_a .name )
58
+ var b_order = name_order .find (block_definition_b .name )
59
+ return a_order >= 0 and a_order < b_order or b_order == - 1
0 commit comments