Рефактор.

This commit is contained in:
sasha80
2024-06-14 14:57:29 +03:00
parent c1010b5b93
commit 3c63ab16b1
5 changed files with 107 additions and 80 deletions

View File

@@ -2,64 +2,16 @@
[ext_resource type="Script" path="res://scenes/button-flat/nine-patch-button.gd" id="1_ui6sg"]
[ext_resource type="Texture2D" uid="uid://ct0ajcwno03h7" path="res://data/кнопка-квадрат-0.png" id="2_0cn5u"]
[ext_resource type="Shader" path="res://shaders/strips.gdshader" id="2_5ngiq"]
[sub_resource type="StyleBoxEmpty" id="1"]
[sub_resource type="Shader" id="Shader_2bftm"]
code = "shader_type canvas_item;
#include \"res://shaders/tools.gdshaderinc\"
const vec2 center = vec2(0.125, 0.125);
const float sharpness = 300.0;
uniform float rotation = 0.0;
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()
{
rotate_vec2(UV, rotation, center);
}
void fragment()
{
COLOR = color;
if (disabled)
{
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);
COLOR.a += v0 * v1 * v2 * v3 * v4 * v5 * v6;
}
COLOR.a *= color.a;
}
}
"
[sub_resource type="ShaderMaterial" id="ShaderMaterial_hhdyc"]
resource_local_to_scene = true
shader = SubResource("Shader_2bftm")
shader = ExtResource("2_5ngiq")
shader_parameter/rotation = 0.0
shader_parameter/color = Vector4(1, 1, 1, 0.1)
shader_parameter/width = 3.0
shader_parameter/width = 1.0
shader_parameter/speed = 0.0
shader_parameter/disabled = false
shader_parameter/scale = Vector2(1, 1)

View File

@@ -27,32 +27,38 @@ func get_path_from_meta(meta: String, paths: Array, tokens: Array = ['[', ']', '
i0 = i1 + 1
func _on_request_rtr_request_completed(result, _response_code, _headers, body: PackedByteArray):
var rs = $request_rtr.get_result_string(result)
func _on_request_rtr_request_completed(result, _response_code, headers, body: PackedByteArray):
if result != 0:
log.error('ошибка при приёме: \"%s\"' % rs)
var rs = $request_rtr.get_result_string(result)
log.error('ошибка: \"%s\"' % rs)
return
var json_str: String = body.get_string_from_utf8()
if not json_str:
push_error('ошибка: не удаётся получить строку utf8 из данных (%s)' % headers)
return
var rc = json_parser.parse(json_str)
if rc != Error.OK:
var err = json_parser.get_error_message()
log.error('ошибка при разборе: \"%s\"' % err)
push_error('ошибка: разбор json прерван - \"%s\" (%s)' % [err, headers])
return
var pp = ['DeviceDescripton', 'DeviceName']
var pp = ['DeviceDescription', 'DeviceName']
var ret_val = [null, false]
var pp_copy = pp.duplicate(true)
tools.get_value_by_path(json_parser.data, pp, ret_val)
if not ret_val[1]:
push_error('ошибка: путь %s не найден (%s)' % [pp_copy, headers])
return
for bort_rtr in [$left, $right]:
var bort_rtr_name = bort_rtr.get_meta('DeviceName', '')
if bort_rtr_name != ret_val[0]:
continue
var bort_rtr_name_left: StringName = $left.get_meta('DeviceName', '')
var bort_rtr_name_right: StringName = $right.get_meta('DeviceName', '')
var bb = {bort_rtr_name_left: $left, bort_rtr_name_right: $right}
if not bb.has(ret_val[0]):
return
var bort_rtr = bb[ret_val[0]]
for child in bort_rtr.get_node('konverter/grid').get_children():
map_data_to_item(json_parser.data, child, 'value0')
map_data_to_item(json_parser.data, child, 'value1')

View File

@@ -10,8 +10,7 @@
[sub_resource type="GDScript" id="GDScript_yhnwg"]
script/source = "extends Timer
func _ready():
wait_time = ProjectSettings.get_setting('application/config/unit_rr_request_period')
func _ready(): wait_time = ProjectSettings.get_setting('application/config/unit_rr_request_period')
"
[node name="pribor_rtr" type="Control"]
@@ -25,8 +24,8 @@ script = ExtResource("1_sqyma")
[node name="lbl_header" type="Label" parent="."]
layout_mode = 0
offset_left = 15.0
offset_top = -30.0
offset_left = 9.0
offset_top = -24.0
offset_right = 930.0
offset_bottom = 5.0
theme_override_font_sizes/font_size = 22
@@ -47,7 +46,7 @@ anchors_preset = 0
offset_right = 590.0
offset_bottom = 1250.0
scale = Vector2(0.8, 0.8)
metadata/DeviceName = "Устройство РР левого борта"
metadata/DeviceName = &"Устройство РР левого борта"
[node name="konverter" type="NinePatchRect" parent="left"]
layout_mode = 0
@@ -1327,6 +1326,28 @@ metadata/state = "SelfTest[0].DevList[0]['ErCode']"
metadata/value0 = "SelfTest[1].DevList[0]['CurrentValue']"
metadata/value1 = "SelfTest[2].DevList[0]['CurrentValue']"
[node name="lbl_left" type="Label" parent="."]
self_modulate = Color(1, 1, 1, 0.627451)
layout_mode = 0
offset_left = 204.0
offset_top = 1001.0
offset_right = 277.0
offset_bottom = 1021.0
theme_override_font_sizes/font_size = 17
text = "левый борт"
vertical_alignment = 1
[node name="lbl_right" type="Label" parent="."]
self_modulate = Color(1, 1, 1, 0.627451)
layout_mode = 0
offset_left = 662.0
offset_top = 1001.0
offset_right = 735.0
offset_bottom = 1021.0
theme_override_font_sizes/font_size = 17
text = "правый борт"
vertical_alignment = 1
[connection signal="child_entered_tree" from="request_rtr" to="request_rtr" method="_on_child_entered_tree"]
[connection signal="request_completed" from="request_rtr" to="." method="_on_request_rtr_request_completed"]
[connection signal="timeout" from="request_rtr/timer" to="request_rtr" method="_on_request_timer"]

View File

@@ -23,9 +23,11 @@ offset_right = 1584.0
offset_bottom = 1059.0
focus_mode = 2
theme_override_colors/selection_color = Color(0.72549, 0.270588, 0.133333, 1)
scroll_following = true
threaded = true
selection_enabled = true
deselect_on_focus_loss_enabled = false
drag_and_drop_selection_enabled = false
script = ExtResource("2_wm8il")
colors = {
1: Color(1, 0.930333, 0.81, 1),

46
shaders/strips.gdshader Normal file
View File

@@ -0,0 +1,46 @@
shader_type canvas_item;
#include "res://shaders/tools.gdshaderinc"
const vec2 center = vec2(0.125, 0.125);
const float sharpness = 300.0;
uniform float rotation = 0.0;
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()
{
rotate_vec2(UV, rotation, center);
}
void fragment()
{
COLOR = color;
if (disabled)
{
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);
COLOR.a += v0 * v1 * v2 * v3 * v4 * v5 * v6;
}
COLOR.a *= color.a;
}
}