1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Move the dynamics-related code into a new script

This also fixes the dynamics previews not working, as `_input()` is now handled locally in the dynamics popup panel.
This commit is contained in:
Emmanouil Papadeas 2024-07-19 19:39:13 +03:00
parent 506004b2a3
commit 64ced35bac
4 changed files with 124 additions and 119 deletions

View file

@ -39,7 +39,7 @@ var _circle_tool_shortcut: Array[Vector2i]
func _ready() -> void:
super._ready()
Global.global_tool_options.dynamics_changed.connect(_reset_dynamics)
Global.global_tool_options.dynamics_panel.dynamics_changed.connect(_reset_dynamics)
Tools.color_changed.connect(_on_Color_changed)
Global.brushes_popup.brush_removed.connect(_on_Brush_removed)

View file

@ -0,0 +1,112 @@
extends PopupPanel
signal dynamics_changed
enum { ALPHA, SIZE }
@onready var alpha_pressure_button: Button = $"%AlphaPressureButton"
@onready var alpha_velocity_button: Button = $"%AlphaVelocityButton"
@onready var size_pressure_button: Button = $"%SizePressureButton"
@onready var size_velocity_button: Button = $"%SizeVelocityButton"
@onready var pressure_preview: ProgressBar = $"%PressurePreview"
@onready var velocity_preview: ProgressBar = $"%VelocityPreview"
@onready var limits_header: HBoxContainer = %LimitsHeader
@onready var thresholds_header: HBoxContainer = %ThresholdsHeader
@onready var alpha_group := alpha_pressure_button.button_group
@onready var size_group := size_pressure_button.button_group
func _ready() -> void:
alpha_pressure_button.toggled.connect(
_on_dynamics_toggled.bind(alpha_pressure_button, ALPHA, Tools.Dynamics.PRESSURE)
)
alpha_velocity_button.toggled.connect(
_on_dynamics_toggled.bind(alpha_velocity_button, ALPHA, Tools.Dynamics.VELOCITY)
)
size_pressure_button.toggled.connect(
_on_dynamics_toggled.bind(size_pressure_button, SIZE, Tools.Dynamics.PRESSURE)
)
size_velocity_button.toggled.connect(
_on_dynamics_toggled.bind(size_velocity_button, SIZE, Tools.Dynamics.VELOCITY)
)
func _input(event: InputEvent) -> void:
pressure_preview.value = 0
velocity_preview.value = 0
if event is InputEventMouseMotion:
pressure_preview.value = event.pressure
velocity_preview.value = event.velocity.length() / Tools.mouse_velocity_max
func _on_dynamics_toggled(
button_pressed: bool, button: BaseButton, property: int, dynamic: Tools.Dynamics
) -> void:
var final_dynamic := dynamic
if not button.button_pressed:
final_dynamic = Tools.Dynamics.NONE
match property:
ALPHA:
Tools.dynamics_alpha = final_dynamic
SIZE:
Tools.dynamics_size = final_dynamic
var has_alpha_dynamic := Tools.dynamics_alpha != Tools.Dynamics.NONE
var has_size_dynamic := Tools.dynamics_size != Tools.Dynamics.NONE
var has_pressure_dynamic := (
Tools.dynamics_alpha == Tools.Dynamics.PRESSURE
or Tools.dynamics_size == Tools.Dynamics.PRESSURE
)
var has_velocity_dynamic := (
Tools.dynamics_alpha == Tools.Dynamics.VELOCITY
or Tools.dynamics_size == Tools.Dynamics.VELOCITY
)
limits_header.visible = has_alpha_dynamic or has_size_dynamic
thresholds_header.visible = limits_header.visible
get_tree().set_group(&"VisibleOnAlpha", "visible", has_alpha_dynamic)
get_tree().set_group(&"VisibleOnSize", "visible", has_size_dynamic)
get_tree().set_group(&"VisibleOnPressure", "visible", has_pressure_dynamic)
get_tree().set_group(&"VisibleOnVelocity", "visible", has_velocity_dynamic)
var texture_button: TextureRect = button.get_node("TextureRect")
var file_name := "check.png"
if !button.button_pressed:
file_name = "uncheck.png"
Global.change_button_texturerect(texture_button, file_name)
dynamics_changed.emit()
func _on_threshold_pressure_updated(value_1: float, value_2: float) -> void:
Tools.pen_pressure_min = minf(value_1, value_2)
Tools.pen_pressure_max = maxf(value_1, value_2)
func _on_threshold_velocity_updated(value_1: float, value_2: float) -> void:
Tools.mouse_velocity_min_thres = minf(value_1, value_2)
Tools.mouse_velocity_max_thres = maxf(value_1, value_2)
func _on_alpha_min_value_changed(value: float) -> void:
Tools.alpha_min = value
dynamics_changed.emit()
func _on_alpha_max_value_changed(value: float) -> void:
Tools.alpha_max = value
dynamics_changed.emit()
func _on_size_min_value_changed(value: float) -> void:
Tools.brush_size_min = int(value)
dynamics_changed.emit()
func _on_size_max_value_changed(value: float) -> void:
Tools.brush_size_max = int(value)
dynamics_changed.emit()
func _on_enable_stabilizer_toggled(toggled_on: bool) -> void:
Tools.stabilizer_enabled = toggled_on
func _on_stabilizer_value_value_changed(value: float) -> void:
Tools.stabilizer_value = value

View file

@ -1,27 +1,12 @@
extends PanelContainer
signal dynamics_changed
enum { ALPHA, SIZE }
@onready var grid_container: GridContainer = find_child("GridContainer")
@onready var horizontal_mirror: BaseButton = grid_container.get_node("Horizontal")
@onready var vertical_mirror: BaseButton = grid_container.get_node("Vertical")
@onready var pixel_perfect: BaseButton = grid_container.get_node("PixelPerfect")
@onready var alpha_lock: BaseButton = grid_container.get_node("AlphaLock")
@onready var dynamics: Button = $"%Dynamics"
@onready var dynamics_panel: PopupPanel = $DynamicsPanel
@onready var alpha_pressure_button: Button = $"%AlphaPressureButton"
@onready var alpha_velocity_button: Button = $"%AlphaVelocityButton"
@onready var size_pressure_button: Button = $"%SizePressureButton"
@onready var size_velocity_button: Button = $"%SizeVelocityButton"
@onready var pressure_preview: ProgressBar = $"%PressurePreview"
@onready var velocity_preview: ProgressBar = $"%VelocityPreview"
@onready var limits_header: HBoxContainer = %LimitsHeader
@onready var thresholds_header: HBoxContainer = %ThresholdsHeader
@onready var alpha_group := alpha_pressure_button.button_group
@onready var size_group := size_pressure_button.button_group
func _ready() -> void:
@ -31,27 +16,6 @@ func _ready() -> void:
vertical_mirror.button_pressed = Tools.vertical_mirror
pixel_perfect.button_pressed = Tools.pixel_perfect
alpha_pressure_button.toggled.connect(
_on_Dynamics_toggled.bind(alpha_pressure_button, ALPHA, Tools.Dynamics.PRESSURE)
)
alpha_velocity_button.toggled.connect(
_on_Dynamics_toggled.bind(alpha_velocity_button, ALPHA, Tools.Dynamics.VELOCITY)
)
size_pressure_button.toggled.connect(
_on_Dynamics_toggled.bind(size_pressure_button, SIZE, Tools.Dynamics.PRESSURE)
)
size_velocity_button.toggled.connect(
_on_Dynamics_toggled.bind(size_velocity_button, SIZE, Tools.Dynamics.VELOCITY)
)
func _input(event: InputEvent) -> void:
pressure_preview.value = 0
velocity_preview.value = 0
if event is InputEventMouseMotion:
pressure_preview.value = event.pressure
velocity_preview.value = event.velocity.length() / Tools.mouse_velocity_max
func _on_resized() -> void:
var tool_panel_size := size
@ -116,76 +80,3 @@ func _on_alpha_lock_toggled(toggled_on: bool) -> void:
func _on_Dynamics_pressed() -> void:
var pos := dynamics.global_position + Vector2(0, 32)
dynamics_panel.popup(Rect2(pos, dynamics_panel.size))
func _on_Dynamics_toggled(
button_pressed: bool, button: BaseButton, property: int, dynamic: Tools.Dynamics
) -> void:
var final_dynamic := dynamic
if not button.button_pressed:
final_dynamic = Tools.Dynamics.NONE
match property:
ALPHA:
Tools.dynamics_alpha = final_dynamic
SIZE:
Tools.dynamics_size = final_dynamic
var has_alpha_dynamic := Tools.dynamics_alpha != Tools.Dynamics.NONE
var has_size_dynamic := Tools.dynamics_size != Tools.Dynamics.NONE
var has_pressure_dynamic := (
Tools.dynamics_alpha == Tools.Dynamics.PRESSURE
or Tools.dynamics_size == Tools.Dynamics.PRESSURE
)
var has_velocity_dynamic := (
Tools.dynamics_alpha == Tools.Dynamics.VELOCITY
or Tools.dynamics_size == Tools.Dynamics.VELOCITY
)
limits_header.visible = has_alpha_dynamic or has_size_dynamic
thresholds_header.visible = limits_header.visible
get_tree().set_group(&"VisibleOnAlpha", "visible", has_alpha_dynamic)
get_tree().set_group(&"VisibleOnSize", "visible", has_size_dynamic)
get_tree().set_group(&"VisibleOnPressure", "visible", has_pressure_dynamic)
get_tree().set_group(&"VisibleOnVelocity", "visible", has_velocity_dynamic)
var texture_button: TextureRect = button.get_node("TextureRect")
var file_name := "check.png"
if !button.button_pressed:
file_name = "uncheck.png"
Global.change_button_texturerect(texture_button, file_name)
dynamics_changed.emit()
func _on_ThresholdPressure_updated(value_1: float, value_2: float) -> void:
Tools.pen_pressure_min = minf(value_1, value_2)
Tools.pen_pressure_max = maxf(value_1, value_2)
func _on_ThresholdVelocity_updated(value_1: float, value_2: float) -> void:
Tools.mouse_velocity_min_thres = minf(value_1, value_2)
Tools.mouse_velocity_max_thres = maxf(value_1, value_2)
func _on_AlphaMin_value_changed(value: float) -> void:
Tools.alpha_min = value
dynamics_changed.emit()
func _on_AlphaMax_value_changed(value: float) -> void:
Tools.alpha_max = value
dynamics_changed.emit()
func _on_SizeMin_value_changed(value: float) -> void:
Tools.brush_size_min = int(value)
dynamics_changed.emit()
func _on_SizeMax_value_changed(value: float) -> void:
Tools.brush_size_max = int(value)
dynamics_changed.emit()
func _on_enable_stabilizer_toggled(toggled_on: bool) -> void:
Tools.stabilizer_enabled = toggled_on
func _on_stabilizer_value_value_changed(value: float) -> void:
Tools.stabilizer_value = value

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=23 format=3 uid="uid://wo0hqxkst808"]
[gd_scene load_steps=24 format=3 uid="uid://wo0hqxkst808"]
[ext_resource type="Texture2D" uid="uid://cjrokejjsp5dm" path="res://assets/graphics/misc/horizontal_mirror_off.png" id="1"]
[ext_resource type="Texture2D" uid="uid://hiduvaa73fr6" path="res://assets/graphics/misc/vertical_mirror_off.png" id="2"]
@ -8,6 +8,7 @@
[ext_resource type="Texture2D" uid="uid://j8eywwy082a4" path="res://assets/graphics/misc/alpha_lock_off.png" id="5_jv20x"]
[ext_resource type="Texture2D" uid="uid://dg3dumyfj1682" path="res://assets/graphics/misc/dynamics.png" id="6"]
[ext_resource type="Texture2D" uid="uid://di8au2u87jgv5" path="res://assets/graphics/misc/uncheck.png" id="7"]
[ext_resource type="Script" path="res://src/UI/GlobalToolOptions/DynamicsPanel.gd" id="7_iqcw1"]
[ext_resource type="PackedScene" uid="uid://bmsc0s03pwji4" path="res://src/UI/Nodes/MaxMinEdit.tscn" id="8"]
[sub_resource type="InputEventAction" id="InputEventAction_4k08w"]
@ -174,6 +175,7 @@ texture = ExtResource("6")
[node name="DynamicsPanel" type="PopupPanel" parent="."]
canvas_item_default_texture_filter = 0
size = Vector2i(300, 334)
script = ExtResource("7_iqcw1")
[node name="VBoxContainer" type="VBoxContainer" parent="DynamicsPanel"]
offset_left = 4.0
@ -480,14 +482,14 @@ offset_bottom = 23.0
[connection signal="toggled" from="ScrollContainer/CenterContainer/GridContainer/PixelPerfect" to="." method="_on_PixelPerfect_toggled"]
[connection signal="toggled" from="ScrollContainer/CenterContainer/GridContainer/AlphaLock" to="." method="_on_alpha_lock_toggled"]
[connection signal="pressed" from="ScrollContainer/CenterContainer/GridContainer/Dynamics" to="." method="_on_Dynamics_pressed"]
[connection signal="toggled" from="DynamicsPanel/VBoxContainer/StabilizerContainer/EnableStabilizer" to="." method="_on_enable_stabilizer_toggled"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/StabilizerContainer/StabilizerValue" to="." method="_on_stabilizer_value_value_changed"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/LimitContainer/AlphaMin" to="." method="_on_AlphaMin_value_changed"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/LimitContainer/AlphaMax" to="." method="_on_AlphaMax_value_changed"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/LimitContainer/SizeMin" to="." method="_on_SizeMin_value_changed"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/LimitContainer/SizeMax" to="." method="_on_SizeMax_value_changed"]
[connection signal="updated" from="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdPressure" to="." method="_on_ThresholdPressure_updated"]
[connection signal="updated" from="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdVelocity" to="." method="_on_ThresholdVelocity_updated"]
[connection signal="toggled" from="DynamicsPanel/VBoxContainer/StabilizerContainer/EnableStabilizer" to="DynamicsPanel" method="_on_enable_stabilizer_toggled"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/StabilizerContainer/StabilizerValue" to="DynamicsPanel" method="_on_stabilizer_value_value_changed"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/LimitContainer/AlphaMin" to="DynamicsPanel" method="_on_alpha_min_value_changed"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/LimitContainer/AlphaMax" to="DynamicsPanel" method="_on_alpha_max_value_changed"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/LimitContainer/SizeMin" to="DynamicsPanel" method="_on_size_min_value_changed"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/LimitContainer/SizeMax" to="DynamicsPanel" method="_on_size_max_value_changed"]
[connection signal="updated" from="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdPressure" to="DynamicsPanel" method="_on_threshold_pressure_updated"]
[connection signal="updated" from="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdVelocity" to="DynamicsPanel" method="_on_threshold_velocity_updated"]
[editable path="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdPressure"]
[editable path="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdVelocity"]