#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

@@ -1,4 +1,4 @@
[gd_scene load_steps=21 format=3 uid="uid://12nak7amd1uq"]
[gd_scene load_steps=30 format=3 uid="uid://12nak7amd1uq"]
[ext_resource type="Script" uid="uid://cqao7n800qy40" path="res://gui/game/scripts/game_gui.gd" id="1_udau0"]
[ext_resource type="Theme" uid="uid://bgcmd213j6gk1" path="res://gui/ressources/default_theme.tres" id="2_nq5i2"]
@@ -10,6 +10,53 @@
[ext_resource type="FontFile" uid="uid://cpnsnrqhfkj3k" path="res://gui/ressources/fonts/spincycle_ot.otf" id="8_n4kem"]
[ext_resource type="Texture2D" uid="uid://b5cuxgisrsfgt" path="res://gui/game/pause/assets/icons/player-pause.svg" id="9_2wykm"]
[sub_resource type="Gradient" id="Gradient_id0t5"]
interpolation_mode = 1
offsets = PackedFloat32Array(0, 0.115169, 0.41573, 0.620786, 0.924157)
colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_ykapk"]
gradient = SubResource("Gradient_id0t5")
fill_to = Vector2(1, 1)
repeat = 1
[sub_resource type="Animation" id="Animation_p6blc"]
resource_name = "default"
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5, 1.03333),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Color(0.950568, 0, 0.346412, 1), Color(0.999996, 0.39403, 0.49625, 1), Color(0.950568, 0, 0.346412, 1)]
}
[sub_resource type="Animation" id="Animation_l73to"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(0.950568, 0, 0.346412, 1)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_l3q4a"]
_data = {
&"RESET": SubResource("Animation_l73to"),
&"default": SubResource("Animation_p6blc")
}
[sub_resource type="AtlasTexture" id="AtlasTexture_ek73b"]
atlas = ExtResource("7_n4kem")
region = Rect2(76, 75, 124, 135)
@@ -21,6 +68,15 @@ font_size = 20
[sub_resource type="LabelSettings" id="LabelSettings_n4kem"]
font_size = 12
[sub_resource type="Gradient" id="Gradient_2wykm"]
offsets = PackedFloat32Array(0, 0.279476, 1)
colors = PackedColorArray(1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_id0t5"]
gradient = SubResource("Gradient_2wykm")
fill = 1
fill_from = Vector2(0.5, 0.5)
[sub_resource type="Animation" id="Animation_iyvkh"]
length = 0.001
tracks/0/type = "value"
@@ -38,66 +94,14 @@ tracks/0/keys = {
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("MarginContainer/PlayerInfo/EnergyInfo:offset_left")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [-44.0]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("Effect:modulate")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 0)]
}
tracks/3/type = "value"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath("MarginContainer/PlayerInfo/EnergyInfo:offset_bottom")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [12.5]
}
[sub_resource type="Animation" id="Animation_n4kem"]
resource_name = "no_energy_left"
length = 0.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("MarginContainer/PlayerInfo/EnergyInfo:offset_left")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.0333333, 0.1, 0.166667, 0.233333, 0.3, 0.366667, 0.433333, 0.5),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1),
"update": 0,
"values": [-44.0, -40.0, -44.0, -48.0, -44.0, -40.0, -44.0, -40.0, -44.0]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Effect:modulate")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.1, 0.266667),
"transitions": PackedFloat32Array(1, 1, 1),
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(0.866667, 0.152941, 0.337255, 0), Color(0.866667, 0.152941, 0.337255, 0.392157), Color(0.866667, 0.152941, 0.337255, 0)]
"values": [Color(1, 1, 1, 0)]
}
[sub_resource type="Animation" id="Animation_id0t5"]
@@ -131,52 +135,86 @@ tracks/0/keys = {
"values": [Color(0.0627451, 0.0588235, 0.168627, 0), Color(0.0627451, 0.0588235, 0.168627, 1), Color(0.0627451, 0.0588235, 0.168627, 1), Color(0.0627451, 0.0588235, 0.168627, 0)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_n4kem"]
_data = {
&"RESET": SubResource("Animation_iyvkh"),
&"not_permitted": SubResource("Animation_id0t5"),
&"pass_day": SubResource("Animation_ykapk")
}
[sub_resource type="Animation" id="Animation_2wykm"]
resource_name = "upgrade"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:modulate")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.2, 0.9),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Color(0.6, 0.580392, 0, 0), Color(0.600196, 0.581106, 0, 0.392157), Color(0.6, 0.580392, 0, 0)]
}
[sub_resource type="Animation" id="Animation_l3q4a"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 0)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_nhqnj"]
_data = {
&"RESET": SubResource("Animation_l3q4a"),
&"upgrade": SubResource("Animation_2wykm")
}
[sub_resource type="Animation" id="Animation_w16yr"]
resource_name = "no_energy_left_appear"
length = 0.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Effect:modulate")
tracks/0/path = NodePath("NoEnergyLeft:position")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.133333, 0.5),
"transitions": PackedFloat32Array(1, 1, 1),
"times": PackedFloat32Array(0.0666667, 0.5),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(0.67451, 0.52549, 0.203922, 0), Color(0.67451, 0.52549, 0.203922, 0.572549), Color(0.67451, 0.52549, 0.203922, 0)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("MarginContainer/PlayerInfo/EnergyInfo:offset_bottom")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.233333, 0.5),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [12.5, -32.0, 12.5]
"values": [Vector2(0, -100), Vector2(0, 0)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_n4kem"]
[sub_resource type="Animation" id="Animation_mbdxg"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("NoEnergyLeft:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0, -100)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_p0xoq"]
_data = {
&"RESET": SubResource("Animation_iyvkh"),
&"no_energy_left": SubResource("Animation_n4kem"),
&"not_permitted": SubResource("Animation_id0t5"),
&"pass_day": SubResource("Animation_ykapk"),
&"upgrade": SubResource("Animation_2wykm")
&"RESET": SubResource("Animation_mbdxg"),
&"no_energy_left_appear": SubResource("Animation_w16yr")
}
[sub_resource type="Gradient" id="Gradient_2wykm"]
offsets = PackedFloat32Array(0, 0.279476, 1)
colors = PackedColorArray(1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_id0t5"]
gradient = SubResource("Gradient_2wykm")
fill = 1
fill_from = Vector2(0.5, 0.5)
[node name="RootGui" type="Control"]
layout_mode = 3
anchors_preset = 15
@@ -189,6 +227,40 @@ size_flags_vertical = 3
mouse_filter = 1
script = ExtResource("1_udau0")
[node name="NoEnergyLeft" type="VBoxContainer" parent="."]
unique_name_in_owner = true
visible = false
modulate = Color(0.950568, 0, 0.346412, 1)
layout_mode = 1
anchors_preset = 10
anchor_right = 1.0
offset_top = -100.0
offset_bottom = 2.0
grow_horizontal = 2
theme = ExtResource("2_nq5i2")
theme_override_constants/separation = 12
[node name="TextureRect" type="TextureRect" parent="NoEnergyLeft"]
custom_minimum_size = Vector2(0, 40)
layout_mode = 2
texture = SubResource("GradientTexture2D_ykapk")
expand_mode = 1
stretch_mode = 1
[node name="Label" type="Label" parent="NoEnergyLeft"]
layout_mode = 2
theme = ExtResource("2_nq5i2")
text = "No energy left"
label_settings = ExtResource("4_ujg5r")
horizontal_alignment = 1
vertical_alignment = 1
[node name="BlinkAnimation" type="AnimationPlayer" parent="NoEnergyLeft"]
libraries = {
&"": SubResource("AnimationLibrary_l3q4a")
}
autoplay = "default"
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 1
anchors_preset = 15
@@ -345,11 +417,6 @@ grow_vertical = 2
mouse_filter = 2
color = Color(0.0627451, 0.0588235, 0.168627, 0)
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_n4kem")
}
[node name="GridContainer" type="GridContainer" parent="."]
layout_mode = 0
offset_right = 40.0
@@ -366,4 +433,20 @@ grow_vertical = 2
mouse_filter = 2
texture = SubResource("GradientTexture2D_id0t5")
[node name="PassDayAnimation" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_n4kem")
}
[node name="EffectAnimation" type="AnimationPlayer" parent="."]
root_node = NodePath("../Effect")
libraries = {
&"": SubResource("AnimationLibrary_nhqnj")
}
[node name="NoEnergyLeftAnimation" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_p0xoq")
}
[connection signal="pressed" from="MarginContainer/TopRightContent/Pause" to="." method="_on_pause_pressed"]

View File

@@ -7,6 +7,8 @@ func _on_player_updated(player:Player):
%EnergyCount.text = str(player.energy) + "/" + str(player.max_energy)
%EnergyInfo.modulate = Color.WHITE if player.energy > 0 else Color.RED
update_no_energy_left_info(player.energy)
%ItemInfo.visible = player.inventory.get_item() != null
if player.inventory.get_item():
var item : Item = player.inventory.get_item()
@@ -34,14 +36,17 @@ func _on_pause_pressed():
func _on_player_upgraded():
$AnimationPlayer.play("upgrade")
func _on_player_action_not_permitted():
$AnimationPlayer.play("not_permitted")
$EffectAnimation.play("upgrade")
func _on_planet_pass_day_started(planet):
$AnimationPlayer.speed_scale = 1/(planet.PASS_DAY_ANIMATION_TIME)
$AnimationPlayer.play("pass_day")
await $AnimationPlayer.animation_finished
$AnimationPlayer.speed_scale = 1
$PassDayAnimation.speed_scale = 1/(planet.PASS_DAY_ANIMATION_TIME)
$PassDayAnimation.play("pass_day")
await $PassDayAnimation.animation_finished
$PassDayAnimation.speed_scale = 1
func update_no_energy_left_info(energy):
if energy == 0 and not %NoEnergyLeft.visible:
%NoEnergyLeft.visible = true
$NoEnergyLeftAnimation.play("no_energy_left_appear")
elif energy != 0 and %NoEnergyLeft.visible:
%NoEnergyLeft.visible = false

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