2023-12-15 22:44:25 +01:00
|
|
|
# (c) 2023-present Eroax
|
|
|
|
# (c) 2023-present Yagich
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
extends ConfirmationDialog
|
|
|
|
class_name OBSWebsocketSetupDialog
|
|
|
|
|
|
|
|
@onready var port_spin_box: SpinBox = %PortSpinBox
|
|
|
|
@onready var password_line_edit: LineEdit = %PasswordLineEdit
|
|
|
|
@onready var connect_button: Button = %ConnectButton
|
2024-02-26 12:37:57 +01:00
|
|
|
@onready var obsws_subscriptions_container: PanelContainer = $VBoxContainer/OBSWSSubscriptionsContainer
|
2023-12-15 22:44:25 +01:00
|
|
|
|
|
|
|
signal connect_button_pressed(state: ConnectionState)
|
|
|
|
|
|
|
|
enum ConnectionState {
|
|
|
|
DISCONNECTED,
|
|
|
|
CONNECTING,
|
|
|
|
CONNECTED,
|
|
|
|
}
|
|
|
|
var state: ConnectionState
|
|
|
|
|
2024-02-21 07:34:17 +01:00
|
|
|
@warning_ignore("narrowing_conversion")
|
2023-12-15 22:44:25 +01:00
|
|
|
@onready var _old_port: int = port_spin_box.value
|
|
|
|
@onready var _old_password: String = password_line_edit.text
|
2024-02-26 12:37:57 +01:00
|
|
|
@onready var _old_subscriptions: int = obsws_subscriptions_container.get_subscriptions()
|
2023-12-15 22:44:25 +01:00
|
|
|
|
2024-01-15 06:35:16 +01:00
|
|
|
|
2023-12-15 22:44:25 +01:00
|
|
|
func get_port() -> int:
|
|
|
|
return int(port_spin_box.value)
|
|
|
|
|
|
|
|
|
|
|
|
func get_password() -> String:
|
|
|
|
return password_line_edit.text
|
|
|
|
|
|
|
|
|
|
|
|
func set_button_state(p_state: ConnectionState) -> void:
|
|
|
|
connect_button.disabled = p_state == ConnectionState.CONNECTING
|
|
|
|
state = p_state
|
|
|
|
|
|
|
|
match p_state:
|
|
|
|
ConnectionState.DISCONNECTED:
|
|
|
|
connect_button.text = "Connect"
|
|
|
|
ConnectionState.CONNECTING:
|
|
|
|
connect_button.text = "Connecting..."
|
|
|
|
ConnectionState.CONNECTED:
|
2024-02-26 12:37:57 +01:00
|
|
|
Connections.save_credentials({
|
|
|
|
"port" : get_port(),
|
|
|
|
"password" : get_password(),
|
|
|
|
"subscriptions": obsws_subscriptions_container.get_subscriptions(),
|
|
|
|
}, "OBS")
|
2023-12-15 22:44:25 +01:00
|
|
|
connect_button.text = "Disconnect"
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
2024-01-15 06:35:16 +01:00
|
|
|
var loaded_creds = Connections.load_credentials("OBS")
|
|
|
|
|
|
|
|
if loaded_creds != null:
|
|
|
|
password_line_edit.text = loaded_creds.data.password
|
|
|
|
port_spin_box.value = loaded_creds.data.port
|
2024-02-26 12:37:57 +01:00
|
|
|
obsws_subscriptions_container.set_subscriptions(loaded_creds.data.subscriptions)
|
|
|
|
else:
|
|
|
|
obsws_subscriptions_container.set_subscriptions(NoOBSWS.Enums.EventSubscription.ALL)
|
|
|
|
|
2023-12-15 22:44:25 +01:00
|
|
|
connect_button.pressed.connect(
|
|
|
|
func():
|
2024-01-15 06:35:16 +01:00
|
|
|
|
2023-12-15 22:44:25 +01:00
|
|
|
connect_button_pressed.emit(state)
|
2024-01-15 06:35:16 +01:00
|
|
|
|
2023-12-15 22:44:25 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
canceled.connect(
|
|
|
|
func():
|
|
|
|
print("canceled")
|
|
|
|
port_spin_box.value = float(_old_port)
|
|
|
|
password_line_edit.text = _old_password
|
|
|
|
)
|
|
|
|
|
|
|
|
confirmed.connect(
|
|
|
|
func():
|
|
|
|
print("confirmed")
|
|
|
|
_old_port = int(port_spin_box.value)
|
|
|
|
_old_password = password_line_edit.text
|
|
|
|
)
|
2024-02-26 12:37:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
func get_subscriptions() -> int:
|
|
|
|
return obsws_subscriptions_container.get_subscriptions()
|