Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Grid Inventory that can be enabled or disabled #194

Merged
merged 6 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions COGITO/Assets/Graphics/ItemIcons/Cogito_LaserRifle_new.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bdh5i4gqsyn72"
path="res://.godot/imported/Cogito_LaserRifle_new.png-3b1963128dfacf33d7422c585d31ecef.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://COGITO/Assets/Graphics/ItemIcons/Cogito_LaserRifle_new.png"
dest_files=["res://.godot/imported/Cogito_LaserRifle_new.png-3b1963128dfacf33d7422c585d31ecef.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
1 change: 1 addition & 0 deletions COGITO/CogitoObjects/Cogito_Container.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func _ready():
interaction_nodes = find_children("","InteractionComponent",true) #Grabs all attached interaction components
interaction_text = text_when_closed
object_state_updated.emit(interaction_text)
inventory_data.apply_initial_inventory()

func interact(_player_interaction_component: PlayerInteractionComponent):
toggle_inventory.emit(self)
Expand Down
14 changes: 12 additions & 2 deletions COGITO/DemoScenes/COGITO_01_Demo.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,20 @@ size = Vector3(0.3, 0.3, 0.1)
script = ExtResource("16_fg1wi")
inventory_item = ExtResource("15_86b07")
quantity = 2
origin_index = -1

[sub_resource type="Resource" id="Resource_eku8j"]
script = ExtResource("16_fg1wi")
inventory_item = ExtResource("17_nl6sa")
quantity = 2
origin_index = -1

[sub_resource type="Resource" id="Resource_kqd0r"]
[sub_resource type="Resource" id="Resource_miudc"]
resource_local_to_scene = true
script = ExtResource("2_chxar")
grid = false
starter_inventory = Array[ExtResource("16_fg1wi")]([])
inventory_size = Vector2i(4, 1)
inventory_slots = Array[ExtResource("16_fg1wi")]([SubResource("Resource_v7b11"), SubResource("Resource_eku8j"), null, null])

[sub_resource type="BoxMesh" id="BoxMesh_w1o4d"]
Expand All @@ -288,12 +293,14 @@ resource_local_to_scene = true
script = ExtResource("16_fg1wi")
inventory_item = ExtResource("17_nl6sa")
quantity = 1
origin_index = -1

[sub_resource type="Resource" id="Resource_u8yjv"]
resource_local_to_scene = true
script = ExtResource("16_fg1wi")
inventory_item = ExtResource("17_nl6sa")
quantity = 1
origin_index = -1

[sub_resource type="BoxMesh" id="BoxMesh_rixwv"]
material = ExtResource("2_4ig6i")
Expand Down Expand Up @@ -349,6 +356,9 @@ size = Vector3(100, 3, 100)
[sub_resource type="Resource" id="Resource_aoreq"]
resource_local_to_scene = true
script = ExtResource("2_chxar")
grid = false
starter_inventory = Array[ExtResource("16_fg1wi")]([])
inventory_size = Vector2i(4, 1)
inventory_slots = Array[ExtResource("16_fg1wi")]([null, null, null, null, null, null, null, null])

[sub_resource type="BoxMesh" id="BoxMesh_fj0b6"]
Expand Down Expand Up @@ -1244,7 +1254,7 @@ transform = Transform3D(1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107,
[node name="Chest" parent="INTERACTIVE_OBJECTS" groups=["external_inventory"] instance=ExtResource("14_d7sxi")]
transform = Transform3D(0.686504, 0, -0.727126, 0, 1, 0, 0.727126, 0, 0.686504, -4.38933, 0.0425703, 5.97176)
inventory_name = "Chest"
inventory_data = SubResource("Resource_kqd0r")
inventory_data = SubResource("Resource_miudc")
uses_animation = true
open_animation = "open"

Expand Down
6 changes: 6 additions & 0 deletions COGITO/DemoScenes/COGITO_04_Demo_Lobby.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ albedo = Color(0.694118, 0.694118, 0.694118, 1)
[sub_resource type="Resource" id="Resource_0kaw2"]
resource_local_to_scene = true
script = ExtResource("4_0kggm")
grid = false
starter_inventory = Array[Resource("res://COGITO/InventoryPD/CustomResources/InventorySlotPD.gd")]([])
inventory_size = Vector2i(4, 1)
inventory_slots = Array[Resource("res://COGITO/InventoryPD/CustomResources/InventorySlotPD.gd")]([null, null, null, null, null, null, null, null])

[sub_resource type="BoxShape3D" id="BoxShape3D_68nml"]
Expand Down Expand Up @@ -2414,6 +2417,9 @@ data = PackedVector3Array(0.6928, 0.0903, -1.6, 0, 0.0903, -1.2, 0.6128, 0.0903,
[sub_resource type="Resource" id="Resource_krl8u"]
resource_local_to_scene = true
script = ExtResource("4_0kggm")
grid = false
starter_inventory = Array[Resource("res://COGITO/InventoryPD/CustomResources/InventorySlotPD.gd")]([])
inventory_size = Vector2i(4, 1)
inventory_slots = Array[Resource("res://COGITO/InventoryPD/CustomResources/InventorySlotPD.gd")]([null, null, null, null])

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_k6s1x"]
Expand Down
9 changes: 1 addition & 8 deletions COGITO/DemoScenes/COGITO_05_Demo_Laboratory.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[gd_scene load_steps=106 format=3 uid="uid://6hh7o77unixk"]
[gd_scene load_steps=104 format=3 uid="uid://6hh7o77unixk"]

[ext_resource type="Script" path="res://COGITO/SceneManagement/cogito_scene.gd" id="1_4dqq6"]
[ext_resource type="Texture2D" uid="uid://sdcljx8f5dhj" path="res://COGITO/Assets/hdris/kloofendal_48d_partly_cloudy_puresky_2k.hdr" id="1_ponqc"]
[ext_resource type="PackedScene" uid="uid://kicjwmh02uwf" path="res://COGITO/PrefabScenes/player.tscn" id="2_7qwrr"]
[ext_resource type="PackedScene" uid="uid://0c32kepv0ahx" path="res://COGITO/PrefabScenes/Player_HUD.tscn" id="3_0c7yw"]
[ext_resource type="Script" path="res://COGITO/InventoryPD/InventoryPD.gd" id="4_hlewe"]
[ext_resource type="PackedScene" uid="uid://dkie3md1cmsip" path="res://COGITO/EasyMenus/Scenes/PauseMenu.tscn" id="4_vc32u"]
[ext_resource type="PackedScene" uid="uid://p3f16jxrcxdt" path="res://COGITO/Assets/Models/Kenney/Furniture/GLTF format/floorFull.glb" id="5_ihscj"]
[ext_resource type="PackedScene" uid="uid://b6yj5prtsl7hy" path="res://COGITO/DemoScenes/DemoPrefabs/floor_3x_3_00.tscn" id="6_bedlu"]
Expand Down Expand Up @@ -70,11 +69,6 @@ volumetric_fog_ambient_inject = 0.1
volumetric_fog_sky_affect = 0.1
volumetric_fog_temporal_reprojection_amount = 0.85

[sub_resource type="Resource" id="Resource_llgao"]
resource_local_to_scene = true
script = ExtResource("4_hlewe")
inventory_slots = Array[Resource("res://COGITO/InventoryPD/CustomResources/InventorySlotPD.gd")]([null, null, null, null, null, null, null, null])

[sub_resource type="BoxShape3D" id="BoxShape3D_w6kc6"]
size = Vector3(10, 0.1, 6)

Expand Down Expand Up @@ -943,7 +937,6 @@ environment = SubResource("Environment_obnk3")
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 5.13854, 0.8, -5.43073)
pause_menu = NodePath("../PauseMenu")
player_hud = NodePath("../Player_HUD")
inventory_data = SubResource("Resource_llgao")

[node name="Player_HUD" parent="." node_paths=PackedStringArray("player") instance=ExtResource("3_0c7yw")]
player = NodePath("../Player")
Expand Down
3 changes: 3 additions & 0 deletions COGITO/DemoScenes/DemoInventories/DemoInventory_Fridge.tres
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
[resource]
resource_local_to_scene = true
script = ExtResource("1_2ltpn")
grid = false
starter_inventory = Array[Resource("res://COGITO/InventoryPD/CustomResources/InventorySlotPD.gd")]([])
inventory_size = Vector2i(4, 1)
inventory_slots = Array[Resource("res://COGITO/InventoryPD/CustomResources/InventorySlotPD.gd")]([null, null, null, null])
7 changes: 7 additions & 0 deletions COGITO/InventoryPD/CustomResources/InventoryItemPD.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class_name InventoryItemPD
@export var hint_icon_on_use : Texture2D
## Hint that is displayed when used. For example "Potion replenished 10 HP!"
@export var hint_text_on_use : String
@export var item_size : Vector2 = Vector2(1,1)

@export_subgroup("Audio")
## Audio that plays when item is used.
Expand All @@ -29,6 +30,12 @@ var player_interaction_component
var is_being_wielded : bool
var wielded_item

func get_region(x, y):
var image = icon.get_image()
var x_chunk = icon.get_width() / item_size.x
var y_chunk = icon.get_height() / item_size.y
var region = Rect2i(Vector2i(x * x_chunk, y * y_chunk), Vector2i(x_chunk, y_chunk))
return image.get_region(region)

#func use(target) -> bool:
## Target should always be player? Null check to override using the CogitoSceneManager, which stores a reference to current player node
Expand Down
7 changes: 6 additions & 1 deletion COGITO/InventoryPD/CustomResources/InventorySlotPD.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const MAX_STACK_SIZE : int = 99
@export var inventory_item : InventoryItemPD
#@export_range(1, MAX_STACK_SIZE) var quantity : int = 1: set = set_quantity
@export var quantity : int = 1
@export var origin_index = -1

func is_origin(index):
return origin_index == index

func set_quantity(value: int):
quantity = value
Expand All @@ -27,8 +31,9 @@ func can_fully_merge_with(other_slot_data: InventorySlotPD) -> bool:
func fully_merge_with(other_slot_data: InventorySlotPD):
quantity += other_slot_data.quantity

func create_single_slot_data() -> InventorySlotPD:
func create_single_slot_data(index: int) -> InventorySlotPD:
var new_slot_data = duplicate()
new_slot_data.origin_index = index
new_slot_data.quantity = 1
quantity -= 1
return new_slot_data
5 changes: 4 additions & 1 deletion COGITO/InventoryPD/Inventories/PlayerInventory.tres
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
[resource]
resource_local_to_scene = true
script = ExtResource("1_vgg6i")
inventory_slots = Array[Resource("res://COGITO/InventoryPD/CustomResources/InventorySlotPD.gd")]([null, null, null, null, null, null, null, null])
grid = true
starter_inventory = Array[Resource("res://COGITO/InventoryPD/CustomResources/InventorySlotPD.gd")]([])
inventory_size = Vector2i(5, 3)
inventory_slots = Array[Resource("res://COGITO/InventoryPD/CustomResources/InventorySlotPD.gd")]([null, null, null, null, null, null, null, null, null, null, null, null, null, null, null])
2 changes: 1 addition & 1 deletion COGITO/InventoryPD/Inventories/TestInventory.tres
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ quantity = 1

[resource]
script = ExtResource("1_wxkif")
inventory_slots = Array[ExtResource("2_83f1b")]([SubResource("Resource_4h4d1"), null, null, null, null])
inventory_slots = [SubResource("Resource_4h4d1"), null, null, null, null]
Loading