Skip to content

Commit

Permalink
Separate XRay and Protrusion transparency, tweak render queue to forc…
Browse files Browse the repository at this point in the history
…e xray behind protrusions, rename sliders, remove dead code
  • Loading branch information
acidbubbles committed Jul 19, 2022
1 parent f08ed47 commit 60b87d7
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 113 deletions.
106 changes: 70 additions & 36 deletions src/ColliderEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class ColliderEditor : MVRScript
private const string _collidersSavePath = "Saves\\PluginData\\ColliderEditor";

private JSONStorableBool _showPreviewsJSON;
private JSONStorableBool _xRayPreviewsJSON;
private JSONStorableStringChooser _presetsJson;
private JSONStorableStringChooser _groupsJson;
private JSONStorableStringChooser _typesJson;
Expand Down Expand Up @@ -102,40 +101,6 @@ private void BuildUI()
var showPreviewsToggle = CreateToggle(_showPreviewsJSON);
showPreviewsToggle.label = "Show Previews";

_xRayPreviewsJSON = new JSONStorableBool("xRayPreviews", ColliderPreviewConfig.DefaultXRayPreviews, value =>
{
Config.XRayPreviews = value;
foreach (var editable in EditablesList.All)
editable.UpdatePreviewsFromConfig();
});
RegisterBool(_xRayPreviewsJSON);
var xRayPreviewsToggle = CreateToggle(_xRayPreviewsJSON);
xRayPreviewsToggle.label = "Use XRay Previews";

var previewOpacityJSON = new JSONStorableFloat("previewOpacity", ColliderPreviewConfig.DefaultPreviewsOpacity, value =>
{
if (!insideRestore) _showPreviewsJSON.val = true;
var alpha = value.ExponentialScale(ColliderPreviewConfig.ExponentialScaleMiddle, 1f);
Config.PreviewsOpacity = alpha;
foreach (var editable in EditablesList.All)
editable.UpdatePreviewsFromConfig();
}, 0f, 1f);
RegisterFloat(previewOpacityJSON);
CreateSlider(previewOpacityJSON).label = "Preview Opacity";

var selectedPreviewOpacityJSON = new JSONStorableFloat("selectedPreviewOpacity", ColliderPreviewConfig.DefaultSelectedPreviewOpacity, value =>
{
if (!insideRestore) _showPreviewsJSON.val = true;
var alpha = value.ExponentialScale(ColliderPreviewConfig.ExponentialScaleMiddle, 1f);
Config.SelectedPreviewsOpacity = alpha;
if (_selected != null)
_selected.UpdatePreviewsFromConfig();
if (_selectedMirror != null)
_selectedMirror.UpdatePreviewsFromConfig();
}, 0f, 1f);
RegisterFloat(selectedPreviewOpacityJSON);
CreateSlider(selectedPreviewOpacityJSON).label = "Selected Preview Opacity";

var loadPresetUI = CreateButton("Load Preset");
loadPresetUI.button.onClick.AddListener(() =>
{
Expand Down Expand Up @@ -223,6 +188,76 @@ private void BuildUI()
CreateTextInput(_textFilterJson, false);
#endif

var previewXRayOpacityJSON = new JSONStorableFloat("previewOpacityXRay", ColliderPreviewConfig.DefaultPreviewXRayOpacity, value =>
{
if (!insideRestore) _showPreviewsJSON.val = true;
var alpha = value.ExponentialScale(ColliderPreviewConfig.ExponentialScaleMiddle, 1f);
Config.PreviewsXRayOpacity = alpha;
foreach (var editable in EditablesList.All)
editable.UpdatePreviewsFromConfig();
}, 0f, 1f);
RegisterFloat(previewXRayOpacityJSON);
CreateSlider(previewXRayOpacityJSON).label = "Preview Opacity (XRay)";

var previewProtrusionsOpacityJSON = new JSONStorableFloat("previewOpacityProtrusions", ColliderPreviewConfig.DefaultPreviewProtrusionsOpacity, value =>
{
if (!insideRestore) _showPreviewsJSON.val = true;
var alpha = value.ExponentialScale(ColliderPreviewConfig.ExponentialScaleMiddle, 1f);
Config.PreviewsProtrusionsOpacity = alpha;
foreach (var editable in EditablesList.All)
editable.UpdatePreviewsFromConfig();
}, 0f, 1f);
RegisterFloat(previewProtrusionsOpacityJSON);
CreateSlider(previewProtrusionsOpacityJSON).label = "Preview Opacity (Protrusions)";

/*
var previewXRayRenderQueueJSON = new JSONStorableFloat("previewRenderQueueXRay", 3001, (float value) =>
{
if (!insideRestore) _showPreviewsJSON.val = true;
Config.PreviewsXRayRenderQueue = (int)value;
foreach (var editable in EditablesList.All)
editable.UpdatePreviewsFromConfig();
}, 0, 5000);
RegisterFloat(previewXRayRenderQueueJSON);
CreateSlider(previewXRayRenderQueueJSON).label = "Preview RenderQueue (XRay)";
var previewProtrusionsRenderQueueJSON = new JSONStorableFloat("previewRenderQueueProtrusions", 3002, (float value) =>
{
if (!insideRestore) _showPreviewsJSON.val = true;
Config.PreviewsProtrusionsRenderQueue = (int)value;
foreach (var editable in EditablesList.All)
editable.UpdatePreviewsFromConfig();
}, 0f, 5000);
RegisterFloat(previewProtrusionsRenderQueueJSON);
CreateSlider(previewProtrusionsRenderQueueJSON).label = "Preview RenderQueue (Protrusions)";
*/

var selectedPreviewXRayOpacityJSON = new JSONStorableFloat("selectedPreviewOpacity", ColliderPreviewConfig.DefaultSelectedPreviewsXRayOpacity, value =>
{
if (!insideRestore) _showPreviewsJSON.val = true;
var alpha = value.ExponentialScale(ColliderPreviewConfig.ExponentialScaleMiddle, 1f);
Config.SelectedPreviewsXRayOpacity = alpha;
if (_selected != null)
_selected.UpdatePreviewsFromConfig();
if (_selectedMirror != null)
_selectedMirror.UpdatePreviewsFromConfig();
}, 0f, 1f);
RegisterFloat(selectedPreviewXRayOpacityJSON);
CreateSlider(selectedPreviewXRayOpacityJSON).label = "Selected Preview Opacity (XRay)";

var selectedPreviewProtrusionsOpacityJSON = new JSONStorableFloat("selectedPreviewOpacity", ColliderPreviewConfig.DefaultSelectedPreviewsProtrusionsOpacity, value =>
{
if (!insideRestore) _showPreviewsJSON.val = true;
var alpha = value.ExponentialScale(ColliderPreviewConfig.ExponentialScaleMiddle, 1f);
Config.SelectedPreviewsProtrusionsOpacity = alpha;
if (_selected != null)
_selected.UpdatePreviewsFromConfig();
if (_selectedMirror != null)
_selectedMirror.UpdatePreviewsFromConfig();
}, 0f, 1f);
RegisterFloat(selectedPreviewProtrusionsOpacityJSON);
CreateSlider(selectedPreviewProtrusionsOpacityJSON).label = "Selected Preview Opacity (Protrusions)";

var syncSymmetryJSON = new JSONStorableBool("autoSyncSymmetry", ColliderPreviewConfig.DefaultSyncSymmetry, value =>
{
Config.SyncSymmetry = value;
Expand Down Expand Up @@ -643,7 +678,6 @@ private void OnBlur(JSONStorableStringChooser except)
public void OnBindingsListRequested(List<object> bindings)
{
bindings.Add(new JSONStorableAction("Toggle_ShowPreviews", () => _showPreviewsJSON.val = !_showPreviewsJSON.val));
bindings.Add(new JSONStorableAction("Toggle_XRayPreviews", () => _xRayPreviewsJSON.val = !_xRayPreviewsJSON.val));
}

private void LogError(string method, string message) => SuperController.LogError($"{nameof(ColliderEditor)}.{method}: {message}");
Expand Down
18 changes: 10 additions & 8 deletions src/ColliderPreviewConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ public class ColliderPreviewConfig
public const float ExponentialScaleMiddle = 0.1f;

public const bool DefaultPreviewsEnabled = false;
public const bool DefaultXRayPreviews = true;
public const float DefaultPreviewsOpacity = 0.5f;
public const float DefaultSelectedPreviewOpacity = 1.0f;
public const float DefaultRelativeXRayOpacity = 0.5f;
public const float DefaultPreviewProtrusionsOpacity = 0.4f;
public const float DefaultPreviewXRayOpacity = 0.1f;
public const float DefaultSelectedPreviewsProtrusionsOpacity = 0.9f;
public const float DefaultSelectedPreviewsXRayOpacity = 0.7f;
public const bool DefaultSyncSymmetry = false;

public bool PreviewsEnabled { get; set; } = DefaultPreviewsEnabled;
public bool XRayPreviews { get; set; } = DefaultXRayPreviews;
public bool SyncSymmetry { get; set; } = DefaultSyncSymmetry;
public float PreviewsOpacity { get; set; } = DefaultPreviewsOpacity.ExponentialScale(ExponentialScaleMiddle, 1f);
public float SelectedPreviewsOpacity { get; set; } = DefaultSelectedPreviewOpacity.ExponentialScale(ExponentialScaleMiddle, 1f);
public float RelativeXRayOpacity { get; set; } = DefaultRelativeXRayOpacity;
public float PreviewsProtrusionsOpacity { get; set; } = DefaultPreviewProtrusionsOpacity.ExponentialScale(ExponentialScaleMiddle, 1f);
public int PreviewsProtrusionsRenderQueue = 3002;
public int PreviewsXRayRenderQueue = 3001;
public float PreviewsXRayOpacity { get; set; } = DefaultPreviewXRayOpacity.ExponentialScale(ExponentialScaleMiddle, 1f);
public float SelectedPreviewsProtrusionsOpacity { get; set; } = DefaultSelectedPreviewsProtrusionsOpacity.ExponentialScale(ExponentialScaleMiddle, 1f);
public float SelectedPreviewsXRayOpacity { get; set; } = DefaultSelectedPreviewsXRayOpacity.ExponentialScale(ExponentialScaleMiddle, 1f);
}
2 changes: 1 addition & 1 deletion src/Models/BoxColliderModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override bool SyncOverrides()

public override void SyncPreviews()
{
SyncPreview(Preview);
SyncPreview(ProtrusionPreview);
SyncPreview(XRayPreview);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Models/CapsuleColliderModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected override void DoResetToInitial()

public override void SyncPreviews()
{
SyncPreview(Preview);
SyncPreview(ProtrusionPreview);
SyncPreview(XRayPreview);
}

Expand Down
Loading

0 comments on commit 60b87d7

Please sign in to comment.