drag & drop with inventory slots
This commit is contained in:
@@ -14,8 +14,6 @@ const SPRITE_SCENE: PackedScene = preload("res://entities/interactables/item_obj
|
||||
|
||||
@onready var object_sprite: ItemObjectSprite = generate_sprite()
|
||||
|
||||
var dragging := false
|
||||
|
||||
func _init(_item = null):
|
||||
if _item:
|
||||
item = _item
|
||||
@@ -26,15 +24,6 @@ func _ready():
|
||||
object_sprite.apply_texture_to_sprite(item.icon, ITEM_SPRITE_SIZE)
|
||||
object_sprite.generate_particles(item.get_particles())
|
||||
|
||||
func _process(_delta):
|
||||
if dragging:
|
||||
global_position = get_global_mouse_position()
|
||||
|
||||
func _on_mouse_entered():
|
||||
mouse_over = true
|
||||
if not dragging:
|
||||
Pointer.inspect(self)
|
||||
|
||||
func pointer_text() -> String:
|
||||
var name_suffix = ""
|
||||
|
||||
@@ -60,12 +49,6 @@ func interact(player : Player) -> bool:
|
||||
|
||||
return false
|
||||
|
||||
func start_dragging():
|
||||
dragging = true
|
||||
|
||||
func stop_dragging():
|
||||
dragging = false
|
||||
|
||||
func pickup_animation(target_position: Vector2):
|
||||
available = false
|
||||
var tween: Tween = get_tree().create_tween()
|
||||
|
||||
@@ -73,16 +73,34 @@ func update_seeds_size(size = seeds_size):
|
||||
while len(seeds) > size and seeds.find(null) != -1:
|
||||
seeds.pop_at(seeds.find(null))
|
||||
|
||||
func add_item_at(item: Item, item_ind: int) -> bool:
|
||||
if item.type == Item.ItemType.CONSUMABLE_ITEM:
|
||||
return add_seed_at(item, item_ind - tools.size())
|
||||
else:
|
||||
return false
|
||||
|
||||
func add_seed_at(s: Item, seed_ind: int) -> bool:
|
||||
update_seeds_size()
|
||||
if seeds[seed_ind]:
|
||||
return false
|
||||
else:
|
||||
seeds[seed_ind] = s
|
||||
updated.emit(self)
|
||||
return true
|
||||
|
||||
func get_all_items_size() -> int:
|
||||
return tools.size() + seeds.size()
|
||||
|
||||
func get_all_items() -> Array[Item]:
|
||||
return tools + seeds
|
||||
|
||||
func get_item(ind: int = current_item_ind) -> Item:
|
||||
if ind < 0 || ind > len(get_all_items()):
|
||||
if ind < 0 || ind > get_all_items_size():
|
||||
return null
|
||||
return get_all_items()[ind]
|
||||
|
||||
func has_item(item: Item) -> bool:
|
||||
return get_all_items().has(item)
|
||||
return tools.has(item) || seeds.has(item)
|
||||
|
||||
func has_item_with_name(name: String) -> bool:
|
||||
var id = get_all_items().find_custom(
|
||||
|
||||
@@ -137,7 +137,11 @@ func take_surrounding_seeds():
|
||||
|
||||
if not data.inventory.is_full():
|
||||
for area in overlapping_areas:
|
||||
if area is ItemObject and not area in just_dropped_item_objects:
|
||||
if (
|
||||
area is ItemObject
|
||||
and not area in just_dropped_item_objects
|
||||
and not Pointer.dragging_inspected
|
||||
):
|
||||
area.interact(self)
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user