From f4f0e4047ece62cf9c5b95bc34de185ed84895f0 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Fri, 12 Jul 2024 14:45:24 +0300 Subject: [PATCH] Fix gradient map layer effect being purple when it's first created --- src/Autoload/Global.gd | 4 +++- src/UI/Nodes/GradientEdit.gd | 11 ++++++++--- src/UI/Nodes/GradientEdit.tscn | 14 +++----------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 5fb168e56..8a0cdb06f 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -1222,7 +1222,9 @@ func create_ui_for_shader_uniforms( gradient_edit.set_gradient_texture(params[u_name]) else: params[u_name] = gradient_edit.texture - value_changed.call(gradient_edit.get_node("TextureRect").texture, u_name) + # This needs to be call_deferred because GradientTexture2D gets updated next frame. + # Without this, the texture is purple. + value_changed.call_deferred(gradient_edit.texture, u_name) gradient_edit.updated.connect( func(_gradient, _cc): value_changed.call(gradient_edit.texture, u_name) ) diff --git a/src/UI/Nodes/GradientEdit.gd b/src/UI/Nodes/GradientEdit.gd index dab02f336..545d6bd5c 100644 --- a/src/UI/Nodes/GradientEdit.gd +++ b/src/UI/Nodes/GradientEdit.gd @@ -8,11 +8,11 @@ signal updated(gradient: Gradient, cc: bool) var continuous_change := true var active_cursor: GradientCursor ## Showing a color picker popup to change a cursor's color +var texture := GradientTexture2D.new() +var gradient := Gradient.new() @onready var x_offset: float = size.x - GradientCursor.WIDTH -@onready var texture_rect: TextureRect = $TextureRect as TextureRect -@onready var texture := texture_rect.texture as GradientTexture2D -@onready var gradient := texture.gradient +@onready var texture_rect := $TextureRect as TextureRect @onready var color_picker := $Popup.get_node("ColorPicker") as ColorPicker @onready var divide_dialog := $DivideConfirmationDialog as ConfirmationDialog @onready var number_of_parts_spin_box := $"%NumberOfPartsSpinBox" as SpinBox @@ -98,7 +98,12 @@ class GradientCursor: set_color(data) +func _init() -> void: + texture.gradient = gradient + + func _ready() -> void: + texture_rect.texture = texture _create_cursors() %InterpolationOptionButton.select(gradient.interpolation_mode) %ColorSpaceOptionButton.select(gradient.interpolation_color_space) diff --git a/src/UI/Nodes/GradientEdit.tscn b/src/UI/Nodes/GradientEdit.tscn index f0a044347..1373646b1 100644 --- a/src/UI/Nodes/GradientEdit.tscn +++ b/src/UI/Nodes/GradientEdit.tscn @@ -1,14 +1,7 @@ -[gd_scene load_steps=4 format=3 uid="uid://bn4aw27dj7pwi"] +[gd_scene load_steps=2 format=3 uid="uid://bn4aw27dj7pwi"] [ext_resource type="Script" path="res://src/UI/Nodes/GradientEdit.gd" id="1"] -[sub_resource type="Gradient" id="Gradient_1k8kj"] -resource_local_to_scene = true - -[sub_resource type="GradientTexture2D" id="GradientTexture2D_fau1l"] -resource_local_to_scene = true -gradient = SubResource("Gradient_1k8kj") - [node name="GradientEdit" type="VBoxContainer"] anchors_preset = 15 anchor_right = 1.0 @@ -19,7 +12,6 @@ script = ExtResource("1") custom_minimum_size = Vector2(0, 30) layout_mode = 2 size_flags_vertical = 3 -texture = SubResource("GradientTexture2D_fau1l") expand_mode = 1 [node name="Value" type="Label" parent="TextureRect"] @@ -38,8 +30,8 @@ offset_bottom = 7.0 [node name="ColorPicker" type="ColorPicker" parent="Popup"] offset_left = 4.0 offset_top = 4.0 -offset_right = 294.0 -offset_bottom = 572.0 +offset_right = 302.0 +offset_bottom = 580.0 [node name="InterpolationContainer" type="HBoxContainer" parent="."] layout_mode = 2