more work on inventory
This commit is contained in:
48
UI/Inventory/InventorySlot.gd
Normal file
48
UI/Inventory/InventorySlot.gd
Normal file
@@ -0,0 +1,48 @@
|
||||
extends Control
|
||||
|
||||
|
||||
@onready var slot_label := $SlotLabel
|
||||
@onready var ammo_label := $AmmoLabel
|
||||
@onready var image_slot := $ItemImage
|
||||
@onready var reload_bar := $ReloadBar
|
||||
@onready var item_selecter := $ItemSelector
|
||||
|
||||
func slot_selected():
|
||||
item_selecter.set_visible(true)
|
||||
|
||||
func slot_deselected():
|
||||
item_selecter.set_visible(false)
|
||||
|
||||
func reload_item(cooldown: float):
|
||||
reload_bar.set_visible(true)
|
||||
reload_bar.set_max(cooldown)
|
||||
reload_bar.set_step(0.1)
|
||||
var tween = get_tree().create_tween()
|
||||
tween.tween_method(reload_bar.set_value, 0.0, cooldown, cooldown)
|
||||
await tween.finished
|
||||
reload_bar.set_visible(false)
|
||||
|
||||
func clear_slot():
|
||||
image_slot.set_texture(null)
|
||||
|
||||
func setup_slot(item_details: Dictionary):
|
||||
clear_slot()
|
||||
var picNode = TextureRect.new()
|
||||
image_slot.add_child(picNode)
|
||||
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)
|
||||
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)
|
||||
ammo_label.set_text(ammo_value)
|
Reference in New Issue
Block a user