From e7a70af6907cba6960f10783fc04a516f7901d44 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Wed, 6 Nov 2019 08:31:38 +0100 Subject: [PATCH] Filtered unwanted mouse events in float editor and updated shader parameter editor --- addons/material_maker/widgets/float_edit.gd | 8 +- .../widgets/node_editor/parameter_float.gd | 17 +++- .../widgets/node_editor/parameter_float.tscn | 77 ++++++++++--------- 3 files changed, 61 insertions(+), 41 deletions(-) diff --git a/addons/material_maker/widgets/float_edit.gd b/addons/material_maker/widgets/float_edit.gd index d6d7259..436ccff 100644 --- a/addons/material_maker/widgets/float_edit.gd +++ b/addons/material_maker/widgets/float_edit.gd @@ -7,6 +7,7 @@ export var min_value : float = 0.0 setget set_min_value export var max_value : float = 1.0 setget set_max_value export var step : float = 0.0 setget set_step +var sliding : bool = false var start_position : float var start_value : float @@ -45,9 +46,12 @@ func _on_LineEdit_gui_input(event : InputEvent) -> void: if event.is_pressed(): start_position = event.position.x start_value = value - elif event is InputEventMouseMotion and event.button_mask == BUTTON_MASK_LEFT: + sliding = true + else: + sliding = false + elif sliding and event is InputEventMouseMotion and event.button_mask == BUTTON_MASK_LEFT: var delta : float = event.position.x-start_position - var v : float = clamp(start_value+sign(delta)*pow(abs(delta)*0.005, 2)*abs(max_value - min_value), min_value, max_value) + var v : float = start_value+sign(delta)*pow(abs(delta)*0.005, 2)*abs(max_value - min_value) if step != 0: v = min_value+floor((v - min_value)/step)*step set_value(v) diff --git a/addons/material_maker/widgets/node_editor/parameter_float.gd b/addons/material_maker/widgets/node_editor/parameter_float.gd index e5c93fd..fed7579 100644 --- a/addons/material_maker/widgets/node_editor/parameter_float.gd +++ b/addons/material_maker/widgets/node_editor/parameter_float.gd @@ -9,18 +9,27 @@ func get_model_data() -> Dictionary: default = $Default.value, } - if $SpinBox.pressed: - data.widget = "spinbox" - return data func set_model_data(data) -> void: if data.has("min"): $Min.value = data.min + $Default.min_value = data.min if data.has("max"): $Max.value = data.max + $Default.max_value = data.max if data.has("step"): $Step.value = data.step + $Default.step = data.step if data.has("default"): $Default.value = data.default - $SpinBox.pressed = ( data.has("widget") && data.widget == "spinbox" ) + + +func _on_Min_value_changed(v : float) -> void: + $Default.min_value = v + +func _on_Max_value_changed(v : float) -> void: + $Default.max_value = v + +func _on_Step_value_changed(v : float) -> void: + $Default.step = v diff --git a/addons/material_maker/widgets/node_editor/parameter_float.tscn b/addons/material_maker/widgets/node_editor/parameter_float.tscn index 7e6ba3e..13f21c0 100644 --- a/addons/material_maker/widgets/node_editor/parameter_float.tscn +++ b/addons/material_maker/widgets/node_editor/parameter_float.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_float.gd" type="Script" id=1] +[ext_resource path="res://addons/material_maker/widgets/float_edit.tscn" type="PackedScene" id=2] [node name="float" type="HBoxContainer"] margin_right = 547.0 @@ -13,67 +14,73 @@ margin_right = 28.0 margin_bottom = 19.0 text = "Min:" -[node name="Min" type="SpinBox" parent="."] +[node name="Min" parent="." instance=ExtResource( 2 )] +anchor_left = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 margin_left = 32.0 -margin_right = 106.0 +margin_right = 90.0 margin_bottom = 24.0 +text = "0" +value = 0.0 min_value = -65536.0 max_value = 65536.0 step = 0.005 -allow_greater = true -allow_lesser = true [node name="LabelMax" type="Label" parent="."] -margin_left = 110.0 +margin_left = 94.0 margin_top = 5.0 -margin_right = 140.0 +margin_right = 124.0 margin_bottom = 19.0 text = "Max:" -[node name="Max" type="SpinBox" parent="."] -margin_left = 144.0 -margin_right = 218.0 +[node name="Max" parent="." instance=ExtResource( 2 )] +anchor_left = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 128.0 +margin_right = 186.0 margin_bottom = 24.0 +text = "1" +value = 1.0 min_value = -65536.0 max_value = 65536.0 step = 0.005 -allow_greater = true -allow_lesser = true [node name="LabelStep" type="Label" parent="."] -margin_left = 222.0 +margin_left = 190.0 margin_top = 5.0 -margin_right = 254.0 +margin_right = 222.0 margin_bottom = 19.0 text = "Step:" -[node name="Step" type="SpinBox" parent="."] -margin_left = 258.0 -margin_right = 332.0 +[node name="Step" parent="." instance=ExtResource( 2 )] +anchor_left = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 226.0 +margin_right = 284.0 margin_bottom = 24.0 +text = "0.1" +value = 0.1 +max_value = 10.0 step = 0.005 -allow_greater = true -allow_lesser = true [node name="LabelDefault" type="Label" parent="."] -margin_left = 336.0 +margin_left = 288.0 margin_top = 5.0 -margin_right = 386.0 +margin_right = 338.0 margin_bottom = 19.0 text = "Default:" -[node name="Default" type="SpinBox" parent="."] -margin_left = 390.0 -margin_right = 464.0 +[node name="Default" parent="." instance=ExtResource( 2 )] +anchor_left = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 342.0 +margin_right = 400.0 margin_bottom = 24.0 -min_value = -65536.0 -max_value = 65536.0 -step = 0.0 -allow_greater = true -allow_lesser = true - -[node name="SpinBox" type="CheckBox" parent="."] -margin_left = 468.0 -margin_right = 547.0 -margin_bottom = 24.0 -text = "SpinBox" +step = 0.1 +[connection signal="value_changed" from="Min" to="." method="_on_Min_value_changed"] +[connection signal="value_changed" from="Max" to="." method="_on_Max_value_changed"] +[connection signal="value_changed" from="Step" to="." method="_on_Step_value_changed"]