Skip to content

Commit 37895ef

Browse files
committed
Get translations working at runtime and add option to select locale in Main Panel
1 parent 8a0fe64 commit 37895ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1604
-224
lines changed

addons/parley/assets/Generate.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://dymfq1lumomnh"
6+
path="res://.godot/imported/Generate.svg-c453b998a82ad5f3f2fd9b38bce67edb.ctex"
7+
metadata={
8+
"has_editor_variant": true,
9+
"vram_texture": false
10+
}
11+
12+
[deps]
13+
14+
source_file="res://addons/parley/assets/Generate.svg"
15+
dest_files=["res://.godot/imported/Generate.svg-c453b998a82ad5f3f2fd9b38bce67edb.ctex"]
16+
17+
[params]
18+
19+
compress/mode=0
20+
compress/high_quality=false
21+
compress/lossy_quality=0.7
22+
compress/hdr_compression=1
23+
compress/normal_map=0
24+
compress/channel_pack=0
25+
mipmaps/generate=false
26+
mipmaps/limit=-1
27+
roughness/mode=0
28+
roughness/src_normal=""
29+
process/fix_alpha_border=true
30+
process/premult_alpha=false
31+
process/normal_map_invert_y=false
32+
process/hdr_as_srgb=false
33+
process/hdr_clamp_exposure=false
34+
process/size_limit=0
35+
detect_3d/compress_to=1
36+
svg/scale=1.0
37+
editor/scale_with_editor_scale=true
38+
editor/convert_colors_with_editor_theme=true
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://es7k6io6r0lm"
6+
path="res://.godot/imported/Translation.svg-c3e1761c64f8d5efb11ee1054cec6a6c.ctex"
7+
metadata={
8+
"has_editor_variant": true,
9+
"vram_texture": false
10+
}
11+
12+
[deps]
13+
14+
source_file="res://addons/parley/assets/Translation.svg"
15+
dest_files=["res://.godot/imported/Translation.svg-c3e1761c64f8d5efb11ee1054cec6a6c.ctex"]
16+
17+
[params]
18+
19+
compress/mode=0
20+
compress/high_quality=false
21+
compress/lossy_quality=0.7
22+
compress/hdr_compression=1
23+
compress/normal_map=0
24+
compress/channel_pack=0
25+
mipmaps/generate=false
26+
mipmaps/limit=-1
27+
roughness/mode=0
28+
roughness/src_normal=""
29+
process/fix_alpha_border=true
30+
process/premult_alpha=false
31+
process/normal_map_invert_y=false
32+
process/hdr_as_srgb=false
33+
process/hdr_clamp_exposure=false
34+
process/size_limit=0
35+
detect_3d/compress_to=1
36+
svg/scale=1.0
37+
editor/scale_with_editor_scale=true
38+
editor/convert_colors_with_editor_theme=true

addons/parley/components/default_balloon.gd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ func start(p_ctx: ParleyContext, p_dialogue_sequence_ast: ParleyDialogueSequence
4040
is_waiting_for_input = false
4141
ctx = p_ctx
4242
dialogue_sequence_ast = p_dialogue_sequence_ast
43-
# TODO: remove
44-
ctx.start_of_run = true
45-
var run_result: ParleyRunResult = await ParleyDialogueSequenceAst.run(ctx, dialogue_sequence_ast, p_start_node if p_start_node else null)
43+
var run_result: ParleyRunResult = await ParleyDialogueSequenceAst.init(ctx, dialogue_sequence_ast, p_start_node if p_start_node else null)
4644
current_node_asts = run_result.node_asts
4745
dialogue_sequence_ast = run_result.dialogue_sequence
4846
run_result.free() # Needed to ensure that everything is correctly freed up at exit

addons/parley/components/dialogue/dialogue_container.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ func _ready() -> void:
2222
func _render() -> void:
2323
if dialogue_text_label:
2424
var character: ParleyCharacter = dialogue_node.resolve_character()
25-
dialogue_text_label.text = "[b]%s[/b] – %s" % [character.name if character.name != '' else 'Unknown', dialogue_node.text]
25+
dialogue_text_label.text = "[b]%s[/b] – %s" % [tr(character.name) if character.name != '' else 'Unknown', dialogue_node.text]

addons/parley/components/dialogue/dialogue_node_editor.gd

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ class_name ParleyDialogueNodeEditor extends ParleyBaseNodeEditor
88
var character_store: ParleyCharacterStore: set = _set_character_store
99
@export var character: String = "": set = _set_character
1010
@export var dialogue: String = "": set = _set_dialogue
11+
@export var text_translation_key: String = "": set = _set_text_translation_key
1112

1213

1314
@onready var character_selector: OptionButton = %CharacterSelector
1415
@onready var dialogue_editor: TextEdit = %DialogueEditor
16+
@onready var text_translation_key_editor: ParleyTranslationKeyEditor = %TranslationKeyEditor
1517

1618

17-
signal dialogue_node_changed(id: String, character: String, dialogue: String)
19+
signal dialogue_node_changed(id: String, character: String, dialogue: String, text_translation_key: String)
1820
#endregion
1921

2022

2123
#region LIFECYCLE
2224
func _ready() -> void:
2325
set_title()
2426
_render_dialogue()
27+
_render_text_translation_key_editor(true)
2528
_render_character_options()
2629
if character_store:
2730
ParleyUtils.signals.safe_connect(character_store.changed, _on_character_store_changed)
@@ -48,6 +51,11 @@ func _set_dialogue(new_dialogue: String) -> void:
4851
func _set_character(new_character: String) -> void:
4952
character = new_character
5053
_render_character()
54+
55+
56+
func _set_text_translation_key(new_text_translation_key: String) -> void:
57+
text_translation_key = new_text_translation_key
58+
_render_text_translation_key_editor()
5159
#endregion
5260

5361

@@ -57,6 +65,14 @@ func _render_dialogue() -> void:
5765
dialogue_editor.text = dialogue
5866

5967

68+
func _render_text_translation_key_editor(on_ready: bool = false) -> void:
69+
if text_translation_key_editor:
70+
if text_translation_key_editor.key != text_translation_key:
71+
text_translation_key_editor.key = text_translation_key
72+
if on_ready:
73+
text_translation_key_editor.label = &"Text Translation Key: "
74+
75+
6076
func _render_character_options() -> void:
6177
if not character_selector:
6278
return
@@ -94,5 +110,15 @@ func _on_character_store_changed() -> void:
94110

95111

96112
func _emit_dialogue_node_changed() -> void:
97-
dialogue_node_changed.emit(id, character, dialogue)
113+
dialogue_node_changed.emit(id, character, dialogue, text_translation_key)
114+
115+
116+
func _on_translation_key_editor_key_changed(new_key: String) -> void:
117+
text_translation_key = new_key
118+
_emit_dialogue_node_changed()
119+
120+
121+
func _on_translation_key_editor_key_generation_requested() -> void:
122+
text_translation_key = ParleyUtils.translation.generate_key(dialogue, dialogue_sequence_ast, node_ast, 'text')
123+
_emit_dialogue_node_changed()
98124
#endregion

addons/parley/components/dialogue/dialogue_node_editor.tscn

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
[gd_scene load_steps=3 format=3 uid="uid://bx0l648bpqw70"]
1+
[gd_scene load_steps=4 format=3 uid="uid://bx0l648bpqw70"]
22

33
[ext_resource type="Script" uid="uid://b0qfehwjd3bm7" path="res://addons/parley/components/dialogue/dialogue_node_editor.gd" id="1_ad3ky"]
44
[ext_resource type="PackedScene" uid="uid://m3v11vm16l8y" path="res://addons/parley/components/node/node_editor.tscn" id="1_okdx1"]
5+
[ext_resource type="PackedScene" uid="uid://n4t3w6dhkt6a" path="res://addons/parley/components/editor/translation_key.tscn" id="3_wbci0"]
56

67
[node name="DialogueNodeEditor" instance=ExtResource("1_okdx1")]
78
script = ExtResource("1_ad3ky")
89
character = ""
910
dialogue = ""
11+
text_translation_key = ""
1012
type = 0
1113

1214
[node name="TitleLabel" parent="TitleContainer/TitlePanelContainer/TitleMarginContainer/TitlePartsContainer" index="0"]
@@ -21,8 +23,8 @@ text = "Character: "
2123

2224
[node name="CharacterSelector" type="OptionButton" parent="BodyMarginContainer/BodyScrollContainer/BodyContainer/CharacterSelectorContainer" index="1"]
2325
unique_name_in_owner = true
24-
layout_mode = 2
2526
custom_minimum_size = Vector2(150, 0)
27+
layout_mode = 2
2628
size_flags_horizontal = 3
2729
text_overrun_behavior = 3
2830
clip_text = true
@@ -43,5 +45,11 @@ size_flags_vertical = 3
4345
placeholder_text = "Dialogue goes here.."
4446
wrap_mode = 1
4547

48+
[node name="TranslationKeyEditor" parent="BodyMarginContainer/BodyScrollContainer/BodyContainer" index="2" instance=ExtResource("3_wbci0")]
49+
unique_name_in_owner = true
50+
layout_mode = 2
51+
4652
[connection signal="item_selected" from="BodyMarginContainer/BodyScrollContainer/BodyContainer/CharacterSelectorContainer/CharacterSelector" to="." method="_on_character_selector_item_selected"]
4753
[connection signal="text_changed" from="BodyMarginContainer/BodyScrollContainer/BodyContainer/DialogueEditorContainer/DialogueEditor" to="." method="_on_dialogue_editor_text_changed"]
54+
[connection signal="key_changed" from="BodyMarginContainer/BodyScrollContainer/BodyContainer/TranslationKeyEditor" to="." method="_on_translation_key_editor_key_changed"]
55+
[connection signal="key_generation_requested" from="BodyMarginContainer/BodyScrollContainer/BodyContainer/TranslationKeyEditor" to="." method="_on_translation_key_editor_key_generation_requested"]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[gd_scene load_steps=4 format=3 uid="uid://n4t3w6dhkt6a"]
2+
3+
[ext_resource type="Script" uid="uid://bbk5c0urv1ug" path="res://addons/parley/components/editor/translation_key_editor.gd" id="1_nxxod"]
4+
[ext_resource type="Texture2D" uid="uid://dymfq1lumomnh" path="res://addons/parley/assets/Generate.svg" id="2_15ow8"]
5+
[ext_resource type="Texture2D" uid="uid://c4qx01xbrjp7h" path="res://addons/parley/assets/Edit.svg" id="3_wy1by"]
6+
7+
[node name="TranslationKeyEditor" type="VBoxContainer"]
8+
size_flags_vertical = 3
9+
script = ExtResource("1_nxxod")
10+
11+
[node name="TranslationKeyLabel" type="Label" parent="."]
12+
unique_name_in_owner = true
13+
layout_mode = 2
14+
15+
[node name="TranslationKeyEditorContainer" type="HBoxContainer" parent="."]
16+
layout_mode = 2
17+
18+
[node name="TranslationKeyEditor" type="LineEdit" parent="TranslationKeyEditorContainer"]
19+
unique_name_in_owner = true
20+
layout_mode = 2
21+
size_flags_horizontal = 3
22+
tooltip_text = "Set the translation key for the associated field"
23+
editable = false
24+
25+
[node name="GenerateTranslationKeyButton" type="Button" parent="TranslationKeyEditorContainer"]
26+
unique_name_in_owner = true
27+
layout_mode = 2
28+
tooltip_text = "Generate the translation key for this Node AST. Be cautious when regenerating this as it is likely to affect existing translations."
29+
icon = ExtResource("2_15ow8")
30+
31+
[node name="EditTranslationKeyButton" type="Button" parent="TranslationKeyEditorContainer"]
32+
unique_name_in_owner = true
33+
layout_mode = 2
34+
tooltip_text = "Edit the translation key for this Node AST. Be cautious when changing this as it is likely to affect existing translations."
35+
toggle_mode = true
36+
icon = ExtResource("3_wy1by")
37+
38+
[connection signal="text_changed" from="TranslationKeyEditorContainer/TranslationKeyEditor" to="." method="_on_translation_key_editor_text_changed"]
39+
[connection signal="pressed" from="TranslationKeyEditorContainer/GenerateTranslationKeyButton" to="." method="_on_generate_translation_key_button_pressed"]
40+
[connection signal="toggled" from="TranslationKeyEditorContainer/EditTranslationKeyButton" to="." method="_on_edit_translation_key_button_toggled"]
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright 2024-2025 the Bisterix Studio authors. All rights reserved. MIT license.
2+
3+
@tool
4+
class_name ParleyTranslationKeyEditor extends VBoxContainer
5+
6+
7+
#region DEFS
8+
var label: String = "": set = _set_label
9+
var key: String = "": set = _set_key
10+
11+
12+
@onready var translation_key_label: Label = %TranslationKeyLabel
13+
@onready var translation_key_editor: LineEdit = %TranslationKeyEditor
14+
@onready var generate_translation_key_button: Button = %GenerateTranslationKeyButton
15+
@onready var edit_translation_key_button: Button = %EditTranslationKeyButton
16+
17+
18+
signal key_changed(new_key: String)
19+
signal key_generation_requested()
20+
#endregion
21+
22+
23+
#region LIFECYCLE
24+
func _ready() -> void:
25+
_render_label()
26+
_render_key(true)
27+
_render_edit_translation_key_button(true)
28+
_render_generate_translation_key_button(true)
29+
#endregion
30+
31+
32+
#region SETTERS
33+
func _set_key(new_key: String) -> void:
34+
key = new_key
35+
_render_key()
36+
37+
38+
func _set_label(new_label: String) -> void:
39+
label = new_label
40+
_render_label()
41+
#endregion
42+
43+
44+
#region RENDERERS
45+
func _render_label() -> void:
46+
if translation_key_label:
47+
translation_key_label.text = label
48+
49+
func _render_key(on_ready: bool = false) -> void:
50+
if translation_key_editor:
51+
if translation_key_editor.text != key:
52+
translation_key_editor.text = key
53+
if on_ready:
54+
translation_key_editor.tooltip_text = &"Set the translation key for the associated field"
55+
translation_key_editor.editable = false
56+
57+
58+
func _render_edit_translation_key_button(on_ready: bool = false) -> void:
59+
if edit_translation_key_button:
60+
if on_ready:
61+
edit_translation_key_button.tooltip_text = &"Edit the translation key for this Node AST. Be cautious when changing this as it is likely to affect existing translations."
62+
edit_translation_key_button.button_pressed = false
63+
64+
65+
func _render_generate_translation_key_button(on_ready: bool = false) -> void:
66+
if generate_translation_key_button:
67+
if on_ready:
68+
generate_translation_key_button.tooltip_text = &"Generate the translation key for this Node AST. Be cautious when regenerating this as it is likely to affect existing translations."
69+
#endregion
70+
71+
72+
#region SIGNALS
73+
func _on_translation_key_editor_text_changed(new_text: String) -> void:
74+
key = new_text
75+
key_changed.emit(key)
76+
77+
78+
func _on_generate_translation_key_button_pressed() -> void:
79+
key_generation_requested.emit()
80+
81+
82+
func _on_edit_translation_key_button_toggled(toggled_on: bool) -> void:
83+
if translation_key_editor:
84+
translation_key_editor.editable = toggled_on
85+
#endregion

0 commit comments

Comments
 (0)