56 lines
1.6 KiB
GDScript
56 lines
1.6 KiB
GDScript
extends Control
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
$Window/NinePatchRect/V/H2/VBoxContainer/Select.clear()
|
|
var id = 0
|
|
var selected = -1
|
|
var near_selected = -1
|
|
var current_locale = TranslationServer.get_locale()
|
|
var root_language = current_locale.split('_')[0]
|
|
for key in TranslationServer.get_loaded_locales():
|
|
if key == TranslationServer.get_locale():
|
|
selected = id
|
|
else:
|
|
var tmp = key.split("_")
|
|
# print("tmp:" + tmp[0])
|
|
if tmp[0] == root_language:
|
|
if tmp.size() == 1:
|
|
near_selected = id
|
|
elif near_selected == -1:
|
|
near_selected = id
|
|
$Window/NinePatchRect/V/H2/VBoxContainer/Select.add_item(TranslationServer.get_locale_name(key) + " [" + key + "]", id)
|
|
id += 1
|
|
if selected == -1 and near_selected != -1:
|
|
selected = near_selected
|
|
if selected == -1:
|
|
# Your language not exist, create it just for the form
|
|
var key = TranslationServer.get_locale()
|
|
$Window/NinePatchRect/V/H2/VBoxContainer/Select.add_item(TranslationServer.get_locale_name(key) + " (" + key + " !)", id)
|
|
selected = id
|
|
$Window/NinePatchRect/V/H2/VBoxContainer/Select.select(selected)
|
|
|
|
|
|
func _on_select_item_selected(_index):
|
|
var pos = 0
|
|
for key in TranslationServer.get_loaded_locales():
|
|
if pos == $Window/NinePatchRect/V/H2/VBoxContainer/Select.get_selected():
|
|
TranslationServer.set_locale(key)
|
|
return
|
|
pos += 1
|
|
|
|
|
|
func _on_quit_pressed():
|
|
$Window.set_visible(false)
|
|
|
|
|
|
func show_window():
|
|
Common.msg_debug("+ Open windows languages")
|
|
$Window.show_window()
|
|
#.visible = true
|
|
|
|
|
|
|
|
func _on_window_old_visibility_changed():
|
|
if $Window.visible:
|
|
$WindowOld/VBoxContainer/Quit.grab_focus()
|