mirror of
https://github.com/CrispyPin/ovr-utils.git
synced 2024-11-22 07:30:25 +01:00
cleanup
This commit is contained in:
parent
0853b121b8
commit
3c216bf885
5 changed files with 66 additions and 36 deletions
|
@ -59,15 +59,15 @@ func begin_move():
|
||||||
# store current states to revert after move
|
# store current states to revert after move
|
||||||
_pre_move_target = get_parent().current_target
|
_pre_move_target = get_parent().current_target
|
||||||
_mover_hand_name = _active_controller
|
_mover_hand_name = _active_controller
|
||||||
_mover_hand_offsets.pos = get_parent().offsets[_mover_hand_name].pos
|
_mover_hand_offsets = get_parent().get_offset_dict(_mover_hand_name)
|
||||||
_mover_hand_offsets.rot = get_parent().offsets[_mover_hand_name].rot
|
|
||||||
|
|
||||||
# calculate offsets from active controller to overlay
|
# calculate offsets from active controller to overlay
|
||||||
var controller_t = tracker_nodes[_active_controller].transform
|
var controller_t = tracker_nodes[_active_controller].transform
|
||||||
var overlay_t = _overlay_area.global_transform
|
var overlay_t = _overlay_area.global_transform
|
||||||
|
|
||||||
get_parent().offsets[_mover_hand_name].rot = Quat(controller_t.basis).inverse() * Quat(overlay_t.basis)
|
var new_pos = controller_t.xform_inv(overlay_t.origin)
|
||||||
get_parent().offsets[_mover_hand_name].pos = controller_t.xform_inv(overlay_t.origin)
|
var new_rot = Quat(controller_t.basis).inverse() * Quat(overlay_t.basis)
|
||||||
|
get_parent().set_offset(_mover_hand_name, new_pos, new_rot)
|
||||||
|
|
||||||
get_parent().current_target = _mover_hand_name
|
get_parent().current_target = _mover_hand_name
|
||||||
|
|
||||||
|
@ -79,12 +79,10 @@ func finish_move():
|
||||||
|
|
||||||
var new_pos = new_target_t.xform_inv(ovelay_t.origin)
|
var new_pos = new_target_t.xform_inv(ovelay_t.origin)
|
||||||
var new_rot = Quat(new_target_t.basis).inverse() * Quat(ovelay_t.basis)
|
var new_rot = Quat(new_target_t.basis).inverse() * Quat(ovelay_t.basis)
|
||||||
get_parent().offsets[_pre_move_target].pos = new_pos
|
get_parent().set_offset(_pre_move_target, new_pos, new_rot)
|
||||||
get_parent().offsets[_pre_move_target].rot = new_rot
|
|
||||||
|
|
||||||
# revert the grabbing hands offsets in case it's used as a fallback
|
# revert the grabbing hands offsets in case it's used as a fallback
|
||||||
get_parent().offsets[_mover_hand_name].pos = _mover_hand_offsets.pos
|
get_parent().set_offset_dict(_mover_hand_name, _mover_hand_offsets)
|
||||||
get_parent().offsets[_mover_hand_name].rot = _mover_hand_offsets.rot
|
|
||||||
|
|
||||||
# reset current_target (parent handles fallback)
|
# reset current_target (parent handles fallback)
|
||||||
get_parent().update_current_target()
|
get_parent().update_current_target()
|
||||||
|
|
|
@ -13,7 +13,7 @@ export var width_meters = 0.4 setget set_width_in_meters
|
||||||
|
|
||||||
# if this is exported, all overlays sync offset when a controller is turned off/on
|
# 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 = {
|
var _offsets:Dictionary = {
|
||||||
"head": {"pos": Vector3(0,0,-0.4), "rot": Quat()},
|
"head": {"pos": Vector3(0,0,-0.4), "rot": Quat()},
|
||||||
"left": {"pos": Vector3(), "rot": Quat()},
|
"left": {"pos": Vector3(), "rot": Quat()},
|
||||||
"right": {"pos": Vector3(), "rot": Quat()},
|
"right": {"pos": Vector3(), "rot": Quat()},
|
||||||
|
@ -22,7 +22,7 @@ var offsets:Dictionary = {
|
||||||
|
|
||||||
# what's actually tracking
|
# 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# most of the time the actual target, but will fall back
|
||||||
var fallback = ["left", "right", "head"]
|
var fallback = ["left", "right", "head"] # TODO setget that updates tracking (not important)
|
||||||
|
|
||||||
var _tracker_id: int = 0
|
var _tracker_id: int = 0
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ func _ready() -> void:
|
||||||
container.add_child(overlay_scene.instance())
|
container.add_child(overlay_scene.instance())
|
||||||
|
|
||||||
update_tracker_id()
|
update_tracker_id()
|
||||||
update_offset()
|
|
||||||
emit_signal("target_changed")
|
emit_signal("target_changed")
|
||||||
set_notify_transform(true)
|
set_notify_transform(true)
|
||||||
|
|
||||||
|
@ -58,14 +57,12 @@ func load_settings():
|
||||||
|
|
||||||
for t_key in Settings.s.overlays[name].offsets:
|
for t_key in Settings.s.overlays[name].offsets:
|
||||||
var t_offset = Settings.s.overlays[name].offsets[t_key]
|
var t_offset = Settings.s.overlays[name].offsets[t_key]
|
||||||
offsets[t_key].pos = t_offset.pos
|
_offsets[t_key].pos = t_offset.pos
|
||||||
offsets[t_key].rot = t_offset.rot
|
_offsets[t_key].rot = t_offset.rot
|
||||||
update_offset()
|
update_offset()
|
||||||
else:
|
else:
|
||||||
#TEMP defaults (remove when dragging any overlay is possible)
|
#TEMP defaults (remove when dragging any overlay is possible)
|
||||||
offsets[current_target].pos = translation
|
set_offset(current_target, translation, transform.basis.get_rotation_quat())
|
||||||
offsets[current_target].rot = transform.basis.get_rotation_quat()
|
|
||||||
update_offset()
|
|
||||||
####
|
####
|
||||||
|
|
||||||
Settings.s.overlays[name] = {}
|
Settings.s.overlays[name] = {}
|
||||||
|
@ -80,11 +77,8 @@ func save_settings():
|
||||||
if not Settings.s.overlays[name].has("offsets"):
|
if not Settings.s.overlays[name].has("offsets"):
|
||||||
Settings.s.overlays[name]["offsets"] = {}
|
Settings.s.overlays[name]["offsets"] = {}
|
||||||
|
|
||||||
for t_key in offsets:
|
for t_key in TARGETS:
|
||||||
if not Settings.s.overlays[name].offsets.has(t_key):
|
Settings.s.overlays[name].offsets[t_key] = _offsets[t_key]
|
||||||
Settings.s.overlays[name].offsets[t_key] = {}
|
|
||||||
Settings.s.overlays[name].offsets[t_key].pos = offsets[t_key].pos
|
|
||||||
Settings.s.overlays[name].offsets[t_key].rot = offsets[t_key].rot
|
|
||||||
Settings.save_settings()
|
Settings.save_settings()
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,8 +100,8 @@ func update_tracker_id() -> void:
|
||||||
|
|
||||||
|
|
||||||
func update_offset() -> void:
|
func update_offset() -> void:
|
||||||
translation = offsets[current_target].pos
|
translation = _offsets[current_target].pos
|
||||||
transform.basis = Basis(offsets[current_target].rot)
|
transform.basis = Basis(_offsets[current_target].rot)
|
||||||
|
|
||||||
match current_target:
|
match current_target:
|
||||||
"head":
|
"head":
|
||||||
|
@ -148,6 +142,22 @@ func _set_current_target(new: String): # overrides target
|
||||||
emit_signal("target_changed")
|
emit_signal("target_changed")
|
||||||
|
|
||||||
|
|
||||||
|
func get_offset_dict(offset_target: String) -> Dictionary:
|
||||||
|
return _offsets[offset_target].duplicate()
|
||||||
|
|
||||||
|
|
||||||
|
func set_offset_dict(offset_target: String, new: Dictionary) -> void:
|
||||||
|
_offsets[offset_target].pos = new.pos
|
||||||
|
_offsets[offset_target].rot = new.rot
|
||||||
|
update_offset()
|
||||||
|
|
||||||
|
|
||||||
|
func set_offset(offset_target: String, pos: Vector3, rot: Quat) -> void:
|
||||||
|
_offsets[offset_target].pos = pos
|
||||||
|
_offsets[offset_target].rot = rot
|
||||||
|
update_offset()
|
||||||
|
|
||||||
|
|
||||||
func set_width_in_meters(width: float):
|
func set_width_in_meters(width: float):
|
||||||
width_meters = width
|
width_meters = width
|
||||||
$OverlayViewport.overlay_width_in_meters = width_meters
|
$OverlayViewport.overlay_width_in_meters = width_meters
|
||||||
|
|
|
@ -4,7 +4,7 @@ signal settings_saved
|
||||||
signal settings_loaded # emitted when settings are loaded from file, needs to be connected in _init()
|
signal settings_loaded # emitted when settings are loaded from file, needs to be connected in _init()
|
||||||
|
|
||||||
var DEBUG_SETTINGS = false
|
var DEBUG_SETTINGS = false
|
||||||
var SETTINGS_PATH = "user://settings.json"
|
var SETTINGS_PATH = "user://overlay_data.json"
|
||||||
const SETTINGS_DEF = preload("res://addons/settings-manager/settings_definition.gd").DEF
|
const SETTINGS_DEF = preload("res://addons/settings-manager/settings_definition.gd").DEF
|
||||||
|
|
||||||
var s: Dictionary = {}
|
var s: Dictionary = {}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
[gd_scene load_steps=5 format=2]
|
[gd_scene load_steps=6 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://overlays/battery.gd" type="Script" id=1]
|
[ext_resource path="res://overlays/battery.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://fonts/OpenSans-Regular.ttf" type="DynamicFontData" id=2]
|
[ext_resource path="res://fonts/OpenSans-Regular.ttf" type="DynamicFontData" id=2]
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxEmpty" id=3]
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id=1]
|
[sub_resource type="StyleBoxFlat" id=1]
|
||||||
bg_color = Color( 0, 0, 0, 0.705882 )
|
bg_color = Color( 0, 0, 0, 0.705882 )
|
||||||
expand_margin_left = 8.0
|
expand_margin_left = 8.0
|
||||||
|
@ -23,26 +25,43 @@ __meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="ColorRect" type="PanelContainer" parent="."]
|
[node name="PanelContainer" type="PanelContainer" parent="."]
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
anchor_top = 0.5
|
anchor_top = 0.5
|
||||||
anchor_right = 0.5
|
anchor_right = 0.5
|
||||||
anchor_bottom = 0.5
|
anchor_bottom = 0.5
|
||||||
margin_left = -673.0
|
margin_left = -199.0
|
||||||
margin_top = -87.5
|
margin_top = -94.5
|
||||||
margin_right = 673.0
|
margin_right = 199.0
|
||||||
margin_bottom = 87.5
|
margin_bottom = 94.5
|
||||||
|
grow_horizontal = 2
|
||||||
|
custom_styles/panel = SubResource( 3 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="CenterContainer" type="CenterContainer" parent="PanelContainer"]
|
||||||
|
margin_right = 398.0
|
||||||
|
margin_bottom = 189.0
|
||||||
|
|
||||||
|
[node name="ColorRect" type="PanelContainer" parent="PanelContainer/CenterContainer"]
|
||||||
|
margin_left = 7.0
|
||||||
|
margin_top = 7.0
|
||||||
|
margin_right = 391.0
|
||||||
|
margin_bottom = 182.0
|
||||||
|
grow_horizontal = 2
|
||||||
size_flags_horizontal = 0
|
size_flags_horizontal = 0
|
||||||
custom_styles/panel = SubResource( 1 )
|
custom_styles/panel = SubResource( 1 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="ColorRect"]
|
[node name="Label" type="Label" parent="PanelContainer/CenterContainer/ColorRect"]
|
||||||
margin_right = 1346.0
|
margin_right = 384.0
|
||||||
margin_bottom = 175.0
|
margin_bottom = 175.0
|
||||||
|
size_flags_horizontal = 0
|
||||||
custom_fonts/font = SubResource( 2 )
|
custom_fonts/font = SubResource( 2 )
|
||||||
text = "Left: 100% Right: 100%"
|
text = "L: 10%"
|
||||||
align = 1
|
align = 1
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
|
|
|
@ -11,19 +11,22 @@ func _process(delta: float) -> void:
|
||||||
|
|
||||||
|
|
||||||
func update_text():
|
func update_text():
|
||||||
var l = "??"
|
var l = ""
|
||||||
var r = "??"
|
var r = ""
|
||||||
|
|
||||||
if OverlayInit.trackers.left != -1:
|
if OverlayInit.trackers.left != -1:
|
||||||
l = OverlayInit.ovr_config.get_device_battery_percentage(OverlayInit.trackers.left)
|
l = OverlayInit.ovr_config.get_device_battery_percentage(OverlayInit.trackers.left)
|
||||||
l = str(int(l * 100))
|
l = str(int(l * 100))
|
||||||
if OverlayInit.ovr_config.is_device_charging(OverlayInit.trackers.left):
|
if OverlayInit.ovr_config.is_device_charging(OverlayInit.trackers.left):
|
||||||
l += "+"
|
l += "+"
|
||||||
|
l = "L: " + l + "%"
|
||||||
|
|
||||||
|
|
||||||
if OverlayInit.trackers.right != -1:
|
if OverlayInit.trackers.right != -1:
|
||||||
r = OverlayInit.ovr_config.get_device_battery_percentage(OverlayInit.trackers.right)
|
r = OverlayInit.ovr_config.get_device_battery_percentage(OverlayInit.trackers.right)
|
||||||
r = str(int(r * 100))
|
r = str(int(r * 100))
|
||||||
if OverlayInit.ovr_config.is_device_charging(OverlayInit.trackers.right):
|
if OverlayInit.ovr_config.is_device_charging(OverlayInit.trackers.right):
|
||||||
r += "+"
|
r += "+"
|
||||||
|
r = "R: " + r + "%"
|
||||||
|
|
||||||
text = "L: " + l + "% R: " + r + "%"
|
text = l + " " + r
|
||||||
|
|
Loading…
Reference in a new issue