Skip to content

Commit

Permalink
Allow changing language without restarting
Browse files Browse the repository at this point in the history
  • Loading branch information
qrrk committed Mar 22, 2022
1 parent 4eb35da commit 2ee788f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
45 changes: 22 additions & 23 deletions scenes/Catapult.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,11 @@ margin_bottom = 100.0
[node name="Tabs" type="TabContainer" parent="Main" groups=["disable_during_backup_operations", "disable_during_mod_operations", "disable_during_soundpack_operations", "disable_while_fetching_releases", "disable_while_installing_game"]]
margin_top = 104.0
margin_right = 592.0
margin_bottom = 487.0
margin_bottom = 373.0
tab_align = 0
script = ExtResource( 16 )

[node name="Game" type="VBoxContainer" parent="Main/Tabs"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 7.5
Expand All @@ -132,7 +131,7 @@ margin_bottom = -7.5

[node name="Channel" type="VBoxContainer" parent="Main/Tabs/Game"]
margin_right = 577.0
margin_bottom = 58.0
margin_bottom = 56.0

[node name="HBox" type="HBoxContainer" parent="Main/Tabs/Game/Channel"]
margin_right = 577.0
Expand All @@ -156,9 +155,9 @@ text = "lbl_changelog"
scroll_active = false

[node name="Group" type="HBoxContainer" parent="Main/Tabs/Game/Channel"]
margin_top = 30.0
margin_top = 28.0
margin_right = 577.0
margin_bottom = 58.0
margin_bottom = 56.0

[node name="RBtnStable" type="CheckBox" parent="Main/Tabs/Game/Channel/Group" groups=["disable_while_fetching_releases", "disable_while_installing_game"]]
margin_right = 102.0
Expand All @@ -177,9 +176,9 @@ group = SubResource( 1 )
text = "rbtn_experimental"

[node name="Builds" type="HBoxContainer" parent="Main/Tabs/Game"]
margin_top = 64.0
margin_top = 60.0
margin_right = 577.0
margin_bottom = 88.0
margin_bottom = 84.0

[node name="Label" type="Label" parent="Main/Tabs/Game/Builds"]
margin_right = 68.0
Expand All @@ -188,24 +187,24 @@ text = "lbl_builds"

[node name="BuildsList" type="OptionButton" parent="Main/Tabs/Game/Builds" groups=["disable_while_fetching_releases", "disable_while_installing_game"]]
margin_left = 74.0
margin_right = 484.0
margin_right = 490.0
margin_bottom = 24.0
hint_tooltip = "tooltip_builds"
size_flags_horizontal = 3
clip_text = true

[node name="BtnRefresh" type="Button" parent="Main/Tabs/Game/Builds" groups=["disable_while_fetching_releases", "disable_while_installing_game"]]
margin_left = 490.0
margin_left = 496.0
margin_right = 577.0
margin_bottom = 24.0
hint_tooltip = "tooltip_refresh"
text = "btn_refresh"

[node name="BtnInstall" type="Button" parent="Main/Tabs/Game" groups=["disable_while_fetching_releases", "disable_while_installing_game"]]
margin_left = 168.0
margin_top = 94.0
margin_top = 88.0
margin_right = 408.0
margin_bottom = 126.0
margin_bottom = 120.0
rect_min_size = Vector2( 240, 32 )
hint_tooltip = "tooltip_install"
size_flags_horizontal = 4
Expand All @@ -214,14 +213,14 @@ icon = ExtResource( 2 )
expand_icon = true

[node name="HSeparator" type="HSeparator" parent="Main/Tabs/Game"]
margin_top = 132.0
margin_top = 124.0
margin_right = 577.0
margin_bottom = 140.0
margin_bottom = 132.0

[node name="CurrentInstall" type="VBoxContainer" parent="Main/Tabs/Game"]
margin_top = 146.0
margin_top = 136.0
margin_right = 577.0
margin_bottom = 238.0
margin_bottom = 224.0

[node name="Label" type="Label" parent="Main/Tabs/Game/CurrentInstall"]
margin_right = 577.0
Expand All @@ -231,9 +230,9 @@ align = 1

[node name="Build" type="HBoxContainer" parent="Main/Tabs/Game/CurrentInstall"]
margin_left = 217.0
margin_top = 30.0
margin_top = 28.0
margin_right = 360.0
margin_bottom = 54.0
margin_bottom = 52.0
size_flags_horizontal = 4
custom_constants/separation = 4

Expand Down Expand Up @@ -261,9 +260,9 @@ texture_normal = ExtResource( 23 )

[node name="Launch" type="HBoxContainer" parent="Main/Tabs/Game/CurrentInstall"]
margin_left = 125.0
margin_top = 60.0
margin_top = 56.0
margin_right = 451.0
margin_bottom = 92.0
margin_bottom = 88.0
size_flags_horizontal = 4

[node name="BtnPlay" type="Button" parent="Main/Tabs/Game/CurrentInstall/Launch" groups=["disable_while_installing_game"]]
Expand All @@ -288,9 +287,9 @@ icon = ExtResource( 25 )
expand_icon = true

[node name="Spacer" type="Control" parent="Main/Tabs/Game"]
margin_top = 244.0
margin_top = 228.0
margin_right = 577.0
margin_bottom = 244.0
margin_bottom = 228.0

[node name="ChangelogDialog" parent="Main/Tabs/Game" instance=ExtResource( 32 )]

Expand Down Expand Up @@ -948,6 +947,7 @@ margin_right = 577.0
margin_bottom = 60.0

[node name="Settings" type="VBoxContainer" parent="Main/Tabs"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 7.5
Expand Down Expand Up @@ -995,7 +995,6 @@ margin_bottom = 24.0
rect_min_size = Vector2( 180, 0 )
size_flags_horizontal = 10
expand_icon = true
selected = 0

[node name="ShowGameDesc" type="CheckButton" parent="Main/Tabs/Settings"]
margin_top = 52.0
Expand Down Expand Up @@ -1212,7 +1211,7 @@ size_flags_horizontal = 4
text = "Print screen info"

[node name="Log" type="RichTextLabel" parent="Main"]
margin_top = 491.0
margin_top = 377.0
margin_right = 592.0
margin_bottom = 692.0
focus_mode = 2
Expand Down
28 changes: 19 additions & 9 deletions scripts/Catapult.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,21 @@ func _ready() -> void:
var theme_file = Settings.read("launcher_theme")
load_ui_theme(theme_file)

OS.set_window_title(tr("window_title"))
assign_localized_text()

var welcome_msg = tr("str_welcome")
if Settings.read("print_tips_of_the_day"):
welcome_msg += tr("str_tip_of_the_day") + _totd.get_tip() + "\n"
Status.post(welcome_msg)

_unpack_utils()
setup_ui()


func assign_localized_text() -> void:

OS.set_window_title(tr("window_title"))

# Apply translation to tab titles.
_tabs.set_tab_title(0, tr("tab_game"))
_tabs.set_tab_title(1, tr("tab_mods"))
_tabs.set_tab_title(2, tr("tab_soundpacks"))
Expand All @@ -50,13 +62,11 @@ func _ready() -> void:

_lbl_changelog.bbcode_text = tr("lbl_changelog")

var welcome_msg = tr("str_welcome")
if Settings.read("print_tips_of_the_day"):
welcome_msg += tr("str_tip_of_the_day") + _totd.get_tip() + "\n"
Status.post(welcome_msg)

_unpack_utils()
setup_ui()
var game = Settings.read("game")
if game == "dda":
_game_desc.bbcode_text = tr("desc_dda")
elif game == "bn":
_game_desc.bbcode_text = tr("desc_bn")


func load_ui_theme(theme_file: String) -> void:
Expand Down
3 changes: 3 additions & 0 deletions scripts/SettingsUI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ func _on_obtnLanguage_item_selected(index: int) -> void:
locale = "ru"
3:
locale = "zh"

Settings.store("launcher_locale", locale)
TranslationServer.set_locale(locale)
_root.assign_localized_text()


func _on_obtnTheme_item_selected(index: int) -> void:
Expand Down

0 comments on commit 2ee788f

Please sign in to comment.