This repository has been archived on 2023-12-19. You can view files and clone it, but cannot push or open issues or pull requests.
MUR/scripts/menus/settings_menu.gd

116 lines
3.2 KiB
GDScript

extends Control
onready var player_settings = find_node("settings_player")
onready var game_tab = find_node("game")
onready var controls_tab = find_node("controls")
onready var graphics_tab = find_node("graphics")
onready var system_tab = find_node("system")
var locale
func _ready():
get_node("menu/back").connect("pressed",self,"_on_back_pressed")
# game
find_node("bots").set_pressed(config.get_value("game","bots", true))
# graphics
find_node("fullscreen").set_pressed(config.get_value("graphics","fullscreen", true))
find_node("light").set_pressed(config.get_value("graphics","light", false))
find_node("shadows").set_pressed(config.get_value("graphics","shadows", false))
find_node("shadows").set_disabled(not find_node("light").is_pressed())
for resolution in config.RESOLUTIONS:
find_node("resolution").add_item(str(resolution.x) + " * " + str(resolution.y))
find_node("resolution").select(config.RESOLUTIONS.find(config.get_value("graphics","resolution", config.RESOLUTIONS[0])))
# system
find_node("server_addr").set_text(game_server.get_server_addr())
find_node("api_addr").set_text(game_server.get_api_addr())
_init_locales()
func _draw():
game_tab.grab_focus()
func _on_back_pressed():
queue_free()
get_tree().get_root().get_node("main_menu").show()
func _on_locales_item_selected(index):
match index:
0:
locale = "en"
1:
locale = "de"
_:
locale = "en"
TranslationServer.set_locale(locale)
game_tab.set_name(tr("GAME"))
controls_tab.set_name(tr("CONTROLS"))
graphics_tab.set_name(tr("GRAPHICS"))
system_tab.set_name(tr("SYSTEM"))
func _init_locales():
var locales = find_node("locales")
locales.clear()
locales.add_item(tr("LOCALE_EN"))
locales.add_item(tr("LOCALE_DE"))
locale = config.get_value("system","locale","en")
match locale:
"en":
locales.select(0)
_on_locales_item_selected(0)
"de":
locales.select(1)
_on_locales_item_selected(1)
func _on_locales_tree_exiting():
config_apply.apply_locale()
func _on_save_pressed():
_on_apply_pressed()
_on_back_pressed()
func _on_apply_pressed():
# game
config.set_value("game","player_name",player_settings.get_name_node().get_text())
config.set_value("game","player_color",player_settings.get_color_node().color)
config.set_value("game","bots",find_node("bots").is_pressed())
# graphics
config.set_value("graphics","resolution",config.RESOLUTIONS[find_node("resolution").get_selected()])
config.set_value("graphics","fullscreen",find_node("fullscreen").is_pressed())
config.set_value("graphics","light",find_node("light").is_pressed())
config.set_value("graphics","shadows",find_node("shadows").is_pressed())
# controls
config.set_value("controls","mapping",find_node("settings_controls").new_inputs)
# system
config.set_value("system","locale",locale)
var server_addr = find_node("server_addr").get_text()
if server_addr.empty():
server_addr = game_server.SERVER_ADDR
config.set_value("system","server_addr",server_addr)
var api_addr = find_node("api_addr").get_text()
if api_addr.empty():
api_addr = game_server.API_ADDR
config.set_value("system","api_addr",api_addr)
config.save()
config_apply.apply_settings()
func _on_light_toggled(button_pressed):
find_node("shadows").set_disabled(not button_pressed)