From ffe3391ed1d73708303464d6df7acbc08396bab8 Mon Sep 17 00:00:00 2001 From: sasha80 Date: Wed, 24 Jan 2024 16:07:09 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0.=20=D0=9E=D1=82=D1=81=D1=82=D1=83=D0=BF=D1=8B=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=B7=D0=B0=D1=87=D1=91=D1=80=D0=BA=D0=B8?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5?= =?UTF-8?q?=20=D1=82=D0=BE=D1=87=D0=BD=D1=8B=D0=B5,=20=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D1=81=D0=BE=D0=B2=D1=81=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scenes/button-flat/button-flat.tscn | 30 +++++++++++++------------ scenes/button-flat/nine-patch-button.gd | 20 ++++++++++------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/scenes/button-flat/button-flat.tscn b/scenes/button-flat/button-flat.tscn index 2569b90..a481d39 100644 --- a/scenes/button-flat/button-flat.tscn +++ b/scenes/button-flat/button-flat.tscn @@ -28,6 +28,7 @@ uniform vec4 color = vec4(1.0, 1.0, 1.0, 1.0); uniform float width = 1.0; uniform float speed = 1.0; uniform bool disabled = false; +uniform vec2 scale = vec2(1.0, 1.0); void vertex() @@ -44,17 +45,18 @@ void fragment() float ds = 1.0 / sharpness; float tx = float(int(TIME * 1000.0 * speed) % 10000) / 1000.0 * center.x + center.x; COLOR.a = 0.0; + vec2 uv = UV; + rotate_vec2(uv, -rotation, center); + float v3 = smoothstep(0.0, 1.0, (uv.x - center.x / 2.0 / scale.x) * sharpness); + float v4 = smoothstep(0.0, 1.0, (uv.y - center.y / 2.0 / scale.y) * sharpness); + float v5 = smoothstep(0.0, 1.0, (center.x * 2.0 - center.x / 2.0 / scale.x - uv.x) * sharpness); + float v6 = smoothstep(0.0, 1.0, (center.y * 2.0 - center.y / 2.0 / scale.y - uv.y) * sharpness); + for (float x = -2.0; x < 2.0; x += 0.03) { float v0 = smoothstep(0.0, 1.0, (tx - UV.x + x) * sharpness + width); float v1 = smoothstep(0.0, 1.0, (UV.x - tx - x) * sharpness + width); float v2 = smooth_px(length(UV.x - center.x), center.x * 2.0 - ds, ds); - vec2 uv = UV; - rotate_vec2(uv, -rotation, center); - float v3 = smoothstep(0.0, 1.0, (uv.x - center.x / 5.0) * sharpness); - float v4 = smoothstep(0.0, 1.0, (uv.y - center.y / 5.0) * sharpness); - float v5 = smoothstep(0.0, 1.0, (center.x * 2.0 - center.x / 5.0 - uv.x) * sharpness); - float v6 = smoothstep(0.0, 1.0, (center.y * 2.0 - center.y / 5.0 - uv.y) * sharpness); COLOR.a += v0 * v1 * v2 * v3 * v4 * v5 * v6; } COLOR.a *= color.a; @@ -66,10 +68,11 @@ void fragment() resource_local_to_scene = true shader = SubResource("Shader_2bftm") shader_parameter/rotation = 45.0 -shader_parameter/color = Vector4(1, 1, 1, 0.2) -shader_parameter/width = 2.0 -shader_parameter/speed = 1.0 +shader_parameter/color = Vector4(1, 1, 1, 0.1) +shader_parameter/width = 3.0 +shader_parameter/speed = 0.0 shader_parameter/disabled = false +shader_parameter/scale = Vector2(1, 1) [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_6nup5"] @@ -90,14 +93,13 @@ extends Sprite2D " [node name="container" type="PanelContainer"] -offset_right = 30.0 -offset_bottom = 30.0 +offset_right = 20.0 +offset_bottom = 20.0 theme_override_styles/panel = SubResource("1") script = ExtResource("1_ui6sg") toggle_mode = true [node name="state" type="NinePatchRect" parent="."] -modulate = Color(1, 1, 1, 0.25) layout_mode = 2 texture = ExtResource("2_0cn5u") patch_margin_left = 10 @@ -121,11 +123,11 @@ clip_text = true [node name="back" type="Sprite2D" parent="."] material = SubResource("ShaderMaterial_hhdyc") -scale = Vector2(30, 30) +scale = Vector2(20, 20) texture = SubResource("PlaceholderTexture2D_6nup5") centered = false script = SubResource("GDScript_uyl5d") -speed = 1.0 +speed = 0.0 [connection signal="resized" from="." to="." method="_on_resized"] [connection signal="toggled" from="button" to="." method="_on_button_toggled"] diff --git a/scenes/button-flat/nine-patch-button.gd b/scenes/button-flat/nine-patch-button.gd index 1e19007..1e67d76 100644 --- a/scenes/button-flat/nine-patch-button.gd +++ b/scenes/button-flat/nine-patch-button.gd @@ -4,6 +4,14 @@ extends PanelContainer var save_modulate: Color +func set_text(val: String): $button.set_text(val) +func set_pressed(val: bool): $button.set_pressed(val) +func set_disabled(val: bool): disabled = val +func button_connect(button_signal: String, proc: Callable): $button.connect(button_signal, proc) +func get_text(): return $button.get_text() +func is_pressed(): return $button.is_pressed() +func is_toggle_mode(): return $button.is_toggle_mode() + @export var texture_state0: Texture2D = preload('res://data/кнопка-квадрат-0.png'): set(val): $state.set_texture(val) @@ -42,18 +50,14 @@ var save_modulate: Color get: return $button.is_toggle_mode() -func set_text(val: String): $button.set_text(val) -func set_pressed(val: bool): $button.set_pressed(val) -func set_disabled(val: bool): disabled = val -func button_connect(button_signal: String, proc: Callable): $button.connect(button_signal, proc) -func get_text(): return $button.get_text() -func is_pressed(): return $button.is_pressed() -func is_toggle_mode(): return $button.is_toggle_mode() -func _on_resized() -> void: $back.scale = size +func _on_resized() -> void: + $back.scale = size + $back.material.set('shader_parameter/scale', size / Vector2(20.0, 20.0)) func _enter_tree() -> void: $back.scale = size + $back.material.set('shader_parameter/scale', size / Vector2(20.0, 20.0)) save_modulate = modulate