RetroDECK/tools/configurator/scripts/main.gd

267 lines
11 KiB
GDScript3
Raw Normal View History

2023-09-23 16:24:55 +00:00
extends Control
2024-09-01 18:49:04 +00:00
@onready var bios_type:int
2024-09-14 17:51:06 +00:00
var custom_theme: Theme
var log_option: OptionButton
var tab_container: TabContainer
var anim_logo: AnimatedSprite2D
var a_button_texture: Texture2D = load("res://assets/icons/kenney_input-prompts-pixel-16/Tiles/tile_0042.png")
var b_button_texture: Texture2D = load("res://assets/icons/kenney_input-prompts-pixel-16/Tiles/tile_0043.png")
2024-09-08 18:03:36 +00:00
var l1_button_texture: Texture2D = load("res://assets/icons/kenney_input-prompts-pixel-16/Tiles/tile_0797.png")
var r1_button_texture: Texture2D = load("res://assets/icons/kenney_input-prompts-pixel-16/Tiles/tile_0798.png")
2024-09-16 15:38:41 +00:00
var style_box_original: StyleBox = preload("res://assets/themes/default_theme.tres::StyleBoxFlat_0ahfc")
2024-08-24 10:39:56 +00:00
2024-09-10 14:33:58 +00:00
func _ready():
_get_nodes()
Theme and Theme Inheritance On branch feat/godot-configurator Changes to be committed: new file: tools/configurator/assets/fonts/OpenDyslexic3/OpenDyslexic3-Bold.ttf new file: tools/configurator/assets/fonts/OpenDyslexic3/OpenDyslexic3-Bold.ttf.import new file: tools/configurator/assets/fonts/OpenDyslexic3/OpenDyslexic3-Regular.ttf new file: tools/configurator/assets/fonts/OpenDyslexic3/OpenDyslexic3-Regular.ttf.import new file: tools/configurator/assets/fonts/akrobat/Akrobat-Black.otf new file: tools/configurator/assets/fonts/akrobat/Akrobat-Black.otf.import new file: tools/configurator/assets/fonts/akrobat/Akrobat-Bold.otf new file: tools/configurator/assets/fonts/akrobat/Akrobat-Bold.otf.import new file: tools/configurator/assets/fonts/akrobat/Akrobat-ExtraLight.otf new file: tools/configurator/assets/fonts/akrobat/Akrobat-ExtraLight.otf.import new file: tools/configurator/assets/fonts/akrobat/Akrobat-Light.otf new file: tools/configurator/assets/fonts/akrobat/Akrobat-Light.otf.import new file: tools/configurator/assets/fonts/akrobat/Akrobat-Regular.otf new file: tools/configurator/assets/fonts/akrobat/Akrobat-Regular.otf.import new file: tools/configurator/assets/fonts/akrobat/Akrobat-SemiBold.otf new file: tools/configurator/assets/fonts/akrobat/Akrobat-SemiBold.otf.import new file: tools/configurator/assets/fonts/akrobat/akrobat-extrabold-webfont.ttf new file: tools/configurator/assets/fonts/akrobat/akrobat-extrabold-webfont.ttf.import new file: tools/configurator/assets/fonts/munro/munro-narrow.ttf new file: tools/configurator/assets/fonts/munro/munro-narrow.ttf.import new file: tools/configurator/assets/fonts/munro/munro-small.ttf new file: tools/configurator/assets/fonts/munro/munro-small.ttf.import new file: tools/configurator/assets/fonts/munro/munro.ttf new file: tools/configurator/assets/fonts/munro/munro.ttf.import new file: tools/configurator/assets/graphics/Rekku/Rekku-test.xcf new file: tools/configurator/assets/graphics/Rekku/base.png new file: tools/configurator/assets/graphics/Rekku/base.png.import new file: tools/configurator/assets/graphics/Rekku/blink1.png new file: tools/configurator/assets/graphics/Rekku/blink1.png.import new file: tools/configurator/assets/graphics/Rekku/blink2.png new file: tools/configurator/assets/graphics/Rekku/blink2.png.import new file: tools/configurator/assets/graphics/Rekku/eyes-open.png new file: tools/configurator/assets/graphics/Rekku/eyes-open.png.import new file: tools/configurator/assets/graphics/Rekku/mouth-A.png new file: tools/configurator/assets/graphics/Rekku/mouth-A.png.import new file: tools/configurator/assets/graphics/Rekku/mouth-O.png new file: tools/configurator/assets/graphics/Rekku/mouth-O.png.import new file: tools/configurator/assets/graphics/Rekku/mouth-base.png new file: tools/configurator/assets/graphics/Rekku/mouth-base.png.import new file: tools/configurator/assets/graphics/Rekku/rekku-blink-down.png new file: tools/configurator/assets/graphics/Rekku/rekku-blink-down.png.import new file: tools/configurator/assets/graphics/Rekku/rekku-blink-up.png new file: tools/configurator/assets/graphics/Rekku/rekku-blink-up.png.import new file: tools/configurator/assets/graphics/Rekku/rekku-idle.png new file: tools/configurator/assets/graphics/Rekku/rekku-idle.png.import new file: tools/configurator/assets/graphics/Rekku/rekku-speak1.png new file: tools/configurator/assets/graphics/Rekku/rekku-speak1.png.import new file: tools/configurator/assets/graphics/Rekku/rekku-speak2.png new file: tools/configurator/assets/graphics/Rekku/rekku-speak2.png.import new file: tools/configurator/assets/graphics/retrodeck.png new file: tools/configurator/assets/graphics/retrodeck.png.import new file: tools/configurator/assets/themes/accesible_theme.tres new file: tools/configurator/assets/themes/default_theme.tres new file: tools/configurator/assets/themes/modern_theme.tres new file: tools/configurator/assets/themes/retro_theme.tres modified: tools/configurator/components/bios_check/bios_check.gd modified: tools/configurator/main.gd modified: tools/configurator/main.tscn modified: tools/configurator/res/pixel_ui_theme/RetroDECKTheme.tres
2024-07-28 18:44:07 +00:00
_connect_signals()
_play_main_animations()
2024-09-16 18:07:58 +00:00
_set_up_globals([])
2024-09-10 13:09:42 +00:00
%locale_option.selected = class_functions.map_locale_id(OS.get_locale_language())
2024-09-10 17:13:53 +00:00
%rd_title.text += class_functions.title
2024-09-08 18:03:36 +00:00
class_functions.logger("i","Started Godot configurator")
2024-09-11 18:23:05 +00:00
#class_functions.display_json_data()
# set current startup tab to match IDE
2024-08-19 19:07:25 +00:00
tab_container.current_tab = 0
#add_child(class_functions) # Needed for threaded results Not need autoload?
2023-12-31 07:58:20 +00:00
var children = findElements(self, "Control")
for n: Control in children: #iterate the children
2024-01-11 07:34:38 +00:00
if (n.focus_mode == FOCUS_ALL):
n.mouse_entered.connect(_on_control_mouse_entered.bind(n)) #grab focus on mouse hover
if (n.is_class("BaseButton") and n.disabled == true): #if button-like control and disabled
n.self_modulate.a = 0.5 #make it half transparent
2024-09-14 15:31:59 +00:00
#combine_tkeys()
2024-09-14 17:51:06 +00:00
change_font(class_functions.font_select)
2024-09-14 15:31:59 +00:00
2024-08-19 19:07:25 +00:00
func _input(event):
if Input.is_action_pressed("quit1") and Input.is_action_pressed("quit2"):
2024-09-06 11:40:29 +00:00
_exit()
2024-09-08 18:03:36 +00:00
if Input.is_action_pressed("next_tab"):
%r1_button.texture_normal = %r1_button.texture_pressed
elif Input.is_action_pressed("previous_tab"):
%l1_button.texture_normal = %l1_button.texture_pressed
elif Input.is_action_pressed("back_button"):
2024-08-19 19:07:25 +00:00
%b_button.texture_normal = %b_button.texture_pressed
elif Input.is_action_pressed("action_button"):
%a_button.texture_normal = %a_button.texture_pressed
else:
2024-09-08 18:03:36 +00:00
%r1_button.texture_normal = r1_button_texture
%l1_button.texture_normal = l1_button_texture
2024-08-19 19:07:25 +00:00
%a_button.texture_normal = a_button_texture
%b_button.texture_normal = b_button_texture
if event.is_action_pressed("quit"):
_exit()
2024-08-18 21:42:40 +00:00
2024-08-27 13:41:16 +00:00
func _exit():
2024-09-08 18:03:36 +00:00
class_functions.logger("i","Exited Godot configurator")
2024-08-27 13:41:16 +00:00
get_tree().root.propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST)
get_tree().quit()
func _get_nodes() -> void:
tab_container = get_node("%TabContainer")
anim_logo = get_node("%logo_animated")
log_option = get_node("%logs_button")
2024-09-13 17:27:07 +00:00
Theme and Theme Inheritance On branch feat/godot-configurator Changes to be committed: new file: tools/configurator/assets/fonts/OpenDyslexic3/OpenDyslexic3-Bold.ttf new file: tools/configurator/assets/fonts/OpenDyslexic3/OpenDyslexic3-Bold.ttf.import new file: tools/configurator/assets/fonts/OpenDyslexic3/OpenDyslexic3-Regular.ttf new file: tools/configurator/assets/fonts/OpenDyslexic3/OpenDyslexic3-Regular.ttf.import new file: tools/configurator/assets/fonts/akrobat/Akrobat-Black.otf new file: tools/configurator/assets/fonts/akrobat/Akrobat-Black.otf.import new file: tools/configurator/assets/fonts/akrobat/Akrobat-Bold.otf new file: tools/configurator/assets/fonts/akrobat/Akrobat-Bold.otf.import new file: tools/configurator/assets/fonts/akrobat/Akrobat-ExtraLight.otf new file: tools/configurator/assets/fonts/akrobat/Akrobat-ExtraLight.otf.import new file: tools/configurator/assets/fonts/akrobat/Akrobat-Light.otf new file: tools/configurator/assets/fonts/akrobat/Akrobat-Light.otf.import new file: tools/configurator/assets/fonts/akrobat/Akrobat-Regular.otf new file: tools/configurator/assets/fonts/akrobat/Akrobat-Regular.otf.import new file: tools/configurator/assets/fonts/akrobat/Akrobat-SemiBold.otf new file: tools/configurator/assets/fonts/akrobat/Akrobat-SemiBold.otf.import new file: tools/configurator/assets/fonts/akrobat/akrobat-extrabold-webfont.ttf new file: tools/configurator/assets/fonts/akrobat/akrobat-extrabold-webfont.ttf.import new file: tools/configurator/assets/fonts/munro/munro-narrow.ttf new file: tools/configurator/assets/fonts/munro/munro-narrow.ttf.import new file: tools/configurator/assets/fonts/munro/munro-small.ttf new file: tools/configurator/assets/fonts/munro/munro-small.ttf.import new file: tools/configurator/assets/fonts/munro/munro.ttf new file: tools/configurator/assets/fonts/munro/munro.ttf.import new file: tools/configurator/assets/graphics/Rekku/Rekku-test.xcf new file: tools/configurator/assets/graphics/Rekku/base.png new file: tools/configurator/assets/graphics/Rekku/base.png.import new file: tools/configurator/assets/graphics/Rekku/blink1.png new file: tools/configurator/assets/graphics/Rekku/blink1.png.import new file: tools/configurator/assets/graphics/Rekku/blink2.png new file: tools/configurator/assets/graphics/Rekku/blink2.png.import new file: tools/configurator/assets/graphics/Rekku/eyes-open.png new file: tools/configurator/assets/graphics/Rekku/eyes-open.png.import new file: tools/configurator/assets/graphics/Rekku/mouth-A.png new file: tools/configurator/assets/graphics/Rekku/mouth-A.png.import new file: tools/configurator/assets/graphics/Rekku/mouth-O.png new file: tools/configurator/assets/graphics/Rekku/mouth-O.png.import new file: tools/configurator/assets/graphics/Rekku/mouth-base.png new file: tools/configurator/assets/graphics/Rekku/mouth-base.png.import new file: tools/configurator/assets/graphics/Rekku/rekku-blink-down.png new file: tools/configurator/assets/graphics/Rekku/rekku-blink-down.png.import new file: tools/configurator/assets/graphics/Rekku/rekku-blink-up.png new file: tools/configurator/assets/graphics/Rekku/rekku-blink-up.png.import new file: tools/configurator/assets/graphics/Rekku/rekku-idle.png new file: tools/configurator/assets/graphics/Rekku/rekku-idle.png.import new file: tools/configurator/assets/graphics/Rekku/rekku-speak1.png new file: tools/configurator/assets/graphics/Rekku/rekku-speak1.png.import new file: tools/configurator/assets/graphics/Rekku/rekku-speak2.png new file: tools/configurator/assets/graphics/Rekku/rekku-speak2.png.import new file: tools/configurator/assets/graphics/retrodeck.png new file: tools/configurator/assets/graphics/retrodeck.png.import new file: tools/configurator/assets/themes/accesible_theme.tres new file: tools/configurator/assets/themes/default_theme.tres new file: tools/configurator/assets/themes/modern_theme.tres new file: tools/configurator/assets/themes/retro_theme.tres modified: tools/configurator/components/bios_check/bios_check.gd modified: tools/configurator/main.gd modified: tools/configurator/main.tscn modified: tools/configurator/res/pixel_ui_theme/RetroDECKTheme.tres
2024-07-28 18:44:07 +00:00
func _connect_signals() -> void:
#signal_theme_changed.connect(_conf_theme)
2024-09-14 17:51:06 +00:00
%font_optionbutton.item_selected.connect(change_font)
log_option.item_selected.connect(_load_log)
%borders_button.pressed.connect(_hide_show_buttons.bind(%borders_button,%borders_gridcontainer,%decorations_gridcontainer))
%button_layout.pressed.connect(_hide_show_buttons.bind(%button_layout,%borders_gridcontainer,%decorations_gridcontainer))
%decorations_save.pressed.connect(_hide_show_buttons.bind(%decorations_save,%decorations_save.get_parent(),null))
%decorations_button.pressed.connect(_hide_show_containers.bind(%decorations_button, %decorations_gridcontainer))
%systems_button.pressed.connect(_hide_show_containers.bind(%systems_button, %systems_gridcontainer))
2024-09-13 17:27:07 +00:00
class_functions.update_global_signal.connect(_set_up_globals)
func _load_log(index: int) -> void:
var log_content:String
match index:
1:
2024-09-08 18:03:36 +00:00
class_functions.logger("i","Loading RetroDeck log")
2024-09-06 21:41:28 +00:00
log_content = class_functions.import_text_file(class_functions.rd_log_folder +"/retrodeck.log")
load_popup("RetroDeck Log", "res://components/logs_view/logs_popup_content.tscn", log_content)
2:
2024-09-08 18:03:36 +00:00
class_functions.logger("i","Loading ES-DE log")
2024-09-06 21:41:28 +00:00
log_content = class_functions.import_text_file(class_functions.rd_log_folder +"/ES-DE/es_log.txt")
load_popup("ES-DE Log", "res://components/logs_view/logs_popup_content.tscn",log_content)
3:
2024-09-08 18:03:36 +00:00
class_functions.logger("i","Loading RetroArch log")
2024-09-06 21:41:28 +00:00
log_content = class_functions.import_text_file(class_functions.rd_log_folder +"/retroarch/logs/log.txt")
2024-09-14 15:31:59 +00:00
load_popup("Retroarch Log", "res://components/logs_view/logs_popup_content.tscn",log_content)
func _play_main_animations() -> void:
anim_logo.play()
func _hide_show_containers(button: Button, grid_container: GridContainer) -> void:
match button.name:
"decorations_button", "systems_button":
grid_container.visible = true
if button.toggle_mode:
button.toggle_mode=false
grid_container.visible = false
else:
button.toggle_mode=true
# TODO Pass GridContainer(might need 2?) as above
# TODO load existing settings or default to enable all
func _hide_show_buttons(button: Button, buttons_gridcontainer: GridContainer, hidden_gridcontainer: GridContainer) -> void:
match button.name:
"borders_button", "button_layout":
buttons_gridcontainer.visible = true
if button.toggle_mode == false:
for i in range(buttons_gridcontainer.get_child_count()):
var child = buttons_gridcontainer.get_child(i)
child.button_pressed=true
for i in range(hidden_gridcontainer.get_child_count()):
var child = hidden_gridcontainer.get_child(i)
if child is Button and child != button:
child.visible=false
elif button.toggle_mode == true and %borders_gridcontainer.visible == true:
buttons_gridcontainer.visible = false
#button.toggle_mode = false
for i in range(hidden_gridcontainer.get_child_count()):
var child = hidden_gridcontainer.get_child(i)
if child is Button:
child.visible=true
child.toggle_mode = false
button.toggle_mode = true
2024-08-19 19:07:25 +00:00
2023-12-31 07:58:20 +00:00
func findElements(node: Node, className: String, result: Array = []) -> Array:
if node.is_class(className):
result.push_back(node)
for child in node.get_children():
result = findElements(child, className, result)
return result
func _on_control_mouse_entered(control: Node):
control.grab_focus()
2024-01-11 18:19:16 +00:00
func load_popup(title:String, content_path:String, display_text: String):
2024-01-11 18:19:16 +00:00
var popup = load("res://components/popup.tscn").instantiate() as Control
popup.set_title(title)
popup.set_content(content_path)
popup.set_display_text(display_text)
2024-01-11 18:19:16 +00:00
$Background.add_child(popup)
2024-01-12 07:37:05 +00:00
func _on_bios_button_pressed():
_play_main_animations()
2024-09-01 18:49:04 +00:00
bios_type = 1
2024-09-08 18:03:36 +00:00
class_functions.logger("i","Bios Check")
load_popup("BIOS File Check", "res://components/bios_check/bios_popup_content.tscn","")
2024-09-01 18:49:04 +00:00
bios_type = 0
func _on_bios_button_expert_pressed():
_play_main_animations()
2024-09-01 18:49:04 +00:00
bios_type = 2
2024-09-08 18:03:36 +00:00
class_functions.logger("i","Advanced Bios Check")
load_popup("BIOS File Check", "res://components/bios_check/bios_popup_content.tscn","")
2024-09-01 18:49:04 +00:00
bios_type = 0
2024-01-12 07:37:05 +00:00
func _on_exit_button_pressed():
_play_main_animations()
2024-09-06 21:41:28 +00:00
_exit()
2024-09-09 13:32:18 +00:00
_exit()
2024-08-27 13:41:16 +00:00
2024-09-14 15:31:59 +00:00
#func _on_locale_selected(index):
#match index:
#0:
#TranslationServer.set_locale("en")
#_:
#TranslationServer.set_locale("en")
#combine_tkeys()
#func combine_tkeys(): #More as a test
#pass
2024-09-06 14:54:24 +00:00
#%cheats.text = tr("TK_CHEATS") + " " + tr("TK_SOON") # switched to access as a unique name as easier to refactor
#$Background/MarginContainer/TabContainer/TK_SYSTEM/ScrollContainer/VBoxContainer/HBoxContainer/GridContainer/cheats.text = tr("TK_CHEATS") + " " + tr("TK_SOON")
#%tate_mode.text = tr("TK_TATE") + " " + tr("TK_SOON")
#%hotkey_sound.text = tr("TK_HOTKEYSOUND") + " " + tr("TK_SOON")
#$Background/MarginContainer/TabContainer/TK_NETWORK/ScrollContainer/VBoxContainer/cheevos_container/cheevos_advanced_container/cheevos_hardcore.text = tr("TK_CHEEVOSHARDCORE") + " " + tr("TK_SOON")
#$Background/MarginContainer/TabContainer/TK_NETWORK/ScrollContainer/VBoxContainer/data_mng_container/saves_sync.text = tr("TK_SAVESSYNC") + " " + tr("TK_SOON")
#$Background/MarginContainer/TabContainer/TK_CONFIGURATOR/ScrollContainer/VBoxContainer/system_container/easter_eggs.text = tr("TK_EASTEREGGS") + " " + tr("TK_SOON")
2024-09-13 17:27:07 +00:00
2024-09-16 18:07:58 +00:00
func _set_up_globals(state: Array) -> void:
2024-09-17 11:19:48 +00:00
#TODO on initial run pass array date?
2024-09-17 13:29:38 +00:00
print (state)
2024-09-15 18:18:48 +00:00
%update_notification_button.button_pressed = class_functions.update_check
2024-09-16 15:38:41 +00:00
%quick_resume_button.button_pressed = class_functions.quick_resume_status
%retroarch_quick_resume_button.button_pressed = class_functions.quick_resume_status
%sound_button.button_pressed = class_functions.sound_effects
%volume_effects_slider.visible = class_functions.sound_effects
2024-09-17 16:30:36 +00:00
mixed_mode(%button_swap_button, class_functions.abxy_state)
mixed_mode(%ask_to_exit_button, class_functions.ask_to_exit_state)
mixed_mode(%border_button, class_functions.border_state)
mixed_mode(%widescreen_button, class_functions.widescreen_state)
#match class_functions.ask_to_exit_state:
#"true":
#%ask_to_exit_button.button_pressed = true
#%ask_to_exit_button.add_theme_stylebox_override("normal", style_box_original)
#"false":
#%ask_to_exit_button.button_pressed = false
#%ask_to_exit_button.add_theme_stylebox_override("normal", style_box_original)
#"mixed":
#mixed_status(%ask_to_exit_button)
#match class_functions.border_state:
#"true":
#%border_button.button_pressed = true
#%border_button.add_theme_stylebox_override("normal", style_box_original)
#"false":
#%border_button.button_pressed = false
#%border_button.add_theme_stylebox_override("normal", style_box_original)
#"mixed":
#mixed_status(%border_button)
#match class_functions.widescreen_state:
#"true":
#%widescreen_button.button_pressed = true
#%widescreen_button.add_theme_stylebox_override("normal", style_box_original)
#"false":
#%widescreen_button.button_pressed = false
#%widescreen_button.add_theme_stylebox_override("normal", style_box_original)
#"mixed":
#mixed_status(%widescreen_button)
func mixed_mode (button: Button, state: String) -> void:
match [class_functions.button_list]:
[class_functions.button_list]:
if state == "true":
button.button_pressed = true
button.add_theme_stylebox_override("normal", style_box_original)
elif state == "false":
button.button_pressed = false
button.add_theme_stylebox_override("normal", style_box_original)
elif state == "mixed":
mixed_status(button)
2024-09-17 11:19:48 +00:00
func mixed_status (button: Button) -> void:
button.button_pressed = false
button.toggle_mode = false
var style_box = StyleBoxFlat.new()
style_box.bg_color = Color(1, 0.54902, 0, 1)
style_box.border_color = Color(0.102, 0.624, 1, 1)
style_box.border_blend = true
style_box.corner_radius_top_left = 25
style_box.corner_radius_top_right = 25
style_box.corner_radius_bottom_right = 25
style_box.corner_radius_bottom_left = 25
style_box.border_width_left = 15
style_box.border_width_top = 15
style_box.border_width_right = 15
style_box.border_width_bottom = 15
button.add_theme_stylebox_override("normal", style_box)
2024-09-14 15:31:59 +00:00
2024-09-14 17:51:06 +00:00
func change_font(index: int) -> void:
var font_file: FontFile
2024-09-14 15:31:59 +00:00
match index:
1:
2024-09-14 17:51:06 +00:00
font_file = load("res://res/pixel_ui_theme/pixel-sans.otf")
2024-09-14 15:31:59 +00:00
2:
2024-09-14 17:51:06 +00:00
font_file = load("res://assets/fonts/munro/munro.ttf")
2024-09-14 15:31:59 +00:00
3:
2024-09-14 17:51:06 +00:00
font_file = load("res://assets/fonts/akrobat/Akrobat-Regular.otf")
2024-09-14 15:31:59 +00:00
4:
2024-09-14 17:51:06 +00:00
font_file = load("res://assets/fonts/OpenDyslexic3/OpenDyslexic3-Regular.ttf")
custom_theme = load("res://assets/themes/default_theme.tres")
custom_theme.set_font("font", "Control", font_file)
2024-09-14 15:31:59 +00:00
$".".theme = custom_theme
2024-09-14 17:51:06 +00:00
data_handler.change_cfg_value(class_functions.config_file_path, "font", "options", str(index))