Доработка, поворот целей на заданный угол по нажатию кнопки, либо таймеру. Кнопка загрузки начального состояния целей.

This commit is contained in:
MaD_CaT
2024-08-14 14:46:42 +03:00
parent 4f9c0eaae1
commit 866a4e49be
9 changed files with 184 additions and 39 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

BIN
load.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -2,16 +2,16 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://blpkoi7s8qugp" uid="uid://dhveg2jqmo0pr"
path="res://.godot/imported/document-save-0.png-60b8d3ba0e847ee0dfdc87427675d7b1.ctex" path="res://.godot/imported/load.png-9c8c9adf120191f851f7891d8703288b.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://document-save-0.png" source_file="res://load.png"
dest_files=["res://.godot/imported/document-save-0.png-60b8d3ba0e847ee0dfdc87427675d7b1.ctex"] dest_files=["res://.godot/imported/load.png-9c8c9adf120191f851f7891d8703288b.ctex"]
[params] [params]

31
main.gd
View File

@@ -1,20 +1,32 @@
extends Node2D extends Node2D
var sock = PacketPeerUDP.new() var sock = PacketPeerUDP.new()
@onready var table_threads = get_node('tabs/threats/table_t') @onready var table_threats = get_node('ColorRect/tabs/threats/table_t')
@onready var btn_add_threads = get_node('tabs/threats/btn_add') @onready var btn_add_threats = get_node('ColorRect/tabs/threats/btn_add')
@onready var btn_del_threads = get_node('tabs/threats/btn_del') @onready var btn_del_threats = get_node('ColorRect/tabs/threats/btn_del')
@onready var btn_save_threads = get_node('tabs/threats/btn_save') @onready var btn_save_threats = get_node('ColorRect/tabs/threats/btn_save')
@onready var btn_load_threats = get_node('ColorRect/tabs/threats/btn_load')
@onready var btn_rotate = get_node('ColorRect/tabs/threats/panel_rotate/btn_rotate')
@onready var entry_rotate = get_node('ColorRect/tabs/threats/panel_rotate/entry_rotate')
@onready var chkbx_rotate = get_node('ColorRect/tabs/threats/panel_rotate/chkbx_rotate')
@onready var table_pomehi = get_node('tabs/pomehi/table_p') @onready var table_pomehi = get_node('ColorRect/tabs/pomehi/table_p')
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
var nodes: Dictionary = {
'btn_add': btn_add_threats,
'btn_del': btn_del_threats,
'btn_save': btn_save_threats,
'btn_load': btn_load_threats,
'btn_rt': btn_rotate,
'entry_rt': entry_rotate,
'chkbx_rt': chkbx_rotate}
sock.bind(Consts.MAIN_ADDR[1], Consts.MAIN_ADDR[0]) sock.bind(Consts.MAIN_ADDR[1], Consts.MAIN_ADDR[0])
sock.set_dest_address(Consts.DST_ADDR[0], Consts.DST_ADDR[1]) sock.set_dest_address(Consts.DST_ADDR[0], Consts.DST_ADDR[1])
Threats.init_treats(table_threads, btn_add_threads, btn_del_threads, btn_save_threads) Threats.init_treats(table_threats, nodes)
Interfers.init_pomehi(table_pomehi) Interfers.init_pomehi(table_pomehi)
fs.init_fs($tabs/pomehi, $tabs/pomehi/fs_rect) fs.init_fs($ColorRect/tabs/pomehi, $ColorRect/tabs/pomehi/fs_rect)
var timer = Timer.new() var timer = Timer.new()
timer.connect('timeout', Callable(self, 'on_timeout').bind()) timer.connect('timeout', Callable(self, 'on_timeout').bind())
add_child(timer) #to process add_child(timer) #to process
@@ -54,7 +66,6 @@ func on_receive(data):
fs.on_receive_msg8(json_data) fs.on_receive_msg8(json_data)
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
while sock.get_available_packet_count() > 0: while sock.get_available_packet_count() > 0:
@@ -63,7 +74,3 @@ func _process(delta):
var port: = sock.get_packet_port() var port: = sock.get_packet_port()
var addr_port: = [addr, port] var addr_port: = [addr, port]
on_receive(data) on_receive(data)

105
main.tscn
View File

@@ -1,23 +1,37 @@
[gd_scene load_steps=7 format=3 uid="uid://87gtvqd7bbje"] [gd_scene load_steps=10 format=3 uid="uid://87gtvqd7bbje"]
[ext_resource type="Script" path="res://main.gd" id="1_jt2ds"] [ext_resource type="Script" path="res://main.gd" id="1_jt2ds"]
[ext_resource type="Script" path="res://table/table.gd" id="2_61iss"] [ext_resource type="Script" path="res://table/table.gd" id="2_61iss"]
[ext_resource type="Texture2D" uid="uid://cex4jiu1pcj3x" path="res://edit-add-0.png" id="3_0aqi0"] [ext_resource type="Texture2D" uid="uid://cex4jiu1pcj3x" path="res://edit-add-0.png" id="3_0aqi0"]
[ext_resource type="Texture2D" uid="uid://cx746np1wexnd" path="res://edit-add-1.png" id="4_s8cxp"] [ext_resource type="Texture2D" uid="uid://cx746np1wexnd" path="res://edit-add-1.png" id="4_s8cxp"]
[ext_resource type="Texture2D" uid="uid://blpkoi7s8qugp" path="res://document-save-0.png" id="5_8l4uh"]
[ext_resource type="Texture2D" uid="uid://wh7p3t4frxf" path="res://disconnect.png" id="6_hj3vd"] [ext_resource type="Texture2D" uid="uid://wh7p3t4frxf" path="res://disconnect.png" id="6_hj3vd"]
[ext_resource type="Texture2D" uid="uid://csolqkavjib0q" path="res://save.png" id="6_xh685"]
[ext_resource type="Texture2D" uid="uid://dhveg2jqmo0pr" path="res://load.png" id="7_v45w5"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_4dilt"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_uy4ow"]
[node name="main" type="Node2D"] [node name="main" type="Node2D"]
script = ExtResource("1_jt2ds") script = ExtResource("1_jt2ds")
[node name="tabs" type="TabContainer" parent="."] [node name="ColorRect" type="ColorRect" parent="."]
offset_right = 1596.0
offset_bottom = 898.0
color = Color(0, 0, 0, 1)
[node name="tabs" type="TabContainer" parent="ColorRect"]
self_modulate = Color(0, 0, 0, 1)
offset_right = 1594.0 offset_right = 1594.0
offset_bottom = 897.0 offset_bottom = 897.0
[node name="threats" type="Panel" parent="tabs"] [node name="threats" type="Panel" parent="ColorRect/tabs"]
self_modulate = Color(0, 0, 0, 1)
light_mask = 2
layout_mode = 2 layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxEmpty_4dilt")
[node name="table_t" type="GridContainer" parent="tabs/threats"] [node name="table_t" type="GridContainer" parent="ColorRect/tabs/threats"]
layout_mode = 1 layout_mode = 1
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
@@ -31,7 +45,7 @@ grow_vertical = 2
script = ExtResource("2_61iss") script = ExtResource("2_61iss")
node_type_file = "res://ячейка-1.tscn" node_type_file = "res://ячейка-1.tscn"
[node name="btn_add" type="TextureButton" parent="tabs/threats"] [node name="btn_add" type="TextureButton" parent="ColorRect/tabs/threats"]
layout_mode = 0 layout_mode = 0
offset_left = 1533.0 offset_left = 1533.0
offset_top = -2.0 offset_top = -2.0
@@ -40,15 +54,7 @@ offset_bottom = 46.0
texture_normal = ExtResource("3_0aqi0") texture_normal = ExtResource("3_0aqi0")
texture_pressed = ExtResource("4_s8cxp") texture_pressed = ExtResource("4_s8cxp")
[node name="btn_save" type="TextureButton" parent="tabs/threats"] [node name="btn_del" type="TextureButton" parent="ColorRect/tabs/threats"]
layout_mode = 0
offset_left = 1442.0
offset_top = -1.0
offset_right = 1490.0
offset_bottom = 47.0
texture_normal = ExtResource("5_8l4uh")
[node name="btn_del" type="TextureButton" parent="tabs/threats"]
layout_mode = 0 layout_mode = 0
offset_left = 1499.0 offset_left = 1499.0
offset_top = 1.0 offset_top = 1.0
@@ -57,11 +63,74 @@ offset_bottom = 67.0
scale = Vector2(0.62, 0.62) scale = Vector2(0.62, 0.62)
texture_normal = ExtResource("6_hj3vd") texture_normal = ExtResource("6_hj3vd")
[node name="pomehi" type="Panel" parent="tabs"] [node name="btn_save" type="TextureButton" parent="ColorRect/tabs/threats"]
layout_mode = 0
offset_left = 1454.0
offset_top = 0.999999
offset_right = 1966.0
offset_bottom = 513.0
scale = Vector2(0.08, 0.08)
texture_normal = ExtResource("6_xh685")
[node name="btn_load" type="TextureButton" parent="ColorRect/tabs/threats"]
layout_mode = 0
offset_left = 1410.0
offset_top = 1.0
offset_right = 1922.0
offset_bottom = 513.0
scale = Vector2(0.08, 0.08)
texture_normal = ExtResource("7_v45w5")
[node name="panel_rotate" type="Panel" parent="ColorRect/tabs/threats"]
self_modulate = Color(0.389287, 0.389287, 0.389287, 1)
layout_mode = 0
offset_left = 3.0
offset_top = 6.0
offset_right = 150.0
offset_bottom = 50.0
theme_override_styles/panel = SubResource("StyleBoxFlat_uy4ow")
[node name="btn_rotate" type="Button" parent="ColorRect/tabs/threats/panel_rotate"]
layout_mode = 2
offset_left = 1.0
offset_top = 2.0
offset_right = 118.0
offset_bottom = 29.0
scale = Vector2(0.8, 0.8)
text = "Повернуть на "
[node name="entry_rotate" type="LineEdit" parent="ColorRect/tabs/threats/panel_rotate"]
layout_mode = 2
offset_left = 97.0
offset_top = 2.0
offset_right = 154.688
offset_bottom = 29.0
scale = Vector2(0.8, 0.8)
text = "45"
alignment = 1
[node name="lbl_rotate" type="Label" parent="ColorRect/tabs/threats/panel_rotate"]
layout_mode = 0
offset_left = 5.0
offset_top = 26.0
offset_right = 119.0
offset_bottom = 45.0
scale = Vector2(0.8, 0.8)
text = "Вращать цели:"
[node name="chkbx_rotate" type="CheckBox" parent="ColorRect/tabs/threats/panel_rotate"]
layout_mode = 0
offset_left = 110.0
offset_top = 24.0
offset_right = 134.0
offset_bottom = 48.0
scale = Vector2(0.8, 0.8)
[node name="pomehi" type="Panel" parent="ColorRect/tabs"]
visible = false visible = false
layout_mode = 2 layout_mode = 2
[node name="table_p" type="GridContainer" parent="tabs/pomehi"] [node name="table_p" type="GridContainer" parent="ColorRect/tabs/pomehi"]
layout_mode = 0 layout_mode = 0
offset_top = 30.0 offset_top = 30.0
offset_right = 1587.0 offset_right = 1587.0
@@ -69,7 +138,7 @@ offset_bottom = 886.0
script = ExtResource("2_61iss") script = ExtResource("2_61iss")
node_type_file = "res://ячейка-1.tscn" node_type_file = "res://ячейка-1.tscn"
[node name="fs_rect" type="ReferenceRect" parent="tabs/pomehi"] [node name="fs_rect" type="ReferenceRect" parent="ColorRect/tabs/pomehi"]
layout_mode = 0 layout_mode = 0
offset_left = 1000.0 offset_left = 1000.0
offset_top = 91.0 offset_top = 91.0

BIN
save.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

34
save.png.import Normal file
View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://csolqkavjib0q"
path="res://.godot/imported/save.png-1fda18d696be34ca219c753e7bfa9be7.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://save.png"
dest_files=["res://.godot/imported/save.png-1fda18d696be34ca219c753e7bfa9be7.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@@ -266,7 +266,7 @@ class Threat:
return value return value
func init_treats(table, btn_add, btn_del, btn_save): # Инициализация вкладки с целями func init_treats(table, nodes): # Инициализация вкладки с целями
for i in range(ID_ARRAY_LEN): # Заполняет массив ID целей for i in range(ID_ARRAY_LEN): # Заполняет массив ID целей
id_array.append(i+1) id_array.append(i+1)
table.set_header(TABLE_HEADER_TYPES) table.set_header(TABLE_HEADER_TYPES)
@@ -278,10 +278,15 @@ func init_treats(table, btn_add, btn_del, btn_save): # Инициализ
table.connect('row_pressed', Callable(self, 'on_row_pressed').bind(table)) table.connect('row_pressed', Callable(self, 'on_row_pressed').bind(table))
table.connect_columns(self, 'text_submitted', 'on_edit_entry', TABLE_ENTRY_COLUMNS, []) table.connect_columns(self, 'text_submitted', 'on_edit_entry', TABLE_ENTRY_COLUMNS, [])
table.connect_columns(self, 'item_selected', 'on_item_selected', COLUMN_OPT_BTN, []) table.connect_columns(self, 'item_selected', 'on_item_selected', COLUMN_OPT_BTN, [])
btn_add.connect('button_up', Callable(self, 'on_btn_add').bind(table)) nodes.btn_add.connect('button_up', Callable(self, 'on_btn_add').bind(table))
btn_del.connect('button_up', Callable(self, 'on_btn_del').bind(table)) nodes.btn_del.connect('button_up', Callable(self, 'on_btn_del').bind(table))
btn_save.connect('button_up', Callable(self, 'on_btn_save')) nodes.btn_save.connect('button_up', Callable(self, 'on_btn_save'))
nodes.btn_load.connect('pressed', Callable(self, 'on_btn_load').bind(table))
nodes.btn_rt.connect('pressed', Callable(self, 'on_rotate_th').bind(nodes.entry_rt, table))
var timer = Timer.new()
timer.connect('timeout', Callable(self, 'on_timeout').bind(nodes.entry_rt, table, nodes.chkbx_rt))
add_child(timer) #to process
timer.start(1) #to start
func load_treats(table): func load_treats(table):
var file = FileAccess.open('user://save.json', FileAccess.READ) var file = FileAccess.open('user://save.json', FileAccess.READ)
@@ -467,3 +472,33 @@ func set_ticks(treat):
var tick = Time.get_ticks_msec() var tick = Time.get_ticks_msec()
var cell = g_table.get_node2(COLUMN_TICK, treat.row_id) var cell = g_table.get_node2(COLUMN_TICK, treat.row_id)
cell.text = str(treat.set_tick(str(tick%60000))) cell.text = str(treat.set_tick(str(tick%60000)))
func on_rotate_th(entry, table):
if entry.text.is_valid_float():
for th in treats.values():
var aoa = th.row.aoa[0]
aoa += float(entry.text)
if aoa > 360.0:
aoa -= 360.0
elif aoa < 0:
aoa += 360.0
th.set_aoa(str(aoa))
var node_aoa = table.get_node2(1, th.row_id)
if th.row.aoa[1]:
node_aoa.text = str(th.row.aoa[0])
else:
print_debug('Угол поворота целей задан не верно')
func on_timeout(entry, table, chkbx_rt):
if chkbx_rt.button_pressed:
on_rotate_th(entry, table)
func on_btn_load(table):
for i in table.get_rows_count():
var cell = table.get_node2(0, 0)
treats.erase(cell.text)
table.remove_row(0)
load_treats(table)