Skip to content

Commit 8381962

Browse files
authored
Merge pull request #404 from DoomTas3r/simple-to-string-block
Adds to_string block with optional types
2 parents 3a04120 + dac4d63 commit 8381962

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[gd_resource type="Resource" load_steps=4 format=3 uid="uid://bfugvntm6mdjm"]
2+
3+
[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_i1nej"]
4+
[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="2_xs7a8"]
5+
6+
[sub_resource type="Resource" id="Resource_ie4sg"]
7+
script = ExtResource("1_i1nej")
8+
selected = 0
9+
items = ["0", "true", "Vector2(0, 0)", "Vector3(0, 0, 0)", "Color(0, 0, 0, 1)", "Object(Object, \"script\": null)"]
10+
11+
[resource]
12+
script = ExtResource("2_xs7a8")
13+
name = &"to_string"
14+
target_node_class = ""
15+
description = "Converts [i]parameter[/i] to a [b]String[/b]"
16+
category = "Log"
17+
type = 3
18+
variant_type = 4
19+
display_template = "{parameter: NIL} to string"
20+
code_template = "str({{parameter}})"
21+
defaults = {
22+
"parameter": SubResource("Resource_ie4sg")
23+
}
24+
signal_name = ""
25+
is_advanced = true

addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ signal drag_started(offset: Vector2)
66
const Constants = preload("res://addons/block_code/ui/constants.gd")
77
const OptionData = preload("res://addons/block_code/code_generation/option_data.gd")
88
const Types = preload("res://addons/block_code/types/types.gd")
9+
const Option_Theme = preload("res://addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn::StyleBoxFlat_7m75r")
910

1011
signal modified
1112

@@ -286,6 +287,24 @@ func _switch_input(node: Node):
286287
c.visible = c == node
287288
_background.visible = node not in [_option_input, null]
288289
_background.is_pointy_value = node == _bool_input
290+
if option_data:
291+
_option_input.add_theme_stylebox_override("focus", Option_Theme)
292+
_option_input.add_theme_stylebox_override("hover", Option_Theme)
293+
_option_input.add_theme_stylebox_override("pressed", Option_Theme)
294+
_option_input.add_theme_stylebox_override("normal", Option_Theme)
295+
var raw_input = get_raw_input()
296+
var data = str_to_var("" if raw_input == null or raw_input is Block else raw_input)
297+
if typeof(data):
298+
var empty_theme = StyleBoxEmpty.new()
299+
_option_input.add_theme_stylebox_override("focus", empty_theme)
300+
_option_input.add_theme_stylebox_override("hover", empty_theme)
301+
_option_input.add_theme_stylebox_override("pressed", empty_theme)
302+
_option_input.add_theme_stylebox_override("normal", empty_theme)
303+
variant_type = typeof(data)
304+
_background.visible = true
305+
_background.is_pointy_value = variant_type == TYPE_BOOL
306+
snap_point.visible = true
307+
snap_point.variant_type = variant_type
289308

290309

291310
func _update_option_input(current_value: Variant = null):
@@ -350,6 +369,7 @@ func _update_background_color(new_color):
350369
func _on_option_input_item_selected(index):
351370
if not editable:
352371
return
372+
_update_visible_input()
353373
modified.emit()
354374

355375

0 commit comments

Comments
 (0)