Доработка. Добавлен индикатор диапазонов

This commit is contained in:
sasha80
2026-03-10 12:56:15 +03:00
parent 720cba0ae5
commit d14d1724af
3 changed files with 91 additions and 0 deletions

76
scenes/hranges/panel.gd Normal file
View File

@@ -0,0 +1,76 @@
@tool
extends PanelContainer
@export_range(0.0, 1.0) var gap_top: float = 0.05 ## Зазор сверху
@export_range(0.0, 1.0) var gap_bottom: float = 0.05 ## Зазор снизу
@export var ranges_group_name: StringName = 'ranges' ## Имя группы для диапазонов
@export var ranges_save: Dictionary[StringName, Array] ## <имя диапазона>: [диапазон(x - начало, y - конец), цвет]
## Добавляет новый диапазон.
func set_range(nm: StringName, x0: float, x1: float, col: Color) -> void:
ranges_save[nm] = [Vector2(x0, x1), col]
_on_resized()
func set_range_color(nm: StringName, col: Color):
if not ranges_save.has(nm):
push_error('нет такого диапазона: \"%s\"' % nm)
return false
ranges_save[nm][1] = col
var rng: = get_node_or_null(NodePath(nm))
if not rng:
push_error('нет такого элемента: \"%s\"' % nm)
return false
rng.color = col
return true
func clear_ranges():
var l0 = ranges_save.size()
ranges_save.clear()
var l1 = ranges_save.size()
_on_resized()
return l1 < l0
func del_range(nm: StringName) -> bool:
var rc = ranges_save.erase(nm)
_on_resized()
return rc
func _add_range_view(nm: StringName, x0: float, x1: float, col: Color):
var rng = Polygon2D.new()
var point0 = size * Vector2(x0, gap_bottom) ## лево низ
var point1 = size * Vector2(x0, 1.0 - gap_top) ## лево верх
var point2 = size * Vector2(x1, 1.0 - gap_top) ## право верх
var point3 = size * Vector2(x1, gap_bottom) ## право низ
rng.polygon = [point0, point1, point2, point3]
rng.name = nm
rng.color = col
add_child(rng)
rng.add_to_group(ranges_group_name)
## Удаляет заданный диапазон.
func _del_range_view(nm: StringName) -> void:
var rng: = get_node(NodePath(nm))
remove_child(rng)
rng.queue_free()
func _clear_ranges_view():
var range_views = get_tree().get_nodes_in_group(ranges_group_name)
for rng in range_views:
remove_child(rng)
rng.queue_free()
func _on_resized() -> void:
_clear_ranges_view()
for nm in ranges_save:
var rng = ranges_save[nm][0]
var col = ranges_save[nm][1]
_add_range_view(nm, rng.x, rng.y, col)

View File

@@ -0,0 +1 @@
uid://jtio1scc72bl

14
scenes/hranges/panel.tscn Normal file
View File

@@ -0,0 +1,14 @@
[gd_scene load_steps=3 format=3 uid="uid://hr55mkcneaer"]
[ext_resource type="Script" uid="uid://jtio1scc72bl" path="res://scenes/hranges/panel.gd" id="1_pg3d7"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ajqhv"]
[node name="panel" type="PanelContainer"]
offset_right = 690.0
offset_bottom = 75.0
theme_override_styles/panel = SubResource("StyleBoxFlat_ajqhv")
script = ExtResource("1_pg3d7")
lines_count = null
[connection signal="resized" from="." to="." method="_on_resized"]