Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Reference Panel #735

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions material_maker/panels/reference/color_slot.gd
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
extends ColorRect


signal clicked
extends Button


func _ready() -> void:
pass # Replace with function body.
button_group.pressed.connect(func(_x): $ColorRect.queue_redraw())
toggled.connect(func(_x): $ColorRect.queue_redraw())


func set_slot_color(c) -> void:
$ColorRect.color = c

func select(b : bool) -> void:
color = Color(1.0, 1.0, 1.0, 1.0) if b else Color(1.0, 1.0, 1.0, 0.0)

func _on_ColorSlot_gui_input(event : InputEvent):
if event is InputEventMouseButton and event.pressed:
emit_signal("clicked", self)

func _get_drag_data(_position):
var preview = ColorRect.new()
preview.color = $ColorRect.color
preview.custom_minimum_size = Vector2(32, 32)
set_drag_preview(preview)
return $ColorRect.color


func _on_color_rect_draw() -> void:
if button_pressed:
var picker_icon := get_theme_icon("color_picker", "MM_Icons")
$ColorRect.draw_texture(picker_icon, ($ColorRect.get_rect().size-picker_icon.get_size())/2.0)
13 changes: 8 additions & 5 deletions material_maker/panels/reference/color_slot.tscn
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
[gd_scene load_steps=2 format=3 uid="uid://cqalnln5sq2ff"]

[ext_resource type="Script" path="res://material_maker/panels/reference/color_slot.gd" id="1"]
[ext_resource type="Script" uid="uid://ctlul33mwpeby" path="res://material_maker/panels/reference/color_slot.gd" id="1"]

[node name="ColorSlot" type="ColorRect"]
[node name="ColorSlot" type="Button"]
custom_minimum_size = Vector2(32, 32)
offset_right = 32.0
offset_bottom = 32.0
color = Color(1, 1, 1, 0)
toggle_mode = true
script = ExtResource("1")

[node name="ColorRect" type="ColorRect" parent="."]
layout_mode = 0
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 2.0
offset_top = 2.0
offset_right = -2.0
offset_bottom = -2.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
color = Color(0.501961, 0.501961, 0.501961, 1)

[connection signal="gui_input" from="." to="." method="_on_ColorSlot_gui_input"]
[connection signal="draw" from="ColorRect" to="." method="_on_color_rect_draw"]
22 changes: 11 additions & 11 deletions material_maker/panels/reference/gradient_slot.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
extends ColorRect
extends Button

var gradient = MMGradient.new()

signal clicked

func _ready() -> void:
button_group.pressed.connect(func(_x): $ColorRect/Icon.queue_redraw())
toggled.connect(func(_x): $ColorRect/Icon.queue_redraw())


func set_gradient(g) -> void:
Expand All @@ -18,15 +21,6 @@ func set_gradient(g) -> void:
update_shader_parameters()


func select(b : bool) -> void:
color = Color(1.0, 1.0, 1.0, 1.0) if b else Color(1.0, 1.0, 1.0, 0.0)


func _on_ColorSlot_gui_input(event : InputEvent):
if event is InputEventMouseButton and event.pressed:
emit_signal("clicked", self)


func _get_drag_data(_position):
var preview = ColorRect.new()
preview.material = $ColorRect.material
Expand All @@ -39,3 +33,9 @@ func update_shader_parameters() -> void:
var parameter_values : Dictionary = gradient.get_parameter_values("")
for n in parameter_values.keys():
$ColorRect.material.set_shader_parameter(n, parameter_values[n])


func _on_icon_draw() -> void:
if button_pressed:
var picker_icon := get_theme_icon("color_picker", "MM_Icons")
$ColorRect/Icon.draw_texture(picker_icon, ($ColorRect/Icon.get_rect().size-picker_icon.get_size())/2.0)
28 changes: 17 additions & 11 deletions material_maker/panels/reference/gradient_slot.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=4 format=3 uid="uid://jyqnc0l3oaeu"]

[ext_resource type="Script" path="res://material_maker/panels/reference/gradient_slot.gd" id="1"]
[ext_resource type="Script" uid="uid://dhn8uwj5mh2cq" path="res://material_maker/panels/reference/gradient_slot.gd" id="1"]

[sub_resource type="Shader" id="1"]

Expand All @@ -9,18 +9,16 @@ resource_local_to_scene = true
render_priority = 0
shader = SubResource("1")

[node name="GradientSlot" type="ColorRect"]
[node name="GradientSlot" type="Button"]
custom_minimum_size = Vector2(32, 32)
offset_right = 32.0
offset_bottom = 32.0
custom_minimum_size = Vector2(32, 32)
color = Color(1, 1, 1, 0)
toggle_mode = true
script = ExtResource("1")
__meta__ = {
"_edit_use_anchors_": false
}

[node name="ColorRect" type="ColorRect" parent="."]
material = SubResource("2")
layout_mode = 0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 3.0
Expand All @@ -29,8 +27,16 @@ offset_right = -3.0
offset_bottom = -3.0
mouse_filter = 2
color = Color(0.501961, 0.501961, 0.501961, 1)
__meta__ = {
"_edit_use_anchors_": false
}

[connection signal="gui_input" from="." to="." method="_on_ColorSlot_gui_input"]
[node name="Icon" type="ColorRect" parent="ColorRect"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
color = Color(1, 1, 1, 0)

[connection signal="draw" from="ColorRect" to="." method="_on_color_rect_draw"]
[connection signal="draw" from="ColorRect/Icon" to="." method="_on_icon_draw"]
Loading
Loading