Added console panel with device and host console, logs and domain console.
This commit is contained in:
1 parent
6038b816b7
commit
b98ed82619
17 files changed
+551
-22
No files matched your search
@@ -16,8 +16,12 @@ signal deactivated
|
||||
@export_node_path("Control") var initial_focus: NodePath
|
||||
|
||||
var is_active: bool = false
|
||||
var _layout_editing := false
|
||||
var _registered := false
|
||||
var _blocked_shortcuts: Dictionary = {}
|
||||
var _frame_host: Control
|
||||
const EMBEDDED_PANEL = preload("res://themes/layout_embedded_panel.tres")
|
||||
var _last_focus: Control
|
||||
var _shortcut_available: bool = true
|
||||
var _initial_focus_control: Control
|
||||
@onready var content: VBoxContainer = $MarginContainer/VBoxContainer/Content
|
||||
@onready var _panel: PanelContainer = $PanelContainer
|
||||
@@ -33,16 +37,13 @@ func _ready() -> void:
|
||||
_route_content_child(child)
|
||||
child_entered_tree.connect(_on_child_entered_tree)
|
||||
add_to_group("keyboard_focus_containers")
|
||||
_registered = true
|
||||
focus_mode = Control.FOCUS_NONE
|
||||
_shortcut.focus_mode = Control.FOCUS_NONE
|
||||
_shortcut.pressed.connect(activate)
|
||||
for other in get_tree().get_nodes_in_group("keyboard_focus_containers"):
|
||||
if other != self and other.get_viewport() == get_viewport() and other.focus_key == focus_key and other._shortcut_available:
|
||||
_shortcut_available = false
|
||||
_shortcut.disabled = true
|
||||
_shortcut.tooltip_text = "Shortcut already assigned to " + other.title
|
||||
push_warning("Duplicate panel shortcut: " + OS.get_keycode_string(focus_key))
|
||||
break
|
||||
refresh_shortcuts(get_tree())
|
||||
get_window().focus_exited.connect(deactivate)
|
||||
theme_changed.connect(_update_style)
|
||||
get_viewport().gui_focus_changed.connect(_on_focus_changed)
|
||||
visibility_changed.connect(_on_visibility_changed)
|
||||
_update_style()
|
||||
@@ -54,7 +55,10 @@ func _refresh_header() -> void:
|
||||
if label != null:
|
||||
label.text = title
|
||||
if badge != null:
|
||||
badge.visible = focus_key != KEY_NONE
|
||||
badge.disabled = not is_shortcut_available(focus_key)
|
||||
badge.text = OS.get_keycode_string(focus_key) + (" · ACTIVE" if is_active else "")
|
||||
badge.tooltip_text = "Shortcut already used by " + str(_blocked_shortcuts.get(focus_key, "")) if _blocked_shortcuts.has(focus_key) else "Focus this panel"
|
||||
|
||||
func _on_child_entered_tree(child: Node) -> void:
|
||||
# SceneTree may still be adding the node when this signal fires.
|
||||
@@ -68,11 +72,12 @@ func _route_content_child(child: Node) -> void:
|
||||
child.reparent(content, false)
|
||||
|
||||
func activate() -> void:
|
||||
if Engine.is_editor_hint() or not is_visible_in_tree() or not _shortcut_available:
|
||||
if Engine.is_editor_hint() or not focus_available():
|
||||
return
|
||||
for other in get_tree().get_nodes_in_group("keyboard_focus_containers"):
|
||||
if other != self and other.get_viewport() == get_viewport():
|
||||
if other != self:
|
||||
other.deactivate()
|
||||
get_window().grab_focus()
|
||||
var was_active := is_active
|
||||
is_active = true
|
||||
focus_mode = Control.FOCUS_ALL
|
||||
@@ -105,15 +110,14 @@ func deactivate() -> void:
|
||||
deactivated.emit()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if Engine.is_editor_hint() or not event is InputEventKey or not is_visible_in_tree():
|
||||
if Engine.is_editor_hint() or not is_visible_in_tree() or _layout_editing:
|
||||
return
|
||||
if dispatch_focus_shortcut(event, get_tree()):
|
||||
get_viewport().set_input_as_handled()
|
||||
return
|
||||
if not event is InputEventKey:
|
||||
return
|
||||
var key := event as InputEventKey
|
||||
if key.keycode == focus_key and not key.alt_pressed and not key.ctrl_pressed and not key.meta_pressed and not key.shift_pressed and _shortcut_available:
|
||||
# Consume releases and repeats as well, so shortcuts never become input.
|
||||
get_viewport().set_input_as_handled()
|
||||
if key.pressed and not key.echo:
|
||||
activate()
|
||||
return
|
||||
if not is_active or not key.pressed:
|
||||
return
|
||||
if key.keycode == KEY_ESCAPE:
|
||||
@@ -145,8 +149,77 @@ func _on_focus_changed(control: Control) -> void:
|
||||
func _on_visibility_changed() -> void:
|
||||
if not is_visible_in_tree():
|
||||
deactivate()
|
||||
if is_inside_tree():
|
||||
refresh_shortcuts(get_tree())
|
||||
|
||||
func _update_style() -> void:
|
||||
var style_name := "panel_active" if is_active else "panel_inactive"
|
||||
_panel.add_theme_stylebox_override("panel", get_theme_stylebox(style_name, "SurfaceSide"))
|
||||
if is_instance_valid(_frame_host):
|
||||
_panel.add_theme_stylebox_override("panel", EMBEDDED_PANEL)
|
||||
_frame_host.add_theme_stylebox_override("panel", get_theme_stylebox(style_name, "SurfaceSide"))
|
||||
else:
|
||||
_panel.add_theme_stylebox_override("panel", get_theme_stylebox(style_name, "SurfaceSide"))
|
||||
_refresh_header()
|
||||
|
||||
func get_focus_shortcuts() -> Array[Key]:
|
||||
return [focus_key] if focus_key != KEY_NONE else []
|
||||
|
||||
func is_shortcut_available(key: Key) -> bool:
|
||||
return key != KEY_NONE and not _blocked_shortcuts.has(key)
|
||||
|
||||
func focus_available() -> bool:
|
||||
return _registered and is_inside_tree() and is_visible_in_tree() and not _layout_editing
|
||||
|
||||
func activate_shortcut(_key: Key) -> void:
|
||||
activate()
|
||||
|
||||
func set_layout_editing(editing: bool) -> void:
|
||||
_layout_editing = editing
|
||||
if editing:
|
||||
deactivate()
|
||||
if is_inside_tree():
|
||||
refresh_shortcuts(get_tree())
|
||||
|
||||
func set_frame_host(host: Control) -> void:
|
||||
_frame_host = host
|
||||
if is_node_ready():
|
||||
_update_style()
|
||||
|
||||
func _exit_tree() -> void:
|
||||
_registered = false
|
||||
if not Engine.is_editor_hint() and get_tree() != null:
|
||||
refresh_shortcuts(get_tree())
|
||||
|
||||
static func refresh_shortcuts(tree: SceneTree) -> void:
|
||||
var scopes := tree.get_nodes_in_group("keyboard_focus_containers")
|
||||
scopes.sort_custom(func(a: Node, b: Node) -> bool: return a.get_instance_id() < b.get_instance_id())
|
||||
var claimed: Dictionary = {}
|
||||
for scope in scopes:
|
||||
scope._blocked_shortcuts.clear()
|
||||
if scope.focus_available():
|
||||
for key in scope.get_focus_shortcuts():
|
||||
if key == KEY_NONE:
|
||||
continue
|
||||
if claimed.has(key) and claimed[key] != scope:
|
||||
scope._blocked_shortcuts[key] = claimed[key].title
|
||||
else:
|
||||
claimed[key] = scope
|
||||
scope._refresh_header()
|
||||
|
||||
static func dispatch_focus_shortcut(event: InputEvent, tree: SceneTree) -> bool:
|
||||
if not event is InputEventKey or event.alt_pressed or event.ctrl_pressed or event.meta_pressed or event.shift_pressed:
|
||||
return false
|
||||
var matches := false
|
||||
for scope in tree.get_nodes_in_group("keyboard_focus_containers"):
|
||||
if scope.focus_available() and event.keycode in scope.get_focus_shortcuts():
|
||||
matches = true
|
||||
break
|
||||
if not matches:
|
||||
return false
|
||||
refresh_shortcuts(tree)
|
||||
for scope in tree.get_nodes_in_group("keyboard_focus_containers"):
|
||||
if scope.focus_available() and event.keycode in scope.get_focus_shortcuts() and scope.is_shortcut_available(event.keycode):
|
||||
if event.pressed and not event.echo:
|
||||
scope.activate_shortcut(event.keycode)
|
||||
return true
|
||||
return false
|
||||
Reference in new issue
Block a user