LargeScreen/main.gd

183 lines
5.0 KiB
GDScript3
Raw Permalink Normal View History

2024-12-18 19:45:53 +08:00
extends Control
2025-01-03 14:02:17 +08:00
var StateTab = null
2025-01-13 14:39:58 +08:00
var isEnd = false
var url = ""
signal finished
2025-01-03 14:02:17 +08:00
func _ready() -> void:
StateTab = find_child("StateTab")
2025-01-13 14:39:58 +08:00
Websocket.connected_to_server.connect(connected_to_server)
Websocket.message_received.connect(message_received)
#while !isEnd:
#print($HTTPRequest.read_response_body_chunk().s,"/",$HTTPRequest.get_body_size())
#await get_tree().create_timer(0.1).timeout
#
while true:
for urlItem in Global.urlArr:
url = urlItem
get_Advertise()
await finished
await get_tree().physics_frame
func connected_to_server():
CurrentStationInfo_Report()
all_station_info()
pass
var stations
var arrName = []
var current_stationName = ""
func message_received(data:Dictionary):
if data.is_empty():return
if !data.has("topic"):return
match data.topic:
#站点信息反馈
"/hmi_input/app/display/current_station_info":
#print(data.msg.current_station)#当前站点
#print(data.msg.target_station)#下一站点
if (!arrName.is_empty()) and current_stationName != data.msg.current_station.name:
current_stationName = data.msg.current_station.name
for index in arrName.size():
if arrName[index] == data.msg.current_station.name:
print(data.msg.target_station.name,"===",data.msg.current_station.name,"===",arrName[index-1],"===",arrName[index-2])
%StationView.set_station(data.msg.target_station.name,data.msg.current_station.name,arrName[index-1],arrName[index-2])
pass
pass
#获取所有站点信息
"/app/display/all_station_info":
stations = data.msg.stations
for item in stations:
arrName.append(item.name)
pass
#所有站点反馈
func all_station_info():
var send_data = {
"op": "subscribe",
"topic": "/app/display/all_station_info",
"type": "pixmoving_hmi_msgs/msg/V2dAllStationInfo"
}
Websocket.send_msg(str(send_data))
#任务站点信息反馈
func CurrentStationInfo_Report():
var send_data = {
"op": "subscribe",
"topic": "/hmi_input/app/display/current_station_info",
"type": "pixmoving_hmi_msgs/msg/V2dCurrentStationInfo"
}
Websocket.send_msg(str(send_data))
2024-12-18 19:45:53 +08:00
func _on_more_option_pressed() -> void:
2024-12-19 19:13:12 +08:00
%MoreOptionPanel.visibility_layer=not %MoreOptionPanel.visibility_layer
pass # Replace with function body.
func _on_ad_view_self_click(is_selected: bool) -> void:
%ADPanel.visible=not is_selected
2025-01-13 14:39:58 +08:00
if !%ADPanel.visible:
%AdpanelVideoStreamPlayer.stream = null
else:
get_Advertise()
2024-12-19 19:13:12 +08:00
if not is_selected:
%ADTab.hide()
2025-01-03 14:02:17 +08:00
StateTab.hide()
2024-12-19 19:13:12 +08:00
pass # Replace with function body.
func _on_tunnel_panel_request_hide() -> void:
%ADTab.hide()
2025-01-03 14:02:17 +08:00
StateTab.hide()
2024-12-19 19:13:12 +08:00
pass # Replace with function body.
func _on_tunnel_panel_search_click(str: String) -> void:
2025-01-13 14:39:58 +08:00
%AdpanelVideoStreamPlayer.stop()
finished.emit()
2024-12-19 19:13:12 +08:00
pass # Replace with function body.
func _on_language_pressed() -> void:
if %ADView.is_select:
2025-01-03 14:02:17 +08:00
StateTab.set_current_tab(0)
StateTab.show()
2024-12-19 19:13:12 +08:00
else:
%ADTab.set_current_tab(0)
%ADTab.show()
pass # Replace with function body.
func _on_tunnel_pressed() -> void:
if %ADView.is_select:
2025-01-03 14:02:17 +08:00
StateTab.set_current_tab(1)
StateTab.show()
2024-12-19 19:13:12 +08:00
else:
%ADTab.set_current_tab(1)
%ADTab.show()
pass # Replace with function body.
func _on_language_panel_horizontal_click(index: int) -> void:
%LanguageVertical.set_select(index)
pass # Replace with function body.
func _on_language_vertical_click(index: int) -> void:
%LanguagePanelHorizontal.set_select(index)
pass # Replace with function body.
func _on_language_close_requeset() -> void:
%ADTab.hide()
2025-01-03 14:02:17 +08:00
StateTab.hide()
2025-01-13 14:39:58 +08:00
pass # Replace with function body.
var download_start_time: int = 0
func get_Advertise():
var file_path = "user://"+url.get_file()
if FileAccess.file_exists(file_path):
%AdpanelVideoStreamPlayer.stream = load(file_path)
%AdpanelVideoStreamPlayer.play()
pass
else:
# 假设要下载的视频地址
print("开始下载广告视频" + url)
# 向服务器发起下载请求
$HTTPRequest.request(url)
pass
func _on_http_request_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray) -> void:
if result != OK or response_code != 200:
push_error("下载失败Result: %d, Response Code: %d" % [result, response_code])
return
# 计算下载总耗时(毫秒)
var total_time_ms = Time.get_ticks_msec() - download_start_time
var total_time_s = float(total_time_ms) / 1000.0
var total_size_bytes = body.size()
var speed_bps = total_size_bytes / total_time_s # 字节/秒
var speed_kbps = speed_bps / 1024.0
print("平均速度: %.2f KB/s" % speed_kbps)
# 写文件 + 播放
var file_path = "user://" + url.get_file()
var file = FileAccess.open(file_path, FileAccess.WRITE)
if file:
file.store_buffer(body)
file.close()
%AdpanelVideoStreamPlayer.stream = load(file_path)
%AdpanelVideoStreamPlayer.play()
else:
push_error("文件写入失败!")
pass # Replace with function body.
func _process(delta: float) -> void:
%AdpanelTextureRect.texture = %AdpanelVideoStreamPlayer.get_video_texture()
func _on_adpanel_video_stream_player_finished() -> void:
finished.emit()
2024-12-18 19:45:53 +08:00
pass # Replace with function body.