Files
uarep-ctl/scenes/frame-ecm-params/scroll-ecm-params.gd

98 lines
3.8 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends ScrollContainer
## Отображает список параметров помехи в таблице.
const CellLineEdit = preload('res://table/ячейка-2.tscn') ## Ячейка таблицы.
const TableHeader = preload('res://table/header.tscn') ## Ячейка заголовок таблицы.
const TABLE_HEADER = [ TableHeader, TableHeader ] ## Описание ряда заголовка.
const TABLE_ROW = [ CellLineEdit, CellLineEdit ] ## Описание ряда.
const TABLE_HEADERS_TEXT = ['Параметр', 'Значение' ] ## Назания колонок.
const TABLE_COLUMN_SIZE = [ 370, 85 ] ## Ширины колонок.
const TABLE_PARAMS = {
'kni': [0, 'Курсовой улог, гр.', false, 0.0, 360.0],
'powp': [1, 'Мощность, %', true, 0.0, 100.0],
'freq': [2, 'Частота, МГц', true, 400.0, 6000.0],
'width': [3, 'Занимая полоса частот, МГц', true, 0.0, 120.0],
'dur': [4, 'Длительность импульса, мкс', true, 0.0, 1000000.0],
'period': [5, 'Период повтора, мкс', true, 0.0, 1000000.0] }
func init_table():
for i in TABLE_PARAMS.size(): $table.add_row(TABLE_ROW)
for key in TABLE_PARAMS.keys():
var p = TABLE_PARAMS[key]
$table.set_node_text(0, p[0], p[1])
$table.set_node_alligment(0, p[0], HORIZONTAL_ALIGNMENT_LEFT)
$table.set_node_editable(0, p[0], false)
$table.set_node_editable(1, p[0], false)
$table.set_node_user_data(1, p[0], key)
$table.connect_columns(self, 'text_submitted', 'on_edit_entry', [1], [])
$table.set_columns_min_size(TABLE_COLUMN_SIZE)
$table.set_meta('id', 0)
# Called when the node enters the scene tree for the first time.
func _ready():
signaller.connect('interfer_selected', Callable(self, 'on_interfer_selected'))
signaller.connect('rto_threat_unsel', Callable(self, 'on_rto_threat_unsel'))
call_deferred('init_table')
func on_edit_entry(text : String, entry):
var ecm = $table.get_meta('ecm')
if $table.has_meta('ecm') == false: return
var indexis = $table.get_key_indexes(entry[0].name)
var row_i = indexis[1]
var param = $table.get_node_user_data(1, row_i)
var p = TABLE_PARAMS[param]
var old_val = ecm.get_value(param)
var val = check_value(text, p[3], p[4], old_val)
ecm.set_value(val, param)
signaller.emit_signal('interfer_new', ecm)
func check_value(val, min_val, max_val, old_val):
if val.is_valid_float():
if float(val) < min_val: return min_val
if float(val) > max_val: return max_val
return float(val)
else: return old_val
func on_interfer_selected(ecm):
if ecm != null:
$table.set_meta('ecm', ecm)
else:
$table.set_meta('ecm', null)
on_ecm_update()
func on_ecm_update():
for item in range(len(TABLE_PARAMS)):
$table.set_node_text(1, item, '')
$table.set_node_editable(1, item, false)
if $table.has_meta('ecm') == false: return
var ecm: interfer.Interfer = $table.get_meta('ecm')
var mnms = tools.get_members_names(ecm)
for item in ecm['params'].keys():
mnms.append(item)
for member_name in mnms:
if not TABLE_PARAMS.has(member_name): continue
var p = TABLE_PARAMS[member_name]
var val = ecm.get_value(member_name)
$table.set_node_text(1, p[0], '%s' % val)
$table.set_node_editable(1, p[0], p[2])
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func on_rto_threat_unsel(_th_id):
for item in range(len(TABLE_PARAMS)):
$table.set_node_text(1, item, '')
$table.set_node_editable(1, item, false)