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:
13
gui/game/inventory_gui/inventory_gui.tscn
Normal file
13
gui/game/inventory_gui/inventory_gui.tscn
Normal 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")
|
||||
107
gui/game/inventory_gui/inventory_item/inventory_gui_item.tscn
Normal file
107
gui/game/inventory_gui/inventory_item/inventory_gui_item.tscn
Normal 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
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
uid://c8qfny4dlg7ql
|
||||
26
gui/game/inventory_gui/scripts/inventory_gui.gd
Normal file
26
gui/game/inventory_gui/scripts/inventory_gui.gd
Normal 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
|
||||
1
gui/game/inventory_gui/scripts/inventory_gui.gd.uid
Normal file
1
gui/game/inventory_gui/scripts/inventory_gui.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dplbbs2dlq308
|
||||
Reference in New Issue
Block a user