Доработка. Убран список целей в обработчиках, т.к. не используется. Добавлено событие "изменение размера списка целей".
This commit is contained in:
@@ -24,7 +24,7 @@ const TABLE_PARAMS = {
|
||||
## Обрабатывает сигнал [signal Threats.threat_selected]
|
||||
func on_threat_selected(th):
|
||||
$table.set_meta('id', th.id)
|
||||
on_threat_update(null, th)
|
||||
on_threat_update(th)
|
||||
|
||||
|
||||
func init_table():
|
||||
@@ -50,7 +50,7 @@ func _ready() -> void:
|
||||
|
||||
## Обрабатывает сигнал [signal Threats.threat_update].
|
||||
## Обновляет отображение только для выбранной цели.
|
||||
func on_threat_update(_threats, th):
|
||||
func on_threat_update(th):
|
||||
if th.id != $table.get_meta('id'): return
|
||||
var mnms = Tools.get_members_names(th)
|
||||
for member_name in mnms:
|
||||
|
||||
@@ -47,21 +47,21 @@ func rehash(table_index: Dictionary):
|
||||
|
||||
|
||||
## Обрабатывает сигнал [b]threat_update[/b]
|
||||
func on_threat_update(_threats, th, table_index: Dictionary):
|
||||
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(_threats, th, table_index: Dictionary):
|
||||
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(_threats, th, table_index):
|
||||
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)
|
||||
|
||||
@@ -3,6 +3,7 @@ extends Control
|
||||
|
||||
func on_line_changed(unit, addr): Log.message(Logger.INFO, 'Состояние связи: %s %s' % [unit, addr])
|
||||
func on_command_fail(unit, addr): Log.message(Logger.ERROR, 'Ошибка: команда не выполнена: %s %s' % [unit, addr])
|
||||
func on_threats_changed(th: Object, msg: String): Log.message(Logger.INFO, '%s: %s' % [msg, th.to_string()])
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -12,10 +13,6 @@ func _ready() -> void:
|
||||
Threats.connect('threat_lost', Callable(self, 'on_threats_changed').bind('Цель потеряна'))
|
||||
|
||||
|
||||
func on_threats_changed(_threats: Dictionary, th: Object, msg: String):
|
||||
Log.message(Logger.INFO, '%s: %s' % [msg, th.to_string()])
|
||||
|
||||
|
||||
func _on_clear_button_down() -> void:
|
||||
$content.clear()
|
||||
Log.info('Cодержание журнала очищено оператором')
|
||||
|
||||
@@ -45,7 +45,7 @@ func _on_full_screen(): toggle_full_screen(window_0_id)
|
||||
|
||||
|
||||
## Обработчик сигнала изменения списка целей
|
||||
func on_threats_changed(threats: Dictionary, _th): $count_all_pad/count_all.text = '%02d' % threats.size()
|
||||
func on_threats_resized(threats: Dictionary): $count_all_pad/count_all.text = '%02d' % threats.size()
|
||||
|
||||
|
||||
## Производит инициализацию
|
||||
@@ -57,11 +57,10 @@ func _ready():
|
||||
drag_fsm = DragFSM.OFF
|
||||
var nodes: = get_tree().get_nodes_in_group('группа-режим-помехи')
|
||||
nodes.any(func(btn): btn.button_connect('pressed', Callable(self, 'on_button_pressed').bind(btn, nodes)))
|
||||
Threats.connect('threat_lost', Callable(self, 'on_threat_lost'))
|
||||
Threats.connect('threat_lost', Callable(self, 'on_threats_changed'))
|
||||
Threats.connect('threat_new', Callable(self, 'on_threat_new'))
|
||||
Threats.connect('threat_new', Callable(self, 'on_threats_changed'))
|
||||
Threats.connect('threat_update', Callable(self, 'on_threat_update'))
|
||||
Threats.connect('threat_new', Callable(self, 'on_threat_new'))
|
||||
Threats.connect('threat_lost', Callable(self, 'on_threat_lost'))
|
||||
Threats.connect('threats_resized', Callable(self, 'on_threats_resized'))
|
||||
Threats.connect('threat_update', Callable(self, 'on_threat_update'))
|
||||
|
||||
|
||||
## Производит отображение цели на диаграмму
|
||||
@@ -77,13 +76,13 @@ func map_threat_to_bip(th: Threats.Threat, bip: Sprite2D):
|
||||
|
||||
|
||||
## Обработчик сигнала обновления цели
|
||||
func on_threat_update(_threats: Dictionary, th):
|
||||
func on_threat_update(th):
|
||||
var bip = get_node('%d' % th.id)
|
||||
map_threat_to_bip(th, bip)
|
||||
|
||||
|
||||
## Обработчик сигнала обнаружения цели
|
||||
func on_threat_new(_threats: Dictionary, th) -> void:
|
||||
func on_threat_new(th) -> void:
|
||||
var bip = Bip.instantiate()
|
||||
bip.name = '%d' % th.id
|
||||
map_threat_to_bip(th, bip)
|
||||
@@ -91,7 +90,7 @@ func on_threat_new(_threats: Dictionary, th) -> void:
|
||||
|
||||
|
||||
## Обработчик сигнала потери цели
|
||||
func on_threat_lost(_threats: Dictionary, th) -> void:
|
||||
func on_threat_lost(th) -> void:
|
||||
var bip = get_node('%d' % th.id)
|
||||
remove_child(bip)
|
||||
bip.free()
|
||||
|
||||
@@ -31,7 +31,7 @@ offset_top = 6.0
|
||||
offset_right = 1592.0
|
||||
offset_bottom = 1169.0
|
||||
|
||||
[node name="frm_ths_list" type="NinePatchRect" parent="grd_side"]
|
||||
[node name="frm_threats" type="NinePatchRect" parent="grd_side"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
@@ -41,7 +41,7 @@ patch_margin_top = 30
|
||||
patch_margin_right = 15
|
||||
patch_margin_bottom = 10
|
||||
|
||||
[node name="header" type="Label" parent="grd_side/frm_ths_list"]
|
||||
[node name="header" type="Label" parent="grd_side/frm_threats"]
|
||||
clip_contents = true
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
@@ -53,7 +53,7 @@ text = "Список целей"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="scroll" type="ScrollContainer" parent="grd_side/frm_ths_list"]
|
||||
[node name="scroll" type="ScrollContainer" parent="grd_side/frm_threats"]
|
||||
layout_mode = 0
|
||||
offset_left = 4.0
|
||||
offset_top = 51.0
|
||||
@@ -61,12 +61,12 @@ offset_right = 476.0
|
||||
offset_bottom = 282.0
|
||||
script = ExtResource("5_tr3hj")
|
||||
|
||||
[node name="table" type="GridContainer" parent="grd_side/frm_ths_list/scroll"]
|
||||
[node name="table" type="GridContainer" parent="grd_side/frm_threats/scroll"]
|
||||
layout_mode = 2
|
||||
columns = 4
|
||||
script = ExtResource("6_fpdpm")
|
||||
|
||||
[node name="frm_ths_params" type="NinePatchRect" parent="grd_side"]
|
||||
[node name="frm_params" type="NinePatchRect" parent="grd_side"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
@@ -76,7 +76,7 @@ patch_margin_top = 30
|
||||
patch_margin_right = 15
|
||||
patch_margin_bottom = 10
|
||||
|
||||
[node name="header" type="Label" parent="grd_side/frm_ths_params"]
|
||||
[node name="header" type="Label" parent="grd_side/frm_params"]
|
||||
clip_contents = true
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
@@ -88,7 +88,7 @@ text = "Параметры цели"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="scroll" type="ScrollContainer" parent="grd_side/frm_ths_params"]
|
||||
[node name="scroll" type="ScrollContainer" parent="grd_side/frm_params"]
|
||||
layout_mode = 0
|
||||
offset_left = 4.0
|
||||
offset_top = 54.0
|
||||
@@ -96,7 +96,7 @@ offset_right = 476.0
|
||||
offset_bottom = 282.0
|
||||
script = ExtResource("6_tict0")
|
||||
|
||||
[node name="table" type="GridContainer" parent="grd_side/frm_ths_params/scroll"]
|
||||
[node name="table" type="GridContainer" parent="grd_side/frm_params/scroll"]
|
||||
layout_mode = 2
|
||||
script = ExtResource("6_fpdpm")
|
||||
|
||||
|
||||
@@ -36,39 +36,42 @@ class Threat:
|
||||
items.any(func(vn): set(vn, dic_vals[vn]); fflags[vn] = true; return false)
|
||||
|
||||
|
||||
signal threat_new(threats: Dictionary, th: Threat)
|
||||
signal threat_lost(threats: Dictionary, th: Threat)
|
||||
signal threat_update(threats: Dictionary, th: Threat)
|
||||
|
||||
|
||||
var threats = {} ## Список целей. Индекс - <номер цели>
|
||||
signal threat_new(th: Threat)
|
||||
signal threat_lost(th: Threat)
|
||||
signal threat_update(th: Threat)
|
||||
signal threats_resized(th: Dictionary)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Log.info('Модуль обработки целей готов')
|
||||
var threats = {} ## Список целей. Индекс - <номер цели>
|
||||
var unit_key = REPSettings.get_unit_key('уарэп-капсрпб-отп')
|
||||
var unit = REPNetwork.units[unit_key]
|
||||
var timer_check_lost: = Timer.new()
|
||||
add_child(timer_check_lost)
|
||||
unit.connect('data_received', Callable(self, 'on_data_capsrpb_received'))
|
||||
timer_check_lost.connect('timeout', Callable(self, 'on_timer_check_lost').bind(REPSettings.ThreatParams.time_lost))
|
||||
unit.connect('data_received', Callable(self, 'on_data_capsrpb_received').bind(threats))
|
||||
timer_check_lost.connect('timeout', Callable(self, 'on_timer_check_lost').bind(REPSettings.ThreatParams.time_lost, threats))
|
||||
timer_check_lost.start(REPSettings.ThreatParams.time_lost / 1000.0)
|
||||
|
||||
|
||||
## Периодически удаляет устаревшие цели
|
||||
func on_timer_check_lost(time_lost: int):
|
||||
func on_timer_check_lost(time_lost: int, threats: Dictionary):
|
||||
var tick = Time.get_ticks_msec()
|
||||
var sz: = threats.size()
|
||||
for th in threats.values():
|
||||
if (tick - th.tick_rx) >= time_lost:
|
||||
threats.erase(th.id)
|
||||
emit_signal('threat_lost', threats, th)
|
||||
call_deferred('emit_signal', 'threat_lost', th)
|
||||
if sz != threats.size():
|
||||
call_deferred('emit_signal', 'threats_resized', threats)
|
||||
|
||||
|
||||
## Производит приём целей
|
||||
func on_data_capsrpb_received(unit: capsrpb.CapsRpb):
|
||||
func on_data_capsrpb_received(unit: capsrpb.CapsRpb, threats: Dictionary):
|
||||
if not unit.json_dic.has('mis'):
|
||||
return
|
||||
var mis = unit.json_dic['mis']
|
||||
var sz: = threats.size()
|
||||
for dic_th in mis:
|
||||
if dic_th.has('id'):
|
||||
var id = int(dic_th['id'])
|
||||
@@ -77,10 +80,12 @@ func on_data_capsrpb_received(unit: capsrpb.CapsRpb):
|
||||
th.clear_fflags()
|
||||
th.set_from_dic(dic_th)
|
||||
th.tick_rx = unit.tick
|
||||
call_deferred('emit_signal', 'threat_update', threats, th)
|
||||
call_deferred('emit_signal', 'threat_update', th)
|
||||
else:
|
||||
var th = Threat.new()
|
||||
th.set_from_dic(dic_th)
|
||||
threats[id] = th
|
||||
th.tick_rx = unit.tick
|
||||
call_deferred('emit_signal', 'threat_new', threats, th)
|
||||
call_deferred('emit_signal', 'threat_new', th)
|
||||
if sz != threats.size():
|
||||
call_deferred('emit_signal', 'threats_resized', threats)
|
||||
|
||||
Reference in New Issue
Block a user