#57 rework des inputs et actions

This commit is contained in:
2025-09-05 15:11:29 +02:00
parent 3d0104ed4a
commit 2dc365736f
21 changed files with 490 additions and 358 deletions

View File

@@ -4,7 +4,7 @@
[ext_resource type="Texture2D" uid="uid://bspffyprdywgc" path="res://gui/pointer/assets/cursors/pointer.svg" id="2_q4bvb"]
[ext_resource type="AudioStream" uid="uid://bym03qp4n6vep" path="res://gui/pointer/assets/sounds/click.wav" id="3_kj0cm"]
[ext_resource type="Texture2D" uid="uid://djb52fosgmv4j" path="res://gui/pointer/assets/icons/left_click.svg" id="3_pshoq"]
[ext_resource type="Texture2D" uid="uid://y3083o1fhgn0" path="res://gui/pointer/assets/icons/right_click.svg" id="4_b4uwv"]
[ext_resource type="Script" uid="uid://c2en2hc6a7ils" path="res://gui/pointer/scripts/action_zone.gd" id="4_pshoq"]
[node name="Pointer" type="Node"]
process_mode = 3
@@ -37,37 +37,26 @@ z_index = 1
layout_mode = 2
text = "Item"
[node name="Interact" type="HBoxContainer" parent="CanvasLayer/Inspector/Container"]
[node name="Action" type="HBoxContainer" parent="CanvasLayer/Inspector/Container"]
unique_name_in_owner = true
modulate = Color(1, 1, 0.168627, 1)
layout_mode = 2
[node name="TextureRect" type="TextureRect" parent="CanvasLayer/Inspector/Container/Interact"]
[node name="TextureRect" type="TextureRect" parent="CanvasLayer/Inspector/Container/Action"]
layout_mode = 2
texture = ExtResource("3_pshoq")
[node name="InspectorInteractionText" type="Label" parent="CanvasLayer/Inspector/Container/Interact"]
[node name="ActionText" type="Label" parent="CanvasLayer/Inspector/Container/Action"]
unique_name_in_owner = true
z_index = 1
layout_mode = 2
text = "Take"
horizontal_alignment = 1
[node name="Use" type="HBoxContainer" parent="CanvasLayer/Inspector/Container"]
[node name="ActionZone" type="Sprite2D" parent="CanvasLayer/Inspector"]
unique_name_in_owner = true
modulate = Color(1, 1, 0.168627, 1)
layout_mode = 2
[node name="TextureRect" type="TextureRect" parent="CanvasLayer/Inspector/Container/Use"]
layout_mode = 2
texture = ExtResource("4_b4uwv")
[node name="InspectorUseText" type="Label" parent="CanvasLayer/Inspector/Container/Use"]
unique_name_in_owner = true
z_index = 1
layout_mode = 2
text = "Gloubi"
horizontal_alignment = 1
position = Vector2(0, -1)
script = ExtResource("4_pshoq")
[node name="Audio" type="Node" parent="."]

View File

@@ -0,0 +1,17 @@
extends Sprite2D
class_name ActionZone
const OPACITY = 0.4
const ACTIVATED_COLOR = Color.TURQUOISE
const DEACTIVATED_COLOR = Color.REBECCA_PURPLE
var radius : int = 0
var active : bool = false
func _draw():
draw_circle(
Vector2.ZERO,
radius,
Color((ACTIVATED_COLOR if active else DEACTIVATED_COLOR), OPACITY)
)

View File

@@ -0,0 +1 @@
uid://c2en2hc6a7ils

View File

@@ -3,36 +3,62 @@ extends Node
@export var default_cursor : Texture2D
var inspected_entity : InspectableEntity = null
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()
)
var player : Player # renseigné par Player
var can_interact : bool = false
var current_selected_item : Item = null
var can_use_item : bool = false
func _ready():
Input.set_custom_mouse_cursor(default_cursor)
%InspectorText.visible = false
%Interact.visible = false
%Use.visible = false
%Action.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
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 = inspected_entity as Interactable
player.try_interact(interactable)
elif can_use_item:
player.try_use_item(
player.inventory.get_item(),
player.get_global_mouse_position()
)
func _process(_delta):
%Inspector.position = get_viewport().get_mouse_position()
if player:
can_interact = (
inspected_entity
and inspected_entity is Interactable
and player.can_interact(inspected_entity)
)
current_selected_item = player.inventory.get_item()
can_use_item = (
current_selected_item
and player.preview_can_use_item(current_selected_item)
)
if current_selected_item:
%ActionZone.radius = current_selected_item.use_zone_radius
%ActionZone.active = can_use_item
else:
%ActionZone.radius = 0
%ActionZone.queue_redraw()
update_inspector()
func inspect_entity(entity : InspectableEntity):
if inspected_entity and inspected_entity != entity:
inspected_entity.inspected = false
@@ -41,24 +67,22 @@ func inspect_entity(entity : InspectableEntity):
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()
if can_interact and inspected_entity and inspected_entity is Interactable:
%Action.visible = true
%ActionText.text = inspected_entity.interact_text()
elif can_use_item and current_selected_item:
%Action.visible = true
%ActionText.text = current_selected_item.use_text()
else:
%Action.visible = false
%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
%Action.visible = false
func stop_inspect_entity(entity : InspectableEntity):
entity.inspected = false