UI shows pew count.
This commit is contained in:
parent
41fc5de4d3
commit
023e749833
|
|
@ -6,6 +6,7 @@ extends Interactable
|
||||||
# var a = 2
|
# var a = 2
|
||||||
# var b = "text"
|
# var b = "text"
|
||||||
export var item :Resource
|
export var item :Resource
|
||||||
|
export var count :int = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,8 @@ func touch_the_thing(the_thing: Interactable) -> bool:
|
||||||
movement_state_machine.change_to_known_state('enter_right')
|
movement_state_machine.change_to_known_state('enter_right')
|
||||||
the_thing.trigger_interaction()
|
the_thing.trigger_interaction()
|
||||||
if the_thing is ItemPickup:
|
if the_thing is ItemPickup:
|
||||||
player_inventory.add_to_inventory(the_thing.item)
|
player_inventory.add_to_inventory(the_thing.item, the_thing.count)
|
||||||
player_inventory.select_secondary(the_thing.item)
|
#player_inventory.select_secondary(the_thing.item)
|
||||||
the_thing.trigger_interaction()
|
the_thing.trigger_interaction()
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,14 +87,17 @@ func select_secondary(_item :Item) -> void:
|
||||||
if _items.has(_item):
|
if _items.has(_item):
|
||||||
secondary_selection = _item
|
secondary_selection = _item
|
||||||
|
|
||||||
func add_to_inventory(_item :Item) -> int:
|
func add_to_inventory(_item :Item, _count :int = 1) -> int:
|
||||||
if _items.has(_item):
|
if _items.has(_item):
|
||||||
_items[_item] += 1
|
_items[_item] += _count
|
||||||
else:
|
else:
|
||||||
_items[_item] = 1
|
_items[_item] = _count
|
||||||
|
if primary_selection == null:
|
||||||
|
primary_selection = _item
|
||||||
|
elif secondary_selection == null:
|
||||||
|
secondary_selection = _item
|
||||||
return _items[_item]
|
return _items[_item]
|
||||||
|
|
||||||
|
|
||||||
func remove_from_inventory (_item :Item) -> int:
|
func remove_from_inventory (_item :Item) -> int:
|
||||||
if _items.has(_item):
|
if _items.has(_item):
|
||||||
if _item.consumable:
|
if _item.consumable:
|
||||||
|
|
@ -115,6 +118,10 @@ func remove_from_inventory (_item :Item) -> int:
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
func get_item_inventory_count(_item :Item) -> int:
|
||||||
|
if _items.has(_item):
|
||||||
|
return _items[_item]
|
||||||
|
return 0
|
||||||
|
|
||||||
func clear_item_from_inventory (_item :Item) -> void:
|
func clear_item_from_inventory (_item :Item) -> void:
|
||||||
if _items.has(_item):
|
if _items.has(_item):
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,7 @@ tile_data = PoolIntArray( -65536, 0, 0, -65521, 0, 0, 65535, 0, 0, 16, 0, 0, 524
|
||||||
position = Vector2( 203, 38 )
|
position = Vector2( 203, 38 )
|
||||||
type_name = "item_pickup"
|
type_name = "item_pickup"
|
||||||
item = ExtResource( 8 )
|
item = ExtResource( 8 )
|
||||||
|
count = 10
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="ItemPickup" index="0"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="ItemPickup" index="0"]
|
||||||
shape = SubResource( 6 )
|
shape = SubResource( 6 )
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,21 @@ script = ExtResource( 8 )
|
||||||
[node name="PrimaryItem" type="TextureRect" parent="SelectedInventoryItems"]
|
[node name="PrimaryItem" type="TextureRect" parent="SelectedInventoryItems"]
|
||||||
margin_bottom = 16.0
|
margin_bottom = 16.0
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="SelectedInventoryItems/PrimaryItem"]
|
||||||
|
margin_right = 20.0
|
||||||
|
margin_bottom = 10.0
|
||||||
|
custom_fonts/font = ExtResource( 2 )
|
||||||
|
align = 2
|
||||||
|
valign = 2
|
||||||
|
|
||||||
[node name="SecondaryItem" type="TextureRect" parent="SelectedInventoryItems"]
|
[node name="SecondaryItem" type="TextureRect" parent="SelectedInventoryItems"]
|
||||||
margin_left = 4.0
|
margin_left = 4.0
|
||||||
margin_right = 4.0
|
margin_right = 4.0
|
||||||
margin_bottom = 16.0
|
margin_bottom = 16.0
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="SelectedInventoryItems/SecondaryItem"]
|
||||||
|
margin_right = 20.0
|
||||||
|
margin_bottom = 10.0
|
||||||
|
custom_fonts/font = ExtResource( 2 )
|
||||||
|
align = 2
|
||||||
|
valign = 2
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ extends HBoxContainer
|
||||||
onready var primary_item = $PrimaryItem
|
onready var primary_item = $PrimaryItem
|
||||||
onready var secondary_item = $SecondaryItem
|
onready var secondary_item = $SecondaryItem
|
||||||
|
|
||||||
|
onready var _primary_item_count = $PrimaryItem/Label
|
||||||
|
onready var _secondary_item_count = $SecondaryItem/Label
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
|
|
@ -16,10 +18,22 @@ func _ready():
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
if (PlayerInfo.player_inventory.primary_selection):
|
if (PlayerInfo.player_inventory.primary_selection):
|
||||||
primary_item.texture = PlayerInfo.player_inventory.primary_selection.inventory_icon
|
primary_item.texture = PlayerInfo.player_inventory.primary_selection.inventory_icon
|
||||||
|
var count = PlayerInfo.player_inventory.get_item_inventory_count(PlayerInfo.player_inventory.primary_selection)
|
||||||
|
if count > 1:
|
||||||
|
_primary_item_count.text = str(count)
|
||||||
|
else:
|
||||||
|
_primary_item_count.text = ''
|
||||||
else:
|
else:
|
||||||
primary_item.texture = null
|
primary_item.texture = null
|
||||||
|
_primary_item_count.text = ''
|
||||||
|
|
||||||
if (PlayerInfo.player_inventory.secondary_selection):
|
if (PlayerInfo.player_inventory.secondary_selection):
|
||||||
secondary_item.texture = PlayerInfo.player_inventory.secondary_selection.inventory_icon
|
secondary_item.texture = PlayerInfo.player_inventory.secondary_selection.inventory_icon
|
||||||
|
var count = PlayerInfo.player_inventory.get_item_inventory_count(PlayerInfo.player_inventory.secondary_selection)
|
||||||
|
if count > 1:
|
||||||
|
_secondary_item_count.text = str(count)
|
||||||
|
else:
|
||||||
|
_secondary_item_count.text = ''
|
||||||
else:
|
else:
|
||||||
secondary_item.texture = null
|
secondary_item.texture = null
|
||||||
|
_secondary_item_count.text = ''
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user