broken_seals/game/ui/loot_window/LootWindow.gd

83 lines
2.4 KiB
GDScript3
Raw Normal View History

2019-11-20 14:30:34 +01:00
extends Control
2019-12-22 19:20:38 +01:00
# Copyright (c) 2019 Péter Magyar
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
2019-11-20 14:30:34 +01:00
export(PackedScene) var entry_scene : PackedScene
export(NodePath) var container_path : NodePath
var container : Node
var player : Entity
var target_bag : Bag
func _ready():
container = get_node(container_path)
connect("visibility_changed", self, "on_visibility_changed")
if entry_scene == null:
Logger.error("LootWindow: entry_scene is null")
func refresh():
for child in container.get_children():
child.queue_free()
if target_bag == null:
return
for i in range(target_bag.get_size()):
var ii : ItemInstance = target_bag.get_item(i)
if ii:
var e : Node = entry_scene.instance()
container.add_child(e)
e.owner = container
e.set_item(i, ii, player)
func set_player(p_player : Entity) -> void:
player = p_player
player.connect("ctarget_bag_changed", self, "ctarget_bag_changed")
func on_visibility_changed():
if visible:
refresh()
else:
target_bag.disconnect("item_removed", self, "on_item_removed")
target_bag = null
func on_item_removed(bag: Bag, item: ItemInstance, slot_id: int) -> void:
refresh()
func ctarget_bag_changed(entity: Entity, bag: Bag) -> void:
if target_bag != null:
target_bag.disconnect("item_removed", self, "on_item_removed")
target_bag = null
target_bag = bag
if target_bag == null:
return
target_bag.connect("item_removed", self, "on_item_removed")