Skip to content

Commit

Permalink
Add block code demo scene
Browse files Browse the repository at this point in the history
Helps: #196
  • Loading branch information
dylanmccall committed Sep 19, 2024
1 parent 760a579 commit a3b6ce2
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 16 deletions.
5 changes: 4 additions & 1 deletion addons/block_code/ui/block_canvas/block_canvas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ func set_child(n: Node):
func _on_context_changed():
clear_canvas()

var edited_node = EditorInterface.get_inspector().get_edited_object() as Node
var edited_node: Node

if Engine.is_editor_hint():
edited_node = EditorInterface.get_inspector().get_edited_object() as Node

if _context.block_script != _current_block_script:
_window.position = Vector2(0, 0)
Expand Down
9 changes: 7 additions & 2 deletions addons/block_code/ui/block_canvas/block_canvas.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ layout_mode = 2

[node name="Window" type="Control" parent="WindowContainer"]
unique_name_in_owner = true
visible = false
layout_mode = 2
anchors_preset = 0
offset_right = 1152.0
Expand Down Expand Up @@ -60,10 +61,12 @@ theme_override_constants/margin_bottom = 4

[node name="ZoomButton" type="Button" parent="WindowContainer/Overlay/MarginContainer"]
unique_name_in_owner = true
visible = false
modulate = Color(1, 1, 1, 0.470588)
layout_mode = 2
focus_mode = 0
theme_override_font_sizes/font_size = 24
text = "1.0x"

[node name="MouseOverride" type="MarginContainer" parent="."]
unique_name_in_owner = true
Expand All @@ -72,7 +75,6 @@ mouse_filter = 2

[node name="EmptyBox" type="VBoxContainer" parent="."]
unique_name_in_owner = true
visible = false
layout_mode = 2
size_flags_vertical = 4

Expand All @@ -90,7 +92,7 @@ size_flags_vertical = 4
[node name="Label" type="Label" parent="SelectedNodeBox"]
custom_minimum_size = Vector2(200, 0)
layout_mode = 2
text = "Use block coding to create custom behavior and game mechanics for \"{node}\"."
text = "Use block coding to create custom behavior and game mechanics for \"BlockCanvas\"."
horizontal_alignment = 1
autowrap_mode = 2

Expand All @@ -103,6 +105,7 @@ unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 4
theme_type_variation = &"InspectorActionButton"
disabled = true
text = "Add Block Code"
icon = ExtResource("2_710vn")

Expand All @@ -128,13 +131,15 @@ unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 4
theme_type_variation = &"InspectorActionButton"
disabled = true
text = "Open in Editor"

[node name="ReplaceBlockCodeButton" type="Button" parent="SelectedNodeWithBlockCodeBox/ButtonsBox"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 4
theme_type_variation = &"InspectorActionButton"
disabled = true
text = "Override Block Code"
icon = ExtResource("2_710vn")

Expand Down
15 changes: 10 additions & 5 deletions addons/block_code/ui/main_panel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ const VariableDefinition = preload("res://addons/block_code/code_generation/vari
@onready var _drag_manager: DragManager = %DragManager
@onready var _title_bar: TitleBar = %TitleBar
@onready var _delete_node_button: Button = %DeleteNodeButton
@onready var _editor_inspector: EditorInspector = EditorInterface.get_inspector()
@onready var _picker_split: HSplitContainer = %PickerSplit
@onready var _collapse_button: Button = %CollapseButton

@onready var _icon_delete := EditorInterface.get_editor_theme().get_icon("Remove", "EditorIcons")
@onready var _icon_collapse := EditorInterface.get_editor_theme().get_icon("Back", "EditorIcons")
@onready var _icon_expand := EditorInterface.get_editor_theme().get_icon("Forward", "EditorIcons")
@onready var _icon_delete := EditorInterface.get_editor_theme().get_icon("Remove", "EditorIcons") if Engine.is_editor_hint() else null
@onready var _icon_collapse := EditorInterface.get_editor_theme().get_icon("Back", "EditorIcons") if Engine.is_editor_hint() else null
@onready var _icon_expand := EditorInterface.get_editor_theme().get_icon("Forward", "EditorIcons") if Engine.is_editor_hint() else null

const Constants = preload("res://addons/block_code/ui/constants.gd")

Expand Down Expand Up @@ -66,7 +65,10 @@ func _on_show_script_button_pressed():


func _on_delete_node_button_pressed():
var scene_root = EditorInterface.get_edited_scene_root()
var scene_root: Node

if Engine.is_editor_hint():
scene_root = EditorInterface.get_edited_scene_root()

if not scene_root:
return
Expand Down Expand Up @@ -130,6 +132,9 @@ func save_script():
print("No script loaded to save.")
return

if not Engine.is_editor_hint():
return

var scene_node = EditorInterface.get_edited_scene_root()

if not BlockCodePlugin.is_block_code_editable(_context.block_code_node):
Expand Down
9 changes: 5 additions & 4 deletions addons/block_code/ui/main_panel.tscn

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions addons/block_code/ui/title_bar/title_bar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ signal node_name_changed(node_name: String)
@onready var _context := BlockEditorContext.get_default()

@onready var _block_code_icon = load("res://addons/block_code/block_code_node/block_code_node.svg") as Texture2D
@onready var _editor_inspector: EditorInspector = EditorInterface.get_inspector()
@onready var _editor_selection: EditorSelection = EditorInterface.get_selection()
@onready var _node_option_button: OptionButton = %NodeOptionButton


Expand All @@ -34,7 +32,7 @@ func _on_context_changed():
func _update_node_option_button_items():
_node_option_button.clear()

var scene_root = EditorInterface.get_edited_scene_root()
var scene_root = EditorInterface.get_edited_scene_root() if Engine.is_editor_hint() else null

if not scene_root:
return
Expand All @@ -61,6 +59,7 @@ func _get_block_script_index(block_script: BlockScriptSerialization) -> int:


func _on_node_option_button_item_selected(index):
var _editor_selection := EditorInterface.get_selection()
var block_code_node = _node_option_button.get_item_metadata(index) as BlockCode
var parent_node = block_code_node.get_parent() as Node
_editor_selection.clear()
Expand Down
13 changes: 13 additions & 0 deletions block_code_demo.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends Control

@onready var _context := BlockEditorContext.get_default()

@onready var _block_code := %BlockCode


func _ready() -> void:
#var block_script: BlockScriptSerialization =
#block_script.script_inherits = _get_custom_or_native_class(get_parent())
#block_script.generated_script = new_block_script.generated_script.replace("INHERIT_DEFAULT", new_block_script.script_inherits)

_context.set_block_code_node.call_deferred(_block_code)
68 changes: 68 additions & 0 deletions block_code_demo.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[gd_scene load_steps=12 format=3 uid="uid://d2sgdkbau3tfv"]

[ext_resource type="PackedScene" uid="uid://bq37yla8ya707" path="res://addons/block_code/ui/main_panel.tscn" id="1_kvne0"]
[ext_resource type="Script" path="res://block_code_demo.gd" id="1_obq7i"]
[ext_resource type="Texture2D" uid="uid://dr8e0tvfxjy1f" path="res://icon.svg" id="2_liip2"]
[ext_resource type="Script" path="res://addons/block_code/block_code_node/block_code.gd" id="2_x7fcc"]
[ext_resource type="Script" path="res://addons/block_code/serialization/block_serialization_tree.gd" id="3_73e6f"]
[ext_resource type="Script" path="res://addons/block_code/serialization/block_serialization.gd" id="4_1yrvj"]
[ext_resource type="Script" path="res://addons/block_code/serialization/block_script_serialization.gd" id="5_bnd5w"]
[ext_resource type="Script" path="res://addons/block_code/code_generation/variable_definition.gd" id="6_h8s2d"]

[sub_resource type="Resource" id="Resource_oalom"]
script = ExtResource("4_1yrvj")
name = &"ready"
children = Array[ExtResource("4_1yrvj")]([])
arguments = {}

[sub_resource type="Resource" id="Resource_8sqy5"]
script = ExtResource("3_73e6f")
root = SubResource("Resource_oalom")
canvas_position = Vector2(54, 47)

[sub_resource type="Resource" id="Resource_ho2y6"]
script = ExtResource("5_bnd5w")
script_inherits = "Sprite2D"
block_serialization_trees = Array[ExtResource("3_73e6f")]([SubResource("Resource_8sqy5")])
variables = Array[ExtResource("6_h8s2d")]([])
generated_script = "extends Sprite2D"
version = 0

[node name="BlockCodeDemo" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_obq7i")

[node name="VSplitContainer" type="VSplitContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="SubViewportContainer" type="SubViewportContainer" parent="VSplitContainer"]
layout_mode = 2
size_flags_vertical = 3
stretch = true

[node name="SubViewport" type="SubViewport" parent="VSplitContainer/SubViewportContainer"]
handle_input_locally = false
size = Vector2i(1152, 318)
render_target_update_mode = 4

[node name="Sprite2D" type="Sprite2D" parent="VSplitContainer/SubViewportContainer/SubViewport"]
position = Vector2(537, 188)
texture = ExtResource("2_liip2")

[node name="BlockCode" type="Node" parent="VSplitContainer/SubViewportContainer/SubViewport/Sprite2D"]
unique_name_in_owner = true
script = ExtResource("2_x7fcc")
block_script = SubResource("Resource_ho2y6")

[node name="MainPanel" parent="VSplitContainer" instance=ExtResource("1_kvne0")]
layout_mode = 2
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ config_version=5
[application]

config/name="Block Coding Plugin"
run/main_scene="res://addons/block_code/examples/pong_game/pong_game.tscn"
run/main_scene="res://block_code_demo.tscn"
config/features=PackedStringArray("4.3", "GL Compatibility")
config/icon="res://icon.svg"

Expand Down

0 comments on commit a3b6ce2

Please sign in to comment.