RetroDECK/tools/configurator/scripts/TabSystem.gd

126 lines
6.3 KiB
GDScript3
Raw Permalink Normal View History

2024-08-27 13:41:16 +00:00
extends Control
var app_data := AppData.new()
2024-08-27 15:57:12 +00:00
var current_system := Emulator.new()
2024-09-05 11:32:13 +00:00
var press_time: float = 0.0
2024-09-05 14:11:02 +00:00
var is_reset_pressed: bool = false
var reset_result: Dictionary
2024-09-05 11:32:13 +00:00
@export var PRESS_DURATION: float = 3.0
2024-08-27 13:41:16 +00:00
func _ready():
app_data = data_handler.app_data
_connect_signals()
2024-09-05 11:32:13 +00:00
func _process(delta: float) -> void:
2024-09-05 14:11:02 +00:00
if is_reset_pressed:
press_time += delta
%reset_progress.value = press_time / PRESS_DURATION * 100.0
2024-09-05 11:32:13 +00:00
if press_time >= PRESS_DURATION:
_do_complete()
press_time = 0.0
2024-09-05 14:11:02 +00:00
is_reset_pressed = false
%reset_progress.value = 0.0
2024-09-05 11:32:13 +00:00
2024-08-27 13:41:16 +00:00
func _connect_signals() -> void:
2024-09-12 18:28:14 +00:00
#TODO make for loops for each function linked to button function call
2024-09-17 11:19:48 +00:00
# Change to follow hoe TabGlobals Works
2024-09-10 11:17:04 +00:00
%retroarch_button.pressed.connect(standard_buttons.bind(%retroarch_button,%system_gridcontainer, %action_gridcontainer))
%mame_button.pressed.connect(standard_buttons.bind(%mame_button,%system_gridcontainer, %action_gridcontainer))
%ruffle_button.pressed.connect(standard_buttons.bind(%ruffle_button,%system_gridcontainer, %action_gridcontainer))
%melonds_button.pressed.connect(standard_buttons.bind(%melonds_button,%system_gridcontainer, %action_gridcontainer))
%pcsx2_button.pressed.connect(standard_buttons.bind(%pcsx2_button,%system_gridcontainer, %action_gridcontainer))
%duckstation_button.pressed.connect(standard_buttons.bind(%duckstation_button,%system_gridcontainer, %action_gridcontainer))
%ppsspp_button.pressed.connect(standard_buttons.bind(%ppsspp_button,%system_gridcontainer, %action_gridcontainer))
%vita3k_button.pressed.connect(standard_buttons.bind(%vita3k_button,%system_gridcontainer, %action_gridcontainer))
%rpcs3_button.pressed.connect(standard_buttons.bind(%rpcs3_button,%system_gridcontainer, %action_gridcontainer))
%ryujinx_button.pressed.connect(standard_buttons.bind(%ryujinx_button,%system_gridcontainer, %action_gridcontainer))
%dolphin_button.pressed.connect(standard_buttons.bind(%dolphin_button,%system_gridcontainer, %action_gridcontainer))
%primehack_button.pressed.connect(standard_buttons.bind(%primehack_button,%system_gridcontainer, %action_gridcontainer))
2024-09-10 17:13:53 +00:00
%cemu_button.pressed.connect(standard_buttons.bind(%cemu_button,%system_gridcontainer, %action_gridcontainer))
%xemu_button.pressed.connect(standard_buttons.bind(%xemu_button,%system_gridcontainer, %action_gridcontainer))
%esde_button.pressed.connect(standard_buttons.bind(%esde_button,%system_gridcontainer, %action_gridcontainer))
2024-08-27 15:57:12 +00:00
%help_button.pressed.connect(_do_action.bind(%help_button))
2024-09-05 11:32:13 +00:00
#%launch_button.pressed.connect(_do_action.bind(%launch_button))
%launch_button.pressed.connect(_do_action.bind(%launch_button))
2024-09-05 14:11:02 +00:00
%reset_button.button_down.connect(_do_action.bind(%reset_button))
%reset_button.button_up.connect(_on_Button_released.bind(%reset_progress))
2024-09-10 11:17:04 +00:00
%rpcs3_firmware_button.pressed.connect(_do_action.bind(%rpcs3_firmware_button))
2024-09-10 14:33:58 +00:00
%vita3k_firmware_button.pressed.connect(_do_action.bind(%vita3k_firmware_button))
%retroarch_quick_resume_button.pressed.connect(class_functions.run_function.bind(%retroarch_quick_resume_button, "quick_resume"))
2024-09-10 14:33:58 +00:00
2024-09-10 11:17:04 +00:00
func standard_buttons(button: Button, buttons_gridcontainer: GridContainer, hidden_gridcontainer: GridContainer) -> void:
2024-08-27 15:57:12 +00:00
current_system = app_data.emulators[button.text.to_lower()]
2024-09-10 11:17:04 +00:00
%reset_button.text="RESET"
2024-08-27 13:41:16 +00:00
match button.name:
2024-09-10 14:33:58 +00:00
"vita3k_button":
%vita3k_firmware_button.visible = true
2024-09-10 11:17:04 +00:00
"rpcs3_button":
%rpcs3_firmware_button.visible = true
2024-09-12 18:28:14 +00:00
"retroarch_button":
%retroarch_quick_resume_button.visible = true
2024-09-10 11:17:04 +00:00
_:
2024-09-10 14:33:58 +00:00
%vita3k_firmware_button.visible = false
2024-09-10 11:17:04 +00:00
%rpcs3_firmware_button.visible = false
2024-09-12 18:28:14 +00:00
%retroarch_quick_resume_button.visible = false
2024-09-10 11:17:04 +00:00
hidden_gridcontainer.visible = true
if button.toggle_mode == false:
for i in range(buttons_gridcontainer.get_child_count()):
var child = buttons_gridcontainer.get_child(i)
if child is Button and child != button:
child.visible=false
elif button.toggle_mode == true and hidden_gridcontainer.visible == true:
hidden_gridcontainer.visible = false
for i in range(buttons_gridcontainer.get_child_count()):
var child = buttons_gridcontainer.get_child(i)
if child is Button:
child.visible=true
child.toggle_mode = false
if hidden_gridcontainer.visible == true:
button.toggle_mode = true
2024-08-27 15:57:12 +00:00
2024-09-05 14:11:02 +00:00
func _on_Button_released(progress: ProgressBar) -> void:
is_reset_pressed = false
2024-09-05 15:38:42 +00:00
%reset_progress.visible = false
2024-09-05 11:32:13 +00:00
press_time = 0.0
2024-09-05 14:11:02 +00:00
progress.value = 0.0
2024-09-05 11:32:13 +00:00
2024-08-27 15:57:12 +00:00
func _do_action(button: Button) -> void:
2024-09-16 15:38:41 +00:00
var original_txt = button.text
2024-08-27 15:57:12 +00:00
match [button.name, current_system.name]:
["help_button", current_system.name]:
2024-09-10 13:09:42 +00:00
if class_functions.desktop_mode != "gamescope":
2024-09-24 17:12:24 +00:00
print ("URL %s" %current_system.url)
2024-09-10 13:09:42 +00:00
class_functions.logger("i", "Launching " + current_system.name + " Help")
class_functions.launch_help(current_system.url)
else:
2024-09-12 18:28:14 +00:00
button.text = "Help only works in Desktop Mode"
2024-09-10 13:09:42 +00:00
await class_functions.wait(3.0)
2024-09-16 15:38:41 +00:00
button.text = original_txt
2024-08-27 15:57:12 +00:00
["launch_button", current_system.name]:
2024-09-08 18:03:36 +00:00
class_functions.logger("i", "Launching " + current_system.name)
2024-09-06 14:54:24 +00:00
var launch = class_functions.execute_command(current_system.launch,[], false)
2024-09-08 18:03:36 +00:00
class_functions.logger("d", "Exit Code: " + str(launch["exit_code"]))
2024-09-05 14:11:02 +00:00
["reset_button", current_system.name]:
is_reset_pressed = true
2024-09-05 15:38:42 +00:00
%reset_progress.visible = true
2024-09-10 11:17:04 +00:00
["rpcs3_firmware_button", current_system.name]:
class_functions.logger("i", "Firmware install " + current_system.name)
var launch = class_functions.execute_command(class_functions.wrapper_command,["update_rpcs3_firmware"], false)
class_functions.logger("d", "Exit Code: " + str(launch["exit_code"]))
2024-09-10 14:33:58 +00:00
["vita3k_firmware_button", current_system.name]:
class_functions.logger("i", "Firmware install " + current_system.name)
var launch = class_functions.execute_command(class_functions.wrapper_command,["update_vita3k_firmware"], false)
class_functions.logger("d", "Exit Code: " + str(launch["exit_code"]))
2024-09-05 11:32:13 +00:00
func _do_complete() ->void:
2024-09-05 14:11:02 +00:00
if is_reset_pressed:
2024-09-10 13:09:42 +00:00
var tmp_txt = %reset_button.text
2024-09-05 14:11:02 +00:00
%reset_button.text = "RESETTING-NOW"
2024-09-08 18:03:36 +00:00
class_functions.logger("i", "Resetting " + current_system.name)
var parameters = ["prepare_component","reset",current_system.name]
reset_result = await class_functions.run_thread_command(class_functions.wrapper_command,parameters, false)
class_functions.logger("d", "Exit Code: " + str(reset_result["exit_code"]))
2024-09-05 14:11:02 +00:00
%reset_button.text = "RESET COMPLETED"
2024-09-10 13:09:42 +00:00
await class_functions.wait(3.0)
%reset_button.text = tmp_txt