Skip to content

Commit

Permalink
more or less finish up plugin, add demo, add icon
Browse files Browse the repository at this point in the history
  • Loading branch information
you-win committed Oct 10, 2021
1 parent d3191f3 commit cd9b9f7
Show file tree
Hide file tree
Showing 7 changed files with 512 additions and 57 deletions.
88 changes: 82 additions & 6 deletions addons/obs_websocket_gd/obs_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,28 @@ const STOP_RECORDING: String = "Stop Recording"

var obs_websocket

var scene_data: Dictionary = {} # String: ObsScene

var current_scene: String = "changeme"
onready var scenes: VBoxContainer = $VBoxContainer/HBoxContainer/Scenes

onready var sources: VBoxContainer = $VBoxContainer/HBoxContainer/Sources
enum ButtonType { NONE = 0, SCENE, SOURCE }

onready var source_items: HBoxContainer = $VBoxContainer/SourceItems
onready var render: CheckButton = $VBoxContainer/SourceItems/Render

onready var scenes: VBoxContainer = $VBoxContainer/HBoxContainer/Scenes/ScenesScroll/VBoxContainer
var scene_button_group := ButtonGroup.new()

onready var sources: VBoxContainer = $VBoxContainer/HBoxContainer/Sources/SourcesScroll/VBoxContainer
var source_button_group := ButtonGroup.new()

onready var connect_button: Button = $VBoxContainer/HBoxContainer/Websocket/Connect
var is_connection_established := false
onready var host_value: LineEdit = $VBoxContainer/HBoxContainer/Websocket/Host/Value
onready var port_value: LineEdit = $VBoxContainer/HBoxContainer/Websocket/Port/Value
onready var password_value: LineEdit = $VBoxContainer/HBoxContainer/Websocket/Password/Value

onready var refresh_data: Button = $VBoxContainer/HBoxContainer/Websocket/RefreshData

onready var stream: Button = $VBoxContainer/HBoxContainer/Controls/Stream
var is_streaming := false
Expand All @@ -41,9 +54,14 @@ func _ready():
# Setup connection values from script
host_value.text = obs_websocket.host
port_value.text = obs_websocket.port
password_value.text = obs_websocket.password

render.connect("toggled", self, "_on_source_item_toggled", [render.text])

connect_button.connect("pressed", self, "_on_connect_pressed")

refresh_data.connect("pressed", self, "_on_refresh_data_pressed")

stream.text = START_STREAMING
stream.connect("pressed", self, "_on_stream_pressed")

Expand All @@ -63,6 +81,7 @@ func _on_connect_pressed() -> void:

obs_websocket.host = host_value.text
obs_websocket.port = port_value.text
obs_websocket.password = password_value.text

match is_connection_established:
true:
Expand Down Expand Up @@ -103,22 +122,79 @@ func _on_obs_updated(obs_data: Dictionary) -> void:
func _on_obs_connected() -> void:
obs_websocket.get_scene_list()

func _on_refresh_data_pressed() -> void:
if obs_websocket.obs_client.get_connection_status() != WebSocketClient.CONNECTION_CONNECTED:
return
obs_websocket.get_scene_list()

func _on_obs_scene_list_returned(data) -> void:
print("asdf")
current_scene = data.current_scene

scene_data.clear()

for child in scenes.get_children():
child.queue_free()

for child in sources.get_children():
child.queue_free()

# We clear everything, so no source item will be selected
source_items.visible = false

for i in data.scenes:
var button := Button.new()
button.text = i.obs_name
scenes.call_deferred("add_child", button)
var scene_button := CheckButton.new()
scene_button.text = i.obs_name
if scene_button.text == current_scene:
scene_button.set_pressed_no_signal(true)
scene_button.group = scene_button_group
scene_button.connect("toggled", self, "_on_button_toggled_with_name", [scene_button.text, ButtonType.SCENE])
scenes.call_deferred("add_child", scene_button)

if i.obs_name == current_scene:
for j in i.sources:
_create_source_button(j.obs_name)

scene_data[i.obs_name] = i

func _on_source_item_toggled(button_pressed: bool, button_name: String) -> void:
match button_name:
"Render":
obs_websocket.send_command("SetSceneItemRender", {
"source": source_button_group.get_pressed_button().text,
"render": button_pressed
})
_:
print("Unhandled source item toggled")

func _on_button_toggled_with_name(button_pressed: bool, button_name: String, button_type: int) -> void:
# Buttons cannot be unpressed with a button group I guess, so just match positives
match button_type:
ButtonType.SCENE:
source_items.visible = false
obs_websocket.send_command("SetCurrentScene", {"scene-name": button_name})
for child in sources.get_children():
child.free()
for i in scene_data[button_name].sources:
_create_source_button(i.obs_name)
ButtonType.SOURCE:
source_items.visible = true
# I like to live dangerously
# If you remove items in OBS without refreshing data, you might null pointer?
for i in scene_data[scene_button_group.get_pressed_button().text].sources:
if i.obs_name == button_name:
render.set_pressed_no_signal(i.render)

###############################################################################
# Private functions #
###############################################################################

func _create_source_button(button_name: String) -> void:
var source_button := CheckButton.new()
source_button.text = button_name
source_button.group = source_button_group
source_button.connect("toggled", self, "_on_button_toggled_with_name", [source_button.text, ButtonType.SOURCE])
sources.call_deferred("add_child", source_button)

###############################################################################
# Public functions #
###############################################################################
172 changes: 138 additions & 34 deletions addons/obs_websocket_gd/obs_ui.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -18,100 +18,204 @@ margin_right = 1017.0
margin_bottom = 593.0

[node name="SourceItems" type="HBoxContainer" parent="VBoxContainer"]
visible = false
margin_right = 1010.0
margin_bottom = 82.0
margin_bottom = 40.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="Render" type="CheckButton" parent="VBoxContainer/SourceItems"]
margin_right = 125.0
margin_bottom = 40.0
text = "Render"

[node name="VSeparator" type="VSeparator" parent="VBoxContainer/SourceItems"]
margin_left = 129.0
margin_right = 133.0
margin_bottom = 40.0

[node name="HSeparator" type="HSeparator" parent="VBoxContainer"]
margin_top = 86.0
margin_right = 1010.0
margin_bottom = 90.0
margin_bottom = 4.0
mouse_filter = 2

[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 94.0
margin_top = 8.0
margin_right = 1010.0
margin_bottom = 586.0
size_flags_horizontal = 3
size_flags_vertical = 3
size_flags_stretch_ratio = 6.0

[node name="Scenes" type="VBoxContainer" parent="VBoxContainer/HBoxContainer"]
margin_right = 249.0
margin_bottom = 492.0
margin_right = 243.0
margin_bottom = 578.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/Scenes"]
margin_right = 243.0
margin_bottom = 14.0
text = "Scenes"
align = 1

[node name="ScenesScroll" type="ScrollContainer" parent="VBoxContainer/HBoxContainer/Scenes"]
margin_top = 18.0
margin_right = 243.0
margin_bottom = 578.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/HBoxContainer/Scenes/ScenesScroll"]
margin_right = 243.0
margin_bottom = 560.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="VSeparator" type="VSeparator" parent="VBoxContainer/HBoxContainer"]
margin_left = 247.0
margin_right = 251.0
margin_bottom = 578.0

[node name="Sources" type="VBoxContainer" parent="VBoxContainer/HBoxContainer"]
margin_left = 253.0
margin_right = 503.0
margin_bottom = 492.0
margin_left = 255.0
margin_right = 499.0
margin_bottom = 578.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/Sources"]
margin_right = 244.0
margin_bottom = 14.0
text = "Sources"
align = 1

[node name="SourcesScroll" type="ScrollContainer" parent="VBoxContainer/HBoxContainer/Sources"]
margin_top = 18.0
margin_right = 244.0
margin_bottom = 578.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/HBoxContainer/Sources/SourcesScroll"]
margin_right = 244.0
margin_bottom = 560.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="VSeparator2" type="VSeparator" parent="VBoxContainer/HBoxContainer"]
margin_left = 503.0
margin_right = 507.0
margin_bottom = 578.0

[node name="Controls" type="VBoxContainer" parent="VBoxContainer/HBoxContainer"]
margin_left = 507.0
margin_right = 756.0
margin_bottom = 492.0
margin_left = 511.0
margin_right = 754.0
margin_bottom = 578.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/Controls"]
margin_right = 243.0
margin_bottom = 14.0
text = "Controls"
align = 1

[node name="Stream" type="Button" parent="VBoxContainer/HBoxContainer/Controls"]
margin_right = 249.0
margin_bottom = 20.0
margin_top = 18.0
margin_right = 243.0
margin_bottom = 38.0
text = "Start Streaming"

[node name="Record" type="Button" parent="VBoxContainer/HBoxContainer/Controls"]
margin_top = 24.0
margin_right = 249.0
margin_bottom = 44.0
margin_top = 42.0
margin_right = 243.0
margin_bottom = 62.0
text = "Start Recording"

[node name="VSeparator3" type="VSeparator" parent="VBoxContainer/HBoxContainer"]
margin_left = 758.0
margin_right = 762.0
margin_bottom = 578.0

[node name="Websocket" type="VBoxContainer" parent="VBoxContainer/HBoxContainer"]
margin_left = 760.0
margin_left = 766.0
margin_right = 1010.0
margin_bottom = 492.0
margin_bottom = 578.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/Websocket"]
margin_right = 244.0
margin_bottom = 14.0
text = "OBS Websocket"
align = 1

[node name="Host" type="HBoxContainer" parent="VBoxContainer/HBoxContainer/Websocket"]
margin_right = 250.0
margin_bottom = 24.0
margin_top = 18.0
margin_right = 244.0
margin_bottom = 42.0

[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/Websocket/Host"]
margin_top = 5.0
margin_right = 123.0
margin_right = 120.0
margin_bottom = 19.0
size_flags_horizontal = 3
text = "Host:"

[node name="Value" type="LineEdit" parent="VBoxContainer/HBoxContainer/Websocket/Host"]
margin_left = 127.0
margin_right = 250.0
margin_left = 124.0
margin_right = 244.0
margin_bottom = 24.0
size_flags_horizontal = 3
text = "127.0.0.1"

[node name="Port" type="HBoxContainer" parent="VBoxContainer/HBoxContainer/Websocket"]
margin_top = 28.0
margin_right = 250.0
margin_bottom = 52.0
margin_top = 46.0
margin_right = 244.0
margin_bottom = 70.0

[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/Websocket/Port"]
margin_top = 5.0
margin_right = 123.0
margin_right = 120.0
margin_bottom = 19.0
size_flags_horizontal = 3
text = "Port:"

[node name="Value" type="LineEdit" parent="VBoxContainer/HBoxContainer/Websocket/Port"]
margin_left = 127.0
margin_right = 250.0
margin_left = 124.0
margin_right = 244.0
margin_bottom = 24.0
size_flags_horizontal = 3
text = "4444"

[node name="Password" type="HBoxContainer" parent="VBoxContainer/HBoxContainer/Websocket"]
margin_top = 74.0
margin_right = 244.0
margin_bottom = 98.0

[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/Websocket/Password"]
margin_top = 5.0
margin_right = 120.0
margin_bottom = 19.0
size_flags_horizontal = 3
text = "Port:"

[node name="Value" type="LineEdit" parent="VBoxContainer/HBoxContainer/Websocket/Password"]
margin_left = 124.0
margin_right = 244.0
margin_bottom = 24.0
size_flags_horizontal = 3
text = "password"
secret = true

[node name="Connect" type="Button" parent="VBoxContainer/HBoxContainer/Websocket"]
margin_top = 56.0
margin_right = 250.0
margin_bottom = 76.0
margin_top = 102.0
margin_right = 244.0
margin_bottom = 122.0
text = "Connect"

[node name="RefreshData" type="Button" parent="VBoxContainer/HBoxContainer/Websocket"]
margin_top = 126.0
margin_right = 244.0
margin_bottom = 146.0
text = "Refresh Data"
Loading

0 comments on commit cd9b9f7

Please sign in to comment.