From b42adccaceb05464d99d259f8d8ee6a3746a2b7a Mon Sep 17 00:00:00 2001 From: Eneko Nieto Date: Sun, 25 Aug 2024 17:54:24 +0200 Subject: [PATCH] fix(inventory): show/hide inventory on hide/show menu --- .../escoria-ui-return-monkey-island/game.gd | 4 ++ .../escoria-ui-return-monkey-island/game.tscn | 5 -- .../inventory/inventory_ui.gd | 49 ++++++------------- .../inventory/inventory_ui.tscn | 4 ++ 4 files changed, 22 insertions(+), 40 deletions(-) diff --git a/addons/escoria-ui-return-monkey-island/game.gd b/addons/escoria-ui-return-monkey-island/game.gd index 0a17b470..a94e35b8 100644 --- a/addons/escoria-ui-return-monkey-island/game.gd +++ b/addons/escoria-ui-return-monkey-island/game.gd @@ -369,22 +369,26 @@ func close_inventory(): $CanvasLayer/ui/HBoxContainer/inventory_ui.hide_inventory() func hide_ui(): + $CanvasLayer/ui/HBoxContainer/inventory_ui.hide_ui() $CanvasLayer/ui/HBoxContainer/inventory_ui.hide() $CanvasLayer/ui.hide() func show_ui(): $CanvasLayer/ui/HBoxContainer/inventory_ui.show() + $CanvasLayer/ui/HBoxContainer/inventory_ui.show_ui() $CanvasLayer/ui.show() func hide_main_menu(): if get_node(main_menu).visible: get_node(main_menu).hide() + show_ui() func show_main_menu(): if not get_node(main_menu).visible: get_node(main_menu).reset() get_node(main_menu).show() + hide_ui() func unpause_game(): if get_node(pause_menu).visible: diff --git a/addons/escoria-ui-return-monkey-island/game.tscn b/addons/escoria-ui-return-monkey-island/game.tscn index 488051dd..f12fd93e 100644 --- a/addons/escoria-ui-return-monkey-island/game.tscn +++ b/addons/escoria-ui-return-monkey-island/game.tscn @@ -89,11 +89,6 @@ margin_right = 1186.0 margin_bottom = 90.0 size_flags_horizontal = 3 -[node name="inventory_bg" type="Polygon2D" parent="CanvasLayer/ui/HBoxContainer"] -position = Vector2( 0, -964 ) -color = Color( 0.156863, 0.0627451, 0, 1 ) -polygon = PoolVector2Array( 0, 874, 1280, 874, 1280, 1047, 0, 1047 ) - [node name="inventory_ui" parent="CanvasLayer/ui/HBoxContainer" instance=ExtResource( 1 )] anchor_right = 0.0 anchor_bottom = 0.0 diff --git a/addons/escoria-ui-return-monkey-island/inventory/inventory_ui.gd b/addons/escoria-ui-return-monkey-island/inventory/inventory_ui.gd index c4c47837..2b0b347b 100644 --- a/addons/escoria-ui-return-monkey-island/inventory/inventory_ui.gd +++ b/addons/escoria-ui-return-monkey-island/inventory/inventory_ui.gd @@ -7,46 +7,25 @@ var inventory_visible: bool = false func _ready() -> void: $FloatingInventory/panel.rect_position.x = ProjectSettings.get_setting("display/window/size/width") - $FloatingInventory/panel.rect_size.x - # Hide inventory by default - # $FloatingInventory/panel.rect_position.x = \ - # ProjectSettings.get_setting("display/window/size/width") - -func _on_inventory_button_pressed(): - if $FloatingInventory/InventoryTween.is_active(): - return - if inventory_visible: - hide_inventory() - else: - show_inventory() func show_inventory(): - $FloatingInventory/InventoryTween.stop_all() - $FloatingInventory/InventoryTween.remove_all() - $FloatingInventory/InventoryTween.interpolate_property( - $FloatingInventory/panel, - "visible", - 0, - 1, - 0.6 - ) - $FloatingInventory/InventoryTween.start() - yield($FloatingInventory/InventoryTween,"tween_all_completed") - $FloatingInventory/InventoryTween.stop_all() + $FloatingInventory/panel.show() inventory_visible = true func hide_inventory(): - $FloatingInventory/InventoryTween.stop_all() - $FloatingInventory/InventoryTween.remove_all() - $FloatingInventory/InventoryTween.interpolate_property( - $FloatingInventory/panel, - "visible", - 1, - 0, - 0.01 - ) - $FloatingInventory/InventoryTween.start() - yield($FloatingInventory/InventoryTween,"tween_all_completed") - $FloatingInventory/InventoryTween.stop_all() + $FloatingInventory/panel.hide() + inventory_visible = false + + +func show_ui(): + $FloatingInventory/inventory_bg.show() + $FloatingInventory/panel/MarginContainer/ScrollContainer/container.show() + inventory_visible = true + + +func hide_ui(): + $FloatingInventory/inventory_bg.hide() + $FloatingInventory/panel/MarginContainer/ScrollContainer/container.hide() inventory_visible = false diff --git a/addons/escoria-ui-return-monkey-island/inventory/inventory_ui.tscn b/addons/escoria-ui-return-monkey-island/inventory/inventory_ui.tscn index 12e14cf9..b90b8fd3 100644 --- a/addons/escoria-ui-return-monkey-island/inventory/inventory_ui.tscn +++ b/addons/escoria-ui-return-monkey-island/inventory/inventory_ui.tscn @@ -20,6 +20,10 @@ inventory_ui_container = NodePath("FloatingInventory/panel/MarginContainer/Scrol [node name="FloatingInventory" type="CanvasLayer" parent="."] +[node name="inventory_bg" type="Polygon2D" parent="FloatingInventory"] +color = Color( 0.156863, 0.0627451, 0, 1 ) +polygon = PoolVector2Array( -3, 578, 1280, 578, 1280, 752, -3, 757 ) + [node name="panel" type="TextureRect" parent="FloatingInventory"] anchor_left = 1.0 anchor_top = 1.0