forked from datawhale/whale-town-front
fix: 修复欢迎板和通知板通知无法关闭问题
- 修复欢迎板和通知板当前被ChatUI 抢占鼠标问题,通过设置启动弹窗时ChatUI 根节点 mouse_filter 临时改为 IGNORE来实现 - ToDo: 后续统一规划事件逻辑
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
extends CanvasLayer
|
||||
|
||||
var _chat_ui: Control
|
||||
var _chat_ui_prev_mouse_filter: int = Control.MOUSE_FILTER_STOP
|
||||
var _chat_ui_mouse_disabled: bool = false
|
||||
|
||||
func _ready():
|
||||
_disable_chat_ui_mouse_input()
|
||||
|
||||
# Connect close button (X)
|
||||
var header_close = find_child("CloseButton", true, false)
|
||||
if header_close:
|
||||
@@ -11,6 +17,9 @@ func _ready():
|
||||
if start_btn:
|
||||
start_btn.pressed.connect(_on_close_pressed)
|
||||
|
||||
func _exit_tree():
|
||||
_restore_chat_ui_mouse_input()
|
||||
|
||||
func _on_close_pressed():
|
||||
queue_free()
|
||||
|
||||
@@ -18,3 +27,23 @@ func _input(event):
|
||||
# Allow ESC to close
|
||||
if event.is_action_pressed("ui_cancel"):
|
||||
queue_free()
|
||||
|
||||
func _disable_chat_ui_mouse_input():
|
||||
var current_scene = get_tree().current_scene
|
||||
if current_scene:
|
||||
_chat_ui = current_scene.get_node_or_null("UILayer/ChatUI") as Control
|
||||
|
||||
if _chat_ui == null:
|
||||
_chat_ui = get_tree().root.find_child("ChatUI", true, false) as Control
|
||||
|
||||
if _chat_ui:
|
||||
_chat_ui_prev_mouse_filter = _chat_ui.mouse_filter
|
||||
_chat_ui.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_chat_ui_mouse_disabled = true
|
||||
|
||||
func _restore_chat_ui_mouse_input():
|
||||
if _chat_ui_mouse_disabled and is_instance_valid(_chat_ui):
|
||||
_chat_ui.mouse_filter = _chat_ui_prev_mouse_filter
|
||||
|
||||
_chat_ui_mouse_disabled = false
|
||||
_chat_ui = null
|
||||
|
||||
Reference in New Issue
Block a user