Added inventory
parent
4491414b83
commit
cb0c37c5f9
|
@ -1,60 +1,73 @@
|
|||
extends CenterContainer
|
||||
|
||||
const InventoryItem = preload("../../player/inventory_item.gd")
|
||||
|
||||
onready var _selected_frame = $HBoxContainer/HotbarSlot/HotbarSlotSelect
|
||||
onready var _slot_container = $HBoxContainer
|
||||
onready var _block_types = get_node("/root/Main/Blocks")
|
||||
onready var _inventory = get_node("../Inventory")
|
||||
|
||||
var _inventory := [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
var _inventory_index := 0
|
||||
var _hotbar_index := 0
|
||||
|
||||
|
||||
func _ready():
|
||||
assert(len(_inventory) == _slot_container.get_child_count())
|
||||
for i in len(_inventory):
|
||||
var block_id = _inventory[i]
|
||||
var slot = _slot_container.get_child(i)
|
||||
slot.set_block_id(block_id)
|
||||
call_deferred("_update_views")
|
||||
|
||||
|
||||
func _update_views():
|
||||
for i in _inventory.get_hotbar_slot_count():
|
||||
var slot_data = _inventory.get_hotbar_slot_data(i)
|
||||
var slot_view = _slot_container.get_child(i)
|
||||
slot_view.get_display().set_item(slot_data)
|
||||
|
||||
|
||||
func select_slot(i: int):
|
||||
if _inventory_index == i:
|
||||
if _hotbar_index == i:
|
||||
return
|
||||
assert(i >= 0 and i < len(_inventory))
|
||||
_inventory_index = i
|
||||
assert(i >= 0 and i < _inventory.get_hotbar_slot_count())
|
||||
_hotbar_index = i
|
||||
|
||||
var block_id = _inventory[_inventory_index]
|
||||
if block_id != -1:
|
||||
var block = _block_types.get_block(block_id)
|
||||
print("Inventory select ", block.base_info.name)
|
||||
var item = _inventory.get_hotbar_slot_data(_hotbar_index)
|
||||
if item != null:
|
||||
if item.type == InventoryItem.TYPE_BLOCK:
|
||||
var block = _block_types.get_block(item.id)
|
||||
print("Hotbar select block ", block.base_info.name)
|
||||
|
||||
elif item.type == InventoryItem.TYPE_ITEM:
|
||||
# TODO Item db
|
||||
print("Hotbar select item ", item.id)
|
||||
|
||||
_selected_frame.get_parent().remove_child(_selected_frame)
|
||||
var slot = _slot_container.get_child(i)
|
||||
slot.add_child(_selected_frame)
|
||||
|
||||
|
||||
func get_selected_block_type() -> int:
|
||||
return _inventory[_inventory_index]
|
||||
func get_selected_item() -> InventoryItem:
|
||||
return _inventory.get_hotbar_slot_data(_hotbar_index)
|
||||
|
||||
|
||||
func try_select_slot_by_block_id(block_id: int):
|
||||
for i in len(_inventory):
|
||||
var id = _inventory[i]
|
||||
if id == block_id:
|
||||
select_slot(i)
|
||||
break
|
||||
for i in _inventory.get_hotbar_slot_count():
|
||||
var item = _inventory.get_hotbar_slot_data(i)
|
||||
if item.type == InventoryItem.TYPE_BLOCK:
|
||||
if item.id == block_id:
|
||||
select_slot(i)
|
||||
break
|
||||
|
||||
|
||||
func select_next_slot():
|
||||
var i = _inventory_index + 1
|
||||
if i >= len(_inventory):
|
||||
var i = _hotbar_index + 1
|
||||
if i >= _inventory.get_hotbar_slot_count():
|
||||
i = 0
|
||||
select_slot(i)
|
||||
|
||||
|
||||
func select_previous_slot():
|
||||
var i = _inventory_index - 1
|
||||
var i = _hotbar_index - 1
|
||||
if i < 0:
|
||||
i = len(_inventory) - 1
|
||||
i = _inventory.get_hotbar_slot_count() - 1
|
||||
select_slot(i)
|
||||
|
||||
|
||||
func _on_Inventory_changed():
|
||||
_update_views()
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
extends Control
|
||||
|
||||
|
||||
onready var _texture_rect = $TextureRect
|
||||
onready var _block_types = get_node("/root/Main/Blocks")
|
||||
onready var _display = $TextureRect
|
||||
|
||||
|
||||
func set_block_id(id: int):
|
||||
if id == -1:
|
||||
_texture_rect.texture = null
|
||||
else:
|
||||
var block = _block_types.get_block(id)
|
||||
_texture_rect.texture = block.base_info.sprite_texture
|
||||
func get_display():
|
||||
return _display
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://blocky_game/blocks/dirt/dirt_sprite.png" type="Texture" id=1]
|
||||
[ext_resource path="res://blocky_game/gui/hotbar/hotbar_slot.gd" type="Script" id=2]
|
||||
[ext_resource path="res://blocky_game/gui/hotbar/hotbar_slot_bg.png" type="Texture" id=3]
|
||||
[ext_resource path="res://blocky_game/gui/inventory_item_display.gd" type="Script" id=4]
|
||||
|
||||
[node name="HotbarSlot" type="Control"]
|
||||
margin_right = 64.0
|
||||
|
@ -32,6 +33,7 @@ margin_bottom = -4.0
|
|||
texture = ExtResource( 1 )
|
||||
expand = true
|
||||
stretch_mode = 1
|
||||
script = ExtResource( 4 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
extends Control
|
||||
|
||||
|
||||
onready var _display = $TextureRect
|
||||
|
||||
|
||||
func _ready():
|
||||
set_process(false)
|
||||
|
||||
|
||||
func start(item_data):
|
||||
_display.set_item(item_data)
|
||||
set_process(true)
|
||||
show()
|
||||
|
||||
|
||||
func stop():
|
||||
set_process(false)
|
||||
hide()
|
||||
|
||||
|
||||
func _process(delta):
|
||||
var mpos = get_parent().get_local_mouse_position()
|
||||
rect_position = mpos - rect_size / 2.0
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
extends Control
|
||||
|
||||
signal changed
|
||||
|
||||
const BAG_WIDTH = 9
|
||||
const BAG_HEIGHT = 3
|
||||
const HOTBAR_HEIGHT = 1
|
||||
|
||||
const InventoryItem = preload("../../player/inventory_item.gd")
|
||||
|
||||
onready var _bag_container = $CC/PC/VB/Bag
|
||||
onready var _hotbar_container = $CC/PC/VB/Hotbar
|
||||
onready var _dragged_item_view = $DraggedItem
|
||||
|
||||
# TODO Is it worth having the hotbar in the first indexes instead of the last ones?
|
||||
var _slots := []
|
||||
var _slot_views := []
|
||||
var _previous_mouse_mode := 0
|
||||
var _dragged_slot := -1
|
||||
|
||||
|
||||
func _ready():
|
||||
_slots.resize(BAG_WIDTH * (BAG_HEIGHT + HOTBAR_HEIGHT))
|
||||
assert(_bag_container.get_child_count() == BAG_WIDTH * BAG_HEIGHT)
|
||||
assert(_hotbar_container.get_child_count() == BAG_WIDTH * HOTBAR_HEIGHT)
|
||||
|
||||
# Initial contents
|
||||
var hotbar_begin_index := BAG_WIDTH * BAG_HEIGHT
|
||||
var hotbar_block_ids := [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
for i in BAG_WIDTH:
|
||||
var item := InventoryItem.new()
|
||||
item.type = InventoryItem.TYPE_BLOCK
|
||||
item.id = hotbar_block_ids[i]
|
||||
_slots[hotbar_begin_index + i] = item
|
||||
|
||||
# Init views
|
||||
var slot_idx := 0
|
||||
_slot_views.resize(len(_slots))
|
||||
for container in [_bag_container, _hotbar_container]:
|
||||
for i in container.get_child_count():
|
||||
var slot = container.get_child(i)
|
||||
slot.get_display().set_item(_slots[slot_idx])
|
||||
slot.connect("pressed", self, "_on_slot_pressed", [slot_idx])
|
||||
_slot_views[slot_idx] = slot
|
||||
slot_idx += 1
|
||||
|
||||
|
||||
func _update_views():
|
||||
var slot_idx := 0
|
||||
for container in [_bag_container, _hotbar_container]:
|
||||
for i in container.get_child_count():
|
||||
var slot = container.get_child(i)
|
||||
slot.get_display().set_item(_slots[slot_idx])
|
||||
slot_idx += 1
|
||||
|
||||
|
||||
func get_hotbar_slot_count() -> int:
|
||||
return BAG_WIDTH
|
||||
|
||||
|
||||
func get_hotbar_slot_data(i) -> InventoryItem:
|
||||
var hotbar_begin_index := BAG_WIDTH * BAG_HEIGHT
|
||||
return _slots[hotbar_begin_index + i]
|
||||
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event is InputEventKey:
|
||||
if event.pressed:
|
||||
if event.scancode == KEY_E:
|
||||
visible = not visible
|
||||
|
||||
|
||||
func _notification(what: int):
|
||||
if what == NOTIFICATION_VISIBILITY_CHANGED:
|
||||
if visible:
|
||||
_update_views()
|
||||
|
||||
_previous_mouse_mode = Input.get_mouse_mode()
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
|
||||
else:
|
||||
if _dragged_slot != -1:
|
||||
# Cancel drag
|
||||
_slot_views[_dragged_slot].get_display().set_item(_slots[_dragged_slot])
|
||||
_dragged_item_view.stop()
|
||||
_dragged_slot = -1
|
||||
_dragged_item_view.stop()
|
||||
|
||||
Input.set_mouse_mode(_previous_mouse_mode)
|
||||
|
||||
|
||||
func _on_slot_pressed(idx: int):
|
||||
if _dragged_slot == -1:
|
||||
if _slots[idx] == null:
|
||||
return
|
||||
# Start drag
|
||||
_dragged_slot = idx
|
||||
_slot_views[_dragged_slot].get_display().set_item(null)
|
||||
_dragged_item_view.start(_slots[idx])
|
||||
|
||||
else:
|
||||
if _slots[idx] == null:
|
||||
# Move
|
||||
_slots[idx] = _slots[_dragged_slot]
|
||||
_slots[_dragged_slot] = null
|
||||
_slot_views[idx].get_display().set_item(_slots[idx])
|
||||
_dragged_item_view.stop()
|
||||
_dragged_slot = -1
|
||||
emit_signal("changed")
|
||||
|
||||
else:
|
||||
if _dragged_slot != idx:
|
||||
# Swap
|
||||
var tmp = _slots[idx]
|
||||
_slots[idx] = _slots[_dragged_slot]
|
||||
_slots[_dragged_slot] = tmp
|
||||
_dragged_item_view.start(tmp)
|
||||
|
||||
else:
|
||||
_dragged_slot = -1
|
||||
_dragged_item_view.stop()
|
||||
|
||||
_slot_views[idx].get_display().set_item(_slots[idx])
|
||||
|
||||
emit_signal("changed")
|
|
@ -0,0 +1,358 @@
|
|||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://blocky_game/gui/inventory/inventory.gd" type="Script" id=1]
|
||||
[ext_resource path="res://blocky_game/gui/inventory/inventory_slot.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://blocky_game/gui/inventory_item_display.gd" type="Script" id=3]
|
||||
[ext_resource path="res://blocky_game/gui/inventory/dragged_item_view.gd" type="Script" id=4]
|
||||
[ext_resource path="res://blocky_game/blocks/dirt/dirt_sprite.png" type="Texture" id=5]
|
||||
|
||||
[node name="Inventory" type="ColorRect"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 4.0
|
||||
margin_top = 4.0
|
||||
margin_right = 4.0
|
||||
margin_bottom = 4.0
|
||||
color = Color( 0, 0, 0, 0.25098 )
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="CC" type="CenterContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="PC" type="PanelContainer" parent="CC"]
|
||||
margin_left = 201.0
|
||||
margin_top = 142.0
|
||||
margin_right = 823.0
|
||||
margin_bottom = 458.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VB" type="VBoxContainer" parent="CC/PC"]
|
||||
margin_left = 7.0
|
||||
margin_top = 7.0
|
||||
margin_right = 615.0
|
||||
margin_bottom = 309.0
|
||||
|
||||
[node name="Label" type="Label" parent="CC/PC/VB"]
|
||||
margin_right = 608.0
|
||||
margin_bottom = 14.0
|
||||
text = "Inventory"
|
||||
|
||||
[node name="HSeparator2" type="HSeparator" parent="CC/PC/VB"]
|
||||
margin_top = 18.0
|
||||
margin_right = 608.0
|
||||
margin_bottom = 22.0
|
||||
|
||||
[node name="Bag" type="GridContainer" parent="CC/PC/VB"]
|
||||
margin_top = 26.0
|
||||
margin_right = 608.0
|
||||
margin_bottom = 226.0
|
||||
columns = 9
|
||||
|
||||
[node name="InventorySlot" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_right = 64.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot2" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 68.0
|
||||
margin_right = 132.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot3" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 136.0
|
||||
margin_right = 200.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot4" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 204.0
|
||||
margin_right = 268.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot5" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 272.0
|
||||
margin_right = 336.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot6" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 340.0
|
||||
margin_right = 404.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot7" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 408.0
|
||||
margin_right = 472.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot8" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 476.0
|
||||
margin_right = 540.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot9" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 544.0
|
||||
margin_right = 608.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot10" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_top = 68.0
|
||||
margin_right = 64.0
|
||||
margin_bottom = 132.0
|
||||
|
||||
[node name="InventorySlot11" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 68.0
|
||||
margin_top = 68.0
|
||||
margin_right = 132.0
|
||||
margin_bottom = 132.0
|
||||
|
||||
[node name="InventorySlot12" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 136.0
|
||||
margin_top = 68.0
|
||||
margin_right = 200.0
|
||||
margin_bottom = 132.0
|
||||
|
||||
[node name="InventorySlot13" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 204.0
|
||||
margin_top = 68.0
|
||||
margin_right = 268.0
|
||||
margin_bottom = 132.0
|
||||
|
||||
[node name="InventorySlot14" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 272.0
|
||||
margin_top = 68.0
|
||||
margin_right = 336.0
|
||||
margin_bottom = 132.0
|
||||
|
||||
[node name="InventorySlot15" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 340.0
|
||||
margin_top = 68.0
|
||||
margin_right = 404.0
|
||||
margin_bottom = 132.0
|
||||
|
||||
[node name="InventorySlot16" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 408.0
|
||||
margin_top = 68.0
|
||||
margin_right = 472.0
|
||||
margin_bottom = 132.0
|
||||
|
||||
[node name="InventorySlot17" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 476.0
|
||||
margin_top = 68.0
|
||||
margin_right = 540.0
|
||||
margin_bottom = 132.0
|
||||
|
||||
[node name="InventorySlot18" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 544.0
|
||||
margin_top = 68.0
|
||||
margin_right = 608.0
|
||||
margin_bottom = 132.0
|
||||
|
||||
[node name="InventorySlot19" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_top = 136.0
|
||||
margin_right = 64.0
|
||||
margin_bottom = 200.0
|
||||
|
||||
[node name="InventorySlot20" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 68.0
|
||||
margin_top = 136.0
|
||||
margin_right = 132.0
|
||||
margin_bottom = 200.0
|
||||
|
||||
[node name="InventorySlot21" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 136.0
|
||||
margin_top = 136.0
|
||||
margin_right = 200.0
|
||||
margin_bottom = 200.0
|
||||
|
||||
[node name="InventorySlot22" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 204.0
|
||||
margin_top = 136.0
|
||||
margin_right = 268.0
|
||||
margin_bottom = 200.0
|
||||
|
||||
[node name="InventorySlot23" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 272.0
|
||||
margin_top = 136.0
|
||||
margin_right = 336.0
|
||||
margin_bottom = 200.0
|
||||
|
||||
[node name="InventorySlot24" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 340.0
|
||||
margin_top = 136.0
|
||||
margin_right = 404.0
|
||||
margin_bottom = 200.0
|
||||
|
||||
[node name="InventorySlot25" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 408.0
|
||||
margin_top = 136.0
|
||||
margin_right = 472.0
|
||||
margin_bottom = 200.0
|
||||
|
||||
[node name="InventorySlot26" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 476.0
|
||||
margin_top = 136.0
|
||||
margin_right = 540.0
|
||||
margin_bottom = 200.0
|
||||
|
||||
[node name="InventorySlot27" parent="CC/PC/VB/Bag" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 544.0
|
||||
margin_top = 136.0
|
||||
margin_right = 608.0
|
||||
margin_bottom = 200.0
|
||||
|
||||
[node name="HSeparator" type="HSeparator" parent="CC/PC/VB"]
|
||||
margin_top = 230.0
|
||||
margin_right = 608.0
|
||||
margin_bottom = 234.0
|
||||
|
||||
[node name="Hotbar" type="HBoxContainer" parent="CC/PC/VB"]
|
||||
margin_top = 238.0
|
||||
margin_right = 608.0
|
||||
margin_bottom = 302.0
|
||||
|
||||
[node name="InventorySlot" parent="CC/PC/VB/Hotbar" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_right = 64.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot2" parent="CC/PC/VB/Hotbar" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 68.0
|
||||
margin_right = 132.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot3" parent="CC/PC/VB/Hotbar" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 136.0
|
||||
margin_right = 200.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot4" parent="CC/PC/VB/Hotbar" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 204.0
|
||||
margin_right = 268.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot5" parent="CC/PC/VB/Hotbar" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 272.0
|
||||
margin_right = 336.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot6" parent="CC/PC/VB/Hotbar" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 340.0
|
||||
margin_right = 404.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot7" parent="CC/PC/VB/Hotbar" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 408.0
|
||||
margin_right = 472.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot8" parent="CC/PC/VB/Hotbar" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 476.0
|
||||
margin_right = 540.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="InventorySlot9" parent="CC/PC/VB/Hotbar" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 544.0
|
||||
margin_right = 608.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="DraggedItem" type="Control" parent="."]
|
||||
margin_left = 51.0
|
||||
margin_top = 47.0
|
||||
margin_right = 107.0
|
||||
margin_bottom = 103.0
|
||||
mouse_filter = 2
|
||||
script = ExtResource( 4 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="DraggedItem"]
|
||||
margin_right = 56.0
|
||||
margin_bottom = 56.0
|
||||
rect_min_size = Vector2( 56, 56 )
|
||||
mouse_filter = 2
|
||||
texture = ExtResource( 5 )
|
||||
expand = true
|
||||
stretch_mode = 1
|
||||
script = ExtResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
extends Control
|
||||
|
||||
signal pressed
|
||||
|
||||
const InventoryItemDisplay = preload("../inventory_item_display.gd")
|
||||
|
||||
onready var _select_bg = $SelectBG
|
||||
onready var _display = $TextureRect
|
||||
|
||||
|
||||
func _gui_input(event):
|
||||
if event is InputEventMouseButton:
|
||||
if event.pressed:
|
||||
emit_signal("pressed")
|
||||
|
||||
|
||||
func _notification(what: int):
|
||||
match what:
|
||||
NOTIFICATION_MOUSE_ENTER:
|
||||
_select_bg.visible = true
|
||||
|
||||
NOTIFICATION_MOUSE_EXIT:
|
||||
_select_bg.visible = false
|
||||
|
||||
NOTIFICATION_VISIBILITY_CHANGED:
|
||||
if not is_visible_in_tree():
|
||||
_select_bg.visible = false
|
||||
|
||||
|
||||
func get_display() -> InventoryItemDisplay:
|
||||
return _display
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://blocky_game/gui/inventory/inventory_slot.gd" type="Script" id=1]
|
||||
[ext_resource path="res://blocky_game/gui/hotbar/hotbar_slot_bg.png" type="Texture" id=2]
|
||||
[ext_resource path="res://blocky_game/blocks/dirt/dirt_sprite.png" type="Texture" id=3]
|
||||
[ext_resource path="res://blocky_game/gui/inventory_item_display.gd" type="Script" id=4]
|
||||
|
||||
[node name="InventorySlot" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_right = -960.0
|
||||
margin_bottom = -536.0
|
||||
rect_min_size = Vector2( 64, 64 )
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="BG" type="TextureRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
texture = ExtResource( 2 )
|
||||
expand = true
|
||||
|
||||
[node name="SelectBG" type="TextureRect" parent="."]
|
||||
visible = false
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
texture = ExtResource( 2 )
|
||||
expand = true
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 4.0
|
||||
margin_top = 4.0
|
||||
margin_right = -4.0
|
||||
margin_bottom = -4.0
|
||||
texture = ExtResource( 3 )
|
||||
expand = true
|
||||
script = ExtResource( 4 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
extends TextureRect
|
||||
|
||||
const InventoryItem = preload("res://blocky_game/player/inventory_item.gd")
|
||||
const DefaultTexture = preload("res://icon.png")
|
||||
const Blocks = preload("../blocks/blocks.gd")
|
||||
|
||||
onready var _block_types : Blocks = get_node("/root/Main/Blocks")
|
||||
|
||||
|
||||
func set_item(data: InventoryItem):
|
||||
if data == null:
|
||||
texture = null
|
||||
|
||||
elif data.type == InventoryItem.TYPE_BLOCK:
|
||||
var block := _block_types.get_block(data.id)
|
||||
texture = block.base_info.sprite_texture
|
||||
|
||||
elif data.type == InventoryItem.TYPE_ITEM:
|
||||
# TODO Items db
|
||||
texture = DefaultTexture
|
||||
|
||||
else:
|
||||
assert(false)
|
|
@ -2,6 +2,7 @@ extends Node
|
|||
|
||||
const Util = preload("res://common/util.gd")
|
||||
const Blocks = preload("../blocks/blocks.gd")
|
||||
const InventoryItem = preload("./inventory_item.gd")
|
||||
|
||||
const COLLISION_LAYER_AVATAR = 2
|
||||
|
||||
|
@ -88,9 +89,9 @@ func _physics_process(delta):
|
|||
if has_cube == false:
|
||||
pos = hit.position
|
||||
if _can_place_voxel_at(pos):
|
||||
var block_id = _hotbar.get_selected_block_type()
|
||||
if block_id != -1:
|
||||
_place_single_block(pos, block_id)
|
||||
var item = _hotbar.get_selected_item()
|
||||
if item != null and item.type == InventoryItem.TYPE_BLOCK:
|
||||
_place_single_block(pos, item.id)
|
||||
print("Place voxel at ", pos)
|
||||
else:
|
||||
print("Can't place here!")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=8 format=2]
|
||||
[gd_scene load_steps=9 format=2]
|
||||
|
||||
[ext_resource path="res://blocky_game/player/character_controller.gd" type="Script" id=1]
|
||||
[ext_resource path="res://blocky_game/player/avatar_camera.gd" type="Script" id=2]
|
||||
|
@ -6,11 +6,9 @@
|
|||
[ext_resource path="res://blocky_terrain/crosshair.png" type="Texture" id=4]
|
||||
[ext_resource path="res://blocky_terrain/center.gd" type="Script" id=5]
|
||||
[ext_resource path="res://blocky_game/gui/hotbar/hotbar.tscn" type="PackedScene" id=6]
|
||||
[ext_resource path="res://blocky_game/gui/inventory/inventory.tscn" type="PackedScene" id=7]
|
||||
|
||||
|
||||
|
||||
|
||||
[sub_resource type="CubeMesh" id=2]
|
||||
[sub_resource type="CubeMesh" id=1]
|
||||
size = Vector3( 0.8, 1.8, 0.8 )
|
||||
|
||||
[node name="CharacterAvatar" type="Spatial"]
|
||||
|
@ -24,7 +22,6 @@ near = 0.1
|
|||
far = 500.0
|
||||
script = ExtResource( 2 )
|
||||
sensitivity = 0.3
|
||||
distance = 0.0
|
||||
|
||||
[node name="Interaction" type="Node" parent="."]
|
||||
script = ExtResource( 3 )
|
||||
|
@ -43,7 +40,7 @@ omni_range = 10.0
|
|||
omni_attenuation = 2.54912
|
||||
|
||||
[node name="MeshInstance" type="MeshInstance" parent="."]
|
||||
mesh = SubResource( 2 )
|
||||
mesh = SubResource( 1 )
|
||||
material/0 = null
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="."]
|
||||
|
@ -63,3 +60,8 @@ mouse_filter = 2
|
|||
texture = ExtResource( 4 )
|
||||
|
||||
[node name="HotBar" parent="." instance=ExtResource( 6 )]
|
||||
|
||||
[node name="Inventory" parent="." instance=ExtResource( 7 )]
|
||||
visible = false
|
||||
color = Color( 0, 0, 0, 0.501961 )
|
||||
[connection signal="changed" from="Inventory" to="HotBar" method="_on_Inventory_changed"]
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
const TYPE_BLOCK = 0
|
||||
const TYPE_ITEM = 1
|
||||
|
||||
var type := TYPE_BLOCK
|
||||
var id := 0
|
||||
#var count := 0
|
||||
|
||||
# TODO Can't type hint self
|
||||
func duplicate():
|
||||
var d = get_script().new()
|
||||
d.type = type
|
||||
d.id = id
|
||||
return d
|
||||
|
Loading…
Reference in New Issue