Add Brogether debug panel

This commit is contained in:
Kroonk
2026-05-23 00:42:15 +02:00
parent 536cbff829
commit de73f4a51d
3 changed files with 108 additions and 1 deletions

View File

@@ -53,6 +53,7 @@ Danach Brotato komplett neu starten.
## Debug-Tasten
```text
F5 Debug-Panel ein-/ausblenden
F6 Steam-Lobby erstellen
F7 Lobby suchen / joinen
F9 Lobby verlassen
@@ -60,6 +61,8 @@ F10 Ping senden
F11 Lokalen Loopback-Test starten
```
Zusätzlich zeigt Brogether ein kleines Debug-Panel oben rechts mit Buttons fuer Host, Join, Leave, Ping und Loopback. Das Panel ist fuer die naechsten Zwei-Client-Tests gedacht und ersetzt die meisten Hotkey-Aktionen.
Brogether schreibt ein eigenes Log nach:
```text

View File

@@ -29,6 +29,7 @@ Danach Brotato ueber Steam starten. Die Mod sollte im Mod-Menue auftauchen.
## Debug-Hotkeys im Spiel
- `F5`: Debug-Panel ein-/ausblenden
- `F6`: oeffentliche Dev-Steam-Lobby erstellen
- `F7`: Brogether-Lobby suchen und beitreten
- `F9`: Lobby verlassen

View File

@@ -11,6 +11,9 @@ var is_host := false
var packet_sequence := 0
var status_layer: CanvasLayer = null
var status_label: Label = null
var panel: PanelContainer = null
var panel_status_label: Label = null
var panel_log_label: Label = null
var status_time_left := 0.0
var current_run_id := ""
var current_run_active := false
@@ -28,8 +31,9 @@ func _ready() -> void:
set_process_input(true)
_clear_log()
_create_status_overlay()
_create_debug_panel()
_init_steam()
_log("loaded. F6=create lobby, F7=find/join lobby, F9=leave, F10=ping, F11=loopback test")
_log("loaded. F5=toggle panel, F6=create lobby, F7=find/join lobby, F9=leave, F10=ping, F11=loopback test")
func _process(_delta: float) -> void:
@@ -49,6 +53,9 @@ func _input(event: InputEvent) -> void:
if not event is InputEventKey or not event.pressed or event.echo:
return
match event.scancode:
KEY_F5:
toggle_debug_panel()
get_tree().set_input_as_handled()
KEY_F6:
create_lobby()
get_tree().set_input_as_handled()
@@ -72,6 +79,7 @@ func create_lobby() -> void:
return
if lobby_id != 0:
_log("already in lobby %s" % lobby_id)
_update_debug_panel()
return
var lobby_type := 2
_log("creating public dev lobby")
@@ -108,6 +116,7 @@ func leave_lobby() -> void:
lobby_id = 0
lobby_members.clear()
is_host = false
_update_debug_panel()
func send_ping() -> void:
@@ -239,6 +248,7 @@ func _on_lobby_created(connect: int, created_lobby_id: int) -> void:
steam.call("setLobbyData", lobby_id, "brogether", "1")
steam.call("setLobbyData", lobby_id, "version", "0.1.0")
_refresh_lobby_members()
_update_debug_panel()
func _on_lobby_joined(joined_lobby_id: int, _permissions: int, _locked: bool, response: int) -> void:
@@ -251,6 +261,7 @@ func _on_lobby_joined(joined_lobby_id: int, _permissions: int, _locked: bool, re
is_host = steam.has_method("getLobbyOwner") and int(steam.call("getLobbyOwner", lobby_id)) == steam_id
_log("joined lobby %s as %s with %s member(s)" % [lobby_id, "host" if is_host else "client", lobby_members.size()])
_send_p2p_packet(0, {"type": "handshake", "from": steam_id})
_update_debug_panel()
func _on_lobby_match_list(lobbies: Array) -> void:
@@ -268,6 +279,7 @@ func _on_lobby_chat_update(this_lobby_id: int, _changed_id: int, _making_change_
return
_refresh_lobby_members()
_send_p2p_packet(0, {"type": "handshake", "from": steam_id})
_update_debug_panel()
func _on_p2p_session_request(remote_id: int) -> void:
@@ -292,6 +304,7 @@ func _refresh_lobby_members() -> void:
persona = steam.call("getFriendPersonaName", member_id)
lobby_members.append({"steam_id": member_id, "name": persona})
_log("members: %s" % lobby_members)
_update_debug_panel()
func _read_all_p2p_packets(read_count: int = 0) -> void:
@@ -374,6 +387,7 @@ func _log(message: String) -> void:
var line := "[Brogether] %s" % message
print(line)
_show_status(message)
_update_debug_panel(message)
var file := File.new()
var error := file.open(LOG_PATH, File.READ_WRITE)
if error != OK:
@@ -394,6 +408,7 @@ func _clear_log() -> void:
func _create_status_overlay() -> void:
status_layer = CanvasLayer.new()
status_layer.name = "BrogetherStatusLayer"
status_layer.layer = 100
status_layer.pause_mode = Node.PAUSE_MODE_PROCESS
add_child(status_layer)
@@ -412,6 +427,94 @@ func _create_status_overlay() -> void:
status_layer.add_child(status_label)
func _create_debug_panel() -> void:
panel = PanelContainer.new()
panel.name = "BrogetherPanel"
panel.anchor_left = 1.0
panel.anchor_right = 1.0
panel.anchor_top = 0.0
panel.anchor_bottom = 0.0
panel.margin_left = -280
panel.margin_right = -16
panel.margin_top = 54
panel.margin_bottom = 286
panel.pause_mode = Node.PAUSE_MODE_PROCESS
var style := StyleBoxFlat.new()
style.bg_color = Color(0.05, 0.07, 0.08, 0.88)
style.border_color = Color(0.25, 1.0, 0.65, 0.9)
style.set_border_width_all(1)
style.set_corner_radius_all(4)
style.content_margin_left = 10
style.content_margin_right = 10
style.content_margin_top = 10
style.content_margin_bottom = 10
panel.add_stylebox_override("panel", style)
var box := VBoxContainer.new()
box.name = "Content"
box.add_constant_override("separation", 6)
panel.add_child(box)
var title := Label.new()
title.text = "Brogether"
title.add_color_override("font_color", Color(0.25, 1.0, 0.65, 1.0))
box.add_child(title)
panel_status_label = Label.new()
panel_status_label.text = "Steam: ..."
panel_status_label.autowrap = true
box.add_child(panel_status_label)
var grid := GridContainer.new()
grid.columns = 2
grid.add_constant_override("hseparation", 6)
grid.add_constant_override("vseparation", 6)
box.add_child(grid)
_add_panel_button(grid, "Host", "create_lobby")
_add_panel_button(grid, "Join", "find_lobbies")
_add_panel_button(grid, "Leave", "leave_lobby")
_add_panel_button(grid, "Ping", "send_ping")
_add_panel_button(grid, "Loopback", "run_loopback_test")
_add_panel_button(grid, "Hide F5", "toggle_debug_panel")
panel_log_label = Label.new()
panel_log_label.text = "Ready"
panel_log_label.autowrap = true
panel_log_label.rect_min_size = Vector2(240, 46)
box.add_child(panel_log_label)
status_layer.add_child(panel)
_update_debug_panel()
func _add_panel_button(parent: Control, label: String, method_name: String) -> void:
var button := Button.new()
button.text = label
button.rect_min_size = Vector2(118, 30)
button.focus_mode = Control.FOCUS_NONE
button.connect("pressed", self, method_name)
parent.add_child(button)
func toggle_debug_panel() -> void:
if panel == null:
return
panel.visible = not panel.visible
_show_status("debug panel %s" % ("shown" if panel.visible else "hidden"))
func _update_debug_panel(last_message: String = "") -> void:
if panel_status_label == null:
return
var lobby_text := "none" if lobby_id == 0 else str(lobby_id)
var role := "host" if is_host else "client"
panel_status_label.text = "Steam %s\nLobby %s\nRole %s | Members %s" % [steam_id, lobby_text, role, lobby_members.size()]
if panel_log_label != null and not last_message.empty():
panel_log_label.text = last_message
func _show_status(message: String) -> void:
if status_label == null:
return