First commit 🎉

This commit is contained in:
Tony Bark 2025-07-17 01:49:18 -04:00
commit 43ea213f9b
728 changed files with 37080 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://s4phlorab5ds"
path="res://.godot/imported/inventory_grid_down_button.png-ffac1afa54860747ab14c6a1f8220bae.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/popochiu/engine/objects/gui/components/inventory_grid/images/inventory_grid_down_button.png"
dest_files=["res://.godot/imported/inventory_grid_down_button.png-ffac1afa54860747ab14c6a1f8220bae.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dfa511cxg31g5"
path="res://.godot/imported/inventory_grid_up_button.png-dd40c7fcb22a7dfc4741c7c1c2d05d54.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/popochiu/engine/objects/gui/components/inventory_grid/images/inventory_grid_up_button.png"
dest_files=["res://.godot/imported/inventory_grid_up_button.png-dd40c7fcb22a7dfc4741c7c1c2d05d54.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -0,0 +1,226 @@
@tool
class_name PopochiuInventoryGrid
extends HBoxContainer
const EMPTY_SLOT := "[Empty Slot]00"
@export var slot_scene: PackedScene = null : set = set_slot_scene
@export var columns := 4 : set = set_columns
@export var visible_rows := 2 : set = set_visible_rows
@export var number_of_slots := 16 : set = set_number_of_slots
@export var h_separation := 0 : set = set_h_separation
@export var v_separation := 0 : set = set_v_separation
@export var show_arrows := true : set = set_show_arrows
@export var scroll_with_mouse_wheel := true
var rows := 0
var max_scroll := 0.0
var slot_size: float = 0.0
@onready var scroll_container: ScrollContainer = $ScrollContainer
@onready var box: GridContainer = %Box
@onready var scroll_buttons: VBoxContainer = $ScrollButtons
@onready var up: TextureButton = %Up
@onready var down: TextureButton = %Down
@onready var gap_size: int = box.get_theme_constant("v_separation")
#region Godot ######################################################################################
func _ready():
if Engine.is_editor_hint():
_update_box()
return
scroll_container.mouse_filter = (
Control.MOUSE_FILTER_PASS if scroll_with_mouse_wheel else Control.MOUSE_FILTER_IGNORE
)
_update_box()
_calculate_rows_and_scroll()
# _check_starting_items()
# Connect to child signals
up.pressed.connect(_on_up_pressed)
down.pressed.connect(_on_down_pressed)
scroll_container.get_v_scroll_bar().value_changed.connect(_on_scroll)
# Connect to singletons signals
PopochiuUtils.i.item_added.connect(_add_item)
PopochiuUtils.i.item_removed.connect(_remove_item)
PopochiuUtils.i.item_replaced.connect(_replace_item)
_check_scroll_buttons()
#endregion
#region SetGet #####################################################################################
func set_visible_rows(value: int) -> void:
visible_rows = value
_update_box()
func set_columns(value: int) -> void:
columns = value
_update_box()
func set_slot_scene(value: PackedScene) -> void:
slot_scene = value
_update_box()
func set_number_of_slots(value: int) -> void:
number_of_slots = value
_update_box()
func set_h_separation(value: int) -> void:
h_separation = value
_update_box()
func set_v_separation(value: int) -> void:
v_separation = value
_update_box()
func set_show_arrows(value: bool) -> void:
show_arrows = value
if is_instance_valid(scroll_buttons):
scroll_buttons.visible = value
#endregion
#region Private ####################################################################################
func _update_box() -> void:
if not is_instance_valid(box): return
box.columns = columns
box.add_theme_constant_override("h_separation", h_separation)
box.add_theme_constant_override("v_separation", v_separation)
# Fix: remove the child immediately (instead of calling queue_free()), and do not await for
# a process frame cause it can cause an issue when adding items marked as "Start with it".
for child in box.get_children():
child.free()
for idx in number_of_slots:
var slot := slot_scene.instantiate()
box.add_child(slot)
slot.name = EMPTY_SLOT
slot_size = slot.size.y
scroll_container.custom_minimum_size = Vector2(
(columns * (slot_size + h_separation)) - h_separation,
(visible_rows * (slot_size + v_separation)) - v_separation
)
## Calculate the number of rows in the box and the max scroll
func _calculate_rows_and_scroll() -> void:
var visible_slots := 0
for slot in box.get_children():
if slot.visible:
visible_slots += 1
@warning_ignore("integer_division")
rows = visible_slots / box.columns
max_scroll = ((slot_size + gap_size) * int(rows / 2))
## Check if there are inventory items in the scene tree and add them to the
## Inventory interface class (I).
func _check_starting_items() -> void:
for slot in box.get_children():
if (slot.get_child_count() > 0
and slot.get_child(0) is PopochiuInventoryItem
):
PopochiuUtils.i.items.append(slot.get_child(0).script_name)
slot.name = slot.get_child(0).script_name
else:
slot.name = EMPTY_SLOT
func _on_up_pressed() -> void:
scroll_container.scroll_vertical -= (slot_size + gap_size) + 1
_check_scroll_buttons()
func _on_down_pressed() -> void:
scroll_container.scroll_vertical += (slot_size + gap_size) + 1
_check_scroll_buttons()
func _add_item(item: PopochiuInventoryItem, _animate := true) -> void:
var slot := box.get_child(PopochiuUtils.i.items.size() - 1)
slot.name = "[%s]" % item.script_name
slot.add_child(item)
item.expand_mode = TextureRect.EXPAND_FIT_WIDTH
if slot.has_method("get_content_height"):
item.custom_minimum_size.y = slot.get_content_height()
else:
item.custom_minimum_size.y = slot.size.y
box.set_meta(item.script_name, slot)
item.selected.connect(_change_cursor)
_check_scroll_buttons()
# Common call to all inventories. Should be in the class from where inventory panels will
# inherit from
await get_tree().process_frame
PopochiuUtils.i.item_add_done.emit(item)
func _remove_item(item: PopochiuInventoryItem, _animate := true) -> void:
item.selected.disconnect(_change_cursor)
box.get_meta(item.script_name).remove_child(item)
box.get_meta(item.script_name).name = EMPTY_SLOT
_check_scroll_buttons()
await get_tree().process_frame
PopochiuUtils.i.item_remove_done.emit(item)
func _replace_item(
item: PopochiuInventoryItem, new_item: PopochiuInventoryItem
) -> void:
item.replace_by(new_item)
box.remove_meta(item.script_name)
box.set_meta(new_item.script_name, new_item.get_parent())
_check_scroll_buttons()
await get_tree().process_frame
PopochiuUtils.i.item_replace_done.emit()
func _change_cursor(item: PopochiuInventoryItem) -> void:
PopochiuUtils.i.set_active_item(item)
## Checks if the UP and DOWN buttons should be enabled
func _check_scroll_buttons() -> void:
up.disabled = scroll_container.scroll_vertical == 0
down.disabled = (
scroll_container.scroll_vertical >= max_scroll
or not (PopochiuUtils.i.items.size() > box.columns * visible_rows)
)
func _on_scroll(_value: float) -> void:
_check_scroll_buttons()
#endregion

View file

@ -0,0 +1 @@
uid://5iimjg0vmeqf

View file

@ -0,0 +1,91 @@
[gd_scene load_steps=14 format=3 uid="uid://cn2b5v8k1lseo"]
[ext_resource type="Script" path="res://addons/popochiu/engine/objects/gui/components/inventory_grid/inventory_grid.gd" id="1_0y5i1"]
[ext_resource type="Theme" uid="uid://dpequqav4rjaf" path="res://addons/popochiu/engine/objects/gui/resources/base_gui_theme.tres" id="1_kaq1v"]
[ext_resource type="Texture2D" uid="uid://dfa511cxg31g5" path="res://addons/popochiu/engine/objects/gui/components/inventory_grid/images/inventory_grid_up_button.png" id="2_6y3so"]
[ext_resource type="PackedScene" uid="uid://db6csk6i4f3un" path="res://addons/popochiu/engine/objects/gui/components/inventory_grid/inventory_grid_slot.tscn" id="3_ma7vn"]
[ext_resource type="Texture2D" uid="uid://s4phlorab5ds" path="res://addons/popochiu/engine/objects/gui/components/inventory_grid/images/inventory_grid_down_button.png" id="3_yoinj"]
[sub_resource type="AtlasTexture" id="AtlasTexture_7tbkh"]
atlas = ExtResource("2_6y3so")
region = Rect2(0, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_yafup"]
atlas = ExtResource("2_6y3so")
region = Rect2(32, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_8r5xk"]
atlas = ExtResource("2_6y3so")
region = Rect2(16, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_73nr4"]
atlas = ExtResource("2_6y3so")
region = Rect2(48, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_mcgs4"]
atlas = ExtResource("3_yoinj")
region = Rect2(0, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_kw4h2"]
atlas = ExtResource("3_yoinj")
region = Rect2(32, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_pi25e"]
atlas = ExtResource("3_yoinj")
region = Rect2(16, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_pejpn"]
atlas = ExtResource("3_yoinj")
region = Rect2(48, 0, 16, 16)
[node name="InventoryGrid" type="HBoxContainer" groups=["popochiu_gui_component"]]
offset_right = 152.0
offset_bottom = 50.0
size_flags_horizontal = 3
size_flags_vertical = 3
mouse_filter = 0
theme = ExtResource("1_kaq1v")
script = ExtResource("1_0y5i1")
slot_scene = ExtResource("3_ma7vn")
[node name="ScrollButtons" type="VBoxContainer" parent="."]
custom_minimum_size = Vector2(24, 0)
layout_mode = 2
theme_override_constants/separation = 0
[node name="Up" type="TextureButton" parent="ScrollButtons"]
texture_filter = 1
layout_mode = 2
size_flags_vertical = 3
texture_normal = SubResource("AtlasTexture_7tbkh")
texture_pressed = SubResource("AtlasTexture_yafup")
texture_hover = SubResource("AtlasTexture_8r5xk")
texture_disabled = SubResource("AtlasTexture_73nr4")
stretch_mode = 3
[node name="Down" type="TextureButton" parent="ScrollButtons"]
texture_filter = 1
layout_mode = 2
size_flags_vertical = 3
texture_normal = SubResource("AtlasTexture_mcgs4")
texture_pressed = SubResource("AtlasTexture_kw4h2")
texture_hover = SubResource("AtlasTexture_pi25e")
texture_disabled = SubResource("AtlasTexture_pejpn")
stretch_mode = 3
[node name="ScrollContainer" type="ScrollContainer" parent="."]
custom_minimum_size = Vector2(100, 50)
layout_mode = 2
size_flags_horizontal = 3
scroll_vertical_custom_step = 27.0
horizontal_scroll_mode = 3
vertical_scroll_mode = 3
[node name="Box" type="GridContainer" parent="ScrollContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/h_separation = 0
theme_override_constants/v_separation = 0
columns = 4

View file

@ -0,0 +1,17 @@
[gd_scene load_steps=2 format=3 uid="uid://db6csk6i4f3un"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_fjc4l"]
content_margin_left = 2.0
content_margin_top = 2.0
content_margin_right = 2.0
content_margin_bottom = 2.0
bg_color = Color(0.180392, 0.172549, 0.607843, 1)
border_width_left = 1
border_width_top = 1
border_width_right = 1
border_width_bottom = 1
border_color = Color(1, 1, 1, 1)
[node name="Slot" type="PanelContainer"]
custom_minimum_size = Vector2(31, 25)
theme_override_styles/panel = SubResource("StyleBoxFlat_fjc4l")