From 6342dccbf480bc44f0b873348759078610207f92 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 12 Aug 2020 15:54:40 +0200 Subject: [PATCH] The LootWindow now closes when the player moves. --- game/player/Player.gd | 7 +++++++ game/ui/loot_window/LootWindow.gd | 9 ++++++++- game/ui/loot_window/LootWindow.tscn | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/game/player/Player.gd b/game/player/Player.gd index fa7d1d39..7c764e41 100644 --- a/game/player/Player.gd +++ b/game/player/Player.gd @@ -24,6 +24,13 @@ class_name PlayerGD # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +signal player_moved() + +func _moved(): + ._moved() + + emit_signal("player_moved") + func _process(delta): if Input.is_action_just_pressed("sheath"): get_character_skeleton().toggle_sheath() diff --git a/game/ui/loot_window/LootWindow.gd b/game/ui/loot_window/LootWindow.gd index 425bf8ff..814a5139 100644 --- a/game/ui/loot_window/LootWindow.gd +++ b/game/ui/loot_window/LootWindow.gd @@ -59,6 +59,10 @@ func set_player(p_player : Entity) -> void: player.connect("ctarget_bag_changed", self, "ctarget_bag_changed") player.connect("onc_open_loot_winow_request", self, "onc_open_loot_winow_request") +func on_player_moved(): + if visible: + hide() + func on_visibility_changed(): if visible: refresh() @@ -66,7 +70,7 @@ func on_visibility_changed(): if target_bag != null: 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() @@ -84,3 +88,6 @@ func ctarget_bag_changed(entity: Entity, bag: Bag) -> void: func onc_open_loot_winow_request() -> void: show() + + if player.has_signal("player_moved") && !player.is_connected("player_moved", self, "on_player_moved"): + player.connect("player_moved", self, "on_player_moved", [], CONNECT_ONESHOT) diff --git a/game/ui/loot_window/LootWindow.tscn b/game/ui/loot_window/LootWindow.tscn index 5aa5eb58..980f7002 100644 --- a/game/ui/loot_window/LootWindow.tscn +++ b/game/ui/loot_window/LootWindow.tscn @@ -45,6 +45,6 @@ size_flags_horizontal = 3 [node name="Button" type="Button" parent="VBoxContainer"] margin_top = 566.0 margin_right = 1016.0 -margin_bottom = 592.269 +margin_bottom = 592.57 text = "close" [connection signal="pressed" from="VBoxContainer/Button" to="." method="hide"]