adding focus handling to card board

This commit is contained in:
betalars 2023-07-11 15:04:46 +02:00
parent 079150aa10
commit 67cde4ca17
1 changed files with 12 additions and 3 deletions

View File

@ -3,6 +3,16 @@ extends PanelContainer
var area_dict = {} var area_dict = {}
enum ui_context {DROPZONE, POST_IT_LIST, ASSIGN_POST_IT} enum ui_context {DROPZONE, POST_IT_LIST, ASSIGN_POST_IT}
var has_focus = false:
set(focus):
if focus != has_focus:
if focus:
has_focus = true
self.mouse_filter = Control.MOUSE_FILTER_PASS
else:
has_focus = false
self.mouse_filter = Control.MOUSE_FILTER_IGNORE
@onready var dropzone = $HBoxContainer/dropzone @onready var dropzone = $HBoxContainer/dropzone
@onready var postit_container = $HBoxContainer/ScrollContainer/VBoxContainer @onready var postit_container = $HBoxContainer/ScrollContainer/VBoxContainer
@onready var board_of_devs = $"board of devs" @onready var board_of_devs = $"board of devs"
@ -31,13 +41,12 @@ func _ready():
func _process(delta): func _process(delta):
# Reset information about Areas being dragged, if the mouse is not longer pressed. # Reset information about Areas being dragged, if the mouse is not longer pressed.
# Needed because otherwise it can happen that the areas don't register it if you stop clicking on them. # Needed because otherwise it can happen that the areas don't register it if you stop clicking on them.
if !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and is_area_dragged: if has_focus and !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and is_area_dragged:
currently_dragged_area.is_dragged = false currently_dragged_area.is_dragged = false
is_area_dragged = false is_area_dragged = false
currently_dragged_area = null currently_dragged_area = null
# Will be used later to spawn Cards and Post-Its and remember them in the dictionary # Will be used later to spawn Cards and Post-Its and remember them in the dictionary
func populate_board(card_names: Array): func populate_board(card_names: Array):
var all_cards = Array() var all_cards = Array()
@ -191,7 +200,7 @@ func reorder_areas(reorder: String):
# Takes the inputs for control inputs # Takes the inputs for control inputs
func _input(event): func _input(event):
# Return, if the input is a mouse event (mouse events are handled separately) # Return, if the input is a mouse event (mouse events are handled separately)
if event is InputEventMouse: return if event is InputEventMouse or !has_focus: return
if event.is_action_pressed("ui_up"): # up to select an element above if event.is_action_pressed("ui_up"): # up to select an element above
match active_context: match active_context: