allow setting text based on game choices

This commit is contained in:
Arnaud Vergnet 2021-04-26 11:07:38 +02:00
parent b1c6237824
commit 775ef72160
9 changed files with 168 additions and 66 deletions

View file

@ -1,14 +1,16 @@
extends Control
export(String) var choice_name = ""
export(String) var dilemma_name = ""
export(String) var dilemma_description = ""
export(float) var deferred_show = 0
export(Array, String) var choices_names = []
export(Array, String, MULTILINE) var choices_descriptions = []
var choice : int = 0 setget set_choice
onready var tween = $Tween
onready var hover_control = $HoverControl
onready var timer = $Timer
onready var container = $VBoxContainer
onready var choice_label = $VBoxContainer/ChoiceLabel
onready var dilemma_label = $VBoxContainer/DilemmaLabel
@ -17,30 +19,36 @@ onready var texture = $VBoxContainer/TextureRect
func _ready():
container.hide()
choice_label.text = choice_name
dilemma_label.text = dilemma_name
choice_label.text = ""
hover_control.selection_object = texture
hover_control.infobox_position = "top"
hover_control.info_panel.title = dilemma_name
hover_control.info_panel.content = dilemma_description
tween.interpolate_property(container, "rect_scale", Vector2(0, 0), Vector2(1, 1), 1, Tween.TRANS_ELASTIC, Tween.EASE_IN_OUT)
tween.interpolate_property(container, "rect_position", Vector2(75, 75), Vector2(0, 0), 1, Tween.TRANS_ELASTIC, Tween.EASE_IN_OUT)
if deferred_show > 0:
timer.wait_time = deferred_show
timer.start()
else:
start_anim()
hover_control.info_panel.title = ""
hover_control.info_panel.content = ""
func start_anim():
tween.interpolate_property(container, "rect_scale", Vector2(0, 0), Vector2(1, 1), 1, Tween.TRANS_ELASTIC, Tween.EASE_IN_OUT)
tween.interpolate_property(container, "rect_position", Vector2(75, 75), Vector2(0, 0), 1, Tween.TRANS_ELASTIC, Tween.EASE_IN_OUT)
container.rect_scale = Vector2(0, 0)
container.rect_position = Vector2(75, 75)
container.show()
tween.start()
func _on_Timer_timeout():
func _set_description():
if choice < choices_names.size() and choice < choices_descriptions.size():
hover_control.info_panel.title = choices_names[choice]
hover_control.info_panel.content = choices_descriptions[choice]
choice_label.text = choices_names[choice]
else:
hover_control.info_panel.title = ""
hover_control.info_panel.content = ""
choice_label.text = ""
func set_choice(new_value: int):
print("setting choice")
choice = new_value
_set_description()
start_anim()

View file

@ -56,8 +56,4 @@ align = 1
[node name="Tween" type="Tween" parent="."]
[node name="Timer" type="Timer" parent="."]
one_shot = true
[node name="HoverControl" parent="." instance=ExtResource( 4 )]
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]

View file

@ -1,22 +1,47 @@
extends Control
export(String) var title := ""
export(String) var description := ""
export(Texture) var texture_normal
export(Texture) var texture_hover
export(bool) var is_left := true
export(String) var title := ""
export(Texture) var texture_bad
export(Texture) var texture_neutral
export(Texture) var texture_good
onready var button = $TextureButton
export(String, MULTILINE) var description_bad: = ""
export(String, MULTILINE) var description_neutral := ""
export(String, MULTILINE) var description_good := ""
var DESCRIPTION_THRESHOLDS = [40, 60]
var relation : float = 0 setget set_relation
onready var texture_rect = $TextureRect
onready var hover_control = $HoverControl
func _ready():
button.texture_normal = texture_normal
button.texture_hover = texture_hover
hover_control.selection_object = button
texture_rect.texture = texture_neutral
hover_control.selection_object = texture_rect
if is_left:
hover_control.infobox_position = "right"
else:
hover_control.infobox_position = "left"
hover_control.info_panel.title = title
hover_control.info_panel.content = description
hover_control.info_panel.content = ""
func _set_description():
if relation < DESCRIPTION_THRESHOLDS[0]:
hover_control.info_panel.content = description_bad
texture_rect.texture = texture_bad
elif relation > DESCRIPTION_THRESHOLDS[1]:
hover_control.info_panel.content = description_good
texture_rect.texture = texture_good
else:
hover_control.info_panel.content = description_neutral
texture_rect.texture = texture_neutral
func set_relation(new_value: float):
relation = new_value
_set_description()

View file

@ -1,6 +1,6 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://characters/Evelyne/evelyne_neutre.png" type="Texture" id=1]
[ext_resource path="res://characters/Evelyne/evelyne_angry.png" type="Texture" id=1]
[ext_resource path="res://scenes/end-screen/EndCharacter.gd" type="Script" id=2]
[ext_resource path="res://scenes/end-screen/HoverControl.tscn" type="PackedScene" id=3]
@ -13,11 +13,11 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="TextureButton" type="TextureButton" parent="."]
[node name="TextureRect" type="TextureRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_default_cursor_shape = 2
texture_normal = ExtResource( 1 )
texture = ExtResource( 1 )
expand = true
stretch_mode = 5
__meta__ = {

View file

@ -13,17 +13,22 @@ var relations_ranges := [[-5, 6], [-3, 5]]
var gauges_values := []
var relations_values := []
var choices_values := []
var gauges := {}
var relations := {}
var choices := {}
onready var progress_container = $VBoxContainer/Control/RecapContainer/MarginContainer/Panel/MarginContainer/VBoxContainer/MarginContainer/GaugesContainer
onready var choices_container = $VBoxContainer/MarginContainer/MarginContainer/HBoxContainer2
onready var main_container = $VBoxContainer/Control
onready var recap_container = $VBoxContainer/Control/RecapContainer
onready var characters_container = $VBoxContainer/Control/CharactersContainer
onready var gauges_timer = $GaugesTimer
onready var choices_timer = $ChoicesTimer
var shown_gauge_index = 0
var shown_choice_index = 0
func _ready():
progress_container.connect("mouse_entered", self, '_on_mouse_entered')
@ -31,17 +36,24 @@ func _ready():
_recover_variables()
gauges_values = _get_percentages(gauges, gauges_names, gauges_ranges)
relations_values = _get_percentages(relations, relations_names, relations_ranges)
choices_values = _get_choices_array()
_set_characters_relations()
print(gauges_values)
print(relations_values)
print(choices_values)
gauges_timer.start()
# Do not wait to show the first choice
_on_ChoicesTimer_timeout()
choices_timer.start()
func _on_mouse_exited():
main_container.move_child(recap_container, 0)
func _on_mouse_entered():
# Make sure the recap is behind the characters
# This allows showing the infobox above the recap
@ -81,7 +93,23 @@ func _get_percentages(data: Dictionary, names: Array, ranges: Array) -> Array:
return final_array
func _on_GaugesTimer_timeout():
func _get_choices_array() -> Array:
var final_array := []
for i in range(0, choices.size()):
final_array.append(choices[choices_names[i]]["value"])
return final_array
func _set_characters_relations():
for i in range(0, relations_values.size()):
var child_index = i
# take the spacer into account
if i >= 1:
child_index += 1
characters_container.get_child(child_index).relation = relations_values[i]
func _on_GaugesTimer_timeout() -> void:
var c = progress_container.get_child(shown_gauge_index)
c.progress = gauges_values[shown_gauge_index]
shown_gauge_index += 1
@ -89,5 +117,21 @@ func _on_GaugesTimer_timeout():
gauges_timer.stop()
func _on_ChoicesTimer_timeout() -> void:
print("timeout")
# take spacers into account
var c = choices_container.get_child(shown_choice_index * 2)
if shown_choice_index < choices_values.size():
print(choices_values[shown_choice_index / 2])
c.choice = int(choices_values[shown_choice_index / 2])
shown_choice_index += 1
if shown_choice_index >= choices_container.get_child_count():
choices_timer.stop()
else:
choices_timer.stop()
func _on_ExitButton_pressed():
Transit.change_scene("res://scenes/MainMenu.tscn", 0.5)

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=18 format=2]
[gd_scene load_steps=20 format=2]
[ext_resource path="res://scenes/end-screen/EndRecap.gd" type="Script" id=1]
[ext_resource path="res://backgrounds/bureauGroupe-1.jpg" type="Texture" id=2]
@ -12,8 +12,10 @@
[ext_resource path="res://fonts/open-sans/OpenSans-Regular.ttf" type="DynamicFontData" id=10]
[ext_resource path="res://characters/Evelyne/evelyne_satisfaite.png" type="Texture" id=11]
[ext_resource path="res://characters/Evelyne/evelyne_neutre.png" type="Texture" id=12]
[ext_resource path="res://characters/Jean-Michel/Jean-Michel_narquois.png" type="Texture" id=13]
[ext_resource path="res://characters/Evelyne/evelyne_angry.png" type="Texture" id=13]
[ext_resource path="res://styles/Panel.tres" type="StyleBox" id=14]
[ext_resource path="res://characters/Jean-Michel/Jean-Michel_haineux3.png" type="Texture" id=15]
[ext_resource path="res://characters/Jean-Michel/Jean-Méchant.png" type="Texture" id=16]
[sub_resource type="DynamicFont" id=1]
size = 80
@ -27,7 +29,7 @@ outline_size = 3
outline_color = Color( 0.384314, 0.380392, 0.380392, 1 )
font_data = ExtResource( 3 )
[sub_resource type="DynamicFont" id=4]
[sub_resource type="DynamicFont" id=3]
size = 30
outline_size = 2
outline_color = Color( 0.384314, 0.380392, 0.380392, 1 )
@ -139,7 +141,7 @@ __meta__ = {
[node name="Label" type="Label" parent="VBoxContainer/Control/RecapContainer/MarginContainer/Panel/MarginContainer/VBoxContainer"]
margin_right = 872.0
margin_bottom = 42.0
custom_fonts/font = SubResource( 4 )
custom_fonts/font = SubResource( 3 )
text = "Récapitulatif"
align = 1
@ -164,7 +166,6 @@ margin_left = 128.0
margin_right = 248.0
margin_bottom = 337.0
gauge_name = "Travail"
gauge_description = "ceci est un test"
gauge_color = Color( 0.576471, 0.345098, 0.313726, 1 )
[node name="EducationProgress" parent="VBoxContainer/Control/RecapContainer/MarginContainer/Panel/MarginContainer/VBoxContainer/MarginContainer/GaugesContainer" instance=ExtResource( 9 )]
@ -227,9 +228,12 @@ __meta__ = {
[node name="Evelyne" parent="VBoxContainer/Control/CharactersContainer" instance=ExtResource( 6 )]
title = "Evelyne"
description = "Elle est cool"
texture_normal = ExtResource( 12 )
texture_hover = ExtResource( 11 )
texture_bad = ExtResource( 13 )
texture_neutral = ExtResource( 12 )
texture_good = ExtResource( 11 )
description_bad = "bad"
description_neutral = "neutral"
description_good = "good"
[node name="Spacer" type="Control" parent="VBoxContainer/Control/CharactersContainer"]
margin_left = 404.0
@ -244,11 +248,14 @@ __meta__ = {
[node name="JM" parent="VBoxContainer/Control/CharactersContainer" instance=ExtResource( 6 )]
margin_left = 1520.0
margin_right = 1920.0
title = "Jen-Michel"
description = "il est méchant"
texture_normal = ExtResource( 13 )
texture_hover = ExtResource( 5 )
is_left = false
title = "Jen-Michel"
texture_bad = ExtResource( 15 )
texture_neutral = ExtResource( 16 )
texture_good = ExtResource( 5 )
description_bad = "bad"
description_neutral = "neutral"
description_good = "good"
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"]
margin_top = 850.0
@ -296,13 +303,12 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="ChoiceCircle" parent="VBoxContainer/MarginContainer/MarginContainer/HBoxContainer2" instance=ExtResource( 7 )]
[node name="ChoiceCircle1" parent="VBoxContainer/MarginContainer/MarginContainer/HBoxContainer2" instance=ExtResource( 7 )]
margin_left = 0.0
margin_top = 0.0
margin_right = 150.0
margin_bottom = 200.0
rect_rotation = 0.0
choice_name = "Choice 1"
dilemma_name = "Dilemma 1"
[node name="Spacer" type="Control" parent="VBoxContainer/MarginContainer/MarginContainer/HBoxContainer2"]
@ -317,9 +323,7 @@ margin_top = 0.0
margin_right = 815.0
margin_bottom = 200.0
rect_rotation = 0.0
choice_name = "Choice 2"
dilemma_name = "Dilemma 2"
deferred_show = 0.3
[node name="Spacer2" type="Control" parent="VBoxContainer/MarginContainer/MarginContainer/HBoxContainer2"]
margin_left = 819.0
@ -333,11 +337,13 @@ margin_top = 0.0
margin_right = 1480.0
margin_bottom = 200.0
rect_rotation = 0.0
choice_name = "Choice 3"
dilemma_name = "Dilemma 2"
deferred_show = 0.7
[node name="GaugesTimer" type="Timer" parent="."]
wait_time = 0.5
[node name="ChoicesTimer" type="Timer" parent="."]
wait_time = 0.5
[connection signal="pressed" from="VBoxContainer/Control/RecapContainer/MarginContainer/Panel/MarginContainer/VBoxContainer/CenterContainer/ExitButton" to="." method="_on_ExitButton_pressed"]
[connection signal="timeout" from="GaugesTimer" to="." method="_on_GaugesTimer_timeout"]
[connection signal="timeout" from="ChoicesTimer" to="." method="_on_ChoicesTimer_timeout"]

View file

@ -1,8 +1,14 @@
extends MarginContainer
export(String) var gauge_name = ""
export(String) var gauge_description = ""
export(Color) var gauge_color = Color.white
export(String) var gauge_name := ""
export(Color) var gauge_color := Color.white
export(String, MULTILINE) var description_bad: = ""
export(String, MULTILINE) var description_neutral := ""
export(String, MULTILINE) var description_good := ""
var DESCRIPTION_THRESHOLDS = [40, 60]
var progress : float = 0 setget set_progress
@ -18,7 +24,7 @@ func _ready():
hover_control.selection_object = progress_bar
hover_control.infobox_position = "left"
hover_control.info_panel.title = gauge_name
hover_control.info_panel.content = gauge_description
hover_control.info_panel.content = ""
label.text = gauge_name
progress_bar.tint_progress = gauge_color
container.modulate = Color(1, 1, 1, 0)
@ -29,8 +35,19 @@ func start_anim():
container.show()
func _set_description():
if progress < DESCRIPTION_THRESHOLDS[0]:
hover_control.info_panel.content = description_bad
elif progress > DESCRIPTION_THRESHOLDS[1]:
hover_control.info_panel.content = description_good
else:
hover_control.info_panel.content = description_neutral
func set_progress(new_value: float):
progress = new_value
_set_description()
# hover_control.info_panel.content = variable_descriptions[]
tween.interpolate_property(progress_bar, "value", 0, progress, 1.5, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
tween.interpolate_property(container, "modulate", Color(1, 1, 1, 0), Color(1, 1, 1, 1), 1, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
start_anim()

View file

@ -20,16 +20,23 @@ func _on_mouse_exited():
hover_tween.interpolate_property(info_panel, "modulate", null, Color(1, 1, 1, 0), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
hover_tween.start()
func _on_mouse_entered():
set_infobox_position()
info_panel.show()
hover_tween.stop_all()
hover_tween.interpolate_property(selection_object, "modulate", null, Color("#615ea4"), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
hover_tween.interpolate_property(info_panel, "modulate", null, Color(1, 1, 1, 1), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
hover_tween.start()
if _can_show_info_panel():
mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
set_infobox_position()
info_panel.show()
hover_tween.interpolate_property(selection_object, "modulate", null, Color("#615ea4"), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
hover_tween.interpolate_property(info_panel, "modulate", null, Color(1, 1, 1, 1), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
hover_tween.start()
else:
mouse_default_cursor_shape = Control.CURSOR_ARROW
func _can_show_info_panel():
return not info_panel.content.empty()
func set_infobox_position():
var s = rect_size
var info_s = info_panel.rect_size

View file

@ -9,7 +9,6 @@ onready var content_label = $MarginContainer/VBoxContainer/Content
func set_title(new_value: String):
title = new_value
title_label.text = title
print(title)
func set_content(new_value: String):