godot-third-person-basic-scene/scenes/languages/languages.gd

45 lines
1.3 KiB
GDScript3
Raw Normal View History

2022-02-12 19:45:44 +00:00
extends Control
# Called when the node enters the scene tree for the first time.
func _ready():
$Window/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/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/VBoxContainer/Select.add_item(TranslationServer.get_locale_name(key) + " (" + key + " !)", id)
selected = id
$Window/VBoxContainer/Select.select(selected)
func _on_select_item_selected(index):
var pos = 0
for key in TranslationServer.get_loaded_locales():
if pos == $Window/VBoxContainer/Select.get_selected():
TranslationServer.set_locale(key)
return
pos += 1
func _on_quit_pressed():
$Window.visible = false