forked from UVASGD/student-game-developers-at-uva-spring-2025-student-game-developers-at-uva-fall-2024-ProjectTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinventory_slot.gd
85 lines (67 loc) · 2 KB
/
inventory_slot.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
extends Node2D
var is_hovered = false
@export var index:int
@export var is_overflow:bool
@onready var sprite = $Sprite2D
var cached_sprite_path = null
var selected = false
var hovercolor = Color(0.53,0.53,0.53,0.5)
var defaultcolor = Color(0.33,0.33,0.33,0.4)
func _ready() -> void:
print(index)
print(PlayerData.inventory(index))
if is_overflow:
hide()
pass # Replace with function body.
func _process(_delta: float) -> void:
update_display()
func remove_item():
if item:
PlayerData.remove_inv(index)
func add_stack(other):
item().count += other.item().count
PlayerData.remove_inv(other.index)
func split_stack():
@warning_ignore("shadowed_variable")
var item = item()
if item and item.stackable and item.count > 1:
var new_item = Items.clone(item)
new_item.count = item.count - floor(item.count /2.0)
item.count = item.count - ceil(item.count/2.0)
PlayerData.add_overflow(new_item)
func update_display():
if not is_overflow:
if is_hovered:
$ColorRect.color = hovercolor
else:
$ColorRect.color = defaultcolor
if selected:
$SelectedBorder.show()
else:
$SelectedBorder.hide()
if item() == null:
$displaycount.text = ""
sprite.texture = null
return
elif item().stackable:
$displaycount.text = str(item().count)
@warning_ignore("shadowed_variable")
var item = item()
if item.sprite_path != cached_sprite_path:
var image = load(item.sprite_path)
var texture = ImageTexture.create_from_image(image)
sprite.texture = texture
return
func item():
return PlayerData.inventory(index)
func drop():
PlayerData.drop(index)
func _on_clickbox_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
if event.is_action_pressed("leftclick"):
SignalBus.emit_signal("invslot_clicked", self)
func _on_clickbox_mouse_entered() -> void:
SignalBus.emit_signal("invslot_hovered", self)
pass # Replace with function body.
func _on_clickbox_mouse_exited() -> void:
SignalBus.emit_signal("invslot_unhovered", self)
pass # Replace with function body.