From ea654acf7f2f35d3de0dff7aa85b5ba4b4b87107 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 29 Nov 2019 10:18:17 +0100 Subject: [PATCH] Item count support for the ui. --- HEADS | 2 +- game/ui/bags/BagEntry.gd | 32 +++++++++++++++++++++++++++++++- game/ui/bags/BagEntry.tscn | 24 ++++++++++++++++++++++++ game/ui/bags/InventoryGUI.gd | 1 + 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/HEADS b/HEADS index 80fc24fd..f57add02 100644 --- a/HEADS +++ b/HEADS @@ -1 +1 @@ -{"engine": "7735af7e768e16efb4b3b6de1c72c3dfb50c9412", "world_generator": "290d973ea9580f748881a54502850ae5fecfb586", "entity_spell_system": "2ba11eec7742295a40146da898ebe02ac4aa5a12", "ui_extensions": "271dcf89e9afe5cb6350de2f2433c8ebf8aba785", "voxelman": "2b369f5be8efc5fe0ef13da57afa46317c413f47", "texture_packer": "604c330188e220c15d10ea5bd545a6fc5aab0132", "fastnoise": "41b7ea05a1f7aa2b8ecddaa1fd739e64d6970f7e", "entity-spell-system-addons": "8568888b3c11dec56dbf1088a84bc898d68bd6ce"} \ No newline at end of file +{"engine": "f82539944b609dc8327536aa92a3da3851ac1338", "world_generator": "290d973ea9580f748881a54502850ae5fecfb586", "entity_spell_system": "992d0672f9b143fc0b3996e798dcf9aa7e064a92", "ui_extensions": "271dcf89e9afe5cb6350de2f2433c8ebf8aba785", "voxelman": "2b369f5be8efc5fe0ef13da57afa46317c413f47", "texture_packer": "604c330188e220c15d10ea5bd545a6fc5aab0132", "fastnoise": "41b7ea05a1f7aa2b8ecddaa1fd739e64d6970f7e", "entity-spell-system-addons": "8568888b3c11dec56dbf1088a84bc898d68bd6ce"} \ No newline at end of file diff --git a/game/ui/bags/BagEntry.gd b/game/ui/bags/BagEntry.gd index e7eaecc2..c5b4364c 100644 --- a/game/ui/bags/BagEntry.gd +++ b/game/ui/bags/BagEntry.gd @@ -6,9 +6,13 @@ extends Button export (NodePath) var button_path : NodePath export (NodePath) var icon_path : NodePath + export (NodePath) var cooldown_indicator_path : NodePath export (NodePath) var cooldown_text_path : NodePath +export (NodePath) var stack_counter : NodePath +var _stack_counter : Label + var _tooltip : Popup var button : Button @@ -35,7 +39,13 @@ func _ready() -> void: cooldown_indicator = get_node(cooldown_indicator_path) as TextureProgress cooldown_text = get_node(cooldown_text_path) as Label + _stack_counter = get_node(stack_counter) as Label + button.connect("pressed", self, "_on_button_pressed") + +#func _exit_tree(): +# if item != null: +# item.disconnect("stack_size_changed", self, "stack_size_changed") func _process(delta : float) -> void: if cd == null and gcd < 0.001: @@ -75,10 +85,19 @@ func hide_cooldown_timer() -> void: cooldown_text.hide() func set_item_instance(pitem : ItemInstance) -> void: + if item != null and item.item_template.stack_size > 1: + item.disconnect("stack_size_changed", self, "stack_size_changed") + _stack_counter.hide() + item = pitem setup_icon() + if item != null and item.item_template.stack_size > 1: + item.connect("stack_size_changed", self, "stack_size_changed") + _stack_counter.show() + stack_size_changed(item) + func setup_icon() -> void: if (item == null): icon_rect.texture = null @@ -105,11 +124,22 @@ func _on_button_pressed() -> void: pass func set_button_entry_data(ii : ItemInstance) -> void: + if item != null and item.item_template.stack_size > 1: + item.disconnect("stack_size_changed", self, "stack_size_changed") + _stack_counter.hide() item = ii - + setup_icon() + if item != null and item.item_template.stack_size > 1: + item.connect("stack_size_changed", self, "stack_size_changed") + _stack_counter.show() + stack_size_changed(item) + +func stack_size_changed(ii : ItemInstance) -> void: + _stack_counter.text = str(ii.stack_size) + func get_drag_data(pos: Vector2) -> Object: if item == null: return null diff --git a/game/ui/bags/BagEntry.tscn b/game/ui/bags/BagEntry.tscn index 7e7f2c6c..bd0587b5 100644 --- a/game/ui/bags/BagEntry.tscn +++ b/game/ui/bags/BagEntry.tscn @@ -27,6 +27,7 @@ button_path = NodePath(".") icon_path = NodePath("MarginContainer/TextureRect") cooldown_indicator_path = NodePath("CooldownIndicator") cooldown_text_path = NodePath("CooldownText") +stack_counter = NodePath("MarginContainer2/StackCounter") [node name="MarginContainer" type="MarginContainer" parent="."] anchor_right = 1.0 @@ -78,3 +79,26 @@ clip_text = true __meta__ = { "_edit_use_anchors_": false } + +[node name="MarginContainer2" type="MarginContainer" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +custom_constants/margin_right = 4 +custom_constants/margin_top = 4 +custom_constants/margin_left = 4 +custom_constants/margin_bottom = 3 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="StackCounter" type="Label" parent="MarginContainer2"] +visible = false +margin_left = 4.0 +margin_top = 4.0 +margin_right = 41.0 +margin_bottom = 42.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +align = 2 +valign = 2 diff --git a/game/ui/bags/InventoryGUI.gd b/game/ui/bags/InventoryGUI.gd index 35ebef95..b0a24d5d 100644 --- a/game/ui/bags/InventoryGUI.gd +++ b/game/ui/bags/InventoryGUI.gd @@ -73,6 +73,7 @@ func cbag_changed(entity: Entity, bag: Bag) -> void: if _bag != null: _bag.disconnect("size_changed", self, "bag_size_changed") _bag.disconnect("item_added", self, "bag_item_added") + _bag.disconnect("item_count_changed", self, "item_count_changed") _bag.disconnect("item_removed", self, "item_removed") _bag.disconnect("item_swapped", self, "item_swapped")