basic inventory system ready
This commit is contained in:
parent
3f22eeaf9d
commit
aee93b8d10
20 changed files with 513 additions and 16 deletions
22
inv_system/inventory.gd
Normal file
22
inv_system/inventory.gd
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
extends PanelContainer
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
if Input.get_current_cursor_shape() == CURSOR_FORBIDDEN:
|
||||
DisplayServer.cursor_set_shape(DisplayServer.CURSOR_ARROW)
|
||||
|
||||
var data_bk
|
||||
func _notification(what: int) -> void:
|
||||
if what == Node.NOTIFICATION_DRAG_BEGIN:
|
||||
data_bk = get_viewport().gui_get_drag_data()
|
||||
if what == Node.NOTIFICATION_DRAG_END:
|
||||
if not is_drag_successful():
|
||||
if data_bk:
|
||||
data_bk.icon.show()
|
||||
data_bk = null
|
||||
1
inv_system/inventory.gd.uid
Normal file
1
inv_system/inventory.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c6oycdae5wvjf
|
||||
5
inv_system/item_data.gd
Normal file
5
inv_system/item_data.gd
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
extends Resource
|
||||
class_name ItemData
|
||||
|
||||
@export var item_name : String
|
||||
@export var icon : Texture2D
|
||||
1
inv_system/item_data.gd.uid
Normal file
1
inv_system/item_data.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dccraom7a7e8d
|
||||
41
inv_system/item_slot.gd
Normal file
41
inv_system/item_slot.gd
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
extends Panel
|
||||
|
||||
@export var icon : TextureRect
|
||||
@export var item: ItemData
|
||||
|
||||
func _ready() -> void:
|
||||
update_ui()
|
||||
|
||||
func update_ui():
|
||||
if not item:
|
||||
icon.texture = null
|
||||
return
|
||||
|
||||
icon.texture = item.icon
|
||||
tooltip_text = item.item_name
|
||||
|
||||
func _get_drag_data(at_position: Vector2) -> Variant:
|
||||
if not item:
|
||||
return
|
||||
|
||||
var preview = duplicate()
|
||||
var c = Control.new()
|
||||
c.add_child(preview)
|
||||
preview.position -= Vector2(32,32)
|
||||
preview.self_modulate = Color.TRANSPARENT
|
||||
c.modulate = Color(c.modulate,0.5)
|
||||
set_drag_preview(c)
|
||||
icon.hide()
|
||||
return self
|
||||
|
||||
func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
|
||||
return true
|
||||
|
||||
func _drop_data(at_position: Vector2, data: Variant) -> void:
|
||||
var temp = item
|
||||
item = data.item
|
||||
data.item = temp
|
||||
icon.show()
|
||||
data.icon.show()
|
||||
update_ui()
|
||||
data.update_ui()
|
||||
1
inv_system/item_slot.gd.uid
Normal file
1
inv_system/item_slot.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cpd04flfh5nlc
|
||||
Loading…
Add table
Add a link
Reference in a new issue