Рефактор. Большое перемещение файлов
This commit is contained in:
39
scenes/frame-threats/frame-threats.tscn
Normal file
39
scenes/frame-threats/frame-threats.tscn
Normal file
@@ -0,0 +1,39 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bsd67ktk8xp5a"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://cs6i1xwx0pmdk" path="res://data/рамка-панели.png" id="1_m3no0"]
|
||||
[ext_resource type="Script" path="res://scenes/frame-threats/scroll-threats.gd" id="2_empn3"]
|
||||
[ext_resource type="Script" path="res://table/table.gd" id="3_4bupu"]
|
||||
|
||||
[node name="frm_threats" type="NinePatchRect"]
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
texture = ExtResource("1_m3no0")
|
||||
patch_margin_left = 15
|
||||
patch_margin_top = 30
|
||||
patch_margin_right = 15
|
||||
patch_margin_bottom = 10
|
||||
|
||||
[node name="header" type="Label" parent="."]
|
||||
clip_contents = true
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
offset_bottom = 22.0
|
||||
grow_horizontal = 2
|
||||
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||
text = "Список целей"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="scroll" type="ScrollContainer" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 4.0
|
||||
offset_top = 51.0
|
||||
offset_right = 476.0
|
||||
offset_bottom = 282.0
|
||||
script = ExtResource("2_empn3")
|
||||
|
||||
[node name="table" type="GridContainer" parent="scroll"]
|
||||
layout_mode = 2
|
||||
columns = 4
|
||||
script = ExtResource("3_4bupu")
|
||||
103
scenes/frame-threats/scroll-threats.gd
Normal file
103
scenes/frame-threats/scroll-threats.gd
Normal file
@@ -0,0 +1,103 @@
|
||||
extends ScrollContainer
|
||||
|
||||
## Отображает список целей в таблице.
|
||||
|
||||
|
||||
const CellLineEdit = preload('res://table/ячейка-2.tscn') ## Ячейка таблицы.
|
||||
const TableHeader = preload('res://table/header.tscn') ## Ячейка заголовок таблицы.
|
||||
|
||||
|
||||
const TABLE_HEADER = [ TableHeader, TableHeader, TableHeader, TableHeader ] ## Описание ряда заголовка.
|
||||
const TABLE_ROW = [ CellLineEdit, CellLineEdit, CellLineEdit, CellLineEdit ] ## Описание ряда.
|
||||
const TABLE_COLUMN_PARAM = ['id', 'aoa', 'freq', 'proto' ] ## Параметры цели отображаемые в таблице.
|
||||
const TABLE_HEADERS_TEXT = ['Номер', 'Пеленг', 'Частота, МГц', 'Протокол' ] ## Заголовки таблицы.
|
||||
const TABLE_COLUMN_SIZE = [ 65, 145, 145, 90 ] ## Ширины колонок.
|
||||
|
||||
|
||||
## Вызывается при нажатии указателем мыши на выбранный ряд.
|
||||
func on_row_pressed(i_row: int):
|
||||
row_pressed(i_row)
|
||||
signaller.emit_signal('rto_threat_sel', $table.get_node_user_data(0, i_row).id)
|
||||
|
||||
|
||||
func row_pressed(i_row: int):
|
||||
$table.clear_rows_selected()
|
||||
$table.set_row_selected(i_row, true)
|
||||
var threat = $table.get_node_user_data(0, i_row)
|
||||
signaller.emit_signal('threat_selected', threat)
|
||||
|
||||
|
||||
func init_table():
|
||||
$table.set_header(TABLE_HEADER)
|
||||
$table.set_header_text(TABLE_HEADERS_TEXT)
|
||||
$table.set_columns_min_size(TABLE_COLUMN_SIZE)
|
||||
$table.pin_header(self, get_parent())
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var table_index: = Dictionary()
|
||||
threats.connect('threat_new', Callable(self, 'on_threat_new').bind(table_index))
|
||||
threats.connect('threat_lost', Callable(self, 'on_threat_lost').bind(table_index))
|
||||
threats.connect('threat_update', Callable(self, 'on_threat_update').bind(table_index))
|
||||
signaller.connect('rto_threat_sel', Callable(self, 'on_rto_threat_sel').bind($table))
|
||||
signaller.connect('rto_threat_unsel', Callable(self, 'on_rto_threat_unsel'))
|
||||
$table.connect('row_pressed', Callable(self, 'on_row_pressed'))
|
||||
call_deferred('init_table')
|
||||
|
||||
|
||||
## Перестраивает индекс таблицы. Вызывать при удалении строки
|
||||
func rehash(table_index: Dictionary):
|
||||
var rows_count = $table.get_rows_count()
|
||||
for i_row in rows_count:
|
||||
var item = $table.get_node2(0, i_row)
|
||||
table_index[int(item.text)] = i_row
|
||||
|
||||
|
||||
## Обрабатывает сигнал [b]threat_update[/b]
|
||||
func on_threat_update(th, table_index: Dictionary):
|
||||
var row = map_th_to_row(th)
|
||||
var i_row = table_index[th.id]
|
||||
$table.set_row_text(i_row, row)
|
||||
|
||||
|
||||
## Обрабатывает сигнал [b]threat_lost[/b]
|
||||
func on_threat_lost(th, table_index: Dictionary):
|
||||
$table.remove_row(table_index[th.id])
|
||||
table_index.clear()
|
||||
rehash(table_index)
|
||||
|
||||
|
||||
## Обрабатывает сигнал [b]threat_new[/b]
|
||||
func on_threat_new(th, table_index):
|
||||
var i_row = $table.get_rows_count()
|
||||
$table.add_row(TABLE_ROW)
|
||||
var row = map_th_to_row(th)
|
||||
$table.set_row_text(i_row, row)
|
||||
$table.set_row_editable(i_row, false)
|
||||
$table.set_node_user_data(0, i_row, th)
|
||||
table_index[th.id] = i_row
|
||||
|
||||
|
||||
## Преобразует цель в строку таблицы
|
||||
func map_th_to_row(th) -> Array:
|
||||
var row: = Array()
|
||||
row.resize(TABLE_COLUMN_PARAM.size())
|
||||
var i_col: int = 0
|
||||
for param_name in TABLE_COLUMN_PARAM:
|
||||
row[i_col] = '%s' % th.get(param_name)
|
||||
i_col += 1
|
||||
return row
|
||||
|
||||
|
||||
## Выделяет выбранную цель в таблице
|
||||
func on_rto_threat_sel(th_id, tbl):
|
||||
for i in tbl.get_rows_count():
|
||||
var node = tbl.get_node2(0, i)
|
||||
if node.text.to_int() == th_id:
|
||||
row_pressed(i)
|
||||
break
|
||||
|
||||
|
||||
## Снимает выделение цели
|
||||
func on_rto_threat_unsel(_th_id): $table.clear_rows_selected()
|
||||
|
||||
Reference in New Issue
Block a user