69 lines
3.6 KiB
GDScript
69 lines
3.6 KiB
GDScript
extends Control
|
|
|
|
@export var selected: int = 3
|
|
|
|
# variables for nodes
|
|
@onready var choice: OptionButton = $Choice
|
|
@onready var slogan_text: RichTextLabel = $Slogan_border/Slogan_text
|
|
@onready var motivation_text: RichTextLabel = $Motivation_border/Motivation_text
|
|
@onready var goal_text: RichTextLabel = $Goal_border/Goal_text
|
|
@onready var fear_text: RichTextLabel = $Fear_border/Fear_text
|
|
@onready var strategy_text: RichTextLabel = $Strategy_border/Strategy_text
|
|
@onready var weakness_text: RichTextLabel = $Weakness_border/Weakness_text
|
|
@onready var problem_handling_text: RichTextLabel = $Problem_handling_border/Problem_handling_text
|
|
|
|
# A dict to connect names and content
|
|
var resources: Dictionary = {}
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
load_resources()
|
|
|
|
# Build the Choice
|
|
for resource_idx in resources:
|
|
# Build the Choice OptionButton text display and connect the proper resource as metadata
|
|
choice.add_item(resources[resource_idx].name)
|
|
choice.set_item_metadata(choice.item_count - 1, resource_idx)
|
|
|
|
# Select the chosen one
|
|
choice.select(selected)
|
|
on_item_selected(selected)
|
|
|
|
# Connect the "item_selected" signal of Choice
|
|
choice.item_selected.connect(on_item_selected)
|
|
|
|
func load_resources() -> void:
|
|
# Add resources in the dict (key = name, value = path)
|
|
resources["creator"] = load("res://resources/psychotype/creator.tres")
|
|
resources["explorer"] = load("res://resources/psychotype/explorer.tres")
|
|
resources["guardian_angel"] = load("res://resources/psychotype/guardian_angel.tres")
|
|
resources["heros"] = load("res://resources/psychotype/heros.tres")
|
|
resources["innocent"] = load("res://resources/psychotype/innocent.tres")
|
|
resources["leader"] = load("res://resources/psychotype/leader.tres")
|
|
resources["lover"]= load("res://resources/psychotype/lover.tres")
|
|
resources["mad"] = load("res://resources/psychotype/mad.tres")
|
|
resources["magician"] = load("res://resources/psychotype/magician.tres")
|
|
resources["ordinary"] = load("res://resources/psychotype/ordinary.tres")
|
|
resources["rebel"] = load("res://resources/psychotype/rebel.tres")
|
|
resources["wise"] = load("res://resources/psychotype/wise.tres")
|
|
|
|
func on_item_selected(index: int) -> void:
|
|
# When a Choice is made, get the associate resource saved in metadata and display corresponding text
|
|
var resource:String = choice.get_item_metadata(index)
|
|
if resource:
|
|
# Show desired element(s) of the resource in labels
|
|
slogan_text.text = resources[resource].get("slogan") if "slogan" in resources[resource] else "Aucune description."
|
|
motivation_text.text = resources[resource].get("motivation") if "motivation" in resources[resource] else "Aucune description."
|
|
goal_text.text = resources[resource].get("goal") if "goal" in resources[resource] else "Aucune description."
|
|
fear_text.text = resources[resource].get("fear") if "fear" in resources[resource] else "Aucune description."
|
|
strategy_text.text = resources[resource].get("strategy") if "strategy" in resources[resource] else "Aucune description."
|
|
weakness_text.text = resources[resource].get("weakness") if "weakness" in resources[resource] else "Aucune description."
|
|
problem_handling_text.text = resources[resource].get("problem_handling") if "problem_handling" in resources[resource] else "Aucune description."
|
|
else:
|
|
slogan_text.text = "Ressource introuvable"
|
|
motivation_text.tex = "Ressource introuvable"
|
|
goal_text.text = "Ressource introuvable"
|
|
fear_text.text = "Ressource introuvable"
|
|
strategy_text.text = "Ressource introuvable"
|
|
weakness_text.text = "Ressource introuvable"
|
|
problem_handling_text.text = "Ressource introuvable"
|