This commit is contained in:
Crispy 2021-05-26 13:30:38 +02:00
parent 0853b121b8
commit 3c216bf885
5 changed files with 66 additions and 36 deletions

View file

@ -59,15 +59,15 @@ func begin_move():
# store current states to revert after move
_pre_move_target = get_parent().current_target
_mover_hand_name = _active_controller
_mover_hand_offsets.pos = get_parent().offsets[_mover_hand_name].pos
_mover_hand_offsets.rot = get_parent().offsets[_mover_hand_name].rot
_mover_hand_offsets = get_parent().get_offset_dict(_mover_hand_name)
# calculate offsets from active controller to overlay
var controller_t = tracker_nodes[_active_controller].transform
var overlay_t = _overlay_area.global_transform
get_parent().offsets[_mover_hand_name].rot = Quat(controller_t.basis).inverse() * Quat(overlay_t.basis)
get_parent().offsets[_mover_hand_name].pos = controller_t.xform_inv(overlay_t.origin)
var new_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
@ -79,12 +79,10 @@ func finish_move():
var new_pos = new_target_t.xform_inv(ovelay_t.origin)
var new_rot = Quat(new_target_t.basis).inverse() * Quat(ovelay_t.basis)
get_parent().offsets[_pre_move_target].pos = new_pos
get_parent().offsets[_pre_move_target].rot = new_rot
get_parent().set_offset(_pre_move_target, new_pos, new_rot)
# 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().offsets[_mover_hand_name].rot = _mover_hand_offsets.rot
get_parent().set_offset_dict(_mover_hand_name, _mover_hand_offsets)
# reset current_target (parent handles fallback)
get_parent().update_current_target()

View file

@ -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
# 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()},
"left": {"pos": Vector3(), "rot": Quat()},
"right": {"pos": Vector3(), "rot": Quat()},
@ -22,7 +22,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 fallback = ["left", "right", "head"]
var fallback = ["left", "right", "head"] # TODO setget that updates tracking (not important)
var _tracker_id: int = 0
@ -41,7 +41,6 @@ func _ready() -> void:
container.add_child(overlay_scene.instance())
update_tracker_id()
update_offset()
emit_signal("target_changed")
set_notify_transform(true)
@ -58,14 +57,12 @@ func load_settings():
for t_key in Settings.s.overlays[name].offsets:
var t_offset = Settings.s.overlays[name].offsets[t_key]
offsets[t_key].pos = t_offset.pos
offsets[t_key].rot = t_offset.rot
_offsets[t_key].pos = t_offset.pos
_offsets[t_key].rot = t_offset.rot
update_offset()
else:
#TEMP defaults (remove when dragging any overlay is possible)
offsets[current_target].pos = translation
offsets[current_target].rot = transform.basis.get_rotation_quat()
update_offset()
set_offset(current_target, translation, transform.basis.get_rotation_quat())
####
Settings.s.overlays[name] = {}
@ -80,11 +77,8 @@ func save_settings():
if not Settings.s.overlays[name].has("offsets"):
Settings.s.overlays[name]["offsets"] = {}
for t_key in offsets:
if not Settings.s.overlays[name].offsets.has(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
for t_key in TARGETS:
Settings.s.overlays[name].offsets[t_key] = _offsets[t_key]
Settings.save_settings()
@ -106,8 +100,8 @@ func update_tracker_id() -> void:
func update_offset() -> void:
translation = offsets[current_target].pos
transform.basis = Basis(offsets[current_target].rot)
translation = _offsets[current_target].pos
transform.basis = Basis(_offsets[current_target].rot)
match current_target:
"head":
@ -148,6 +142,22 @@ func _set_current_target(new: String): # overrides target
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):
width_meters = width
$OverlayViewport.overlay_width_in_meters = width_meters

View file

@ -4,7 +4,7 @@ signal settings_saved
signal settings_loaded # emitted when settings are loaded from file, needs to be connected in _init()
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
var s: Dictionary = {}

View file

@ -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://fonts/OpenSans-Regular.ttf" type="DynamicFontData" id=2]
[sub_resource type="StyleBoxEmpty" id=3]
[sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0, 0, 0, 0.705882 )
expand_margin_left = 8.0
@ -23,26 +25,43 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="ColorRect" type="PanelContainer" parent="."]
[node name="PanelContainer" type="PanelContainer" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -673.0
margin_top = -87.5
margin_right = 673.0
margin_bottom = 87.5
margin_left = -199.0
margin_top = -94.5
margin_right = 199.0
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
custom_styles/panel = SubResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="ColorRect"]
margin_right = 1346.0
[node name="Label" type="Label" parent="PanelContainer/CenterContainer/ColorRect"]
margin_right = 384.0
margin_bottom = 175.0
size_flags_horizontal = 0
custom_fonts/font = SubResource( 2 )
text = "Left: 100% Right: 100%"
text = "L: 10%"
align = 1
script = ExtResource( 1 )
__meta__ = {

View file

@ -11,19 +11,22 @@ func _process(delta: float) -> void:
func update_text():
var l = "??"
var r = "??"
var l = ""
var r = ""
if OverlayInit.trackers.left != -1:
l = OverlayInit.ovr_config.get_device_battery_percentage(OverlayInit.trackers.left)
l = str(int(l * 100))
if OverlayInit.ovr_config.is_device_charging(OverlayInit.trackers.left):
l += "+"
l = "L: " + l + "%"
if OverlayInit.trackers.right != -1:
r = OverlayInit.ovr_config.get_device_battery_percentage(OverlayInit.trackers.right)
r = str(int(r * 100))
if OverlayInit.ovr_config.is_device_charging(OverlayInit.trackers.right):
r += "+"
r = "R: " + r + "%"
text = "L: " + l + "% R: " + r + "%"
text = l + " " + r