55 lines
1.5 KiB
GDScript
55 lines
1.5 KiB
GDScript
extends Control
|
|
|
|
|
|
@onready var slot_label := $SlotLabel
|
|
@onready var ammo_label := $AmmoLabel
|
|
@onready var image_slot := $ItemImage
|
|
@onready var reload_bar := $ReloadBar
|
|
@onready var toolbar_slot := $ToolbarSlot
|
|
|
|
@rpc("call_local")
|
|
func slot_selected():
|
|
toolbar_slot.set_modulate(Color("4f58d8"))
|
|
slot_label.show()
|
|
|
|
@rpc("call_local")
|
|
func slot_deselected():
|
|
toolbar_slot.set_modulate(Color("ffffff"))
|
|
slot_label.hide()
|
|
|
|
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)
|
|
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_name("inv_texture")
|
|
picNode.set_texture(item_details.item_texture)
|
|
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_ammo_label(ammo_value: String):
|
|
ammo_label.set_visible(true)
|
|
ammo_label.set_text(ammo_value)
|