hover fix
This commit is contained in:
@@ -3,16 +3,18 @@ class_name ItemObject
|
||||
|
||||
const ITEM_AREA_WIDTH = 20
|
||||
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):
|
||||
item = _item
|
||||
if object_sprite:
|
||||
object_sprite.apply_texture_to_sprite(item.icon, ITEM_SPRITE_SIZE)
|
||||
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):
|
||||
if _item:
|
||||
@@ -24,6 +26,15 @@ func _ready():
|
||||
object_sprite.apply_texture_to_sprite(item.icon, ITEM_SPRITE_SIZE)
|
||||
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:
|
||||
var name_suffix = ""
|
||||
|
||||
@@ -42,21 +53,27 @@ func card_info() -> CardInfo:
|
||||
|
||||
func interact(player : Player) -> bool:
|
||||
if player.can_pick_item(item):
|
||||
await pickup_animation(player)
|
||||
await pickup_animation(player.global_position)
|
||||
queue_free()
|
||||
player.pick_item(item)
|
||||
return true
|
||||
|
||||
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
|
||||
var tween : Tween = get_tree().create_tween()
|
||||
var tween: Tween = get_tree().create_tween()
|
||||
|
||||
if object_sprite:
|
||||
object_sprite.pickup_animation()
|
||||
await tween.tween_property(self, "position", player.position, 0.2).finished
|
||||
Pointer.stop_inspect(self)
|
||||
await tween.tween_property(self , "global_position", target_position, 0.2).finished
|
||||
Pointer.stop_inspect(self )
|
||||
|
||||
func generate_sprite() -> ItemObjectSprite:
|
||||
var sprite_node = SPRITE_SCENE.instantiate() as ItemObjectSprite
|
||||
@@ -71,4 +88,4 @@ func generate_sprite() -> ItemObjectSprite:
|
||||
return sprite_node
|
||||
|
||||
func save() -> EntityData:
|
||||
return ItemObjectData.new(self)
|
||||
return ItemObjectData.new(self )
|
||||
|
||||
@@ -16,7 +16,6 @@ const CARD_UP_PADDING = 50
|
||||
var all_inspected : Array[Node]
|
||||
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
|
||||
@@ -60,9 +59,6 @@ func _process(delta):
|
||||
else :
|
||||
%ActionProgressBar.value = 0.
|
||||
|
||||
var current_inspected := get_current_inspected()
|
||||
if current_inspected != inspected:
|
||||
time_last_inspected += delta
|
||||
%Inspector.position = get_viewport().get_mouse_position()
|
||||
|
||||
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_inspector(current_inspected)
|
||||
update_inspector(get_current_inspected())
|
||||
|
||||
func process_player_actions(delta : float):
|
||||
can_interact = (
|
||||
@@ -154,7 +150,6 @@ func inspect(node: Node):
|
||||
func update_card():
|
||||
if (
|
||||
not inspected or inspected_card_info == null
|
||||
or time_last_inspected > CARD_VISUALISATION_TIME
|
||||
or get_tree().paused
|
||||
or action_disabled
|
||||
):
|
||||
@@ -188,17 +183,19 @@ func update_card():
|
||||
|
||||
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 current_inspected:
|
||||
if 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
|
||||
if inspected.has_method("inspect"):
|
||||
inspected.inspect(true)
|
||||
else:
|
||||
inspected = null
|
||||
|
||||
if player and not action_disabled and (get_tree() and not get_tree().paused):
|
||||
if can_interact and inspected and inspected is Interactable:
|
||||
|
||||
Reference in New Issue
Block a user