1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

Split code from PreferencesDialog.gd to HandleLanguages.gd

Also moved PreferencesDialog script & scene to src/Preferences. More Preferences code splitting will follow.
This commit is contained in:
OverloadedOrama 2020-05-28 03:41:28 +03:00
parent ef89c650b2
commit 379b574257
6 changed files with 66 additions and 64 deletions

View file

@ -176,6 +176,7 @@ var zoom_level_label : Label
var import_sprites_dialog : FileDialog
var export_dialog : AcceptDialog
var preferences_dialog : AcceptDialog
var left_color_picker : ColorPickerButton
var right_color_picker : ColorPickerButton
@ -313,6 +314,7 @@ func _ready() -> void:
import_sprites_dialog = find_node_by_name(root, "ImportSprites")
export_dialog = find_node_by_name(root, "ExportDialog")
preferences_dialog = find_node_by_name(root, "PreferencesDialog")
left_tool_options_container = find_node_by_name(root, "LeftToolOptions")
right_tool_options_container = find_node_by_name(root, "RightToolOptions")

View file

@ -13,8 +13,6 @@ func _ready() -> void:
get_tree().set_auto_accept_quit(false)
setup_application_window_size()
setup_translation_settings()
setup_file_menu()
setup_edit_menu()
setup_view_menu()
@ -82,30 +80,6 @@ func setup_application_window_size() -> void:
OS.window_size = Global.config_cache.get_value("window", "size")
func setup_translation_settings() -> void:
Global.loaded_locales = TranslationServer.get_loaded_locales()
# Make sure locales are always sorted, in the same order
Global.loaded_locales.sort()
# Load language
if Global.config_cache.has_section_key("preferences", "locale"):
var saved_locale : String = Global.config_cache.get_value("preferences", "locale")
TranslationServer.set_locale(saved_locale)
# Set the language option menu's default selected option to the loaded locale
var locale_index: int = Global.loaded_locales.find(saved_locale)
$PreferencesDialog.languages.get_child(0).pressed = false # Unset System Language option in preferences
$PreferencesDialog.languages.get_child(locale_index + 1).pressed = true
else: # If the user doesn't have a language preference, set it to their OS' locale
TranslationServer.set_locale(OS.get_locale())
if "zh" in TranslationServer.get_locale():
theme.default_font = preload("res://assets/fonts/CJK/NotoSansCJKtc-Regular.tres")
else:
theme.default_font = preload("res://assets/fonts/Roboto-Regular.tres")
func setup_file_menu() -> void:
var file_menu_items := {
"New..." : InputMap.get_action_list("new_file")[0].get_scancode_with_modifiers(),

View file

@ -12,7 +12,7 @@
[ext_resource path="res://src/UI/Dialogs/CreateNewImage.tscn" type="PackedScene" id=28]
[ext_resource path="res://src/UI/Dialogs/ImportSprites.tscn" type="PackedScene" id=29]
[ext_resource path="res://src/UI/Dialogs/ScaleImage.tscn" type="PackedScene" id=31]
[ext_resource path="res://src/UI/Dialogs/PreferencesDialog.tscn" type="PackedScene" id=32]
[ext_resource path="res://src/Preferences/PreferencesDialog.tscn" type="PackedScene" id=32]
[ext_resource path="res://src/UI/Dialogs/OutlineDialog.tscn" type="PackedScene" id=33]
[ext_resource path="res://src/UI/Dialogs/AboutDialog.tscn" type="PackedScene" id=34]
[ext_resource path="res://src/UI/Dialogs/RotateImage.tscn" type="PackedScene" id=38]

View file

@ -0,0 +1,59 @@
extends Node
func _ready() -> void:
Global.loaded_locales = TranslationServer.get_loaded_locales()
# Make sure locales are always sorted, in the same order
Global.loaded_locales.sort()
# Load language
if Global.config_cache.has_section_key("preferences", "locale"):
var saved_locale : String = Global.config_cache.get_value("preferences", "locale")
TranslationServer.set_locale(saved_locale)
# Set the language option menu's default selected option to the loaded locale
var locale_index: int = Global.loaded_locales.find(saved_locale)
get_child(0).pressed = false # Unset System Language option in preferences
get_child(locale_index + 1).pressed = true
else: # If the user doesn't have a language preference, set it to their OS' locale
TranslationServer.set_locale(OS.get_locale())
if "zh" in TranslationServer.get_locale():
Global.control.theme.default_font = preload("res://assets/fonts/CJK/NotoSansCJKtc-Regular.tres")
else:
Global.control.theme.default_font = preload("res://assets/fonts/Roboto-Regular.tres")
for child in get_children():
if child is Button:
child.connect("pressed", self, "_on_Language_pressed", [child])
child.hint_tooltip = child.name
func _on_Language_pressed(button : Button) -> void:
var index := 0
var i := -1
for child in get_children():
if child is Button:
if child == button:
button.pressed = true
index = i
else:
child.pressed = false
i += 1
if index == -1:
TranslationServer.set_locale(OS.get_locale())
else:
TranslationServer.set_locale(Global.loaded_locales[index])
if "zh" in TranslationServer.get_locale():
Global.control.theme.default_font = preload("res://assets/fonts/CJK/NotoSansCJKtc-Regular.tres")
else:
Global.control.theme.default_font = preload("res://assets/fonts/Roboto-Regular.tres")
Global.config_cache.set_value("preferences", "locale", TranslationServer.get_locale())
Global.config_cache.save("user://cache.ini")
# Update Translations
Global.update_hint_tooltips()
Global.preferences_dialog._on_PreferencesDialog_popup_hide()
Global.preferences_dialog._on_PreferencesDialog_about_to_show(true)

View file

@ -45,11 +45,6 @@ func _ready() -> void:
# Replace OK with Close since preference changes are being applied immediately, not after OK confirmation
get_ok().text = tr("Close")
for child in languages.get_children():
if child is Button:
child.connect("pressed", self, "_on_Language_pressed", [child])
child.hint_tooltip = child.name
for child in themes.get_children():
if child is Button:
child.connect("pressed", self, "_on_Theme_pressed", [child])
@ -261,36 +256,6 @@ func _on_SmoothZoom_pressed() -> void:
Global.config_cache.save("user://cache.ini")
func _on_Language_pressed(button : Button) -> void:
var index := 0
var i := -1
for child in languages.get_children():
if child is Button:
if child == button:
button.pressed = true
index = i
else:
child.pressed = false
i += 1
if index == -1:
TranslationServer.set_locale(OS.get_locale())
else:
TranslationServer.set_locale(Global.loaded_locales[index])
if "zh" in TranslationServer.get_locale():
Global.control.theme.default_font = preload("res://assets/fonts/CJK/NotoSansCJKtc-Regular.tres")
else:
Global.control.theme.default_font = preload("res://assets/fonts/Roboto-Regular.tres")
Global.config_cache.set_value("preferences", "locale", TranslationServer.get_locale())
Global.config_cache.save("user://cache.ini")
# Update Translations
Global.update_hint_tooltips()
_on_PreferencesDialog_popup_hide()
_on_PreferencesDialog_about_to_show(true)
func _on_Theme_pressed(button : Button) -> void:
var index := 0
var i := 0

View file

@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://src/UI/Dialogs/PreferencesDialog.gd" type="Script" id=1]
[ext_resource path="res://src/Preferences/PreferencesDialog.gd" type="Script" id=1]
[ext_resource path="res://assets/fonts/Roboto-Regular.tres" type="DynamicFont" id=2]
[ext_resource path="res://assets/fonts/CJK/NotoSansCJKtc-Regular.tres" type="DynamicFont" id=3]
[ext_resource path="res://src/Preferences/HandleLanguages.gd" type="Script" id=4]
[node name="PreferencesDialog" type="AcceptDialog"]
margin_left = -3.0
@ -194,6 +195,7 @@ __meta__ = {
margin_top = 184.0
margin_right = 494.0
margin_bottom = 632.0
script = ExtResource( 4 )
[node name="System Language" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"]
margin_right = 494.0