Add NPC and items walking.

This commit is contained in:
Julian Murgia
2020-12-28 08:39:57 +01:00
parent af8a9ea086
commit ff89dc1677
205 changed files with 972 additions and 488 deletions

View File

@@ -0,0 +1,36 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://addons/escoria-core/game/scenes/inventory/inventory_ui.gd" type="Script" id=1]
[ext_resource path="res://game/items/ESCORIA_ALL_ITEMS.tscn" type="PackedScene" id=2]
[ext_resource path="res://game/ui/ui_9verbs/inventory/inventory_ui_container.gd" type="Script" id=3]
[node name="inventory_ui" type="Control"]
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
items_container = NodePath("PanelContainer/ScrollContainer/GridContainer")
[node name="PanelContainer" type="PanelContainer" parent="."]
margin_right = 600.0
margin_bottom = 175.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ScrollContainer" type="ScrollContainer" parent="PanelContainer"]
margin_left = 7.0
margin_top = 7.0
margin_right = 593.0
margin_bottom = 168.0
[node name="GridContainer" type="GridContainer" parent="PanelContainer/ScrollContainer"]
margin_right = 586.0
size_flags_horizontal = 3
custom_constants/vseparation = 16
custom_constants/hseparation = 16
columns = 4
script = ExtResource( 3 )
[node name="ESCORIA_ALL_ITEMS" parent="." instance=ExtResource( 2 )]
position = Vector2( 269.391, 275.003 )

View File

@@ -0,0 +1,42 @@
extends Control
"""
This script is totally user-defined. It does exactly what the user wants the
inventory to look like. It only requires 4 functions to be defined:
- is_empty() -> bool
- get_items() -> Array
- add_item(inventory_item : ESCInventoryItem)
- remove_item(inventory_item : ESCInventoryItem)
The user is free to implement these methods the way s-he likes.
"""
var current_nodes_in_container = {}
func is_empty() -> bool:
return get_child_count() > 0
func get_items() -> Array:
return current_nodes_in_container.keys()
func add_item(inventory_item : ESCInventoryItem):
var center_container = CenterContainer.new()
center_container.size_flags_horizontal = SIZE_EXPAND_FILL
center_container.connect("mouse_entered", inventory_item, "_on_inventory_item_mouse_enter")
center_container.connect("mouse_exited", inventory_item, "_on_inventory_item_mouse_exit")
center_container.connect("gui_input", self, "_on_gui_input", [inventory_item])
center_container.add_child(inventory_item)
add_child(center_container)
current_nodes_in_container[inventory_item] = center_container
func remove_item(inventory_item : ESCInventoryItem):
var node_to_remove = current_nodes_in_container[inventory_item]
current_nodes_in_container.erase(node_to_remove)
node_to_remove.disconnect("mouse_entered", inventory_item, "_on_inventory_item_mouse_enter")
node_to_remove.disconnect("mouse_exited", inventory_item, "_on_inventory_item_mouse_exit")
node_to_remove.disconnect("pressed", self, "_on_gui_input")
remove_child(node_to_remove)
node_to_remove.queue_free()
func _on_gui_input(event : InputEvent, inventory_item : ESCInventoryItem):
if event is InputEventMouseButton and event.is_pressed():
inventory_item._on_inventory_item_pressed()