#44 changement de la méthode d'interaction et d'utilisation du joueur pour une plus grande liberté de la souris
This commit is contained in:
@@ -3,14 +3,32 @@ extends Node
|
||||
@export var default_cursor : Texture2D
|
||||
|
||||
var inspected_entity : InspectableEntity = null
|
||||
var player : Player # renseigné par Player
|
||||
var player : Player :# renseigné par Player
|
||||
set(v):
|
||||
# if player:
|
||||
# player.player_updated.disconnect(update_inspector)
|
||||
player = v
|
||||
player.player_updated.connect(
|
||||
func(p): update_inspector()
|
||||
)
|
||||
|
||||
func _ready():
|
||||
Input.set_custom_mouse_cursor(default_cursor)
|
||||
%InspectorText.visible = false
|
||||
%Interact.visible = false
|
||||
%Use.visible = false
|
||||
|
||||
func _input(_event):
|
||||
if Input.is_action_just_pressed("interact"):
|
||||
$Audio/Click.play()
|
||||
if (
|
||||
player != null
|
||||
and inspected_entity
|
||||
and inspected_entity is Interactable
|
||||
):
|
||||
var interactable = inspected_entity as Interactable
|
||||
if interactable.can_interact(player):
|
||||
player.target_interactable = interactable
|
||||
|
||||
func _process(_delta):
|
||||
%Inspector.position = get_viewport().get_mouse_position()
|
||||
@@ -18,14 +36,32 @@ func _process(_delta):
|
||||
func inspect_entity(entity : InspectableEntity):
|
||||
if inspected_entity and inspected_entity != entity:
|
||||
inspected_entity.inspected = false
|
||||
%InspectorText.text = entity.inspected_text()
|
||||
%InspectorText.visible = true
|
||||
inspected_entity = entity
|
||||
inspected_entity.inspected = true
|
||||
update_inspector()
|
||||
|
||||
func update_inspector():
|
||||
print("updated")
|
||||
|
||||
%InspectorText.visible = inspected_entity != null
|
||||
if inspected_entity:
|
||||
%InspectorText.text = inspected_entity.inspected_text()
|
||||
|
||||
if player:
|
||||
%Interact.visible = inspected_entity and inspected_entity is Interactable and inspected_entity.can_interact(player)
|
||||
if inspected_entity and inspected_entity is Interactable and inspected_entity.can_interact(player):
|
||||
%InspectorInteractionText.text = inspected_entity.interact_text()
|
||||
|
||||
%Use.visible = player.can_use_item
|
||||
if player.inventory.get_item() and player.can_use_item:
|
||||
%InspectorUseText.text = player.inventory.get_item().use_text(player)
|
||||
else:
|
||||
%Interact.visible = false
|
||||
%Use.visible = false
|
||||
|
||||
|
||||
func stop_inspect_entity(entity : InspectableEntity):
|
||||
entity.inspected = false
|
||||
if inspected_entity == entity:
|
||||
%InspectorText.visible = false
|
||||
inspected_entity = null
|
||||
|
||||
update_inspector()
|
||||
|
||||
Reference in New Issue
Block a user