diff --git a/scenes/scrl_threats.gd b/scenes/scrl_threats.gd new file mode 100644 index 00000000..bb28aad9 --- /dev/null +++ b/scenes/scrl_threats.gd @@ -0,0 +1,61 @@ +extends ScrollContainer + +const CellLineEdit = preload('res://scenes/ячейка-2.tscn') +const TableHeader = preload('res://table/header.tscn') +const TableNode = preload('res://table/node.tscn') + + +const TABLE_ROW = [CellLineEdit, CellLineEdit, CellLineEdit, CellLineEdit] +const TABLE_COLUMN_PARAM = ['id', 'aoa', 'freq', 'proto'] ## Параметры цели отображаемые в таблице. +const TABLE_HEADERS_TEXT = ['Номер', 'Пеленг', 'Частота, МГц', 'Протокол'] ## + + +func on_row_pressed(i_row: int): + var selected = $tbl_threats.is_row_selected(i_row) + $tbl_threats.set_row_selected(i_row, not selected) + + +func init_table(): + $tbl_threats.set_header([TableHeader, TableHeader, TableHeader, TableHeader]) + $tbl_threats.set_header_text(TABLE_HEADERS_TEXT) + $tbl_threats.set_columns_min_size([50, 140, 140, 100]) + $tbl_threats.pin_header(self, get_parent()) + $tbl_threats.connect('row_pressed', Callable(self, 'on_row_pressed')) + + +func _ready() -> void: + var th_table_id: = Dictionary() + Threats.connect('threat_new', Callable(self, 'on_threat_new').bind(th_table_id)) + Threats.connect('threat_lost', Callable(self, 'on_threat_lost').bind(th_table_id)) + call_deferred('init_table') + + +func rehash(th_table_id: Dictionary): + var rows_count = $tbl_threats.get_rows_count() + for i_row in rows_count: + var item = $tbl_threats.get_node2(0, i_row) + th_table_id[int(item.text)] = i_row + + +func on_threat_lost(_threats, th, th_table_id: Dictionary): + $tbl_threats.remove_row(th_table_id[th.id]) + th_table_id.clear() + rehash(th_table_id) + + +func on_threat_new(_threats, th, th_table_id): + var i_row = $tbl_threats.get_rows_count() + $tbl_threats.add_row(TABLE_ROW) + var row = map_th_to_row(th) + $tbl_threats.set_row_text(i_row, row) + th_table_id[th.id] = i_row + + +func map_th_to_row(th): + 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