diff --git a/gui/pointer/scripts/pointer.gd b/gui/pointer/scripts/pointer.gd index b88fccf..39c1335 100644 --- a/gui/pointer/scripts/pointer.gd +++ b/gui/pointer/scripts/pointer.gd @@ -13,7 +13,7 @@ const CARD_UP_PADDING = 50 @export var default_cursor : Texture2D @export var hover_cursor : Texture2D -var current_inspect : Node = null +var all_inspected : Array[Node] var inspected : Node = null var inspected_card_info : CardInfo = null var time_last_inspected : float = 0. @@ -28,6 +28,27 @@ var press_action_done := false var action_disabled := false +func get_current_inspected() -> Node: + if all_inspected.size() > 0: + var mouse_pos := player.get_global_mouse_position() + var closest_dist := INF + var closest_ind := -1 + for i in all_inspected.size(): + var node := all_inspected[i] + if not is_instance_valid(node): + all_inspected.remove_at(i) + elif node is Node2D: + var dist = node.global_position.distance_squared_to(mouse_pos) + if dist < closest_dist: + closest_dist = dist + closest_ind = i + elif closest_ind < 0: + closest_ind = i + if all_inspected.size() > 0: + return all_inspected[closest_ind] + + return null + func _ready(): Input.set_custom_mouse_cursor(default_cursor) Input.set_custom_mouse_cursor(hover_cursor, Input.CURSOR_POINTING_HAND) @@ -39,7 +60,8 @@ func _process(delta): else : %ActionProgressBar.value = 0. - if current_inspect != inspected: + var current_inspected := get_current_inspected() + if current_inspected != inspected: time_last_inspected += delta %Inspector.position = get_viewport().get_mouse_position() @@ -53,13 +75,13 @@ func _process(delta): update_card() - update_inspector() + update_inspector(current_inspected) func process_player_actions(delta : float): can_interact = ( - current_inspect - and current_inspect is Interactable - and player.can_interact(current_inspect) + inspected + and inspected is Interactable + and player.can_interact(inspected) ) current_selected_item = player.data.inventory.get_item() @@ -92,7 +114,7 @@ func process_player_actions(delta : float): and current_selected_item.is_action_need_press_time() and not press_action_done and not can_interact - and not current_inspect is InventoryGuiItemMouseDetector + and not inspected is InventoryGuiItemMouseDetector ): press_time += delta %ActionProgressBar.value = press_time/current_selected_item.get_action_press_time() * 100 @@ -114,10 +136,10 @@ func process_player_actions(delta : float): %ActionProgressBar.value = 0. if Input.is_action_just_pressed("action"): - if current_inspect is InventoryGuiItemMouseDetector: + if inspected is InventoryGuiItemMouseDetector: GameInfo.game_data.player_data.inventory.set_current_item(inspected.index) elif can_interact: - var interactable = current_inspect as Interactable + var interactable = inspected as Interactable player.try_interact(interactable) elif can_use_item and not current_selected_item.is_action_need_press_time(): player.try_use_item( @@ -126,18 +148,8 @@ func process_player_actions(delta : float): ) func inspect(node: Node): - if current_inspect and current_inspect != node and current_inspect.has_method("inspect"): - current_inspect.inspect(false) - current_inspect = node - inspected = node - if inspected.has_method("card_info"): - inspected_card_info = inspected.card_info() - else: - inspected_card_info = null - time_last_inspected = 0 - if current_inspect.has_method("inspect"): - current_inspect.inspect(true) - update_inspector() + if not node in all_inspected: + all_inspected.append(node) func update_card(): if ( @@ -174,13 +186,26 @@ func update_card(): # time_last_inspected = 0. -func update_inspector(): +func update_inspector(current_inspected:Node): + + if current_inspected and inspected != current_inspected: + if inspected and inspected.has_method("inspect"): + inspected.inspect(false) + inspected = current_inspected + if inspected.has_method("card_info"): + inspected_card_info = inspected.card_info() + else: + inspected_card_info = null + time_last_inspected = 0 + if inspected.has_method("inspect"): + inspected.inspect(true) + if player and not action_disabled and (get_tree() and not get_tree().paused): - if can_interact and current_inspect and current_inspect is Interactable: + if can_interact and inspected and inspected is Interactable: %Action.visible = true - %ActionText.text = current_inspect.interact_text() - %Action.modulate = DEFAULT_ACTION_COLOR if current_inspect.interaction_cost(player) == 0 else ENERGY_ACTION_COLOR - %ActionEnergyImage.visible = current_inspect.interaction_cost(player) != 0 + %ActionText.text = inspected.interact_text() + %Action.modulate = DEFAULT_ACTION_COLOR if inspected.interaction_cost(player) == 0 else ENERGY_ACTION_COLOR + %ActionEnergyImage.visible = inspected.interaction_cost(player) != 0 elif current_selected_item and current_selected_item.use_text() != "": %Action.visible = true %ActionText.text = current_selected_item.use_text() + (tr("NO_ENERGY_LEFT") if not have_energy_to_use_item else "") @@ -194,9 +219,5 @@ func update_inspector(): else: %Action.visible = false -func stop_inspect(node : Node = current_inspect): - if node.has_method("inspect"): - node.inspect(false) - if current_inspect == node: - current_inspect = null - update_inspector() +func stop_inspect(node : Node = get_current_inspected()): + all_inspected.erase(node)