diff --git a/UI/CardContainer.gd b/UI/CardContainer.gd deleted file mode 100644 index 17f1770..0000000 --- a/UI/CardContainer.gd +++ /dev/null @@ -1,37 +0,0 @@ -extends Control - -signal scene_finished -signal scene_failed - -var active : bool = false - -const card_view_scene = preload("res://UI/CardView.tscn") - -var character : Character = Character.new() setget update_cards_shown -var card_views = [] - - -func update_cards_shown(new_character = null): - - # allow the update card shown function to work with and without setget - if new_character != null: - character = new_character - - # remove the old cards - for card_view in card_views: - yield(card_view.card_view_remove(false), "completed") - card_views = [] - - # add cards the new cards from the character - for card in character.cards: - var new_card_view = card_view_scene.instance() - new_card_view.card = card - $Margin/HBox.add_child(new_card_view) - card_views.append(new_card_view) - new_card_view.connect("card_view_removed", self, "remove_from_card_views") - - -func remove_from_card_views(card_view): - var to_remove : int = card_views.find(card_view) - if to_remove != -1: - card_views.remove(to_remove) diff --git a/UI/CardContainer.tscn b/UI/CardContainer.tscn index e117466..2cb4d3a 100644 --- a/UI/CardContainer.tscn +++ b/UI/CardContainer.tscn @@ -1,11 +1,16 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] -[ext_resource path="res://UI/CardContainer.gd" type="Script" id=5] +[ext_resource path="res://UI/CardView.tscn" type="PackedScene" id=1] +[ext_resource path="res://UI/ItemContainer.gd" type="Script" id=2] [node name="CardContainer" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 -script = ExtResource( 5 ) +script = ExtResource( 2 ) +item_view_scene = ExtResource( 1 ) +child_holder = NodePath("Margin/HBox") +character_property = "cards" +view_property = "card" [node name="Margin" type="MarginContainer" parent="."] anchor_right = 1.0 diff --git a/UI/ItemContainer.gd b/UI/ItemContainer.gd new file mode 100644 index 0000000..9128dff --- /dev/null +++ b/UI/ItemContainer.gd @@ -0,0 +1,40 @@ +extends Control + +signal scene_finished +signal scene_failed + +var active : bool = false + +export (PackedScene) var item_view_scene +export (NodePath) var child_holder +export (String) var character_property = "items" +export (String) var view_property = "item" + +var character : Character = Character.new() setget update_items_shown +var item_views = [] + + +func update_items_shown(new_character = null): + + # allow the update item shown function to work with and without setget + if new_character != null: + character = new_character + + # remove the old items + for item_view in item_views: + yield(item_view.item_view_remove(false), "completed") + item_views = [] + + # add items the new items from the character + for item in character.get(character_property): + var new_item_view = item_view_scene.instance() + new_item_view.set(view_property, item) + get_node(child_holder).add_child(new_item_view) + item_views.append(new_item_view) + new_item_view.connect("item_view_removed", self, "remove_from_item_views") + + +func remove_from_item_views(item_view): + var to_remove : int = item_views.find(item_view) + if to_remove != -1: + item_views.remove(to_remove)