working on items and inventory

This commit is contained in:
2023-02-08 22:55:54 -05:00
parent 836a0e4a93
commit 03402abb6c
24 changed files with 617 additions and 117 deletions

View File

@@ -5,13 +5,17 @@ extends Control
@onready var ammo_label := $AmmoLabel
@onready var image_slot := $ItemImage
@onready var reload_bar := $ReloadBar
@onready var item_selecter := $ItemSelector
@onready var toolbar_slot := $ToolbarSlot
@rpc("call_local")
func slot_selected():
item_selecter.set_visible(true)
toolbar_slot.set_modulate(Color("4f58d8"))
slot_label.show()
@rpc("call_local")
func slot_deselected():
item_selecter.set_visible(false)
toolbar_slot.set_modulate(Color("ffffff"))
slot_label.hide()
func reload_item(cooldown: float):
reload_bar.set_visible(true)
@@ -24,24 +28,26 @@ func reload_item(cooldown: float):
func clear_slot():
image_slot.set_texture(null)
slot_label.set_text("")
ammo_label.set_text("")
ammo_label.set_visible(false)
func setup_slot(item_details: Dictionary):
clear_slot()
slot_label.set_text(item_details.item_name)
var picNode = TextureRect.new()
image_slot.add_child(picNode)
picNode.set_mouse_filter(2)
#picNode.set_mouse_filter(2)
picNode.set_name("inv_texture")
picNode.set_texture(item_details.item_texture)
picNode.set_stretch_mode(TextureRect.STRETCH_KEEP)
picNode.size = Vector2(16, 16)
picNode.position = Vector2(-8, -8)
picNode.set_anchors_preset(Control.PRESET_BOTTOM_WIDE)
picNode.set_anchors_preset(Control.PRESET_FULL_RECT)
# picNode.set_stretch_mode(TextureRect.STRETCH_KEEP)
picNode.size = Vector2(64, 64)
picNode.position = Vector2(-32, -32)
if item_details.item_type == 0: # is weapon
set_ammo_label(str(item_details.item_ammo))
func set_slot_label(slot_index: String):
slot_label.set_text(slot_index)
func set_ammo_label(ammo_value: String):
ammo_label.set_visible(true)

View File

@@ -1,31 +1,10 @@
[gd_scene load_steps=7 format=3 uid="uid://defhc376y3h1d"]
[gd_scene load_steps=5 format=3 uid="uid://defhc376y3h1d"]
[ext_resource type="Script" path="res://UI/Inventory/InventorySlot.gd" id="1_pltri"]
[ext_resource type="FontFile" uid="uid://dj4pldmxeqmtt" path="res://UI/PressStart2P-Regular.ttf" id="1_wew62"]
[ext_resource type="Texture2D" uid="uid://cgtkkroa583fo" path="res://TileSets/Stuff.png" id="2_mxhl7"]
[ext_resource type="Texture2D" uid="uid://4txm3cwkoncp" path="res://UI/Inventory/circle_progress.png" id="3_5flhr"]
[sub_resource type="Animation" id="Animation_wthnv"]
resource_name = "blink"
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:self_modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5, 1),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Color(1, 1, 1, 1), Color(1, 1, 1, 0), Color(1, 1, 1, 1)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_b5fyj"]
_data = {
"blink": SubResource("Animation_wthnv")
}
[node name="InventorySlot" type="Control"]
layout_mode = 3
anchors_preset = 8
@@ -48,34 +27,21 @@ theme_override_fonts/font = ExtResource("1_wew62")
theme_override_font_sizes/font_size = 0
text = "1"
[node name="ItemImage" type="Sprite2D" parent="."]
[node name="ToolbarSlot" type="Sprite2D" parent="."]
scale = Vector2(4, 4)
texture = ExtResource("2_mxhl7")
region_enabled = true
region_rect = Rect2(80, 144, 16, 16)
[node name="ItemSelector" type="Sprite2D" parent="."]
visible = false
modulate = Color(0.054902, 0.290196, 0.258824, 1)
self_modulate = Color(1, 1, 1, 0.822247)
scale = Vector2(4, 4)
texture = ExtResource("2_mxhl7")
region_enabled = true
region_rect = Rect2(64, 144, 16, 16)
[node name="AnimationPlayer" type="AnimationPlayer" parent="ItemSelector"]
autoplay = "blink"
libraries = {
"": SubResource("AnimationLibrary_b5fyj")
}
[node name="SlotLabel" type="Label" parent="."]
visible = false
layout_mode = 0
offset_left = -51.0
offset_top = -58.0
offset_right = 61.0
offset_bottom = -35.0
offset_left = -53.0
offset_top = -65.0
offset_right = 75.0
offset_bottom = -42.0
theme_override_fonts/font = ExtResource("1_wew62")
theme_override_font_sizes/font_size = 0
text = "ItemName"
@@ -92,5 +58,3 @@ texture_under = ExtResource("3_5flhr")
texture_progress = ExtResource("3_5flhr")
tint_under = Color(1, 1, 1, 0)
tint_progress = Color(0.254902, 0.654902, 0.407843, 0.588235)
[node name="ItemImage" type="Sprite2D" parent="."]

View File

@@ -2,18 +2,87 @@ extends Control
@export var items:Array = []
@export var current_slot:int = 0
@export var active_item:Dictionary = {}
@onready var old_slot:int = 0
@onready var current_slot:int = 0
@onready var slot_container = $Panel/HBoxContainer
signal active_item_changed(active_item)
func _process(_delta):
if current_slot == 0:
return
if Input.is_action_just_pressed("drop_item"):
if items[current_slot]:
print("ITEM IN SLOT: ", items[current_slot])
drop_item()
if Input.is_action_just_released("cycle_down"):
var new_slot = current_slot + 1
if new_slot == 6:
new_slot = 1
if new_slot > len(items):
new_slot = 1
set_active_slot(new_slot)
if Input.is_action_just_released("cycle_up"):
var new_slot = current_slot - 1
if new_slot == 0:
new_slot = len(items)
set_active_slot(new_slot)
func add_inventory_item(new_item: Dictionary):
if len(items) == 6:
drop_item(true)
items.append(new_item)
var slot = get_node("Panel/HBoxContainer/InventorySlot" + str(len(items)))
slot.setup_slot(new_item)
if len(items) == 1:
set_active_slot(len(items))
func drop_item(replace: bool = false):
print("CURRENT SLOT: ", current_slot)
var clear_slot = current_slot
if items[clear_slot]:
# TODO: Here we would spawn the item in
items.remove_at(clear_slot)
print("NEW ITEM ARRAY! ", items)
if not replace:
# old_slot = current_slot
# current_slot = current_slot - 1
# if current_slot > -1:
# active_item = items[current_slot]
# else:
# active_item = {}
var slot = get_node("$Panel/HBoxContainer/InventorySlot" + str(current_slot))
slot.clear_slot()
set_active_slot(clear_slot)
func set_active_slot(slot_index: int):
print("CURRENT SLOT: ", current_slot, " SLOT INDEX: ", slot_index)
if current_slot != slot_index and current_slot != 0:
var old_slot = get_node("Panel/HBoxContainer/InventorySlot" + str(current_slot))
old_slot.slot_deselected()
#old_slot.slot_deselected.rpc_id(multiplayer.get_unique_id())
if len(items) == 0:
active_item = {}
current_slot = 0
else:
var slot = get_node("Panel/HBoxContainer/InventorySlot" + str(slot_index))
slot.slot_selected()
#slot.slot_selected.rpc_id(multiplayer.get_unique_id())
current_slot = slot_index
active_item = items[current_slot - 1]
emit_signal("active_item_changed", active_item)
#func set_active_slot():
# if current_slot == -1:
# return
# var old_slot = get_node("Panel/HBoxContainer/InventorySlot" + str(old_slot))
# old_slot.slot_deselected.rpc_id(get_multiplayer_authority())
# var slot = get_node("Panel/HBoxContainer/InventorySlot" + str(current_slot))
# slot.slot_selected.rpc_id(get_multiplayer_authority())

View File

@@ -44,7 +44,6 @@ theme_override_constants/separation = 70
[node name="InventorySlot1" parent="Panel/HBoxContainer" instance=ExtResource("1_a71mm")]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
[node name="InventorySlot2" parent="Panel/HBoxContainer" instance=ExtResource("1_a71mm")]
@@ -65,4 +64,5 @@ size_flags_vertical = 4
[node name="InventorySlot6" parent="Panel/HBoxContainer" instance=ExtResource("1_a71mm")]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4