refonte de l'inventaire en 3D et nettoyage des prints

This commit is contained in:
2026-02-23 00:07:04 +01:00
parent 925bf4465c
commit fa21b3a558
41 changed files with 472 additions and 611 deletions

View File

@@ -37,7 +37,15 @@ import_script/path=""
materials/extract=0
materials/extract_format=0
materials/extract_path=""
_subresources={}
_subresources={
"materials": {
"Material": {
"use_external/enabled": true,
"use_external/fallback_path": "res://common/assets/materials/default_3d.tres",
"use_external/path": "uid://dvvi1k5c5iowc"
}
}
}
blender/nodes/visible=0
blender/nodes/active_collection_only=false
blender/nodes/punctual_lights=true

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,68 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://yqq3unuxmtdl"
path="res://.godot/imported/item_separator.blend-cac4afe123af52ae1e1aa2d79bf56691.scn"
[deps]
source_file="res://gui/game/inventory_gui/assets/3d/item_separator.blend"
dest_files=["res://.godot/imported/item_separator.blend-cac4afe123af52ae1e1aa2d79bf56691.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/root_script=null
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
nodes/use_name_suffixes=true
nodes/use_node_type_suffixes=true
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
materials/extract=0
materials/extract_format=0
materials/extract_path=""
_subresources={
"materials": {
"Material": {
"use_external/enabled": true,
"use_external/fallback_path": "res://common/assets/materials/default_3d.tres",
"use_external/path": "uid://dvvi1k5c5iowc"
}
}
}
blender/nodes/visible=0
blender/nodes/active_collection_only=false
blender/nodes/punctual_lights=true
blender/nodes/cameras=true
blender/nodes/custom_properties=true
blender/nodes/modifiers=1
blender/meshes/colors=false
blender/meshes/uvs=true
blender/meshes/normals=true
blender/meshes/export_geometry_nodes_instances=false
blender/meshes/gpu_instances=false
blender/meshes/tangents=true
blender/meshes/skins=2
blender/meshes/export_bones_deforming_mesh_only=false
blender/materials/unpack_enabled=true
blender/materials/export_materials=1
blender/animation/limit_playback=true
blender/animation/always_sample=true
blender/animation/group_tracks=true
gltf/naming_version=2

Binary file not shown.

View File

@@ -0,0 +1,17 @@
[gd_scene format=3 uid="uid://crbjmwumboelw"]
[ext_resource type="Script" uid="uid://c66acjl2dhd7x" path="res://gui/game/inventory_gui/scripts/inventory_3d.gd" id="1_k2pqu"]
[ext_resource type="PackedScene" uid="uid://4r2ab6foer05" path="res://gui/game/inventory_gui/inventory_item/inventory_item_3d.tscn" id="2_1jdtu"]
[ext_resource type="PackedScene" uid="uid://yqq3unuxmtdl" path="res://gui/game/inventory_gui/assets/3d/item_separator.blend" id="13_8twi0"]
[node name="Inventory3D" type="Node3D" unique_id=810532522]
script = ExtResource("1_k2pqu")
inventory_item_scene = ExtResource("2_1jdtu")
[node name="Items3D" type="Node3D" parent="." unique_id=893360425]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.25, 0, 0)
[node name="ItemSeparator" parent="." unique_id=999679207 instance=ExtResource("13_8twi0")]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.1, 0, 0)

View File

@@ -1,19 +1,85 @@
[gd_scene 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"]
[ext_resource type="Texture2D" uid="uid://dw80a4c5iekir" path="res://common/icons/bar.png" id="3_hqvrf"]
[ext_resource type="Environment" uid="uid://bxyp24f85p0xf" path="res://gui/game/assets/gui_3d_environment.tres" id="3_g6k02"]
[ext_resource type="Material" uid="uid://cr7bp4fhh1ipr" path="res://entities/player_3d/resources/materials/post_process_quad.tres" id="4_6ahyd"]
[ext_resource type="Script" uid="uid://bq7admu4ahs5r" path="res://entities/player/inventory/scripts/item.gd" id="4_tp3yk"]
[ext_resource type="Texture2D" uid="uid://ds4m14vl7he6v" path="res://common/icons/pick.svg" id="5_4v624"]
[ext_resource type="PackedScene" uid="uid://crbjmwumboelw" path="res://gui/game/inventory_gui/inventory_3d.tscn" id="5_hmild"]
[ext_resource type="Texture2D" uid="uid://4mh1w1f4q2sa" path="res://entities/plants/assets/sprites/pili/mature.png" id="6_10rrv"]
[ext_resource type="Script" uid="uid://fnu2d6wna4yc" path="res://entities/player/inventory/scripts/inventory.gd" id="7_upv64"]
[node name="Inventory" type="HBoxContainer" unique_id=1144799110 node_paths=PackedStringArray("bar")]
[sub_resource type="ViewportTexture" id="ViewportTexture_tp3yk"]
viewport_path = NodePath("ViewPortTexture/SubViewport")
[sub_resource type="Resource" id="Resource_13try"]
script = ExtResource("4_tp3yk")
icon = ExtResource("5_4v624")
metadata/_custom_type_script = "uid://bq7admu4ahs5r"
[sub_resource type="Resource" id="Resource_sph21"]
script = ExtResource("4_tp3yk")
metadata/_custom_type_script = "uid://bq7admu4ahs5r"
[sub_resource type="Resource" id="Resource_3d1h6"]
script = ExtResource("4_tp3yk")
icon = ExtResource("6_10rrv")
metadata/_custom_type_script = "uid://bq7admu4ahs5r"
[sub_resource type="Resource" id="Resource_c8v1t"]
script = ExtResource("4_tp3yk")
metadata/_custom_type_script = "uid://bq7admu4ahs5r"
[sub_resource type="Resource" id="Resource_ee31p"]
script = ExtResource("7_upv64")
items = Array[ExtResource("4_tp3yk")]([SubResource("Resource_13try"), SubResource("Resource_sph21"), SubResource("Resource_3d1h6"), SubResource("Resource_c8v1t")])
n_tools = 1
metadata/_custom_type_script = "uid://fnu2d6wna4yc"
[sub_resource type="QuadMesh" id="QuadMesh_tp3yk"]
size = Vector2(2, 2)
[node name="Inventory" type="CenterContainer" unique_id=1041300312]
custom_minimum_size = Vector2(48, 48)
offset_right = 156.0
offset_bottom = 153.0
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 0
size_flags_vertical = 0
script = ExtResource("1_himlj")
inventory_item_scene = ExtResource("2_0vvyy")
bar = NodePath("Bar")
test_size = 4
test_n_tool = 1
[node name="Bar" type="TextureRect" parent="." unique_id=60027067]
[node name="ViewPortTexture" type="TextureRect" parent="." unique_id=997120459]
layout_mode = 2
texture = ExtResource("3_hqvrf")
texture = SubResource("ViewportTexture_tp3yk")
stretch_mode = 2
[node name="SubViewport" type="SubViewport" parent="ViewPortTexture" unique_id=1891358676]
own_world_3d = true
transparent_bg = true
size = Vector2i(1000, 100)
[node name="WorldEnvironment" type="WorldEnvironment" parent="ViewPortTexture/SubViewport" unique_id=604331804]
environment = ExtResource("3_g6k02")
[node name="Inventory3D" parent="ViewPortTexture/SubViewport" unique_id=810532522 instance=ExtResource("5_hmild")]
test_inventory = SubResource("Resource_ee31p")
[node name="Camera3D" type="Camera3D" parent="ViewPortTexture/SubViewport" unique_id=843201055]
transform = Transform3D(-1, 0, -8.742278e-08, -7.433939e-09, 0.996378, 0.08503435, 8.710613e-08, 0.08503435, -0.996378, 0, 0.109818935, -1.4748735)
current = true
fov = 10.1
[node name="MeshInstance3D" type="MeshInstance3D" parent="ViewPortTexture/SubViewport/Camera3D" unique_id=2129450070]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.057, -0.2)
mesh = SubResource("QuadMesh_tp3yk")
skeleton = NodePath("../..")
surface_material_override/0 = ExtResource("4_6ahyd")
[node name="InventoryMouseDetectors" type="HBoxContainer" parent="." unique_id=876676243]
unique_name_in_owner = true
layout_mode = 2
theme_override_constants/separation = 0

View File

@@ -1,184 +0,0 @@
[gd_scene load_steps=12 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"]
[ext_resource type="Texture2D" uid="uid://baaujfw8piywi" path="res://common/icons/dna.svg" id="3_m0ja8"]
[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_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)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("CenterContainer/ItemTexture:modulate")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.033333335),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(0.27058825, 0.27058825, 0.27058825, 1), Color(0.27058825, 0.27058825, 0.27058825, 1)]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("CenterContainer/NoItemTextureRect:modulate")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(0.27058825, 0.27058825, 0.27058825, 1)]
}
[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)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("CenterContainer/ItemTexture:modulate")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(0.27022192, 0.27022192, 0.2702219, 1), Color(1, 1, 1, 1)]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("CenterContainer/NoItemTextureRect:modulate")
tracks/2/interp = 2
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(0.27022192, 0.27022192, 0.2702219, 1), Color(1, 1, 1, 1)]
}
[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
modulate = Color(0.27058825, 0.27058825, 0.27058825, 1)
custom_minimum_size = Vector2(12, 12)
layout_mode = 2
texture = SubResource("GradientTexture2D_vgckh")
expand_mode = 2
stretch_mode = 5
[node name="ItemTexture" type="TextureRect" parent="CenterContainer"]
unique_name_in_owner = true
modulate = Color(0.27058825, 0.27058825, 0.27058825, 1)
custom_minimum_size = Vector2(48, 48)
layout_mode = 2
texture = ExtResource("2_xs0u7")
expand_mode = 1
stretch_mode = 5
[node name="ParticleTexture" type="TextureRect" parent="CenterContainer/ItemTexture"]
unique_name_in_owner = true
layout_mode = 0
offset_left = 26.0
offset_top = 27.0
offset_right = 48.0
offset_bottom = 49.0
texture = ExtResource("3_m0ja8")
expand_mode = 1
stretch_mode = 4
[node name="ParticleTexture2" type="TextureRect" parent="CenterContainer/ItemTexture"]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_top = -22.0
offset_right = 22.0
grow_vertical = 0
texture = ExtResource("3_m0ja8")
expand_mode = 1
stretch_mode = 4
[node name="BottomSpace" type="Control" parent="."]
layout_mode = 2
[connection signal="gui_input" from="." to="." method="_on_gui_input"]

View File

@@ -0,0 +1,80 @@
[gd_scene format=3 uid="uid://4r2ab6foer05"]
[ext_resource type="Script" uid="uid://mrw23oxsai10" path="res://gui/game/inventory_gui/inventory_item/scripts/inventory_item_3d.gd" id="1_nsad1"]
[ext_resource type="PackedScene" uid="uid://oktd71knql00" path="res://gui/game/inventory_gui/assets/3d/item_screen.blend" id="2_1uxm0"]
[ext_resource type="Texture2D" uid="uid://dex283rx00fjb" path="res://common/icons/logout.svg" id="2_hv1tg"]
[ext_resource type="Script" uid="uid://bq7admu4ahs5r" path="res://entities/player/inventory/scripts/item.gd" id="3_ixa47"]
[sub_resource type="Resource" id="Resource_g1uf8"]
script = ExtResource("3_ixa47")
icon = ExtResource("2_hv1tg")
metadata/_custom_type_script = "uid://bq7admu4ahs5r"
[sub_resource type="Gradient" id="Gradient_ixa47"]
offsets = PackedFloat32Array(0, 0.84549356)
colors = PackedColorArray(0.002722778, 0.0025074463, 0.012722934, 1, 0.0627451, 0.05882353, 0.16862746, 1)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_g1uf8"]
gradient = SubResource("Gradient_ixa47")
width = 14
height = 14
fill_from = Vector2(0, 1)
fill_to = Vector2(0, 0)
[sub_resource type="Gradient" id="Gradient_g1uf8"]
colors = PackedColorArray(0.13725491, 0.39215687, 0.6666667, 1, 0.14509805, 0.75686276, 0.2784314, 1)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_jdjjl"]
gradient = SubResource("Gradient_g1uf8")
width = 14
height = 14
fill_from = Vector2(0, 1)
fill_to = Vector2(0, 0)
[sub_resource type="Gradient" id="Gradient_l7avg"]
colors = PackedColorArray(1, 0, 0.43137255, 1, 1, 0.6509804, 0.09019608, 1)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_gj8fm"]
gradient = SubResource("Gradient_l7avg")
width = 14
height = 14
fill_from = Vector2(0, 1)
fill_to = Vector2(0, 0)
[sub_resource type="BoxShape3D" id="BoxShape3D_1uxm0"]
size = Vector3(0.21289063, 0.22167969, 0.2841797)
[node name="InventoryItem3d" type="Node3D" unique_id=797856392]
script = ExtResource("1_nsad1")
item = SubResource("Resource_g1uf8")
[node name="Model" parent="." unique_id=1055300734 instance=ExtResource("2_1uxm0")]
[node name="BlackScreen" type="Sprite3D" parent="." unique_id=1828017914]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.08962244)
texture = SubResource("GradientTexture2D_g1uf8")
[node name="ItemScreen" type="Sprite3D" parent="." unique_id=1128109703]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.08962244)
visible = false
texture = SubResource("GradientTexture2D_jdjjl")
[node name="ToolScreen" type="Sprite3D" parent="." unique_id=1384339729]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.08962244)
visible = false
texture = SubResource("GradientTexture2D_gj8fm")
[node name="ItemIconSprite" type="Sprite3D" parent="." unique_id=1279203709]
unique_name_in_owner = true
transform = Transform3D(-1, 0, 8.742278e-08, 0, 1, 0, -8.742278e-08, 0, -1, 0, 0.004884802, -0.0937915)
modulate = Color(1, 1, 1, 0.3)
pixel_size = 0.0020833334
texture = ExtResource("2_hv1tg")
[node name="Area3D" type="Area3D" parent="." unique_id=426596211]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D" unique_id=2020875183]
shape = SubResource("BoxShape3D_1uxm0")

View File

@@ -1,55 +0,0 @@
extends Control
class_name InventoryGuiItem
@export var no_item_texture_path : Texture2D
signal item_clicked()
const MODULATE_INSPECTED_COLOR = Color.GRAY
var current_item : Item = null
var item : Item = null
var was_selected : bool = false
func _ready():
mouse_entered.connect(
func(): Pointer.inspect(self)
)
mouse_exited.connect(
func(): Pointer.stop_inspect(self)
)
update(null, false)
func inspect(is_inspected : bool = true):
modulate = MODULATE_INSPECTED_COLOR if is_inspected else Color.WHITE
func _on_gui_input(_event: InputEvent) -> void:
if Input.is_action_just_pressed("action"):
emit_signal("item_clicked")
func update(_item: Item, selected : bool):
item = _item
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")
if item and item.icon:
%ItemTexture.texture = item.icon
var particles = item.get_particles()
if len(particles) > 0:
%ParticleTexture.texture = particles[0].texture
%ParticleTexture.modulate = particles[0].color
if len(particles) > 1:
%ParticleTexture2.texture = particles[1].texture
%ParticleTexture2.modulate = particles[1].color
%ItemTexture.visible = item != null
%NoItemTextureRect.visible = item == null
%ParticleTexture.visible = item and len(item.get_particles())>0
%ParticleTexture2.visible = item and len(item.get_particles())>1
current_item = item
was_selected = selected

View File

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

View File

@@ -0,0 +1,34 @@
@tool
extends Node3D
class_name InventoryItem3D
enum State { BLACK,ITEM,TOOL }
const OFF_TRANSPARENCY = 0.3
const SPRITE_SIZE = 0.1
@export var item : Item : set = set_item
@export var state : State = State.BLACK : set = set_state
@export_tool_button("Reset Texture", "Callable") var reset_texture_action = func() : set_item()
func _ready():
set_item()
set_state()
func set_item(i : Item = item):
item = i
if is_node_ready():
if i and i.icon:
%ItemIconSprite.texture = i.icon
%ItemIconSprite.pixel_size = SPRITE_SIZE / i.icon.get_width()
else:
%ItemIconSprite.texture = null
func set_state(s := state):
state = s
if is_node_ready():
%ItemIconSprite.modulate.a = OFF_TRANSPARENCY if state == State.BLACK else 1.0
%BlackScreen.visible = state == State.BLACK
%ItemScreen.visible = state == State.ITEM
%ToolScreen.visible = state == State.TOOL

View File

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

View File

@@ -0,0 +1,62 @@
@tool
extends Node3D
class_name Inventory3D
const INVENTORY_OBJECT_SIZE = 0.2
const SEPARATOR_SIZE = 0.1
@export var inventory_item_scene: PackedScene
@export var bar: TextureRect
@export var test_inventory : Inventory
var last_n_tools = -1
var inventory_item_objects: Array[InventoryItem3D] = []
@export_tool_button("Test Update", "Callable") var update_action = func() : update(test_inventory)
func _ready():
if not Engine.is_editor_hint():
GameInfo.game_data.player_data.inventory.updated.connect(update)
update(GameInfo.game_data.player_data.inventory)
func update(inventory : Inventory):
if len(inventory.items) != len(inventory_item_objects) or last_n_tools != inventory.n_tools:
create_inventory_objects(inventory)
for i in range(len(inventory.items)):
var item : Item= inventory.items[i]
var object : InventoryItem3D = inventory_item_objects[i]
object.item = inventory.items[i]
if inventory.current_item_ind == i:
object.state = (
InventoryItem3D.State.TOOL if i < inventory.n_tools
else InventoryItem3D.State.ITEM
)
else:
object.state = InventoryItem3D.State.BLACK
func create_inventory_objects(inventory : Inventory):
for c in %Items3D.get_children():
c.queue_free()
last_n_tools = inventory.n_tools
inventory_item_objects = []
for i in range(len(inventory.items)):
var new_inventory_object := (inventory_item_scene.instantiate() as InventoryItem3D)
%Items3D.add_child(new_inventory_object)
new_inventory_object.position.x = -INVENTORY_OBJECT_SIZE * i
if i >= inventory.n_tools:
new_inventory_object.position.x -= SEPARATOR_SIZE
inventory_item_objects.append(new_inventory_object)
%Items3D.position.x = (
(len(inventory_item_objects) - 1) * INVENTORY_OBJECT_SIZE + SEPARATOR_SIZE
) / 2
%ItemSeparator.position.x = (
%Items3D.position.x
- (inventory.n_tools) * INVENTORY_OBJECT_SIZE
+ SEPARATOR_SIZE/2
)

View File

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

View File

@@ -1,36 +1,47 @@
extends HBoxContainer
@tool
extends Control
class_name InventoryGui
@export var inventory_item_scene: PackedScene
@export var bar: TextureRect
const SEPARATOR_OBJECT_SIZE = 40
var inventory_item_objects: Array[InventoryGuiItem]
@export var test_size : int
@export var test_n_tool : int
var last_n_tools = -1
var last_inventory_size = 0
@export_tool_button("Test Update", "Callable") var update_action = func() : generate_inventory_mouse_detectors(test_size,test_n_tool,true)
func _ready():
GameInfo.game_data.player_data.inventory.updated.connect(update)
update(GameInfo.game_data.player_data.inventory)
if not Engine.is_editor_hint():
GameInfo.game_data.player_data.inventory.updated.connect(update)
update(GameInfo.game_data.player_data.inventory)
func update(inventory: Inventory):
if len(inventory_item_objects) == 0 or len(inventory_item_objects) != inventory.items.size():
for o in inventory_item_objects:
o.queue_free()
inventory_item_objects = generate_inventory_item_objects(inventory, inventory.items.size())
for i in range(inventory.items.size()):
inventory_item_objects[i].update(inventory.get_item(i), i == inventory.current_item_ind)
if last_inventory_size != len(inventory.items) or last_n_tools != inventory.n_tools:
last_inventory_size = len(inventory.items)
last_n_tools = inventory.n_tools
generate_inventory_mouse_detectors(last_inventory_size, last_n_tools)
func generate_inventory_mouse_detectors(inventory_size: int, n_tool : int, test = false):
for c in %InventoryMouseDetectors.get_children():
c.queue_free()
move_child(bar, inventory.n_tools)
bar.visible = inventory.n_tools > 0 && inventory.items.size() > inventory.n_tools
for i in range(inventory_size):
if i == n_tool:
%InventoryMouseDetectors.add_child(generate_separator(test))
%InventoryMouseDetectors.add_child(generate_item_mouse_detector(i, test))
func generate_inventory_item_objects(inventory: Inventory, 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)
move_child(o, i)
objects.append(o)
o.item_clicked.connect(func(): change_current_item_ind(inventory, i))
return objects
func generate_item_mouse_detector(index : int, test = false) -> ColorRect:
return InventoryGuiItemMouseDetector.new(index, test)
func change_current_item_ind(inventory: Inventory, new_ind: int):
inventory.set_current_item(new_ind)
func generate_separator(test = false) -> ColorRect:
var separator = ColorRect.new()
separator.custom_minimum_size = Vector2(SEPARATOR_OBJECT_SIZE, SEPARATOR_OBJECT_SIZE)
separator.color = Color.RED
if test:
separator.color.a = 0.5
else :
separator.color.a = 0.
return separator

View File

@@ -0,0 +1,30 @@
extends ColorRect
class_name InventoryGuiItemMouseDetector
const SIZE = 80
var index : int
func _init(_index := 0, test := false):
index = _index
color = Color.WHITE
color.a = 0.5 if test else 0.
func _ready():
custom_minimum_size = Vector2.ONE * SIZE
mouse_entered.connect(
func(): Pointer.inspect(self)
)
mouse_exited.connect(
func(): Pointer.stop_inspect(self)
)
func card_info() -> CardInfo:
var inventory := GameInfo.game_data.player_data.inventory
if inventory and index < len(inventory.items):
var item = GameInfo.game_data.player_data.inventory.items[index]
if item:
return item.card_info()
return null

View File

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