Skip to content

Commit

Permalink
Merge pull request #735 from Jowan-Spooner/better-reference-panel
Browse files Browse the repository at this point in the history
Improved Reference Panel
  • Loading branch information
RodZill4 authored Jan 14, 2025
2 parents 5f26942 + 09e2b13 commit a06cd17
Showing 8 changed files with 4,506 additions and 4,308 deletions.
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:
@@ -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
@@ -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"]

@@ -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
@@ -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

0 comments on commit a06cd17

Please sign in to comment.