hover fix

This commit is contained in:
Altaezio
2026-06-05 14:47:37 +02:00
parent 1b56a648c3
commit 52ebf0e7d5
2 changed files with 40 additions and 26 deletions

View File

@@ -3,16 +3,18 @@ class_name ItemObject
const ITEM_AREA_WIDTH = 20 const ITEM_AREA_WIDTH = 20
const ITEM_SPRITE_SIZE = 40. const ITEM_SPRITE_SIZE = 40.
const SPRITE_SCENE : PackedScene = preload("res://entities/interactables/item_object/item_object_sprite.tscn") const SPRITE_SCENE: PackedScene = preload("res://entities/interactables/item_object/item_object_sprite.tscn")
@export var item : Item : @export var item: Item:
set(_item): set(_item):
item = _item item = _item
if object_sprite: if object_sprite:
object_sprite.apply_texture_to_sprite(item.icon, ITEM_SPRITE_SIZE) object_sprite.apply_texture_to_sprite(item.icon, ITEM_SPRITE_SIZE)
object_sprite.generate_particles(item.get_particles()) object_sprite.generate_particles(item.get_particles())
@onready var object_sprite : ItemObjectSprite = generate_sprite() @onready var object_sprite: ItemObjectSprite = generate_sprite()
var dragging := false
func _init(_item = null): func _init(_item = null):
if _item: if _item:
@@ -24,6 +26,15 @@ func _ready():
object_sprite.apply_texture_to_sprite(item.icon, ITEM_SPRITE_SIZE) object_sprite.apply_texture_to_sprite(item.icon, ITEM_SPRITE_SIZE)
object_sprite.generate_particles(item.get_particles()) object_sprite.generate_particles(item.get_particles())
func _process(_delta):
if dragging:
global_position = get_global_mouse_position()
func _on_mouse_entered():
mouse_over = true
if not dragging:
Pointer.inspect(self)
func pointer_text() -> String: func pointer_text() -> String:
var name_suffix = "" var name_suffix = ""
@@ -42,21 +53,27 @@ func card_info() -> CardInfo:
func interact(player : Player) -> bool: func interact(player : Player) -> bool:
if player.can_pick_item(item): if player.can_pick_item(item):
await pickup_animation(player) await pickup_animation(player.global_position)
queue_free() queue_free()
player.pick_item(item) player.pick_item(item)
return true return true
return false return false
func pickup_animation(player : Player): func start_dragging():
dragging = true
func stop_dragging():
dragging = false
func pickup_animation(target_position: Vector2):
available = false available = false
var tween : Tween = get_tree().create_tween() var tween: Tween = get_tree().create_tween()
if object_sprite: if object_sprite:
object_sprite.pickup_animation() object_sprite.pickup_animation()
await tween.tween_property(self, "position", player.position, 0.2).finished await tween.tween_property(self , "global_position", target_position, 0.2).finished
Pointer.stop_inspect(self) Pointer.stop_inspect(self )
func generate_sprite() -> ItemObjectSprite: func generate_sprite() -> ItemObjectSprite:
var sprite_node = SPRITE_SCENE.instantiate() as ItemObjectSprite var sprite_node = SPRITE_SCENE.instantiate() as ItemObjectSprite
@@ -71,4 +88,4 @@ func generate_sprite() -> ItemObjectSprite:
return sprite_node return sprite_node
func save() -> EntityData: func save() -> EntityData:
return ItemObjectData.new(self) return ItemObjectData.new(self )

View File

@@ -16,7 +16,6 @@ const CARD_UP_PADDING = 50
var all_inspected : Array[Node] var all_inspected : Array[Node]
var inspected : Node = null var inspected : Node = null
var inspected_card_info : CardInfo = null var inspected_card_info : CardInfo = null
var time_last_inspected : float = 0.
var player : Player # renseigné par Player var player : Player # renseigné par Player
var can_interact : bool = false var can_interact : bool = false
var current_selected_item : Item = null var current_selected_item : Item = null
@@ -60,9 +59,6 @@ func _process(delta):
else : else :
%ActionProgressBar.value = 0. %ActionProgressBar.value = 0.
var current_inspected := get_current_inspected()
if current_inspected != inspected:
time_last_inspected += delta
%Inspector.position = get_viewport().get_mouse_position() %Inspector.position = get_viewport().get_mouse_position()
if not action_disabled and current_selected_item and SceneManager.actual_scene.scene_id == "REGION": if not action_disabled and current_selected_item and SceneManager.actual_scene.scene_id == "REGION":
@@ -75,7 +71,7 @@ func _process(delta):
update_card() update_card()
update_inspector(current_inspected) update_inspector(get_current_inspected())
func process_player_actions(delta : float): func process_player_actions(delta : float):
can_interact = ( can_interact = (
@@ -154,7 +150,6 @@ func inspect(node: Node):
func update_card(): func update_card():
if ( if (
not inspected or inspected_card_info == null not inspected or inspected_card_info == null
or time_last_inspected > CARD_VISUALISATION_TIME
or get_tree().paused or get_tree().paused
or action_disabled or action_disabled
): ):
@@ -188,17 +183,19 @@ func update_card():
func update_inspector(current_inspected:Node): func update_inspector(current_inspected:Node):
if current_inspected and inspected != current_inspected: if current_inspected:
if inspected and inspected.has_method("inspect"): if inspected != current_inspected:
inspected.inspect(false) if inspected and inspected.has_method("inspect"):
inspected = current_inspected inspected.inspect(false)
if inspected.has_method("card_info"): inspected = current_inspected
inspected_card_info = inspected.card_info() if inspected.has_method("card_info"):
else: inspected_card_info = inspected.card_info()
inspected_card_info = null else:
time_last_inspected = 0 inspected_card_info = null
if inspected.has_method("inspect"): if inspected.has_method("inspect"):
inspected.inspect(true) inspected.inspect(true)
else:
inspected = null
if player and not action_disabled and (get_tree() and not get_tree().paused): if player and not action_disabled and (get_tree() and not get_tree().paused):
if can_interact and inspected and inspected is Interactable: if can_interact and inspected and inspected is Interactable: