diff --git a/Game.tscn b/Game.tscn index 06b5bc1..f320532 100644 --- a/Game.tscn +++ b/Game.tscn @@ -204,3 +204,4 @@ layer = 10 [connection signal="overlay_hide_requested" from="HUD/InventoryBackpack" to="." method="_on_backpack_hide_overlay"] [connection signal="overlay_show_requested" from="HUD/InventoryBackpack" to="." method="_on_backpack_show_overlay"] +[connection signal="item_confirmed" from="InventoryOverlayLayer/InventoryOverlay" to="." method="_on_overlay_item_confirmed"] diff --git a/MainGame.gd b/MainGame.gd index 63b0897..9eede85 100644 --- a/MainGame.gd +++ b/MainGame.gd @@ -3,6 +3,7 @@ extends Node2D var cursors = [load("res://boot_icon.png"), load("res://eye_icon.png"), load("res://hand_icon.png"), load("res://speech_icon.png")] var hourglass_cursor = load("res://hourglass_icon.png") +var item_cursor: Texture2D = null var previous_cursor_index: int = 0 var is_script_running: bool = false var is_cursor_locked: bool = false # When true, hourglass is shown and cursor can't be changed @@ -80,6 +81,16 @@ func _on_backpack_show_overlay() -> void: func _on_backpack_hide_overlay() -> void: $InventoryOverlayLayer/InventoryOverlay.hide_overlay() +func _on_overlay_item_confirmed(item_id: String) -> void: + InventoryManager.select_item(item_id) + var def = InventoryManager.get_item_definition(item_id) + if def and def.icon: + item_cursor = def.icon + Input.set_custom_mouse_cursor(item_cursor) + ActionState.current_action = ActionState.Action.ITEM + else: + Input.set_custom_mouse_cursor(cursors[ActionState.Action.WALK]) + func _input(event): if event.is_action_released("quit"): get_tree().quit() @@ -87,8 +98,8 @@ func _input(event): var prev_action = ActionState.current_action ActionState.current_action = (ActionState.current_action + 1) % 5 if ActionState.current_action == ActionState.Action.ITEM: - if InventoryManager.selected_item: - Input.set_custom_mouse_cursor(cursors[ActionState.current_action], Input.CursorShape.CURSOR_ARROW, Vector2(0,0)) + if InventoryManager.selected_item and item_cursor: + Input.set_custom_mouse_cursor(item_cursor, Input.CursorShape.CURSOR_ARROW, Vector2(0,0)) else: ActionState.current_action = (ActionState.current_action + 1) % 5 Input.set_custom_mouse_cursor(cursors[ActionState.current_action], Input.CursorShape.CURSOR_ARROW, Vector2(0,0)) diff --git a/inventory/ItemDefinition.gd b/inventory/ItemDefinition.gd index 6b5f191..8e0ee9b 100644 --- a/inventory/ItemDefinition.gd +++ b/inventory/ItemDefinition.gd @@ -3,4 +3,5 @@ class_name ItemDefinition @export var id: String = "" @export var name: String = "" +@export var icon: Texture2D @export var combination_category: String = "" diff --git a/inventory/inventory_overlay/InventoryOverlay.gd b/inventory/inventory_overlay/InventoryOverlay.gd index 72d6450..0a9306f 100644 --- a/inventory/inventory_overlay/InventoryOverlay.gd +++ b/inventory/inventory_overlay/InventoryOverlay.gd @@ -193,40 +193,6 @@ func _gui_input(event: InputEvent) -> void: hide_overlay() close_requested.emit() -func _gui_input(event: InputEvent) -> void: - print("HI") - if not _is_visible: - return - - if event is InputEventMouseButton: - print("CLOSE") - if event.button_index == 1 and event.pressed: - - _clear_selection() - hide_overlay() - close_requested.emit() - if not _is_dragging: - pass - elif event.button_index == 1 and not event.pressed: - if _is_dragging: - if _hovered_slot == null: - _clear_selection() - hide_overlay() - close_requested.emit() - elif _hovered_slot == _selected_slot: - _handle_release_same_item() - else: - combine_requested.emit(_selected_slot.item_id, _hovered_slot.item_id) - _clear_selection() - return - - if event is InputEventMouseMotion and _is_dragging and _dragged_item: - _dragged_item.position = get_local_mouse_position() - Vector2(24, 24) - var panel_rect = panel.get_global_rect() - if not panel_rect.has_point(get_global_mouse_position()): - _clear_selection() - hide_overlay() - close_requested.emit() func _on_combination_attempted(item_a_id: String, item_b_id: String) -> void: pass diff --git a/inventory/inventory_overlay/InventoryOverlay.tscn b/inventory/inventory_overlay/InventoryOverlay.tscn index 41ce567..6c360a6 100644 --- a/inventory/inventory_overlay/InventoryOverlay.tscn +++ b/inventory/inventory_overlay/InventoryOverlay.tscn @@ -52,10 +52,15 @@ color = Color(0.15, 0.15, 0.2, 1) [node name="ItemGrid" type="GridContainer" parent="InventoryPanel" unique_id=-1294967291] layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 offset_left = 10.0 offset_top = 10.0 offset_right = -10.0 offset_bottom = -50.0 +grow_horizontal = 2 +grow_vertical = 2 [node name="HoverLabel" type="Label" parent="InventoryPanel" unique_id=-1294967290] layout_mode = 1 diff --git a/inventory/inventory_overlay/InventorySlot.tscn b/inventory/inventory_overlay/InventorySlot.tscn index a96f946..b0e17fe 100644 --- a/inventory/inventory_overlay/InventorySlot.tscn +++ b/inventory/inventory_overlay/InventorySlot.tscn @@ -1,27 +1,32 @@ -[gd_scene format=3 uid="uid://1esl88fgtd2p6"] +[gd_scene format=3 uid="uid://c7depvvxf5s6l"] -[ext_resource type="Script" uid="uid://oegm753jbl9m" path="res://inventory/inventory_overlay/InventorySlot.gd" id="1"] +[ext_resource type="Script" uid="uid://oegm753jbmam" path="res://inventory/inventory_overlay/InventorySlot.gd" id="1"] [node name="InventorySlot" type="Control" unique_id=2000000001] -custom_minimum_size = Vector2i(64, 64) +custom_minimum_size = Vector2(64, 64) +layout_mode = 3 +anchors_preset = 0 script = ExtResource("1") [node name="ItemBox" type="ColorRect" parent="." unique_id=2000000002] layout_mode = 1 -anchors_preset = 8 +anchors_preset = -1 anchor_left = 0.062 anchor_top = 0.062 anchor_right = 0.938 anchor_bottom = 0.938 +grow_horizontal = 2 +grow_vertical = 2 mouse_filter = 1 color = Color(1, 0.6, 0.2, 1) [node name="HoverHighlight" type="ColorRect" parent="." unique_id=2000000003] +visible = false layout_mode = 1 -anchors_preset = 8 -anchor_left = 0.0 -anchor_top = 0.0 +anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 1 color = Color(1, 1, 1, 0.3) -visible = false diff --git a/inventory/items/splash_item.tres b/inventory/items/splash_item.tres index 76439f5..c0d0b63 100644 --- a/inventory/items/splash_item.tres +++ b/inventory/items/splash_item.tres @@ -1,5 +1,6 @@ { - "item_id": "splash", - "name": "Splash", - "combination_category": "potion" + "item_id": "splash", + "name": "Splash", + "icon": "res://splash.png", + "combination_category": "potion" } diff --git a/scenes/kq4_003_fountain_pool/kq4_003_fountain_pool.gd b/scenes/kq4_003_fountain_pool/kq4_003_fountain_pool.gd index 04934c0..f7016f4 100644 --- a/scenes/kq4_003_fountain_pool/kq4_003_fountain_pool.gd +++ b/scenes/kq4_003_fountain_pool/kq4_003_fountain_pool.gd @@ -6,6 +6,7 @@ func _ready() -> void: var def = ItemDefinition.new() def.id = "splash" def.name = "Splash" + def.icon = load("res://splash.png") def.combination_category = "potion" InventoryManager.register_item(def) give_item("splash")