amélioration de l'UI de l'inventaire et ajout de la récompense d'amélioration de taille d'inventaire #52

This commit is contained in:
2025-09-19 17:31:12 +02:00
parent 00c7e9bc4c
commit bcd8038b3a
19 changed files with 329 additions and 104 deletions

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=30 format=3 uid="uid://12nak7amd1uq"]
[gd_scene load_steps=29 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"]
@@ -7,9 +7,8 @@
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://common/icons/bolt.svg" id="4_k4juk"]
[ext_resource type="LabelSettings" uid="uid://dqwayi8yjwau2" path="res://gui/ressources/title_label_settings.tres" id="4_ujg5r"]
[ext_resource type="PackedScene" uid="uid://d3lff5fui1k0c" path="res://gui/game/inspector/inspector.tscn" id="6_dr1y2"]
[ext_resource type="Texture2D" uid="uid://bf6nw4onkhavr" path="res://common/icons/shovel.svg" id="8_h6540"]
[ext_resource type="Texture2D" uid="uid://b5cuxgisrsfgt" path="res://common/icons/player-pause.svg" id="9_2wykm"]
[ext_resource type="Texture2D" uid="uid://bupl1y0cfj21q" path="res://entities/plants/assets/sprites/chardi/mature.png" id="9_id0t5"]
[ext_resource type="PackedScene" uid="uid://clicjf8ts51h8" path="res://gui/game/inventory_gui/inventory_gui.tscn" id="9_id0t5"]
[sub_resource type="Gradient" id="Gradient_id0t5"]
interpolation_mode = 1
@@ -377,33 +376,12 @@ focus_mode = 0
mouse_filter = 1
icon = ExtResource("9_2wykm")
[node name="Inventory" type="HBoxContainer" parent="MarginContainer"]
[node name="Inventory" parent="MarginContainer" instance=ExtResource("9_id0t5")]
unique_name_in_owner = true
custom_minimum_size = Vector2(48, 48)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 8
[node name="TextureRect" type="TextureRect" parent="MarginContainer/Inventory"]
modulate = Color(1, 0, 1, 1)
custom_minimum_size = Vector2(48, 48)
layout_mode = 2
texture = ExtResource("8_h6540")
expand_mode = 3
[node name="TextureRect2" type="TextureRect" parent="MarginContainer/Inventory"]
custom_minimum_size = Vector2(48, 48)
layout_mode = 2
texture = ExtResource("4_k4juk")
expand_mode = 3
[node name="TextureRect3" type="TextureRect" parent="MarginContainer/Inventory"]
modulate = Color(1, 0.37254903, 0.101960786, 1)
custom_minimum_size = Vector2(48, 48)
layout_mode = 2
texture = ExtResource("9_id0t5")
expand_mode = 3
[node name="PassDayFade" type="ColorRect" parent="."]
physics_interpolation_mode = 0
layout_mode = 1
@@ -415,11 +393,6 @@ grow_vertical = 2
mouse_filter = 2
color = Color(0.0627451, 0.0588235, 0.168627, 0)
[node name="GridContainer" type="GridContainer" parent="."]
layout_mode = 0
offset_right = 40.0
offset_bottom = 40.0
[node name="Effect" type="TextureRect" parent="."]
modulate = Color(1, 1, 1, 0)
layout_mode = 1

View File

@@ -0,0 +1,13 @@
[gd_scene load_steps=3 format=3 uid="uid://clicjf8ts51h8"]
[ext_resource type="Script" uid="uid://dplbbs2dlq308" path="res://gui/game/inventory_gui/scripts/inventory_gui.gd" id="1_himlj"]
[ext_resource type="PackedScene" uid="uid://dadihouw8o3jx" path="res://gui/game/inventory_gui/inventory_item/inventory_gui_item.tscn" id="2_0vvyy"]
[node name="Inventory" type="HBoxContainer"]
custom_minimum_size = Vector2(48, 48)
offset_right = 156.0
offset_bottom = 153.0
size_flags_horizontal = 0
size_flags_vertical = 0
script = ExtResource("1_himlj")
inventory_item_scene = ExtResource("2_0vvyy")

View File

@@ -0,0 +1,107 @@
[gd_scene load_steps=11 format=3 uid="uid://dadihouw8o3jx"]
[ext_resource type="Script" uid="uid://c8qfny4dlg7ql" path="res://gui/game/inventory_gui/inventory_item/scripts/inventory_gui_item.gd" id="2_m0ja8"]
[ext_resource type="Texture2D" uid="uid://bf6nw4onkhavr" path="res://common/icons/shovel.svg" id="2_xs0u7"]
[sub_resource type="Animation" id="Animation_046xr"]
length = 0.001
[sub_resource type="Animation" id="Animation_x2pqk"]
resource_name = "squish"
length = 0.2
[sub_resource type="AnimationLibrary" id="AnimationLibrary_k17ff"]
_data = {
&"RESET": SubResource("Animation_046xr"),
&"squish": SubResource("Animation_x2pqk")
}
[sub_resource type="Animation" id="Animation_m0ja8"]
resource_name = "selected"
length = 0.2
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("BottomSpace:custom_minimum_size")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector2(0, 0), Vector2(0, 15)]
}
[sub_resource type="Animation" id="Animation_k17ff"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("BottomSpace:custom_minimum_size")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0, 0)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_2wu2x"]
_data = {
&"RESET": SubResource("Animation_k17ff"),
&"selected": SubResource("Animation_m0ja8")
}
[sub_resource type="Gradient" id="Gradient_fu672"]
interpolation_mode = 1
offsets = PackedFloat32Array(0, 0.44886363)
colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_vgckh"]
gradient = SubResource("Gradient_fu672")
fill = 1
fill_from = Vector2(0.48290598, 0.48290598)
[node name="InventoryItem" type="VBoxContainer"]
custom_minimum_size = Vector2(48, 48)
offset_right = 48.0
offset_bottom = 52.0
size_flags_horizontal = 0
size_flags_vertical = 8
script = ExtResource("2_m0ja8")
[node name="SquishAnimation" type="AnimationPlayer" parent="."]
unique_name_in_owner = true
libraries = {
&"": SubResource("AnimationLibrary_k17ff")
}
[node name="SelectedAnimation" type="AnimationPlayer" parent="."]
unique_name_in_owner = true
libraries = {
&"": SubResource("AnimationLibrary_2wu2x")
}
[node name="CenterContainer" type="CenterContainer" parent="."]
layout_mode = 2
[node name="NoItemTextureRect" type="TextureRect" parent="CenterContainer"]
unique_name_in_owner = true
visible = false
custom_minimum_size = Vector2(12, 12)
layout_mode = 2
texture = SubResource("GradientTexture2D_vgckh")
expand_mode = 2
stretch_mode = 5
[node name="TextureRect" type="TextureRect" parent="CenterContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(48, 48)
layout_mode = 2
texture = ExtResource("2_xs0u7")
expand_mode = 1
stretch_mode = 5
[node name="BottomSpace" type="Control" parent="."]
layout_mode = 2

View File

@@ -0,0 +1,50 @@
extends Control
class_name InventoryGuiItem
@export var no_item_texture_path : Texture2D
const MODULATE_INSPECTED_COLOR = Color.GRAY
var current_item : Item = null
var was_selected : bool = false
func _ready():
mouse_entered.connect(_on_mouse_entered)
mouse_exited.connect(_on_mouse_excited)
update(null, false)
func inspect(is_inspected : bool = true):
modulate = MODULATE_INSPECTED_COLOR if is_inspected else Color.WHITE
func _on_mouse_entered():
if current_item:
Pointer.inspect(self, inspector_info())
func _on_mouse_excited():
if current_item:
Pointer.stop_inspect(self)
func inspector_info() -> Inspector.Info:
return Inspector.Info.new(
current_item.name,
current_item.description,
current_item.icon
)
func update(item: Item, selected : bool):
if selected and not was_selected:
%SelectedAnimation.play("selected")
elif not selected and was_selected:
%SelectedAnimation.play_backwards("selected")
if item != current_item:
%SquishAnimation.play("squish")
print("squish")
if item and item.icon:
%TextureRect.texture = item.icon
%TextureRect.visible = item != null
%NoItemTextureRect.visible = item == null
current_item = item
was_selected = selected

View File

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

View File

@@ -0,0 +1,26 @@
extends HBoxContainer
class_name InventoryGui
@export var inventory_item_scene : PackedScene
var inventory_item_objects : Array[InventoryGuiItem]
func update(inventory : Inventory):
if len(inventory_item_objects) == 0 or len(inventory_item_objects) != inventory.size:
for o in inventory_item_objects:
o.queue_free()
inventory_item_objects = generate_inventory_item_objects(inventory.size)
for i in range(inventory.size):
inventory_item_objects[i].update(
inventory.get_item(i),
i == inventory.current_item_ind and inventory.get_item(i) != null
)
func generate_inventory_item_objects(nb : int = 1) -> Array[InventoryGuiItem]:
var objects : Array[InventoryGuiItem] = []
for i in range(nb):
var o = inventory_item_scene.instantiate() as InventoryGuiItem
add_child(o)
objects.append(o)
return objects

View File

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

View File

@@ -4,29 +4,13 @@ class_name GameGui
signal pause_asked
func _ready():
Pointer.connect("inspected_entity_changed", _on_inspected_entity_changed)
Pointer.connect("inspected_changed", _on_inspected_changed)
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
for i in player.inventory.max_items:
var item : Item = player.inventory.get_item(i)
if item:
if %Inventory.get_child_count() <= i:
var texture_rect = TextureRect.new()
texture_rect.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL
%Inventory.add_child(texture_rect)
%Inventory.get_child(i).texture = item.icon
%Inventory.get_child(i).visible = true
if i == player.inventory.current_item_ind:
%Inventory.get_child(i).modulate = Color.WHITE
else:
%Inventory.get_child(i).modulate = Color.DARK_GRAY
else:
if %Inventory.get_child_count() > i:
%Inventory.get_child(i).visible = false
%Inventory.update(player.inventory)
update_no_energy_left_info(player.energy)
@@ -59,10 +43,7 @@ func _on_planet_pass_day_started(planet):
await $PassDayAnimation.animation_finished
$PassDayAnimation.speed_scale = 1
func _on_inspected_entity_changed(e : InspectableEntity):
var info : Inspector.Info = null
if e:
info = e.inspector_info()
func _on_inspected_changed(info : Inspector.Info):
%Inspector.info = info
func update_no_energy_left_info(energy):