fix: wire item_confirmed signal and set item cursor icon
This commit is contained in:
@@ -204,3 +204,4 @@ layer = 10
|
|||||||
|
|
||||||
[connection signal="overlay_hide_requested" from="HUD/InventoryBackpack" to="." method="_on_backpack_hide_overlay"]
|
[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="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"]
|
||||||
|
|||||||
15
MainGame.gd
15
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 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 hourglass_cursor = load("res://hourglass_icon.png")
|
||||||
|
var item_cursor: Texture2D = null
|
||||||
var previous_cursor_index: int = 0
|
var previous_cursor_index: int = 0
|
||||||
var is_script_running: bool = false
|
var is_script_running: bool = false
|
||||||
var is_cursor_locked: bool = false # When true, hourglass is shown and cursor can't be changed
|
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:
|
func _on_backpack_hide_overlay() -> void:
|
||||||
$InventoryOverlayLayer/InventoryOverlay.hide_overlay()
|
$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):
|
func _input(event):
|
||||||
if event.is_action_released("quit"):
|
if event.is_action_released("quit"):
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
@@ -87,8 +98,8 @@ func _input(event):
|
|||||||
var prev_action = ActionState.current_action
|
var prev_action = ActionState.current_action
|
||||||
ActionState.current_action = (ActionState.current_action + 1) % 5
|
ActionState.current_action = (ActionState.current_action + 1) % 5
|
||||||
if ActionState.current_action == ActionState.Action.ITEM:
|
if ActionState.current_action == ActionState.Action.ITEM:
|
||||||
if InventoryManager.selected_item:
|
if InventoryManager.selected_item and item_cursor:
|
||||||
Input.set_custom_mouse_cursor(cursors[ActionState.current_action], Input.CursorShape.CURSOR_ARROW, Vector2(0,0))
|
Input.set_custom_mouse_cursor(item_cursor, Input.CursorShape.CURSOR_ARROW, Vector2(0,0))
|
||||||
else:
|
else:
|
||||||
ActionState.current_action = (ActionState.current_action + 1) % 5
|
ActionState.current_action = (ActionState.current_action + 1) % 5
|
||||||
Input.set_custom_mouse_cursor(cursors[ActionState.current_action], Input.CursorShape.CURSOR_ARROW, Vector2(0,0))
|
Input.set_custom_mouse_cursor(cursors[ActionState.current_action], Input.CursorShape.CURSOR_ARROW, Vector2(0,0))
|
||||||
|
|||||||
@@ -3,4 +3,5 @@ class_name ItemDefinition
|
|||||||
|
|
||||||
@export var id: String = ""
|
@export var id: String = ""
|
||||||
@export var name: String = ""
|
@export var name: String = ""
|
||||||
|
@export var icon: Texture2D
|
||||||
@export var combination_category: String = ""
|
@export var combination_category: String = ""
|
||||||
|
|||||||
@@ -193,40 +193,6 @@ func _gui_input(event: InputEvent) -> void:
|
|||||||
hide_overlay()
|
hide_overlay()
|
||||||
close_requested.emit()
|
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:
|
func _on_combination_attempted(item_a_id: String, item_b_id: String) -> void:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -52,10 +52,15 @@ color = Color(0.15, 0.15, 0.2, 1)
|
|||||||
|
|
||||||
[node name="ItemGrid" type="GridContainer" parent="InventoryPanel" unique_id=-1294967291]
|
[node name="ItemGrid" type="GridContainer" parent="InventoryPanel" unique_id=-1294967291]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
offset_left = 10.0
|
offset_left = 10.0
|
||||||
offset_top = 10.0
|
offset_top = 10.0
|
||||||
offset_right = -10.0
|
offset_right = -10.0
|
||||||
offset_bottom = -50.0
|
offset_bottom = -50.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
|
||||||
[node name="HoverLabel" type="Label" parent="InventoryPanel" unique_id=-1294967290]
|
[node name="HoverLabel" type="Label" parent="InventoryPanel" unique_id=-1294967290]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
|
|||||||
@@ -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]
|
[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")
|
script = ExtResource("1")
|
||||||
|
|
||||||
[node name="ItemBox" type="ColorRect" parent="." unique_id=2000000002]
|
[node name="ItemBox" type="ColorRect" parent="." unique_id=2000000002]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 8
|
anchors_preset = -1
|
||||||
anchor_left = 0.062
|
anchor_left = 0.062
|
||||||
anchor_top = 0.062
|
anchor_top = 0.062
|
||||||
anchor_right = 0.938
|
anchor_right = 0.938
|
||||||
anchor_bottom = 0.938
|
anchor_bottom = 0.938
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
mouse_filter = 1
|
mouse_filter = 1
|
||||||
color = Color(1, 0.6, 0.2, 1)
|
color = Color(1, 0.6, 0.2, 1)
|
||||||
|
|
||||||
[node name="HoverHighlight" type="ColorRect" parent="." unique_id=2000000003]
|
[node name="HoverHighlight" type="ColorRect" parent="." unique_id=2000000003]
|
||||||
|
visible = false
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 8
|
anchors_preset = 15
|
||||||
anchor_left = 0.0
|
|
||||||
anchor_top = 0.0
|
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
mouse_filter = 1
|
||||||
color = Color(1, 1, 1, 0.3)
|
color = Color(1, 1, 1, 0.3)
|
||||||
visible = false
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"item_id": "splash",
|
"item_id": "splash",
|
||||||
"name": "Splash",
|
"name": "Splash",
|
||||||
"combination_category": "potion"
|
"icon": "res://splash.png",
|
||||||
|
"combination_category": "potion"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ func _ready() -> void:
|
|||||||
var def = ItemDefinition.new()
|
var def = ItemDefinition.new()
|
||||||
def.id = "splash"
|
def.id = "splash"
|
||||||
def.name = "Splash"
|
def.name = "Splash"
|
||||||
|
def.icon = load("res://splash.png")
|
||||||
def.combination_category = "potion"
|
def.combination_category = "potion"
|
||||||
InventoryManager.register_item(def)
|
InventoryManager.register_item(def)
|
||||||
give_item("splash")
|
give_item("splash")
|
||||||
|
|||||||
Reference in New Issue
Block a user