Browse Source

allow setting text based on game choices

Arnaud Vergnet 9 months ago
parent
commit
775ef72160

+ 26
- 18
scenes/end-screen/ChoiceCircle.gd View File

@@ -1,14 +1,16 @@
1 1
 extends Control
2 2
 
3 3
 
4
-export(String) var choice_name = ""
5 4
 export(String) var dilemma_name = ""
6
-export(String) var dilemma_description = ""
7
-export(float) var deferred_show = 0
5
+export(Array, String) var choices_names = []
6
+export(Array, String, MULTILINE) var choices_descriptions = []
7
+
8
+
9
+var choice : int = 0 setget set_choice
10
+
8 11
 
9 12
 onready var tween = $Tween
10 13
 onready var hover_control = $HoverControl
11
-onready var timer = $Timer
12 14
 onready var container = $VBoxContainer
13 15
 onready var choice_label = $VBoxContainer/ChoiceLabel
14 16
 onready var dilemma_label = $VBoxContainer/DilemmaLabel
@@ -17,30 +19,36 @@ onready var texture = $VBoxContainer/TextureRect
17 19
 
18 20
 func _ready():
19 21
 	container.hide()
20
-	choice_label.text = choice_name
21 22
 	dilemma_label.text = dilemma_name
23
+	choice_label.text = ""
22 24
 	hover_control.selection_object = texture
23 25
 	hover_control.infobox_position = "top"
24
-	hover_control.info_panel.title = dilemma_name
25
-	hover_control.info_panel.content = dilemma_description
26
-	
27
-	tween.interpolate_property(container, "rect_scale",  Vector2(0, 0), Vector2(1, 1), 1, Tween.TRANS_ELASTIC, Tween.EASE_IN_OUT)
28
-	tween.interpolate_property(container, "rect_position",  Vector2(75, 75), Vector2(0, 0), 1, Tween.TRANS_ELASTIC, Tween.EASE_IN_OUT)
29
-	
30
-	if deferred_show > 0:
31
-		timer.wait_time = deferred_show
32
-		timer.start()
33
-	else:
34
-		start_anim()
26
+	hover_control.info_panel.title = ""
27
+	hover_control.info_panel.content = ""
28
+
35 29
 
36 30
 func start_anim():
31
+	tween.interpolate_property(container, "rect_scale",  Vector2(0, 0), Vector2(1, 1), 1, Tween.TRANS_ELASTIC, Tween.EASE_IN_OUT)
32
+	tween.interpolate_property(container, "rect_position",  Vector2(75, 75), Vector2(0, 0), 1, Tween.TRANS_ELASTIC, Tween.EASE_IN_OUT)
37 33
 	container.rect_scale = Vector2(0, 0)
38 34
 	container.rect_position = Vector2(75, 75)
39 35
 	container.show()
40 36
 	tween.start()
41 37
 
42 38
 
43
-func _on_Timer_timeout():
44
-	start_anim()
39
+func _set_description():
40
+	if choice < choices_names.size() and choice < choices_descriptions.size():
41
+		hover_control.info_panel.title = choices_names[choice]
42
+		hover_control.info_panel.content = choices_descriptions[choice]
43
+		choice_label.text = choices_names[choice]
44
+	else:
45
+		hover_control.info_panel.title = ""
46
+		hover_control.info_panel.content = ""
47
+		choice_label.text = ""
45 48
 
46 49
 
50
+func set_choice(new_value: int):
51
+	print("setting choice")
52
+	choice = new_value
53
+	_set_description()
54
+	start_anim()

+ 0
- 4
scenes/end-screen/ChoiceCircle.tscn View File

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

+ 34
- 9
scenes/end-screen/EndCharacter.gd View File

@@ -1,22 +1,47 @@
1 1
 extends Control
2 2
 
3
-export(String) var title := ""
4
-export(String) var description := ""
5
-export(Texture) var texture_normal
6
-export(Texture) var texture_hover
7 3
 export(bool) var is_left := true
4
+export(String) var title := ""
5
+export(Texture) var texture_bad
6
+export(Texture) var texture_neutral
7
+export(Texture) var texture_good
8
+
9
+export(String, MULTILINE) var description_bad: = ""
10
+export(String, MULTILINE) var description_neutral := ""
11
+export(String, MULTILINE) var description_good := ""
12
+
13
+
14
+var DESCRIPTION_THRESHOLDS = [40, 60]
15
+var relation : float = 0 setget set_relation
16
+
8 17
 
9
-onready var button = $TextureButton
18
+onready var texture_rect = $TextureRect
10 19
 onready var hover_control = $HoverControl
11 20
 
21
+
12 22
 func _ready():
13
-	button.texture_normal = texture_normal
14
-	button.texture_hover = texture_hover
15
-	hover_control.selection_object = button
23
+	texture_rect.texture = texture_neutral
24
+	hover_control.selection_object = texture_rect
16 25
 	if is_left:
17 26
 		hover_control.infobox_position = "right"
18 27
 	else:
19 28
 		hover_control.infobox_position = "left"
20 29
 	hover_control.info_panel.title = title
21
-	hover_control.info_panel.content = description
30
+	hover_control.info_panel.content = ""
31
+
32
+
33
+func _set_description():
34
+	if relation < DESCRIPTION_THRESHOLDS[0]:
35
+		hover_control.info_panel.content = description_bad
36
+		texture_rect.texture = texture_bad
37
+	elif relation > DESCRIPTION_THRESHOLDS[1]:
38
+		hover_control.info_panel.content = description_good
39
+		texture_rect.texture = texture_good
40
+	else:
41
+		hover_control.info_panel.content = description_neutral
42
+		texture_rect.texture = texture_neutral
43
+
22 44
 
45
+func set_relation(new_value: float):
46
+	relation = new_value
47
+	_set_description()

+ 3
- 3
scenes/end-screen/EndCharacter.tscn View File

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

+ 46
- 2
scenes/end-screen/EndRecap.gd View File

@@ -13,17 +13,22 @@ var relations_ranges := [[-5, 6], [-3, 5]]
13 13
 
14 14
 var gauges_values := []
15 15
 var relations_values := []
16
+var choices_values := []
16 17
 
17 18
 var gauges := {}
18 19
 var relations := {}
19 20
 var choices := {}
20 21
 
21 22
 onready var progress_container = $VBoxContainer/Control/RecapContainer/MarginContainer/Panel/MarginContainer/VBoxContainer/MarginContainer/GaugesContainer
23
+onready var choices_container = $VBoxContainer/MarginContainer/MarginContainer/HBoxContainer2
22 24
 onready var main_container = $VBoxContainer/Control
23 25
 onready var recap_container = $VBoxContainer/Control/RecapContainer
26
+onready var characters_container = $VBoxContainer/Control/CharactersContainer
24 27
 onready var gauges_timer = $GaugesTimer
28
+onready var choices_timer = $ChoicesTimer
25 29
 
26 30
 var shown_gauge_index = 0
31
+var shown_choice_index = 0
27 32
 
28 33
 func _ready():
29 34
 	progress_container.connect("mouse_entered", self, '_on_mouse_entered')
@@ -31,17 +36,24 @@ func _ready():
31 36
 	_recover_variables()
32 37
 	gauges_values = _get_percentages(gauges, gauges_names, gauges_ranges)
33 38
 	relations_values = _get_percentages(relations, relations_names, relations_ranges)
39
+	choices_values = _get_choices_array()
40
+	
41
+	_set_characters_relations()
34 42
 	
35 43
 	print(gauges_values)
36 44
 	print(relations_values)
45
+	print(choices_values)
37 46
 	
38 47
 	gauges_timer.start()
48
+	# Do not wait to show the first choice
49
+	_on_ChoicesTimer_timeout()
50
+	choices_timer.start()
39 51
 
40 52
 
41 53
 func _on_mouse_exited():
42 54
 	main_container.move_child(recap_container, 0)
43 55
 	
44
-  
56
+	
45 57
 func _on_mouse_entered():
46 58
 	# Make sure the recap is behind the characters
47 59
 	# This allows showing the infobox above the recap
@@ -81,7 +93,23 @@ func _get_percentages(data: Dictionary, names: Array, ranges: Array) -> Array:
81 93
 	return final_array
82 94
 
83 95
 
84
-func _on_GaugesTimer_timeout():
96
+func _get_choices_array() -> Array:
97
+	var final_array := []
98
+	for i in range(0, choices.size()):
99
+		final_array.append(choices[choices_names[i]]["value"])
100
+	return final_array
101
+
102
+
103
+func _set_characters_relations():
104
+	for i in range(0, relations_values.size()):
105
+		var child_index = i
106
+		# take the spacer into account
107
+		if i >= 1:
108
+			child_index += 1
109
+		characters_container.get_child(child_index).relation = relations_values[i]
110
+
111
+
112
+func _on_GaugesTimer_timeout() -> void:
85 113
 	var c = progress_container.get_child(shown_gauge_index)
86 114
 	c.progress = gauges_values[shown_gauge_index]
87 115
 	shown_gauge_index += 1
@@ -89,5 +117,21 @@ func _on_GaugesTimer_timeout():
89 117
 		gauges_timer.stop()
90 118
 
91 119
 
120
+func _on_ChoicesTimer_timeout() -> void:
121
+	print("timeout")
122
+	# take spacers into account
123
+	var c = choices_container.get_child(shown_choice_index * 2)
124
+	if shown_choice_index < choices_values.size():
125
+		print(choices_values[shown_choice_index / 2])
126
+		c.choice = int(choices_values[shown_choice_index / 2])
127
+		shown_choice_index += 1
128
+		if shown_choice_index >= choices_container.get_child_count():
129
+			choices_timer.stop()
130
+	else:
131
+		choices_timer.stop()
132
+
133
+
92 134
 func _on_ExitButton_pressed():
93 135
 	Transit.change_scene("res://scenes/MainMenu.tscn", 0.5)
136
+
137
+

+ 24
- 18
scenes/end-screen/EndRecap.tscn View File

@@ -1,4 +1,4 @@
1
-[gd_scene load_steps=18 format=2]
1
+[gd_scene load_steps=20 format=2]
2 2
 
3 3
 [ext_resource path="res://scenes/end-screen/EndRecap.gd" type="Script" id=1]
4 4
 [ext_resource path="res://backgrounds/bureauGroupe-1.jpg" type="Texture" id=2]
@@ -12,8 +12,10 @@
12 12
 [ext_resource path="res://fonts/open-sans/OpenSans-Regular.ttf" type="DynamicFontData" id=10]
13 13
 [ext_resource path="res://characters/Evelyne/evelyne_satisfaite.png" type="Texture" id=11]
14 14
 [ext_resource path="res://characters/Evelyne/evelyne_neutre.png" type="Texture" id=12]
15
-[ext_resource path="res://characters/Jean-Michel/Jean-Michel_narquois.png" type="Texture" id=13]
15
+[ext_resource path="res://characters/Evelyne/evelyne_angry.png" type="Texture" id=13]
16 16
 [ext_resource path="res://styles/Panel.tres" type="StyleBox" id=14]
17
+[ext_resource path="res://characters/Jean-Michel/Jean-Michel_haineux3.png" type="Texture" id=15]
18
+[ext_resource path="res://characters/Jean-Michel/Jean-Méchant.png" type="Texture" id=16]
17 19
 
18 20
 [sub_resource type="DynamicFont" id=1]
19 21
 size = 80
@@ -27,7 +29,7 @@ outline_size = 3
27 29
 outline_color = Color( 0.384314, 0.380392, 0.380392, 1 )
28 30
 font_data = ExtResource( 3 )
29 31
 
30
-[sub_resource type="DynamicFont" id=4]
32
+[sub_resource type="DynamicFont" id=3]
31 33
 size = 30
32 34
 outline_size = 2
33 35
 outline_color = Color( 0.384314, 0.380392, 0.380392, 1 )
@@ -139,7 +141,7 @@ __meta__ = {
139 141
 [node name="Label" type="Label" parent="VBoxContainer/Control/RecapContainer/MarginContainer/Panel/MarginContainer/VBoxContainer"]
140 142
 margin_right = 872.0
141 143
 margin_bottom = 42.0
142
-custom_fonts/font = SubResource( 4 )
144
+custom_fonts/font = SubResource( 3 )
143 145
 text = "Récapitulatif"
144 146
 align = 1
145 147
 
@@ -164,7 +166,6 @@ margin_left = 128.0
164 166
 margin_right = 248.0
165 167
 margin_bottom = 337.0
166 168
 gauge_name = "Travail"
167
-gauge_description = "ceci est un test"
168 169
 gauge_color = Color( 0.576471, 0.345098, 0.313726, 1 )
169 170
 
170 171
 [node name="EducationProgress" parent="VBoxContainer/Control/RecapContainer/MarginContainer/Panel/MarginContainer/VBoxContainer/MarginContainer/GaugesContainer" instance=ExtResource( 9 )]
@@ -227,9 +228,12 @@ __meta__ = {
227 228
 
228 229
 [node name="Evelyne" parent="VBoxContainer/Control/CharactersContainer" instance=ExtResource( 6 )]
229 230
 title = "Evelyne"
230
-description = "Elle est cool"
231
-texture_normal = ExtResource( 12 )
232
-texture_hover = ExtResource( 11 )
231
+texture_bad = ExtResource( 13 )
232
+texture_neutral = ExtResource( 12 )
233
+texture_good = ExtResource( 11 )
234
+description_bad = "bad"
235
+description_neutral = "neutral"
236
+description_good = "good"
233 237
 
234 238
 [node name="Spacer" type="Control" parent="VBoxContainer/Control/CharactersContainer"]
235 239
 margin_left = 404.0
@@ -244,11 +248,14 @@ __meta__ = {
244 248
 [node name="JM" parent="VBoxContainer/Control/CharactersContainer" instance=ExtResource( 6 )]
245 249
 margin_left = 1520.0
246 250
 margin_right = 1920.0
247
-title = "Jen-Michel"
248
-description = "il est méchant"
249
-texture_normal = ExtResource( 13 )
250
-texture_hover = ExtResource( 5 )
251 251
 is_left = false
252
+title = "Jen-Michel"
253
+texture_bad = ExtResource( 15 )
254
+texture_neutral = ExtResource( 16 )
255
+texture_good = ExtResource( 5 )
256
+description_bad = "bad"
257
+description_neutral = "neutral"
258
+description_good = "good"
252 259
 
253 260
 [node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"]
254 261
 margin_top = 850.0
@@ -296,13 +303,12 @@ __meta__ = {
296 303
 "_edit_use_anchors_": false
297 304
 }
298 305
 
299
-[node name="ChoiceCircle" parent="VBoxContainer/MarginContainer/MarginContainer/HBoxContainer2" instance=ExtResource( 7 )]
306
+[node name="ChoiceCircle1" parent="VBoxContainer/MarginContainer/MarginContainer/HBoxContainer2" instance=ExtResource( 7 )]
300 307
 margin_left = 0.0
301 308
 margin_top = 0.0
302 309
 margin_right = 150.0
303 310
 margin_bottom = 200.0
304 311
 rect_rotation = 0.0
305
-choice_name = "Choice 1"
306 312
 dilemma_name = "Dilemma 1"
307 313
 
308 314
 [node name="Spacer" type="Control" parent="VBoxContainer/MarginContainer/MarginContainer/HBoxContainer2"]
@@ -317,9 +323,7 @@ margin_top = 0.0
317 323
 margin_right = 815.0
318 324
 margin_bottom = 200.0
319 325
 rect_rotation = 0.0
320
-choice_name = "Choice 2"
321 326
 dilemma_name = "Dilemma 2"
322
-deferred_show = 0.3
323 327
 
324 328
 [node name="Spacer2" type="Control" parent="VBoxContainer/MarginContainer/MarginContainer/HBoxContainer2"]
325 329
 margin_left = 819.0
@@ -333,11 +337,13 @@ margin_top = 0.0
333 337
 margin_right = 1480.0
334 338
 margin_bottom = 200.0
335 339
 rect_rotation = 0.0
336
-choice_name = "Choice 3"
337 340
 dilemma_name = "Dilemma 2"
338
-deferred_show = 0.7
339 341
 
340 342
 [node name="GaugesTimer" type="Timer" parent="."]
341 343
 wait_time = 0.5
344
+
345
+[node name="ChoicesTimer" type="Timer" parent="."]
346
+wait_time = 0.5
342 347
 [connection signal="pressed" from="VBoxContainer/Control/RecapContainer/MarginContainer/Panel/MarginContainer/VBoxContainer/CenterContainer/ExitButton" to="." method="_on_ExitButton_pressed"]
343 348
 [connection signal="timeout" from="GaugesTimer" to="." method="_on_GaugesTimer_timeout"]
349
+[connection signal="timeout" from="ChoicesTimer" to="." method="_on_ChoicesTimer_timeout"]

+ 21
- 4
scenes/end-screen/GaugeProgress.gd View File

@@ -1,8 +1,14 @@
1 1
 extends MarginContainer
2 2
 
3
-export(String) var gauge_name = ""
4
-export(String) var gauge_description = ""
5
-export(Color) var gauge_color = Color.white
3
+export(String) var gauge_name := ""
4
+export(Color) var gauge_color := Color.white
5
+
6
+export(String, MULTILINE) var description_bad: = ""
7
+export(String, MULTILINE) var description_neutral := ""
8
+export(String, MULTILINE) var description_good := ""
9
+
10
+
11
+var DESCRIPTION_THRESHOLDS = [40, 60]
6 12
 
7 13
 var progress : float = 0 setget set_progress
8 14
 
@@ -18,7 +24,7 @@ func _ready():
18 24
 	hover_control.selection_object = progress_bar
19 25
 	hover_control.infobox_position = "left"
20 26
 	hover_control.info_panel.title = gauge_name
21
-	hover_control.info_panel.content = gauge_description
27
+	hover_control.info_panel.content = ""
22 28
 	label.text = gauge_name
23 29
 	progress_bar.tint_progress = gauge_color
24 30
 	container.modulate = Color(1, 1, 1, 0)
@@ -29,8 +35,19 @@ func start_anim():
29 35
 	container.show()
30 36
 
31 37
 
38
+func _set_description():
39
+	if progress < DESCRIPTION_THRESHOLDS[0]:
40
+		hover_control.info_panel.content = description_bad
41
+	elif progress > DESCRIPTION_THRESHOLDS[1]:
42
+		hover_control.info_panel.content = description_good
43
+	else:
44
+		hover_control.info_panel.content = description_neutral
45
+
46
+
32 47
 func set_progress(new_value: float):
33 48
 	progress = new_value
49
+	_set_description()
50
+#	hover_control.info_panel.content = variable_descriptions[]
34 51
 	tween.interpolate_property(progress_bar, "value", 0, progress, 1.5, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
35 52
 	tween.interpolate_property(container, "modulate",  Color(1, 1, 1, 0), Color(1, 1, 1, 1), 1, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
36 53
 	start_anim()

+ 14
- 7
scenes/end-screen/HoverControl.gd View File

@@ -20,15 +20,22 @@ func _on_mouse_exited():
20 20
 	hover_tween.interpolate_property(info_panel, "modulate",  null, Color(1, 1, 1, 0), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
21 21
 	hover_tween.start()
22 22
 	
23
-  
23
+	
24 24
 func _on_mouse_entered():
25
-	set_infobox_position()
26
-	info_panel.show()
27 25
 	hover_tween.stop_all()
28
-	hover_tween.interpolate_property(selection_object, "modulate",  null, Color("#615ea4"), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
29
-	hover_tween.interpolate_property(info_panel, "modulate",  null, Color(1, 1, 1, 1), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
30
-	hover_tween.start()
31
-
26
+	if _can_show_info_panel():
27
+		mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
28
+		set_infobox_position()
29
+		info_panel.show()
30
+		hover_tween.interpolate_property(selection_object, "modulate",  null, Color("#615ea4"), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
31
+		hover_tween.interpolate_property(info_panel, "modulate",  null, Color(1, 1, 1, 1), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
32
+		hover_tween.start()
33
+	else:
34
+		mouse_default_cursor_shape = Control.CURSOR_ARROW
35
+
36
+
37
+func _can_show_info_panel():
38
+	return not info_panel.content.empty()
32 39
 
33 40
 func set_infobox_position():
34 41
 	var s = rect_size

+ 0
- 1
scenes/end-screen/InfoPanel.gd View File

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

Loading…
Cancel
Save