From 3f817ae4b508a42f190b388fad086d90169a7959 Mon Sep 17 00:00:00 2001 From: Yann Kervran Date: Thu, 28 Nov 2024 18:06:02 +0100 Subject: [PATCH] Adding pins for each element --- main.gd | 2 +- main.tscn | 3 + textures/arrowDown.png | Bin 0 -> 15114 bytes textures/arrowDown.png.import | 34 +++++++++ textures/arrowUp.png | Bin 0 -> 15072 bytes textures/arrowUp.png.import | 34 +++++++++ traits.gd | 136 ++++++++++++++++++++++++++-------- traits.tscn | 39 +++++++++- 8 files changed, 211 insertions(+), 37 deletions(-) create mode 100644 textures/arrowDown.png create mode 100644 textures/arrowDown.png.import create mode 100644 textures/arrowUp.png create mode 100644 textures/arrowUp.png.import diff --git a/main.gd b/main.gd index f4a99b7..f7a83f8 100644 --- a/main.gd +++ b/main.gd @@ -72,7 +72,7 @@ func lets_roll(chosen_seed: int, noise: bool = 1) -> void: # Randomize trait if not keep_traits.button_pressed: - traits.populate() + traits.build_traits() func update_language(new_language: String) -> void: # Change the localisation on Translation Server diff --git a/main.tscn b/main.tscn index 893a430..c173c1d 100644 --- a/main.tscn +++ b/main.tscn @@ -250,6 +250,9 @@ offset_left = -16.512 offset_top = 128.088 offset_right = -15.616 offset_bottom = 112.232 +traits = ["Courage", "Passion", "Creativity", "Temperance", "Sensuality", "Energy", "Responsibility", "Empathy", "Self-esteem", "Flexibility", "Hope", "Will"] +seed = 0 +amount = 3 [node name="Traits_label" type="Label" parent="Traits"] layout_mode = 1 diff --git a/textures/arrowDown.png b/textures/arrowDown.png new file mode 100644 index 0000000000000000000000000000000000000000..b2ee82d49d74af1ec6fe9418227ab4c38699790b GIT binary patch literal 15114 zcmeI3UyKt)9LI+s<~Svse?S6J*AfzpwEO4!=elW&z4pqTSh(CBxx;8=Z+F^TuHCJ> zTiUyjh^Ps87?eOF2LD8TP##QBqlqMkq7o7lG(M0(K%clEnm~9#5*25={WJZ?oC%M! z$+f?m`ToAM^O@gF_ht7EZrZSh>pB803>yZ?F9D0h`98v=iT3^gb@+7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owDown.png.import b/textures/arrowDown.png.import new file mode 100644 index 0000000..702b109 --- /dev/null +++ b/textures/arrowDown.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cafw5ytvxgep4" +path="res://.godot/imported/arrowDown.png-ab79ddb99d5bc29b618e06ce2bcf2e97.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://textures/arrowDown.png" +dest_files=["res://.godot/imported/arrowDown.png-ab79ddb99d5bc29b618e06ce2bcf2e97.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/textures/arrowUp.png b/textures/arrowUp.png new file mode 100644 index 0000000000000000000000000000000000000000..3fd9b93e70f4d6a4a1c489be5a0468ea3cdd137e GIT binary patch literal 15072 zcmeI3TZ|J`7{?Ey1QroiOuR)hbi)SFb}risolLuQ+bz3h3!9~cU1I{XGpD=bwlj5R zO1m3lPz=#02x5Y$FUIJT5Pi`I2_{CvgCuxKG)Rouh(TlG1$~g1tY>C=IlXb#gvZlO z+i%bLfB!S*cfNBvFZ0s)?p^D89_j%AtQ#FkO`vbVd9PlDJ~s`%_#XONQyiJH09d=x zd9MJcUw;6A=t(U*X-{UxM8zlsWYw64fl8r>)Bs3>m7=W7L7SO|GnyXr{dVqxkI~ea zZ+|GmWr|5StBov}aPPwItg#d}aB znQBg)NTsX8q5opOS=%m(EL$#@1Lc8$Va~98G#X_&ffWQlQuwWT-IgnU-Rkp9YCb7w zDW+DmHA80{UwPUn*)gBb8L0lM&Z|(Y52RaFc8DTdk&7%J;Mgunnar)z3WbiDmOTL* zGwV2@m7Om_b^=;P$y6Yc_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git a/textures/arrowUp.png.import b/textures/arrowUp.png.import new file mode 100644 index 0000000..034c0a2 --- /dev/null +++ b/textures/arrowUp.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cfrj22ncm1tiq" +path="res://.godot/imported/arrowUp.png-b09ed087648058278d5b46b9c01afa74.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://textures/arrowUp.png" +dest_files=["res://.godot/imported/arrowUp.png-b09ed087648058278d5b46b9c01afa74.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/traits.gd b/traits.gd index ccc3e33..b162584 100644 --- a/traits.gd +++ b/traits.gd @@ -3,29 +3,117 @@ extends Control @export var traits:Array = [ "Courage", "Passion", - "Créativité", - "Tempérance", - "Sensualité", - "Énergie", - "Responsabilité", - "Empathie", - "Estime de soi", - "Flexibilité", - "Espoir", - "Volonté" + "Creativity", + "Temperance", + "Sensuality", + "Energy", + "Responsibility", + "Empathy", + "Self-esteem", + "Flexibility", + "Hope", + "Will" ] -@export var amount: int = 3 @export var seed: int = 0 +@export var amount: int = 3 +var pin_items: Array = [] # variables for nodes -@onready var traits_list: ItemList = $Trait +@onready var traits_list: VBoxContainer = $Traits_list + +# Variable for icons +@onready var icon_up: Texture2D = load("res://textures/arrowUp.png") +@onready var icon_down: Texture2D = load("res://textures/arrowDown.png") # Called when the node enters the scene tree for the first time. func _ready() -> void: - populate() + build_traits() + +func build_traits() -> void: + # Build the traits list with checkboxes to pin any + var list_amount: int = amount + var pinned: Array = [] + + # First, clear the box for non-pinned traits + for child in traits_list.get_children(): + for sub_child in child.get_children(): + if sub_child is CheckBox: + if sub_child.button_pressed: + list_amount -= 1 + pinned.append([child.get_index(), child]) + + for child in traits_list.get_children(): + for sub_child in child.get_children(): + if sub_child is CheckBox: + if sub_child.button_pressed: + traits_list.remove_child(child) + else: + child.queue_free() + + + # generate the amount of traits needed + var char_traits: Dictionary = generate_traits(traits, seed, list_amount) + var char_traits_list: Array = [] + + for key in char_traits.keys(): + char_traits_list.append([key, char_traits[key][0], char_traits[key][1]]) + + for pin in pinned: + char_traits_list.insert(pin[0], pin[1]) + + # Generate a line for each trait + for traitline in range(amount): + print("At index: ", traitline, " found: ", char_traits_list[traitline]) + if char_traits_list[traitline] is HBoxContainer: + print("Je confirme") + print("Parent: ", char_traits_list[traitline].get_parent()) + traits_list.add_child(char_traits_list[traitline]) + #char_traits_list[traitline].reparent(traits_list) + else: + # Create horizontal container for elements + var container = HBoxContainer.new() + + # Checkbox to pin or not + var checkbox: CheckBox = CheckBox.new() + var checkbox_index: int = pin_items.size() + checkbox.text = "" # No text + checkbox.tooltip_text = "PIN" + checkbox.toggled.connect(Callable(self, "_on_checkbox_toggled").bind(checkbox_index)) + + # Label for trait name + var label: Label = Label.new() + label.text = char_traits_list[traitline][0] + + # Icon for up or down + var icon: Texture2D = icon_down + var icon_rect: TextureRect = TextureRect.new() + icon_rect.texture = icon_down + var value: bool = char_traits_list[traitline][1] + if value: + icon_rect.texture = icon_up + + # Add the elements to the horizontal container + container.add_child(checkbox) + container.add_child(label) + container.add_child(icon_rect) + + # Add the container + traits_list.add_child(container) + + # Stock checkbox reference + pin_items.append(checkbox) + + +func _on_checkbox_toggled(checked: bool, checkbox: int) -> void: + # Manage checkbox signal + pass + func generate_traits(traits_list: Array = traits, chosen_seed: int = 0, chosen_amount: int = 3) -> Dictionary: - # Return a dictionary, with trait as key and boolean as value + # Return a dictionary, + # with trait as key and + # an array with index as first value and boolean as second value + # Inputs: # chosen_seed for random seed # chosen_amount for the amount of traits to return var picked_traits: Dictionary = {} @@ -43,26 +131,10 @@ func generate_traits(traits_list: Array = traits, chosen_seed: int = 0, chosen_a random_value.randomize() var value: bool = random_value.randi_range(0, 1) - # Add the key and value to the array - picked_traits[traits_duplicate[result]] = value + # Add the key and array value to the array + picked_traits[traits_duplicate[result]] = [select, value] # Delete the chosen trait from the possible list traits_duplicate.pop_at(result) return picked_traits - -func populate(traits: Array = traits, seed: int = 0, amount: int = 3) -> void: - # To create an itemlist with traits and values - - traits_list.clear() - - var char_traits: Dictionary = generate_traits(traits, seed, amount) - - for char_trait in char_traits: - var value: String = "" - if char_traits[char_trait]: - value = "↑" - else: - value = "↓" - var full_line: String = char_trait + " " + value - traits_list.add_item(full_line) diff --git a/traits.tscn b/traits.tscn index 913e1f9..a976511 100644 --- a/traits.tscn +++ b/traits.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=3 uid="uid://cl5wswke7jxpi"] +[gd_scene load_steps=3 format=3 uid="uid://cl5wswke7jxpi"] [ext_resource type="Script" path="res://traits.gd" id="1_6h04s"] +[ext_resource type="Texture2D" uid="uid://cafw5ytvxgep4" path="res://textures/arrowDown.png" id="2_iexdr"] [node name="Traits" type="Control"] layout_mode = 3 @@ -13,7 +14,37 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_6h04s") -[node name="Trait" type="ItemList" parent="."] +[node name="Traits_list" type="VBoxContainer" parent="."] layout_mode = 0 -offset_right = 224.0 -offset_bottom = 96.0 +offset_right = 232.0 +offset_bottom = 119.0 + +[node name="HBoxContainer" type="HBoxContainer" parent="Traits_list"] +layout_mode = 2 + +[node name="CheckBox" type="CheckBox" parent="Traits_list/HBoxContainer"] +layout_mode = 2 + +[node name="Label" type="Label" parent="Traits_list/HBoxContainer"] +layout_mode = 2 +text = "My text" + +[node name="TextureRect" type="TextureRect" parent="Traits_list/HBoxContainer"] +layout_mode = 2 +texture = ExtResource("2_iexdr") +expand_mode = 3 + +[node name="HBoxContainer2" type="HBoxContainer" parent="Traits_list"] +layout_mode = 2 + +[node name="CheckBox" type="CheckBox" parent="Traits_list/HBoxContainer2"] +layout_mode = 2 + +[node name="Label" type="Label" parent="Traits_list/HBoxContainer2"] +layout_mode = 2 +text = "My text" + +[node name="TextureRect" type="TextureRect" parent="Traits_list/HBoxContainer2"] +layout_mode = 2 +texture = ExtResource("2_iexdr") +expand_mode = 3