Skip to content

Commit

Permalink
Merge pull request #4 from Jummit/custom-margin
Browse files Browse the repository at this point in the history
Adds a slider to configure the object margin
  • Loading branch information
Zylann committed Jun 26, 2021
2 parents da381f6 + b624123 commit bbce138
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
5 changes: 5 additions & 0 deletions addons/zylann.scatter/tools/palette.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ signal pattern_added(path)
signal pattern_removed(path)

onready var _item_list : ItemList = get_node("VBoxContainer/ItemList")
onready var _margin_spin_box : SpinBox = get_node("VBoxContainer/MarginContainer/MarginSpinBox")

var _file_dialog = null
var _preview_provider : EditorResourcePreview = null
Expand Down Expand Up @@ -96,6 +97,10 @@ func _on_ItemList_multi_selected(_index, _selected):
emit_signal("patterns_selected", selected)


func get_configured_margin():
return _margin_spin_box.value


func _on_AddButton_pressed():
_file_dialog.popup_centered_ratio(0.7)

Expand Down
36 changes: 30 additions & 6 deletions addons/zylann.scatter/tools/palette.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -874.0
rect_min_size = Vector2( 150, 0 )
focus_mode = 2
rect_min_size = Vector2( 210, 0 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
Expand All @@ -25,7 +24,7 @@ __meta__ = {
}

[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_right = 142.0
margin_right = 202.0
margin_bottom = 20.0

[node name="AddButton" type="Button" parent="VBoxContainer/HBoxContainer"]
Expand All @@ -41,11 +40,36 @@ text = "Remove"

[node name="ItemList" type="ItemList" parent="VBoxContainer"]
margin_top = 24.0
margin_right = 142.0
margin_bottom = 592.0
mouse_filter = 1
margin_right = 202.0
margin_bottom = 564.0
size_flags_vertical = 3
select_mode = 1

[node name="MarginContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 568.0
margin_right = 202.0
margin_bottom = 592.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="MarginLabel" type="Label" parent="VBoxContainer/MarginContainer"]
margin_top = 5.0
margin_right = 99.0
margin_bottom = 19.0
size_flags_horizontal = 3
text = "Object margin:"
align = 1

[node name="MarginSpinBox" type="SpinBox" parent="VBoxContainer/MarginContainer"]
margin_left = 103.0
margin_right = 202.0
margin_bottom = 24.0
size_flags_horizontal = 3
max_value = 10.0
step = 0.01
allow_greater = true

[connection signal="pressed" from="VBoxContainer/HBoxContainer/AddButton" to="." method="_on_AddButton_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/RemoveButton" to="." method="_on_RemoveButton_pressed"]
[connection signal="multi_selected" from="VBoxContainer/ItemList" to="." method="_on_ItemList_multi_selected"]
2 changes: 1 addition & 1 deletion addons/zylann.scatter/tools/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func _physics_process(delta):
var too_close = false
if len(_placed_instances) != 0:
var last_placed_transform = _placed_instances[-1].global_transform
if last_placed_transform.origin.distance_to(pos) < _pattern_margin:
if last_placed_transform.origin.distance_to(pos) < _pattern_margin + _palette.get_configured_margin():
too_close = true

if not too_close:
Expand Down

0 comments on commit bbce138

Please sign in to comment.