Exemple #1
0
    public void Show()
    {
        CreateText(new JSONStorableString("", "Export all settings so you can easily re-use them in other scenes or on other atoms.\n\nMake Default will save your settings so that whenever you load this plugin on a new atom, the parameters will be automatically applied.\n\nTo clear your height and body proportions from this instance, e.g. before making a scene public, use Clear Personal Data."), true);

        CreateTitle("Import / Export", true);
        var loadPresetUI = CreateButton("Import Profile...", true);

        loadPresetUI.button.onClick.AddListener(() =>
        {
            FileManagerSecure.CreateDirectory(SaveFormat.SaveFolder);
            var shortcuts = FileManagerSecure.GetShortCutsForDirectory(SaveFormat.SaveFolder);
            SuperController.singleton.GetMediaPathDialog(_storage.LoadProfile, SaveFormat.SaveExt, SaveFormat.SaveFolder, false, true, false, null, false, shortcuts);
        });

        var savePresetUI = CreateButton("Export Profile...", true);

        savePresetUI.button.onClick.AddListener(() =>
        {
            FileManagerSecure.CreateDirectory(SaveFormat.SaveFolder);
            var fileBrowserUI = SuperController.singleton.fileBrowserUI;
            fileBrowserUI.SetTitle("Save Embody Profile");
            fileBrowserUI.fileRemovePrefix            = null;
            fileBrowserUI.hideExtension               = false;
            fileBrowserUI.keepOpen                    = false;
            fileBrowserUI.fileFormat                  = SaveFormat.SaveExt;
            fileBrowserUI.defaultPath                 = SaveFormat.SaveFolder;
            fileBrowserUI.showDirs                    = true;
            fileBrowserUI.shortCuts                   = null;
            fileBrowserUI.browseVarFilesAsDirectories = false;
            fileBrowserUI.SetTextEntry(true);
            fileBrowserUI.Show(_storage.SaveProfile);
            fileBrowserUI.ActivateFileNameField();
        });

        CreateSpacer(true).height = 40f;
        CreateTitle("Default Profile", true);

        var makeDefaults = CreateButton("Save As Default Profile", true);

        makeDefaults.button.onClick.AddListener(_storage.MakeDefault);

        var applyDefaults = CreateButton("Load Default Profile", true);

        applyDefaults.button.onClick.AddListener(() => context.embody.LoadFromDefaults());

        var clearDefaults = CreateButton("Delete Default Profile", true);

        clearDefaults.button.onClick.AddListener(() => FileManagerSecure.DeleteFile(SaveFormat.DefaultsPath));

        CreateSpacer(true).height = 40f;
        CreateTitle("Clear Data", true);

        CreateButton("Clear Personal Data From Plugin", true).button.onClick.AddListener(_storage.ClearPersonalData);
        CreateButton("Reset To Built-In Defaults", true).button.onClick.AddListener(() => Utilities.ResetToDefaults(context));
    }
Exemple #2
0
 private void Import()
 {
     try
     {
         FileManagerSecure.CreateDirectory(_saveFolder);
         var shortcuts = FileManagerSecure.GetShortCutsForDirectory(_saveFolder);
         SuperController.singleton.GetMediaPathDialog(ImportFileSelected, _saveExt, _saveFolder, false, true, false, null, false, shortcuts);
     }
     catch (Exception exc)
     {
         SuperController.LogError($"VamTimeline: Failed to open file dialog: {exc}");
     }
 }
Exemple #3
0
    private void InitPresetUI()
    {
        var loadPresetUI = CreateButton("Load Preset", false);

        loadPresetUI.button.onClick.AddListener(() => {
            FileManagerSecure.CreateDirectory(_saveFolder);
            var shortcuts = FileManagerSecure.GetShortCutsForDirectory(_saveFolder);
            SuperController.singleton.GetMediaPathDialog((string path) => {
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }
                JSONClass jc = (JSONClass)LoadJSON(path);
                RestoreFromJSON(jc);
                SyncSelectedAnchorJSON("");
                SyncHandsOffset();
            }, _saveExt, _saveFolder, false, true, false, null, false, shortcuts);
        });

        var savePresetUI = CreateButton("Save Preset", false);

        savePresetUI.button.onClick.AddListener(() => {
            FileManagerSecure.CreateDirectory(_saveFolder);
            var fileBrowserUI = SuperController.singleton.fileBrowserUI;
            fileBrowserUI.SetTitle("Save colliders preset");
            fileBrowserUI.fileRemovePrefix            = null;
            fileBrowserUI.hideExtension               = false;
            fileBrowserUI.keepOpen                    = false;
            fileBrowserUI.fileFormat                  = _saveExt;
            fileBrowserUI.defaultPath                 = _saveFolder;
            fileBrowserUI.showDirs                    = true;
            fileBrowserUI.shortCuts                   = null;
            fileBrowserUI.browseVarFilesAsDirectories = false;
            fileBrowserUI.SetTextEntry(true);
            fileBrowserUI.Show((string path) => {
                fileBrowserUI.fileFormat = null;
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }
                if (!path.ToLower().EndsWith($".{_saveExt}"))
                {
                    path += $".{_saveExt}";
                }
                var jc = GetJSON();
                jc.Remove("id");
                SaveJSON(jc, path);
            });
            fileBrowserUI.ActivateFileNameField();
        });
    }
    public void OpenImportDialog(bool clear)
    {
        var shortcuts = FileManagerSecure.GetShortCutsForDirectory(_saveFolder);

        SuperController.singleton.GetMediaPathDialog(path =>
        {
            Import(clear, path);
        },
                                                     _saveExt,
                                                     _saveFolder,
                                                     true,
                                                     true,
                                                     false,
                                                     null,
                                                     false,
                                                     shortcuts);
    }
Exemple #5
0
    public void Show()
    {
        CreateText(new JSONStorableString("", "Export all settings so you can easily re-use them in other scenes or on other atoms."), true);

        var loadPresetUI = CreateButton("Import", true);

        loadPresetUI.button.onClick.AddListener(() =>
        {
            FileManagerSecure.CreateDirectory(SaveFormat.SaveFolder);
            var shortcuts = FileManagerSecure.GetShortCutsForDirectory(SaveFormat.SaveFolder);
            SuperController.singleton.GetMediaPathDialog(LoadCallback, SaveFormat.SaveExt, SaveFormat.SaveFolder, false, true, false, null, false, shortcuts);
        });

        var savePresetUI = CreateButton("Export", true);

        savePresetUI.button.onClick.AddListener(() =>
        {
            FileManagerSecure.CreateDirectory(SaveFormat.SaveFolder);
            var fileBrowserUI = SuperController.singleton.fileBrowserUI;
            fileBrowserUI.SetTitle("Save Embody preset");
            fileBrowserUI.fileRemovePrefix            = null;
            fileBrowserUI.hideExtension               = false;
            fileBrowserUI.keepOpen                    = false;
            fileBrowserUI.fileFormat                  = SaveFormat.SaveExt;
            fileBrowserUI.defaultPath                 = SaveFormat.SaveFolder;
            fileBrowserUI.showDirs                    = true;
            fileBrowserUI.shortCuts                   = null;
            fileBrowserUI.browseVarFilesAsDirectories = false;
            fileBrowserUI.SetTextEntry(true);
            fileBrowserUI.Show(SaveCallback);
            fileBrowserUI.ActivateFileNameField();
        });

        var makeDefaults = CreateButton("Make Default (Saves)", true);

        makeDefaults.button.onClick.AddListener(MakeDefault);

        var clearDefaults = CreateButton("Clear Default (Saves)", true);

        clearDefaults.button.onClick.AddListener(() => FileManagerSecure.DeleteFile(SaveFormat.DefaultsPath));

        var clearPersonalData = CreateButton("Clear Personal Data (Plugin)", true);

        clearPersonalData.button.onClick.AddListener(() => ClearPersonalData());
    }
    public PluginReference(MVRScript plugin)
    {
        _plugin       = plugin;
        _selectButton = plugin.CreateButton("Browse...");
        _labelJSON.setCallbackFunction            = val => _selectButton.label = string.IsNullOrEmpty(_labelJSON.val) ? "Browse..." : _labelJSON.val;
        _pluginJSON.beginBrowseWithObjectCallback = jsu => { jsu.shortCuts = FileManagerSecure.GetShortCutsForDirectory("Custom/Scripts", true, true, true, true); };
        _pluginJSON.setCallbackFunction           = val =>
        {
            if (string.IsNullOrEmpty(val))
            {
                return;
            }
            SyncLabel(val);
            onChange.Invoke();
        };
        _pluginJSON.fileBrowseButton = _selectButton.button;

        _removeButton = plugin.CreateButton("Remove", true);
        _removeButton.button.onClick.AddListener(() => onRemove.Invoke());
        _removeButton.textColor   = Color.white;
        _removeButton.buttonColor = Color.red;
    }
Exemple #7
0
        public void LoadModifier(int flags)
        {
            FileManagerSecure.CreateDirectory(Utilities.PresetSavePath);
            var shortcuts = FileManagerSecure.GetShortCutsForDirectory(
                Utilities.PresetSavePath);

            SuperController.singleton.GetMediaPathDialog(
                (string path) =>
            {
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                Synergy.Instance.Manager.LoadPreset(
                    path, Utilities.ModifierPreset | flags);

                Synergy.Instance.UI.NeedsReset("modifier preset loaded");
            },
                Utilities.ModifierPresetExtension, Utilities.PresetSavePath,
                false, true, false, null, false, shortcuts);
        }
Exemple #8
0
    public override void Init()
    {
        try
        {
            if (containingAtom.type == "SessionPluginManager" || containingAtom.type == "CoreControl")
            {
                SuperController.LogError("Embody: Cannot run as a session or scene plugin");
                CreateTextField(new JSONStorableString("Error", "Embody cannot run as a session or scene plugin. Please add it to a Person atom, or an Empty."));
                enabled = false;
                return;
            }

            activeJSON = new JSONStorableBool("Active", false)
            {
                isStorable = false
            };
            activateOnLoadJSON = new JSONStorableBool("ActivateOnLoad", false)
            {
                isStorable = true
            };
            RegisterBool(activateOnLoadJSON);
            returnToSpawnPoint = new JSONStorableStringChooser("ReturnToSpawnPoint", new List <string>(), "", "Return To Spawn Point")
            {
                popupOpenCallback = SyncSpawnPointAtoms
            };
            SyncSpawnPointAtoms();
            RegisterStringChooser(returnToSpawnPoint);

            var isPerson = containingAtom.type == "Person";

            _scaleChangeReceiver = gameObject.AddComponent <EmbodyScaleChangeReceiver>();

            _modules = new GameObject();
            _modules.transform.SetParent(transform, false);
            _modules.SetActive(false);

            _context = new EmbodyContext(this, this);

            var diagnosticsModule  = CreateModule <DiagnosticsModule>(_context);
            var automationModule   = CreateModule <AutomationModule>(_context);
            var worldScaleModule   = CreateModule <WorldScaleModule>(_context);
            var hideGeometryModule = isPerson ? CreateModule <HideGeometryModule>(_context) : null;
            var offsetCameraModule = isPerson ? CreateModule <OffsetCameraModule>(_context) : null;
            var passengerModule    = CreateModule <PassengerModule>(_context);
            var trackersModule     = isPerson ? CreateModule <TrackersModule>(_context) : null;
            var snugModule         = isPerson ? CreateModule <SnugModule>(_context) : null;
            var eyeTargetModule    = isPerson ? CreateModule <EyeTargetModule>(_context) : null;
            var wizardModule       = isPerson ? CreateModule <WizardModule>(_context) : null;

            _context.diagnostics  = diagnosticsModule;
            _context.automation   = automationModule;
            _context.worldScale   = worldScaleModule;
            _context.hideGeometry = hideGeometryModule;
            _context.offsetCamera = offsetCameraModule;
            _context.passenger    = passengerModule;
            _context.trackers     = trackersModule;
            _context.snug         = snugModule;
            _context.eyeTarget    = eyeTargetModule;
            _context.wizard       = wizardModule;

            if (_scaleChangeReceiver != null)
            {
                _context.scaleChangeReceiver = _scaleChangeReceiver;
                _scaleChangeReceiver.context = _context;
                containingAtom.RegisterDynamicScaleChangeReceiver(_scaleChangeReceiver);
            }

            _modules.SetActive(true);

            presetsJSON = InitPresets();
            RegisterStringChooser(presetsJSON);

            _context.automation.enabledJSON.val = true;

            _screensManager = new ScreensManager();
            _screensManager.Add(MainScreen.ScreenName, new MainScreen(_context, _modulesList));
            if (isPerson)
            {
                _screensManager.Add(TrackersSettingsScreen.ScreenName, new TrackersSettingsScreen(_context, trackersModule));
                _screensManager.Add(PassengerSettingsScreen.ScreenName, new PassengerSettingsScreen(_context, passengerModule));
                _screensManager.Add(SnugSettingsScreen.ScreenName, new SnugSettingsScreen(_context, snugModule));
                _screensManager.Add(HideGeometrySettingsScreen.ScreenName, new HideGeometrySettingsScreen(_context, hideGeometryModule));
                _screensManager.Add(OffsetCameraSettingsScreen.ScreenName, new OffsetCameraSettingsScreen(_context, offsetCameraModule));
                _screensManager.Add(WorldScaleSettingsScreen.ScreenName, new WorldScaleSettingsScreen(_context, worldScaleModule));
                _screensManager.Add(EyeTargetSettingsScreen.ScreenName, new EyeTargetSettingsScreen(_context, eyeTargetModule));
                _screensManager.Add(WizardScreen.ScreenName, new WizardScreen(_context, wizardModule));
                _screensManager.Add(ProfilesScreen.ScreenName, new ProfilesScreen(_context));
                _screensManager.Add(MoreScreen.ScreenName, new MoreScreen(_context));
                _screensManager.Add(DiagnosticsScreen.ScreenName, new DiagnosticsScreen(_context, diagnosticsModule));
            }
            else
            {
                _screensManager.Add(PassengerSettingsScreen.ScreenName, new PassengerSettingsScreen(_context, passengerModule));
                _screensManager.Add(WorldScaleSettingsScreen.ScreenName, new WorldScaleSettingsScreen(_context, worldScaleModule));
                _screensManager.Add(MoreScreen.ScreenName, new MoreScreen(_context));
            }

            activeJSON.setCallbackFunction = val =>
            {
                if (val)
                {
                    Activate(false);
                }
                else
                {
                    Deactivate();
                }
            };
            RegisterBool(activeJSON);

            activeToggle                     = CreateToggle(activeJSON, false);
            activeToggle.label               = "Active";
            activeToggle.backgroundColor     = Color.cyan;
            activeToggle.labelText.fontStyle = FontStyle.Bold;
            activeToggle.toggle.onValueChanged.AddListener(v =>
            {
                if (!v)
                {
                    return;
                }
                _activatedManually = true;
            });

            _loadProfileWithPathUrlJSON = new JSONStorableUrl("ProfilePathUrl", string.Empty, url =>
            {
                _loadProfileWithPathUrlJSON.valNoCallback = null;
                new Storage(_context).LoadProfile(url);
            }, SaveFormat.SaveExt, SaveFormat.SaveFolder, true)
            {
                allowFullComputerBrowse       = false,
                allowBrowseAboveSuggestedPath = true,
                hideExtension = false,
                showDirs      = true,
                isRestorable  = false,
                isStorable    = false,
                beginBrowseWithObjectCallback = jsurl =>
                {
                    FileManagerSecure.CreateDirectory(SaveFormat.SaveFolder);
                    jsurl.shortCuts = FileManagerSecure.GetShortCutsForDirectory(SaveFormat.SaveFolder, false, false, true, true);
                }
            };
            RegisterUrl(_loadProfileWithPathUrlJSON);
            _loadProfileWithPathJSON = new JSONStorableActionPresetFilePath("LoadProfileWithPath", url =>
            {
                _loadProfileWithPathUrlJSON.SetFilePath(url);
            }, _loadProfileWithPathUrlJSON);
            RegisterPresetFilePathAction(_loadProfileWithPathJSON);

            var launchWizardJSON = new JSONStorableAction("LaunchWizard", () => StartCoroutine(LaunchWizard()));
            RegisterAction(launchWizardJSON);

            RegisterAction(new JSONStorableAction("ToggleActive", () => activeJSON.val = !activeJSON.val));
            RegisterAction(new JSONStorableAction("ReinitializeIfActive", () => StartCoroutine(ReinitializeIfActiveCo())));
            RegisterAction(new JSONStorableAction("Activate_Possession", () => ActivatePreset("Improved Possession")));
            RegisterAction(new JSONStorableAction("Activate_LeapMotion", () => ActivatePreset("Improved Possession w/ Leap")));
            RegisterAction(new JSONStorableAction("Activate_Passenger", () => ActivatePreset("Passenger")));

            LoadFromDefaults();

            if (containingAtom.on)
            {
                TryInitializeModuleReferences();
            }

            SuperController.singleton.StartCoroutine(DeferredInit());
        }
        catch (Exception)
        {
            enabledJSON.val = false;
            if (_modules != null)
            {
                Destroy(_modules);
            }
            throw;
        }
    }
Exemple #9
0
    private void BuildUI()
    {
        var showPreviews = new JSONStorableBool("showPreviews", ColliderPreviewConfig.DefaultPreviewsEnabled, value =>
        {
            _config.PreviewsEnabled = value;
            foreach (var editable in _editables.All)
            {
                editable.UpdatePreviewFromConfig();
            }
        });

        RegisterBool(showPreviews);
        var showPreviewsToggle = CreateToggle(showPreviews);

        showPreviewsToggle.label = "Show Previews";

        var xRayPreviews = new JSONStorableBool("xRayPreviews", ColliderPreviewConfig.DefaultXRayPreviews, value =>
        {
            _config.XRayPreviews = value;
            foreach (var editable in _editables.All)
            {
                editable.UpdatePreviewFromConfig();
            }
        });

        RegisterBool(xRayPreviews);
        var xRayPreviewsToggle = CreateToggle(xRayPreviews);

        xRayPreviewsToggle.label = "Use XRay Previews";

        JSONStorableFloat previewOpacity = new JSONStorableFloat("previewOpacity", ColliderPreviewConfig.DefaultPreviewsOpacity, value =>
        {
            if (!showPreviews.val)
            {
                showPreviews.val = true;
            }
            var alpha = value.ExponentialScale(ColliderPreviewConfig.ExponentialScaleMiddle, 1f);
            _config.PreviewsOpacity = alpha;
            foreach (var editable in _editables.All)
            {
                editable.UpdatePreviewFromConfig();
            }
        }, 0f, 1f);

        RegisterFloat(previewOpacity);
        CreateSlider(previewOpacity).label = "Preview Opacity";

        JSONStorableFloat selectedPreviewOpacity = new JSONStorableFloat("selectedPreviewOpacity", ColliderPreviewConfig.DefaultSelectedPreviewOpacity, value =>
        {
            if (!showPreviews.val)
            {
                showPreviews.val = true;
            }
            var alpha = value.ExponentialScale(ColliderPreviewConfig.ExponentialScaleMiddle, 1f);
            _config.SelectedPreviewsOpacity = alpha;
            if (_selected != null)
            {
                _selected.UpdatePreviewFromConfig();
            }
        }, 0f, 1f);

        RegisterFloat(selectedPreviewOpacity);
        CreateSlider(selectedPreviewOpacity).label = "Selected Preview Opacity";

        var loadPresetUI = CreateButton("Load Preset");

        loadPresetUI.button.onClick.AddListener(() =>
        {
            FileManagerSecure.CreateDirectory(_collidersSavePath);
            var shortcuts = FileManagerSecure.GetShortCutsForDirectory(_collidersSavePath);
            SuperController.singleton.GetMediaPathDialog(HandleLoadPreset, _saveExt, _collidersSavePath, false, true, false, null, false, shortcuts);
        });

        var savePresetUI = CreateButton("Save Preset");

        savePresetUI.button.onClick.AddListener(() =>
        {
            FileManagerSecure.CreateDirectory(_collidersSavePath);
            var fileBrowserUI = SuperController.singleton.fileBrowserUI;
            fileBrowserUI.SetTitle("Save colliders preset");
            fileBrowserUI.fileRemovePrefix            = null;
            fileBrowserUI.hideExtension               = false;
            fileBrowserUI.keepOpen                    = false;
            fileBrowserUI.fileFormat                  = _saveExt;
            fileBrowserUI.defaultPath                 = _collidersSavePath;
            fileBrowserUI.showDirs                    = true;
            fileBrowserUI.shortCuts                   = null;
            fileBrowserUI.browseVarFilesAsDirectories = false;
            fileBrowserUI.SetTextEntry(true);
            fileBrowserUI.Show(HandleSavePreset);
            fileBrowserUI.fileEntryField.text = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds + "." + _saveExt;
            fileBrowserUI.ActivateFileNameField();
        });

        var resetAllUI = CreateButton("Reset All");

        resetAllUI.button.onClick.AddListener(() =>
        {
            foreach (var editable in _editables.All)
            {
                editable.ResetToInitial();
            }
        });

        var groups = new List <string> {
            _noSelectionLabel
        };

        groups.AddRange(_editables.Groups.Select(e => e.Name).Distinct());
        groups.Add(_allLabel);
        _groupsJson = new JSONStorableStringChooser("Group", groups, groups[0], "Group");
        _groupsJson.setCallbackFunction = _ => UpdateFilter();
        var groupsList = CreateScrollablePopup(_groupsJson, false);

        groupsList.popupPanelHeight = 400f;
        _popups.Add(groupsList);

        var types = new List <string> {
            _noSelectionLabel
        };

        types.AddRange(_editables.All.Select(e => e.Type).Distinct());
        types.Add(_allLabel);
        _typesJson = new JSONStorableStringChooser("Type", types, types[0], "Type");
        _typesJson.setCallbackFunction = _ => UpdateFilter();
        var typesList = CreateScrollablePopup(_typesJson, false);

        typesList.popupPanelHeight = 400f;
        _popups.Add(typesList);

        _modifiedOnlyJson = new JSONStorableBool("Modified Only", false);
        _modifiedOnlyJson.setCallbackFunction = _ => UpdateFilter();
        CreateToggle(_modifiedOnlyJson, false);

        _textFilterJson = new JSONStorableString("Search", _searchDefault);
        _textFilterJson.setCallbackFunction = _ => UpdateFilter();
        CreateTextInput(_textFilterJson, false);

        _editablesJson = new JSONStorableStringChooser(
            "Edit",
            new List <string>(),
            new List <string>(),
            "",
            "Edit");
        var editablesList = CreateScrollablePopup(_editablesJson, true);

        editablesList.popupPanelHeight = 1000f;
        _popups.Add(editablesList);
        _editablesJson.setCallbackFunction = id =>
        {
            IModel val;
            if (_editables.ByUuid.TryGetValue(id, out val))
            {
                SelectEditable(val);
            }
            else
            {
                SelectEditable(null);
            }
        };

        UpdateFilter();
    }