Added UI focus tracking
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
class_name UIManager
|
||||
class_name UI
|
||||
extends Node
|
||||
|
||||
static var focus: Control
|
||||
|
||||
signal chat_message_submitted(message: String)
|
||||
|
||||
@export var login: Signal
|
||||
@ -11,8 +13,18 @@ signal chat_message_submitted(message: String)
|
||||
@export var message_received: Signal
|
||||
|
||||
func _enter_tree():
|
||||
if !get_node_or_null("/root/Main"):
|
||||
connect_fake()
|
||||
if get_node_or_null("/root/Main"):
|
||||
return
|
||||
|
||||
connect_fake()
|
||||
|
||||
func _process(_delta):
|
||||
var new_focus := get_viewport().gui_get_focus_owner()
|
||||
|
||||
if new_focus && new_focus.name != "Unfocus":
|
||||
UI.focus = new_focus
|
||||
else:
|
||||
UI.focus = null
|
||||
|
||||
func connect_fake():
|
||||
for property in get_property_list():
|
||||
@ -21,3 +33,7 @@ func connect_fake():
|
||||
|
||||
add_user_signal(property.name)
|
||||
set(property.name, Signal(self, property.name))
|
||||
|
||||
static func unfocus():
|
||||
if UI.focus:
|
||||
UI.focus.release_focus()
|
@ -19,6 +19,16 @@
|
||||
[node name="UI" type="CanvasLayer"]
|
||||
script = ExtResource("1_l5b6o")
|
||||
|
||||
[node name="Unfocus" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
focus_mode = 1
|
||||
mouse_filter = 1
|
||||
|
||||
[node name="TopLeft" type="MarginContainer" parent="."]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 50.0
|
||||
@ -113,7 +123,7 @@ grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
|
||||
[node name="Chat" type="VBoxContainer" parent="Bottom"]
|
||||
custom_minimum_size = Vector2(200, 0)
|
||||
custom_minimum_size = Vector2(320, 180)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
alignment = 2
|
||||
@ -121,8 +131,12 @@ alignment = 2
|
||||
[node name="ChatBox" type="RichTextLabel" parent="Bottom/Chat"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
focus_mode = 2
|
||||
bbcode_enabled = true
|
||||
scroll_active = false
|
||||
scroll_following = true
|
||||
context_menu_enabled = true
|
||||
selection_enabled = true
|
||||
script = ExtResource("5_43juw")
|
||||
|
||||
[node name="ChatInput" type="LineEdit" parent="Bottom/Chat"]
|
||||
@ -224,7 +238,3 @@ anchor_left = 0.25
|
||||
anchor_top = 0.25
|
||||
anchor_right = 0.75
|
||||
anchor_bottom = 0.75
|
||||
|
||||
[connection signal="focus_entered" from="Bottom/Chat/ChatInput" to="Bottom/Chat/ChatInput" method="_on_focus_entered"]
|
||||
[connection signal="focus_exited" from="Bottom/Chat/ChatInput" to="Bottom/Chat/ChatInput" method="_on_focus_exited"]
|
||||
[connection signal="text_submitted" from="Bottom/Chat/ChatInput" to="Bottom/Chat/ChatInput" method="_on_text_submitted"]
|
||||
|
@ -2,26 +2,27 @@ extends LineEdit
|
||||
|
||||
func _ready():
|
||||
modulate.a = 0.0
|
||||
focus_entered.connect(on_focus_entered)
|
||||
focus_exited.connect(on_focus_exited)
|
||||
text_submitted.connect(on_text_submitted)
|
||||
|
||||
func _unhandled_key_input(event):
|
||||
if Global.interacting_with_ui:
|
||||
if UI.focus:
|
||||
return
|
||||
|
||||
if event.is_action_pressed("open_chat"):
|
||||
call_deferred("grab_focus")
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
func _on_focus_entered():
|
||||
func on_focus_entered():
|
||||
var tween := get_tree().create_tween()
|
||||
tween.tween_property(self, "modulate", Color(1, 1, 1, 1), 0.2)
|
||||
Global.interacting_with_ui = true
|
||||
|
||||
func _on_focus_exited():
|
||||
func on_focus_exited():
|
||||
var tween := get_tree().create_tween()
|
||||
tween.tween_property(self, "modulate", Color(1, 1, 1, 0), 0.2)
|
||||
Global.interacting_with_ui = false
|
||||
|
||||
func _on_text_submitted(message: String):
|
||||
(owner as UIManager).chat_message_submitted.emit(message)
|
||||
func on_text_submitted(message: String):
|
||||
(owner as UI).chat_message_submitted.emit(message)
|
||||
text = ""
|
||||
release_focus()
|
||||
|
@ -3,9 +3,15 @@ extends CheckButton
|
||||
@export var layer_number: int
|
||||
|
||||
func _ready():
|
||||
if !Global.camera:
|
||||
return
|
||||
|
||||
set_pressed_no_signal(Global.camera.cull_mask & (1 << (layer_number - 1)))
|
||||
|
||||
func on_toggled(toggled_on: bool):
|
||||
if !Global.camera:
|
||||
return
|
||||
|
||||
if toggled_on:
|
||||
Global.camera.cull_mask |= 1 << (layer_number - 1)
|
||||
else:
|
||||
|
Reference in New Issue
Block a user