This commit is contained in:
Andriy Yednarovych
2026-02-22 19:26:26 +01:00
parent fd1ff19c4c
commit e877c5f058
211 changed files with 9385 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
[gd_scene format=3 uid="uid://b2r6mp7h13pak"]
[ext_resource type="Texture2D" uid="uid://dxf00vjmse6ab" path="res://items/sprites/items.png" id="1_gwc7x"]
[ext_resource type="Script" uid="uid://cvbri6j1mbq07" path="res://gui/pause/inventory/scripts/inventory_slot_ui.gd" id="1_s0lov"]
[sub_resource type="AtlasTexture" id="AtlasTexture_s0lov"]
atlas = ExtResource("1_gwc7x")
region = Rect2(0, 0, 32, 32)
[node name="InventorySlot" type="Button" unique_id=823052233]
custom_minimum_size = Vector2(32, 32)
offset_right = 32.0
offset_bottom = 32.0
script = ExtResource("1_s0lov")
[node name="TextureRect" type="TextureRect" parent="." unique_id=469228245]
layout_mode = 0
offset_right = 32.0
offset_bottom = 32.0
texture = SubResource("AtlasTexture_s0lov")
stretch_mode = 3
[node name="Label" type="Label" parent="." unique_id=385106309]
layout_mode = 0
offset_right = 32.0
offset_bottom = 16.0
theme_override_font_sizes/font_size = 8
text = "99"
horizontal_alignment = 2

View File

@@ -0,0 +1,9 @@
[gd_resource type="Resource" script_class="InventoryData" format=3 uid="uid://8eo5dhh10mag"]
[ext_resource type="Script" uid="uid://b6ol0ja8441tv" path="res://gui/pause/inventory/scripts/inventory_data.gd" id="1_i443n"]
[ext_resource type="Script" uid="uid://d0boqgd4kawwt" path="res://gui/pause/inventory/scripts/slot_data.gd" id="2_pk4bu"]
[resource]
script = ExtResource("1_i443n")
slots = Array[ExtResource("2_pk4bu")]([null, null, null, null, null, null, null, null, null, null])
metadata/_custom_type_script = "uid://b6ol0ja8441tv"

View File

@@ -0,0 +1,88 @@
class_name InventoryData extends Resource
@export var slots: Array[SlotData]
func _init() -> void:
connect_slots()
func add_item(item: ItemData, count := 1) -> bool:
var slot = get_slot_by_item(item)
if slot:
slot.quantity += count
return true
var empty_slot_index = get_empty_slot_index()
if empty_slot_index > -1:
var new_slot = SlotData.new()
new_slot.item_data = item
new_slot.quantity = count
slots[empty_slot_index] = new_slot
new_slot.changed.connect(on_slot_changed)
return true
print("inventory full")
return false
func get_slot_by_item(item: ItemData) -> SlotData:
var index = slots.find_custom(func(slot: SlotData): return slot != null and slot.item_data == item)
if index > -1:
return slots[index]
return null
func get_empty_slot_index() -> int:
return slots.find_custom(func(slot: SlotData): return !slot)
func get_valid_slots() -> Array[SlotData]:
return slots.filter(func(slot: SlotData): return slot);
func connect_slots() -> void:
for slot: SlotData in get_valid_slots():
slot.changed.connect(on_slot_changed)
func on_slot_changed() -> void:
for slot_index in slots.size():
var slot: SlotData = slots[slot_index]
if slot and slot.quantity < 1:
slot.changed.disconnect(on_slot_changed)
slots[slot_index] = null
emit_changed()
func get_save_data() -> Array:
var item_save := []
for slot in slots:
item_save.append(item_to_save(slot))
return item_save
func item_to_save(slot: SlotData) -> Dictionary:
var result := {
item = "",
quantity = 0
}
if !slot:
return result
result.quantity = slot.quantity
if !slot.item_data:
return result
result.item = slot.item_data.resource_path
return result
func load_save_date(save_data: Array) -> void:
var slots_size = slots.size()
slots.clear()
slots.resize(slots_size)
for save_index in save_data.size():
slots[save_index] = save_to_item(save_data[save_index])
connect_slots()
func save_to_item(save_item: Dictionary) -> SlotData:
if save_item.item == "":
return null
var new_slot := SlotData.new()
new_slot.item_data = load(save_item.item)
new_slot.quantity = int(save_item.quantity)
return new_slot
func use_item(item: ItemData, count := 1) -> bool:
for slot in slots:
if slot and slot.item_data == item and slot.quantity >= count:
slot.quantity -= count
return true
return false

View File

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

View File

@@ -0,0 +1,38 @@
class_name InventorySlotUi extends Button
var slot_data: SlotData :
set = set_slot_data
@onready var texture_rect: TextureRect = $TextureRect
@onready var label: Label = $Label
func _ready() -> void:
texture_rect.texture = null
label.text = ""
focus_entered.connect(on_item_focus)
focus_exited.connect(on_item_unfocus)
pressed.connect(item_pressed)
func set_slot_data(value: SlotData) -> void:
slot_data = value
if slot_data == null:
return
texture_rect.texture = slot_data.item_data.texture
label.text = str(slot_data.quantity)
func on_item_focus() -> void:
if slot_data == null or slot_data.item_data == null:
return
PauseMenu.update_item_description(slot_data.item_data.description)
func on_item_unfocus() -> void:
PauseMenu.update_item_description("")
pass
func item_pressed() -> void:
if !slot_data or !slot_data.item_data:
return
if !slot_data.item_data.use():
return
slot_data.quantity -= 1
label.text = str(slot_data.quantity)

View File

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

View File

@@ -0,0 +1,37 @@
class_name InventoryUi extends Control
const INVENTORY_SLOT = preload("res://gui/pause/inventory/inventory_slot.tscn")
@export var data: InventoryData
var focus_index := 1
func _ready() -> void:
PauseMenu.shown.connect(update)
PauseMenu.hidden.connect(clear)
clear()
data.changed.connect(on_inventory_changed)
func clear() -> void:
for child in get_children():
child.queue_free()
func update() -> void:
for slot in data.slots:
var new_slot = INVENTORY_SLOT.instantiate()
add_child(new_slot)
new_slot.slot_data = slot
new_slot.focus_entered.connect(on_item_focused)
if !data.slots.is_empty():
await get_tree().process_frame
get_child(focus_index).grab_focus()
func on_inventory_changed() -> void:
clear()
update()
func on_item_focused() -> void:
for child_index in get_child_count():
if get_child(child_index).has_focus():
focus_index = child_index
return

View File

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

View File

@@ -0,0 +1,9 @@
class_name SlotData extends Resource
@export var item_data: ItemData
@export var quantity := 0 : set = set_quantity
func set_quantity(new_quantity: int) -> void:
quantity = new_quantity
if quantity < 1:
emit_changed()

View File

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

56
gui/pause/pause.gd Normal file
View File

@@ -0,0 +1,56 @@
extends CanvasLayer
signal shown
signal hidden
@onready var save_button: Button = $Control/HBoxContainer/Save
@onready var load_button: Button = $Control/HBoxContainer/Load
@onready var item_description: Label = $Control/ItemDescription
@onready var audio_player: AudioStreamPlayer = $Control/AudioStreamPlayer
var is_paused := false
func _ready() -> void:
hide_pause()
save_button.pressed.connect(on_save)
load_button.pressed.connect(on_load)
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("pause"):
if !is_paused:
show_pause()
else:
hide_pause()
get_viewport().set_input_as_handled()
func show_pause() -> void:
get_tree().paused = true
visible = true
is_paused = true
shown.emit()
func hide_pause() -> void:
get_tree().paused = false
visible = false
is_paused = false
hidden.emit()
func on_save() -> void:
if !is_paused:
return
SaveManager.save_game()
hide_pause()
func on_load() -> void:
if !is_paused:
return
SaveManager.load_game()
await LevelManager.level_load_started
hide_pause()
func update_item_description(new_description: String) -> void:
item_description.text = new_description
func play_audio(audio: AudioStream) -> void:
audio_player.stream = audio
audio_player.play()

1
gui/pause/pause.gd.uid Normal file
View File

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

116
gui/pause/pause.tscn Normal file
View File

@@ -0,0 +1,116 @@
[gd_scene format=3 uid="uid://dr37gne0tsx3h"]
[ext_resource type="Script" uid="uid://dg1igfflunr7n" path="res://gui/pause/pause.gd" id="1_syqp4"]
[ext_resource type="Texture2D" uid="uid://dxf00vjmse6ab" path="res://items/sprites/items.png" id="2_3oqg8"]
[ext_resource type="PackedScene" uid="uid://b2r6mp7h13pak" path="res://gui/pause/inventory/inventory_slot.tscn" id="3_ev3e7"]
[ext_resource type="Script" uid="uid://b7a5u5kcishd4" path="res://gui/pause/inventory/scripts/inventory_ui.gd" id="3_g4auy"]
[ext_resource type="Resource" uid="uid://8eo5dhh10mag" path="res://gui/pause/inventory/player_inventory.tres" id="4_nr23h"]
[sub_resource type="AtlasTexture" id="AtlasTexture_ev3e7"]
atlas = ExtResource("2_3oqg8")
region = Rect2(96, 0, 32, 32)
[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_g4auy"]
content_margin_left = 10.0
content_margin_top = 10.0
content_margin_right = 10.0
content_margin_bottom = 10.0
texture = SubResource("AtlasTexture_ev3e7")
texture_margin_left = 14.0
texture_margin_top = 14.0
texture_margin_right = 14.0
texture_margin_bottom = 14.0
[node name="Pause" type="CanvasLayer" unique_id=61680245]
process_mode = 3
script = ExtResource("1_syqp4")
[node name="Control" type="Control" parent="." unique_id=220122734]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="ColorRect" type="ColorRect" parent="Control" unique_id=131716919]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0.23392546, 0.23392546, 0.2339254, 0.61960787)
[node name="HBoxContainer" type="HBoxContainer" parent="Control" unique_id=1624860206]
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_top = -31.0
offset_right = 154.0
grow_vertical = 0
size_flags_horizontal = 0
size_flags_vertical = 8
[node name="Save" type="Button" parent="Control/HBoxContainer" unique_id=1562812412]
custom_minimum_size = Vector2(75, 0)
layout_mode = 2
text = "Save"
[node name="Load" type="Button" parent="Control/HBoxContainer" unique_id=673890119]
custom_minimum_size = Vector2(75, 0)
layout_mode = 2
text = "Load"
[node name="Label" type="Label" parent="Control" unique_id=631151135]
layout_mode = 1
offset_right = 80.0
offset_bottom = 23.0
text = "[ paused ]"
[node name="ItemDescription" type="Label" parent="Control" unique_id=1498356388]
layout_mode = 1
offset_top = 184.0
offset_right = 192.0
offset_bottom = 208.0
theme_override_font_sizes/font_size = 10
autowrap_mode = 2
[node name="PanelContainer" type="PanelContainer" parent="Control" unique_id=1571046276]
layout_mode = 1
anchors_preset = 4
anchor_top = 0.5
anchor_bottom = 0.5
offset_top = -44.0
offset_right = 196.0
offset_bottom = 44.0
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxTexture_g4auy")
[node name="GridContainer" type="GridContainer" parent="Control/PanelContainer" unique_id=1929711512]
layout_mode = 2
columns = 5
script = ExtResource("3_g4auy")
data = ExtResource("4_nr23h")
[node name="InventorySlot" parent="Control/PanelContainer/GridContainer" unique_id=823052233 instance=ExtResource("3_ev3e7")]
layout_mode = 2
[node name="InventorySlot2" parent="Control/PanelContainer/GridContainer" unique_id=479001907 instance=ExtResource("3_ev3e7")]
layout_mode = 2
[node name="InventorySlot3" parent="Control/PanelContainer/GridContainer" unique_id=327293097 instance=ExtResource("3_ev3e7")]
layout_mode = 2
[node name="InventorySlot4" parent="Control/PanelContainer/GridContainer" unique_id=355127191 instance=ExtResource("3_ev3e7")]
layout_mode = 2
[node name="InventorySlot5" parent="Control/PanelContainer/GridContainer" unique_id=1654439347 instance=ExtResource("3_ev3e7")]
layout_mode = 2
[node name="InventorySlot6" parent="Control/PanelContainer/GridContainer" unique_id=786772334 instance=ExtResource("3_ev3e7")]
layout_mode = 2
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="Control" unique_id=838536062]
max_polyphony = 4