Files
uarep-ctl/scenes/frame-threats/scroll-threats.gd

107 lines
4.1 KiB
GDScript

class_name scroll_threats 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_rto_threat_unsel(_th_id): $table.clear_rows_selected()
## Вызывается при нажатии указателем мыши на выбранный ряд.
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)
$table.ensure_row_visible(i_row)
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:
var val = th.get(param_name)
row[i_col] = '%0.1f' % val if val is float else '%s' % val
if not th.fflags[param_name]:
row[i_col] = ''
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