Skip to content

Commit 60e74e9

Browse files
committed
Add an empty state for BlockCanvas and Picker
https://phabricator.endlessm.com/T35511
1 parent 5d8c643 commit 60e74e9

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

addons/block_code/ui/block_canvas/block_canvas.gd

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const EXTEND_MARGIN: float = 800
66

77
@onready var _window: Control = %Window
88
@onready var _window_scroll: ScrollContainer = %WindowScroll
9+
@onready var _choose_block_code_label: Label = %ChooseBlockCodeLabel
10+
@onready var _create_block_code_label: Label = %CreateBlockCodeLabel
911

1012
var _block_scenes_by_class = {}
1113

@@ -41,10 +43,27 @@ func set_child(n: Node):
4143
func bsd_selected(bsd: BlockScriptData):
4244
clear_canvas()
4345

46+
_choose_block_code_label.visible = false
47+
_create_block_code_label.visible = false
48+
49+
if not bsd and scene_has_bsd_nodes():
50+
_choose_block_code_label.visible = true
51+
return
52+
elif not bsd and not scene_has_bsd_nodes():
53+
_create_block_code_label.visible = true
54+
return
55+
4456
for tree in bsd.block_trees.array:
4557
load_tree(_window, tree)
4658

4759

60+
func scene_has_bsd_nodes() -> bool:
61+
var scene_root = EditorInterface.get_edited_scene_root()
62+
if not scene_root:
63+
return false
64+
return scene_root.find_children("*", "BlockCode").size() > 0
65+
66+
4867
func clear_canvas():
4968
for child in _window.get_children():
5069
child.queue_free()

addons/block_code/ui/block_canvas/block_canvas.tscn

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@ unique_name_in_owner = true
2424
layout_mode = 2
2525
size_flags_horizontal = 3
2626
mouse_filter = 1
27+
28+
[node name="ChooseBlockCodeLabel" type="Label" parent="."]
29+
unique_name_in_owner = true
30+
visible = false
31+
layout_mode = 2
32+
text = "Choose a BlockCode node in the inspector."
33+
horizontal_alignment = 1
34+
35+
[node name="CreateBlockCodeLabel" type="Label" parent="."]
36+
unique_name_in_owner = true
37+
visible = false
38+
layout_mode = 2
39+
text = "First, add a BlockCode node to the scene."
40+
horizontal_alignment = 1

addons/block_code/ui/picker/picker.gd

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ signal block_picked(block: Block)
88

99

1010
func bsd_selected(bsd: BlockScriptData):
11+
if not bsd:
12+
reset_picker()
13+
return
14+
1115
for class_dict in ProjectSettings.get_global_class_list():
1216
if class_dict.class == bsd.script_inherits:
1317
var script = load(class_dict.path)
@@ -19,10 +23,14 @@ func bsd_selected(bsd: BlockScriptData):
1923
init_picker(CategoryFactory.get_inherited_categories(bsd.script_inherits))
2024

2125

22-
func init_picker(extra_blocks: Array[BlockCategory] = []):
26+
func reset_picker():
2327
for c in _block_list.get_children():
2428
c.queue_free()
2529

30+
31+
func init_picker(extra_blocks: Array[BlockCategory] = []):
32+
reset_picker()
33+
2634
var block_categories := CategoryFactory.get_general_categories()
2735

2836
if extra_blocks.size() > 0:

0 commit comments

Comments
 (0)