remove overlay button now works

This commit is contained in:
Crispy 2021-06-02 15:27:56 +02:00
parent 39f34344cd
commit 33da1d0ff7
5 changed files with 26 additions and 8 deletions

View file

@ -15,7 +15,7 @@ export var add_grabbing := true # add grabbing module
export var add_cursor := false # add cursor module
# if this is exported, all overlays sync offset when a controller is turned off/on
# this seems to be a bug with the godot editor-
# this seems to be a bug with the godot editor
var _offsets:Dictionary = {
"head": {"pos": Vector3(0,0,-0.4), "rot": Quat()},
"left": {"pos": Vector3(), "rot": Quat()},
@ -24,7 +24,7 @@ var _offsets:Dictionary = {
}
# what's actually tracking
var current_target: String = "world" setget _set_current_target# most of the time the actual target, but will fall back
var current_target: String = "world" setget _set_current_target
var fallback = ["left", "right", "head"] # TODO setget that updates tracking (not important)
var interaction_handler: Node
var overlay_visible := true setget set_overlay_visible

View file

@ -25,12 +25,9 @@ func _load_overlays():
func add_overlay(type, name):
if type == "":
print("no type specified for overlay ", name)
return
var scene = load("res://overlays/" + type + ".tscn")
if scene == null:
print("Unknown overlay type: ", type, ". Skipping overlay \"", name, "\"")
if not scene:
print("Unknown overlay type: '", type, "'. Skipping overlay '", name, "'")
return
var instance = preload("res://addons/openvr_overlay/OverlayInstance.tscn").instance()
instance.name = name
@ -38,3 +35,14 @@ func add_overlay(type, name):
instance.type = type
add_child(instance)
emit_signal("added_overlay", name)
func remove_overlay(name):
var to_remove = get_node(name)
if not to_remove:
print("Could not remove overlay '", name, "'")
return
to_remove.queue_free()
emit_signal("removed_overlay", name)
Settings.s.overlays.erase(name)
Settings.save_settings()

View file

@ -3,6 +3,7 @@ extends Control
func _ready() -> void:
get_node("/root/Main/OverlayManager").connect("added_overlay", self, "_add_overlay_to_list")
get_node("/root/Main/OverlayManager").connect("removed_overlay", self, "_remove_overlay_from_list")
for o in Settings.s.overlays:
if o != "MainOverlay":
_add_overlay_to_list(o)
@ -14,6 +15,9 @@ func _add_overlay_to_list(name):
new.overlay_name = name
$VSplitContainer/Control/Overlays.add_child(new)
func _remove_overlay_from_list(name):
$VSplitContainer/Control/Overlays.get_node(name).queue_free()
func _on_GrabMode_toggled(state: bool) -> void:
Settings.s.grab_mode = state

View file

@ -40,7 +40,6 @@ margin_left = 952.0
margin_right = 1128.0
margin_bottom = 191.0
focus_mode = 0
toggle_mode = true
icon = ExtResource( 2 )
[node name="Reset" type="Button" parent="HBoxContainer"]
@ -86,6 +85,7 @@ toggle_mode = true
pressed = true
icon = ExtResource( 8 )
[connection signal="pressed" from="HBoxContainer/Remove" to="." method="_on_Remove_pressed"]
[connection signal="pressed" from="HBoxContainer/Reset" to="." method="_on_Reset_pressed"]
[connection signal="item_selected" from="HBoxContainer/Target" to="." method="_on_Target_item_selected"]
[connection signal="toggled" from="HBoxContainer/Grab" to="." method="_on_Grab_toggled"]

View file

@ -6,6 +6,7 @@ var overlay
func _ready() -> void:
overlay = get_node("/root/Main/OverlayManager").get_node(overlay_name)
$Label.text = overlay_name
name = overlay_name
$HBoxContainer/Target.selected = overlay.TARGETS.find(Settings.s.overlays[overlay_name].target)
overlay.connect("overlay_visibility_changed", self, "_overlay_visibility_changed")
@ -32,3 +33,8 @@ func _overlay_visibility_changed(state: bool):
$HBoxContainer/Visibility.icon = preload("res://icons/visible.svg")
else:
$HBoxContainer/Visibility.icon = preload("res://icons/hidden.svg")
func _on_Remove_pressed() -> void:
get_node("/root/Main/OverlayManager").remove_overlay(overlay_name)