extends Node const DEFAULT_ACTION_COLOR = Color.WHITE const ENERGY_ACTION_COLOR = Color("ffff2b") const NO_ENERGY_ACTION_COLOR = Color.RED const ZONE_OPACITY = 0.4 const ZONE_ACTIVATED_COLOR = Color.TURQUOISE const ZONE_DEACTIVATED_COLOR = Color.REBECCA_PURPLE const CARD_VISUALISATION_TIME = 0.5 const CARD_UP_PADDING = 20 @export var default_cursor : Texture2D var current_inspect : Node = null var inspected : Node = null var inspected_card_info : CardInfo = null var time_last_inspected : float = 0. var player : Player # renseigné par Player var can_interact : bool = false var current_selected_item : Item = null var have_energy_to_use_item : bool = false var could_use_item : bool = false var can_use_item : bool = false func _ready(): Input.set_custom_mouse_cursor(default_cursor) %Action.visible = false func _input(_event): if player: if Input.is_action_just_pressed("move"): player.try_move( player.get_global_mouse_position() ) if Input.is_action_just_pressed("drop"): player.drop_item() if Input.is_action_just_pressed("action"): if can_interact: var interactable = current_inspect as Interactable player.try_interact(interactable) elif can_use_item: player.try_use_item( player.data.inventory.get_item(), player.get_global_mouse_position() ) func _process(delta): if current_inspect != inspected: time_last_inspected += delta %Inspector.position = get_viewport().get_mouse_position() if player: can_interact = ( current_inspect and current_inspect is Interactable and player.can_interact(current_inspect) ) current_selected_item = player.data.inventory.get_item() could_use_item = ( current_selected_item and player.preview_could_use_item(current_selected_item) ) have_energy_to_use_item = ( current_selected_item and player.has_energy_to_use_item(current_selected_item) ) can_use_item = could_use_item and have_energy_to_use_item if current_selected_item: %ActionZone.radius = current_selected_item.usage_zone_radius %ActionZone.color = ZONE_ACTIVATED_COLOR if can_use_item else ZONE_DEACTIVATED_COLOR else: %ActionZone.radius = 0 %ActionZone.queue_redraw() update_card() update_inspector() 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 is InspectableEntity: inspected_card_info = inspected.card_info() elif inspected is InventoryGuiItem and inspected.item != null: inspected_card_info = inspected.item.card_info() else : inspected_card_info = null time_last_inspected = 0 if current_inspect.has_method("inspect"): current_inspect.inspect(true) update_inspector() func update_card(): if not inspected or inspected_card_info == null or time_last_inspected > CARD_VISUALISATION_TIME: %CardVisualiser.hide() elif inspected != null and ( inspected is InspectableEntity or inspected is InventoryGuiItem ): if inspected_card_info != %CardVisualiser.card_info: %CardVisualiser.card_info = inspected_card_info %CardVisualiser.show() var camera = get_viewport().get_camera_2d() var screen_size = get_viewport().get_visible_rect().size if inspected is InspectableEntity: %CardPosition.position = inspected.global_position - camera.global_position + screen_size / 2 + CARD_UP_PADDING * Vector2.UP elif inspected is InventoryGuiItem: %CardPosition.position = inspected.global_position + inspected.size/2 + CARD_UP_PADDING * Vector2.UP if %CardVisualiser.is_mouse_over(): time_last_inspected = 0. func update_inspector(): if player: if can_interact and current_inspect and current_inspect 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 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 "") if can_use_item: %Action.modulate = DEFAULT_ACTION_COLOR if current_selected_item.energy_usage == 0 else ENERGY_ACTION_COLOR else : %Action.modulate = NO_ENERGY_ACTION_COLOR %ActionEnergyImage.visible = current_selected_item.energy_usage != 0 else: %Action.visible = false else: %Action.visible = false func stop_inspect(node : Node): if node.has_method("inspect"): node.inspect(false) if current_inspect == node: current_inspect = null update_inspector()