-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add defaults in Project Settings - Add user settings system to save user preference - By default have turn movement adhere to user/system settings - Add user setting for player height adjustment
- Loading branch information
1 parent
6a9390f
commit b01e7f6
Showing
14 changed files
with
466 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
extends Node | ||
|
||
# our settings | ||
export var snap_turning : bool = true | ||
export var player_height_adjust : float = 0.0 setget set_player_height_adjust | ||
|
||
var settings_file_name = "user://xtools_user_settings.json" | ||
|
||
func set_player_height_adjust(new_value : float) -> void: | ||
player_height_adjust = clamp(new_value, -1.0, 1.0) | ||
|
||
|
||
func reset_to_defaults(): | ||
# Reset to defaults | ||
snap_turning = XRTools.get_default_snap_turning() | ||
player_height_adjust = 0.0 | ||
|
||
|
||
func _load(): | ||
# First reset our values | ||
reset_to_defaults() | ||
|
||
# Now attempt to load our settings file | ||
var file = File.new() | ||
if !file.file_exists(settings_file_name): | ||
return | ||
|
||
if file.open(settings_file_name, File.READ): | ||
var text = file.get_as_text() | ||
file.close() | ||
|
||
var data : Dictionary = parse_json(text) | ||
|
||
# Parse our input settings | ||
if data.has("input"): | ||
var input : Dictionary = data["input"] | ||
if input.has("default_snap_turning"): | ||
snap_turning = input["default_snap_turning"] | ||
|
||
# Parse our player settings | ||
if data.has("player"): | ||
var player : Dictionary = data["player"] | ||
if player.has("height_adjust"): | ||
player_height_adjust = player["height_adjust"] | ||
|
||
func save(): | ||
var data = { | ||
"input" : { | ||
"default_snap_turning" : snap_turning | ||
}, | ||
"player" : { | ||
"height_adjust" : player_height_adjust | ||
} | ||
} | ||
|
||
var file = File.new() | ||
if file.open(settings_file_name, File.WRITE): | ||
file.store_line(to_json(data)) | ||
file.close() | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
_load() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
extends TabContainer | ||
|
||
export (NodePath) var camera | ||
export var player_head_height : float = 0.1 | ||
|
||
func _update(): | ||
# Input | ||
$Input/SnapTurning/SnapTurningCB.pressed = XRToolsUserSettings.snap_turning | ||
|
||
# Player | ||
$Player/PlayerHeight/PlayerHeightSlider.value = XRToolsUserSettings.player_height_adjust | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
if XRToolsUserSettings: | ||
_update() | ||
else: | ||
$Save/Button.disabled = true | ||
|
||
|
||
func _on_Save_pressed(): | ||
if XRToolsUserSettings: | ||
# Save | ||
XRToolsUserSettings.save() | ||
|
||
|
||
func _on_Reset_pressed(): | ||
if XRToolsUserSettings: | ||
XRToolsUserSettings.reset_to_defaults() | ||
_update() | ||
|
||
# Input settings changed | ||
func _on_SnapTurningCB_pressed(): | ||
XRToolsUserSettings.snap_turning = $Input/SnapTurning/SnapTurningCB.pressed | ||
|
||
# Player settings changed | ||
func _on_PlayerHeightSlider_drag_ended(value_changed): | ||
XRToolsUserSettings.player_height_adjust = $Player/PlayerHeight/PlayerHeightSlider.value | ||
|
||
|
||
func _on_PlayerHeightStandard_pressed(): | ||
if !camera: | ||
return | ||
|
||
var camera_node = get_node_or_null(camera) | ||
if !camera_node: | ||
return | ||
|
||
var base_height = camera_node.transform.origin.y + player_head_height | ||
var height_adjust = XRTools.get_player_standard_height() - base_height | ||
XRToolsUserSettings.player_height_adjust = height_adjust | ||
$Player/PlayerHeight/PlayerHeightSlider.value = XRToolsUserSettings.player_height_adjust | ||
|
||
|
Oops, something went wrong.