mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Use ValueSliders for ShaderEffect and add a transparency background
This commit is contained in:
parent
ab35d324fd
commit
9377ce00b0
|
@ -2,6 +2,7 @@ extends ImageEffect
|
|||
|
||||
var shader: Shader
|
||||
var param_names := [] # String[]
|
||||
var value_slider_tscn := preload("res://src/UI/Nodes/ValueSlider.tscn")
|
||||
|
||||
onready var shader_loaded_label: Label = $VBoxContainer/ShaderLoadedLabel
|
||||
onready var shader_params: BoxContainer = $VBoxContainer/ShaderParams
|
||||
|
@ -15,6 +16,7 @@ func _about_to_show() -> void:
|
|||
preview_image.copy_from(selected_cels)
|
||||
preview_texture.create_from_image(preview_image, 0)
|
||||
preview.texture = preview_texture
|
||||
._about_to_show()
|
||||
|
||||
|
||||
func commit_action(cel: Image, project: Project = Global.current_project) -> void:
|
||||
|
@ -46,7 +48,7 @@ func _on_FileDialog_file_selected(path: String) -> void:
|
|||
|
||||
|
||||
func set_nodes() -> void:
|
||||
preview = $VBoxContainer/Preview
|
||||
preview = $VBoxContainer/AspectRatioContainer/Preview
|
||||
|
||||
|
||||
func change_shader(shader_tmp: Shader, name: String) -> void:
|
||||
|
@ -87,7 +89,8 @@ func change_shader(shader_tmp: Shader, name: String) -> void:
|
|||
if u_type == "float" or u_type == "int":
|
||||
var label := Label.new()
|
||||
label.text = u_name
|
||||
var spinbox := SpinBox.new()
|
||||
label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
var slider: ValueSlider = value_slider_tscn.instance()
|
||||
var min_value := 0.0
|
||||
var max_value := 255.0
|
||||
var step := 1.0
|
||||
|
@ -112,7 +115,7 @@ func change_shader(shader_tmp: Shader, name: String) -> void:
|
|||
step = 0.01
|
||||
|
||||
if u_value != "":
|
||||
spinbox.value = float(u_value)
|
||||
slider.value = float(u_value)
|
||||
else:
|
||||
if range_values_array.size() >= 1:
|
||||
min_value = int(range_values_array[0])
|
||||
|
@ -124,39 +127,42 @@ func change_shader(shader_tmp: Shader, name: String) -> void:
|
|||
step = int(range_values_array[2])
|
||||
|
||||
if u_value != "":
|
||||
spinbox.value = int(u_value)
|
||||
spinbox.min_value = min_value
|
||||
spinbox.max_value = max_value
|
||||
spinbox.step = step
|
||||
spinbox.connect("value_changed", self, "set_shader_param", [u_name])
|
||||
slider.value = int(u_value)
|
||||
slider.min_value = min_value
|
||||
slider.max_value = max_value
|
||||
slider.step = step
|
||||
slider.connect("value_changed", self, "set_shader_param", [u_name])
|
||||
var hbox := HBoxContainer.new()
|
||||
hbox.add_child(label)
|
||||
hbox.add_child(spinbox)
|
||||
hbox.add_child(slider)
|
||||
shader_params.add_child(hbox)
|
||||
elif u_type == "vec2":
|
||||
var label := Label.new()
|
||||
label.text = u_name
|
||||
label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
var vector2 := _vec2str_to_vector2(u_value)
|
||||
var spinbox1 := SpinBox.new()
|
||||
spinbox1.value = vector2.x
|
||||
spinbox1.connect("value_changed", self, "_set_vector2_shader_param", [u_name, true])
|
||||
var spinbox2 := SpinBox.new()
|
||||
spinbox2.value = vector2.y
|
||||
spinbox2.connect("value_changed", self, "_set_vector2_shader_param", [u_name, false])
|
||||
var slider1: ValueSlider = value_slider_tscn.instance()
|
||||
slider1.value = vector2.x
|
||||
slider1.connect("value_changed", self, "_set_vector2_shader_param", [u_name, true])
|
||||
var slider2: ValueSlider = value_slider_tscn.instance()
|
||||
slider2.value = vector2.y
|
||||
slider2.connect("value_changed", self, "_set_vector2_shader_param", [u_name, false])
|
||||
var hbox := HBoxContainer.new()
|
||||
hbox.add_child(label)
|
||||
hbox.add_child(spinbox1)
|
||||
hbox.add_child(spinbox2)
|
||||
hbox.add_child(slider1)
|
||||
hbox.add_child(slider2)
|
||||
shader_params.add_child(hbox)
|
||||
elif u_type == "vec4":
|
||||
if "hint_color" in u_hint:
|
||||
var label := Label.new()
|
||||
label.text = u_name
|
||||
label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
var color := _vec4str_to_color(u_value)
|
||||
var color_button := ColorPickerButton.new()
|
||||
color_button.rect_min_size = Vector2(20, 20)
|
||||
color_button.color = color
|
||||
color_button.connect("color_changed", self, "set_shader_param", [u_name])
|
||||
color_button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
var hbox := HBoxContainer.new()
|
||||
hbox.add_child(label)
|
||||
hbox.add_child(color_button)
|
||||
|
@ -164,6 +170,7 @@ func change_shader(shader_tmp: Shader, name: String) -> void:
|
|||
elif u_type == "sampler2D":
|
||||
var label := Label.new()
|
||||
label.text = u_name
|
||||
label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
var file_dialog := FileDialog.new()
|
||||
file_dialog.mode = FileDialog.MODE_OPEN_FILE
|
||||
file_dialog.access = FileDialog.ACCESS_FILESYSTEM
|
||||
|
@ -174,6 +181,7 @@ func change_shader(shader_tmp: Shader, name: String) -> void:
|
|||
var button := Button.new()
|
||||
button.text = "Load texture"
|
||||
button.connect("pressed", file_dialog, "popup_centered")
|
||||
button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
var hbox := HBoxContainer.new()
|
||||
hbox.add_child(label)
|
||||
hbox.add_child(button)
|
||||
|
@ -182,11 +190,13 @@ func change_shader(shader_tmp: Shader, name: String) -> void:
|
|||
elif u_type == "bool":
|
||||
var label := Label.new()
|
||||
label.text = u_name
|
||||
label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
var checkbox := CheckBox.new()
|
||||
checkbox.text = "On"
|
||||
if u_value == "true":
|
||||
checkbox.pressed = true
|
||||
checkbox.connect("toggled", self, "set_shader_param", [u_name])
|
||||
checkbox.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
var hbox := HBoxContainer.new()
|
||||
hbox.add_child(label)
|
||||
hbox.add_child(checkbox)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://src/UI/Dialogs/ImageEffects/ShaderEffect.gd" type="Script" id=1]
|
||||
[ext_resource path="res://src/UI/TransparentChecker.tscn" type="PackedScene" id=2]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=1]
|
||||
|
||||
|
@ -22,48 +23,58 @@ margin_left = 8.0
|
|||
margin_top = 8.0
|
||||
margin_right = -8.0
|
||||
margin_bottom = -36.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer"]
|
||||
margin_right = 384.0
|
||||
margin_right = 442.0
|
||||
margin_bottom = 31.0
|
||||
text = "This is an experimental feature and may not be included in the stable version"
|
||||
autowrap = true
|
||||
|
||||
[node name="Preview" type="TextureRect" parent="VBoxContainer"]
|
||||
material = SubResource( 1 )
|
||||
[node name="AspectRatioContainer" type="AspectRatioContainer" parent="VBoxContainer"]
|
||||
margin_top = 35.0
|
||||
margin_right = 384.0
|
||||
margin_right = 442.0
|
||||
margin_bottom = 235.0
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="Preview" type="TextureRect" parent="VBoxContainer/AspectRatioContainer"]
|
||||
material = SubResource( 1 )
|
||||
margin_left = 121.0
|
||||
margin_right = 321.0
|
||||
margin_bottom = 200.0
|
||||
rect_min_size = Vector2( 200, 200 )
|
||||
expand = true
|
||||
stretch_mode = 6
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="TransparentChecker" parent="VBoxContainer/AspectRatioContainer/Preview" instance=ExtResource( 2 )]
|
||||
show_behind_parent = true
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_right = 0.0
|
||||
margin_bottom = 0.0
|
||||
|
||||
[node name="ChooseShader" type="Button" parent="VBoxContainer"]
|
||||
margin_top = 239.0
|
||||
margin_right = 384.0
|
||||
margin_right = 442.0
|
||||
margin_bottom = 259.0
|
||||
mouse_default_cursor_shape = 2
|
||||
text = "Choose Shader"
|
||||
|
||||
[node name="ShaderLoadedLabel" type="Label" parent="VBoxContainer"]
|
||||
margin_top = 263.0
|
||||
margin_right = 384.0
|
||||
margin_right = 442.0
|
||||
margin_bottom = 277.0
|
||||
text = "No shader loaded!"
|
||||
autowrap = true
|
||||
|
||||
[node name="ShaderParams" type="VBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 281.0
|
||||
margin_right = 384.0
|
||||
margin_right = 442.0
|
||||
margin_bottom = 281.0
|
||||
|
||||
[node name="FileDialog" type="FileDialog" parent="."]
|
||||
margin_left = 8.0
|
||||
margin_top = 8.0
|
||||
margin_right = 392.0
|
||||
margin_right = 450.0
|
||||
margin_bottom = 289.0
|
||||
window_title = "Open a File"
|
||||
resizable = true
|
||||
|
@ -71,8 +82,6 @@ mode = 0
|
|||
access = 2
|
||||
filters = PoolStringArray( "*shader; Godot Shader File" )
|
||||
show_hidden_files = true
|
||||
current_dir = "/"
|
||||
current_path = "/"
|
||||
|
||||
[connection signal="pressed" from="VBoxContainer/ChooseShader" to="." method="_on_ChooseShader_pressed"]
|
||||
[connection signal="file_selected" from="FileDialog" to="." method="_on_FileDialog_file_selected"]
|
||||
|
|
Loading…
Reference in a new issue