public void FloatSlider(ref JSONStorableFloat output, string name, float start, JSONStorableFloat.SetFloatCallback callback, float min, float max, bool right = false, bool constraint = false) { output = new JSONStorableFloat(name, start, callback, min, max, constraint, true) { storeType = JSONStorableParam.StoreType.Full }; script.RegisterFloat(output); script.CreateSlider(output, right); }
// UI helpers private void FloatSlider(ref JSONStorableFloat output, string name, float start, JSONStorableFloat.SetFloatCallback callback, float min, float max, bool rhs) { output = new JSONStorableFloat(name, start, callback, min, max, false, true); RegisterFloat(output); CreateSlider(output, rhs); }
public JSONStorableFloat CreateSlider(string paramName, string label, float startingValue, float minValue, float maxValue, JSONStorableFloat.SetFloatCallback callback, bool constrain, bool interactable, bool rightSide = false, string valueFormat = "F2") { var storable = new JSONStorableFloat(paramName, startingValue, callback, minValue, maxValue, constrain, interactable); Plugin.RegisterFloat(storable); var slider = Plugin.CreateSlider(storable, rightSide); slider.label = label; slider.valueFormat = valueFormat; return(storable); }
public override void Init() { try { _lastBrowseDir = CreateDirectory(GetPluginPath() + @"fmpr_presets\"); _displayRandomizer = new ParamRandomizer("display", null); _displayRandomizer.UpdateEnabledListEvnt += UpdateEnabledList; // make atom selector _atomJSON = new JSONStorableStringChooser("atom", SuperController.singleton.GetAtomUIDs(), null, "Atom", SyncAtom); _atomJSON.storeType = JSONStorableParam.StoreType.Physical; RegisterStringChooser(_atomJSON); SyncAtomChoices(); _displayPopup = CreateScrollablePopup(_atomJSON); _displayPopup.popupPanelHeight = 1100f; // want to always resync the atom choices on opening popup since atoms can be added/removed _displayPopup.popup.onOpenPopupHandlers += SyncAtomChoices; _displayPopup.label = "Atom in Scene"; // make receiver selector _receiverJSON = new JSONStorableStringChooser("receiver", null, null, "Receiver", SyncReceiver); _receiverJSON.storeType = JSONStorableParam.StoreType.Physical; RegisterStringChooser(_receiverJSON); _displayPopup = CreateScrollablePopup(_receiverJSON); _displayPopup.popupPanelHeight = 960f; // want to always resync the receivers, since plugins can be added/removed _displayPopup.popup.onOpenPopupHandlers += SyncReceiverChoices; _displayPopup.label = "Receiver on Atom"; // make receiver target selector _targetJson = new JSONStorableStringChooser("receiverTarget", null, null, "Target", SyncTargets); _targetJson.storeType = JSONStorableParam.StoreType.Physical; _displayPopup = CreateScrollablePopup(_targetJson); _displayPopup.popupPanelHeight = 820f; // want to always resync the targets, since morphs can be marked animatable _displayPopup.popup.onOpenPopupHandlers += SyncTargetChoices; _displayPopup.label = "Parameter on Receiver"; // Add Load/Save buttons var btn = CreateButton("Load Preset"); btn.button.onClick.AddListener(() => { SuperController.singleton.NormalizeMediaPath(_lastBrowseDir); // This sets the path iff it exists SuperController.singleton.GetMediaPathDialog(HandleLoadPreset, saveExt); }); _addAnimatable = new JSONStorableBool("autoSetAnimatable", true); var toggle = CreateToggle(_addAnimatable); toggle.label = "Auto-set 'animatable' on load"; _setReceiverOnLoad = new JSONStorableBool("setReceiverOnLoad", true); toggle = CreateToggle(_setReceiverOnLoad); toggle.label = "Set 'receiver' on load"; _setAtomOnLoad = new JSONStorableBool("setAtomOnLoad", false); btn = CreateButton("Save Preset"); btn.button.onClick.AddListener(() => { SuperController.singleton.NormalizeMediaPath(_lastBrowseDir); // This sets the path iff it exists SuperController.singleton.GetMediaPathDialog(HandleSavePreset, saveExt); // Update the browser to be a Save browser uFileBrowser.FileBrowser browser = SuperController.singleton.mediaFileBrowserUI; browser.SetTextEntry(true); browser.fileEntryField.text = String.Format("{0}.{1}", ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString(), saveExt); browser.ActivateFileNameField(); }); // set atom to current atom to initialize _atomJSON.val = containingAtom.uid; var spacer = CreateSpacer(); spacer.height = 40; btn = CreateButton("Set Min to Current"); btn.button.onClick.AddListener(() => { _displayRandomizer._minVal.val = _displayRandomizer._curVal.val; }); btn = CreateButton("Set Max to Current"); btn.button.onClick.AddListener(() => { _displayRandomizer._maxVal.val = _displayRandomizer._curVal.val; }); spacer = CreateSpacer(); spacer.height = 40; var countLabel = CreateTextField(new JSONStorableString("", "")); JSONStorableFloat.SetFloatCallback callback = (float aVal) => { countLabel.text = pluginName + " " + pluginVersion + "\n" + "\n" + "Active randomizers: " + aVal.ToString() ; pluginLabelJSON.val = String.Format("{0}->{1}, {2} running [{3}]", _atom.name, _receiverJSON.val, _randomizerEnabledList.Count.ToString(), pluginVersion); }; countLabel.height = 10; _activeRandomizersJson = new JSONStorableFloat("activeRandomizers", -1.0f, callback, 0.0f, 0.0f, false, false); spacer = CreateSpacer(); spacer.height = 40; _updateRate = new JSONStorableFloat("update_rate_ms", 15.0f, 0.0f, 1000f, false); RegisterFloat(_updateRate); var slider = CreateSlider(_updateRate); slider.label = "Update Delay (ms)"; toggle = CreateToggle(_displayRandomizer._enabled); toggle.label = "Enable Randomizer"; // Create per-randomizer sliders slider = CreateSlider(_displayRandomizer._period, true); slider.label = "Period\nSec between updates"; slider = CreateSlider(_displayRandomizer._periodRandomMin, true); slider.label = "Period min val"; slider = CreateSlider(_displayRandomizer._periodRandomMax, true); slider.label = "Period max val"; slider = CreateSlider(_displayRandomizer._quickness, true); slider.label = "Quickness"; slider = CreateSlider(_displayRandomizer._minVal, true); slider.label = "Random range min val"; slider = CreateSlider(_displayRandomizer._maxVal, true); slider.label = "Random range max val"; slider = CreateSlider(_displayRandomizer._deltaMinPercent, true); slider.label = "Min target val change %"; slider = CreateSlider(_displayRandomizer._deltaMaxPercent, true); slider.label = "Max target val change %"; slider = CreateSlider(_displayRandomizer._curVal, true); slider.label = "Current value\nYou can slide manually"; slider.defaultButtonEnabled = false; slider.quickButtonsEnabled = false; slider = CreateSlider(_displayRandomizer._targetVal, true); slider.label = "Target Value"; slider.defaultButtonEnabled = false; slider.quickButtonsEnabled = false; // Trigger setting labels _activeRandomizersJson.val = 0.0f; } catch (Exception e) { SuperController.LogError("Exception caught: " + e); } }
public override void Init() { try { _origFileFormat = SuperController.singleton.fileBrowserUI.fileFormat; _displayRandomizer = new ParamRandomizer("display", null); _displayRandomizer.UpdateEnabledListEvnt += UpdateEnabledList; // make atom selector _atomJSON = new JSONStorableStringChooser("atom", SuperController.singleton.GetAtomUIDs(), null, "Atom", SyncAtom); RegisterStringChooser(_atomJSON); SyncAtomChoices(); _displayPopup = CreateScrollablePopup(_atomJSON); _displayPopup.popupPanelHeight = 1100f; // want to always resync the atom choices on opening popup since atoms can be added/removed _displayPopup.popup.onOpenPopupHandlers += SyncAtomChoices; _displayPopup.label = "Atom in Scene"; // make receiver selector _receiverJSON = new JSONStorableStringChooser("receiver", null, null, "Receiver", SyncReceiver); RegisterStringChooser(_receiverJSON); _displayPopup = CreateScrollablePopup(_receiverJSON); _displayPopup.popupPanelHeight = 960f; // want to always resync the receivers, since plugins can be added/removed _displayPopup.popup.onOpenPopupHandlers += SyncReceiverChoices; _displayPopup.label = "Receiver on Atom"; // make receiver target selector _targetJson = new JSONStorableStringChooser("receiverTarget", null, null, "Target", SyncTargets); _displayPopup = CreateScrollablePopup(_targetJson); _displayPopup.popupPanelHeight = 820f; // want to always resync the targets, since morphs can be marked animatable _displayPopup.popup.onOpenPopupHandlers += SyncTargetChoices; _displayPopup.label = "Parameter on Receiver"; // Add Load/Save buttons var btn = CreateButton("Load Preset"); btn.button.onClick.AddListener(() => { uFileBrowser.FileBrowser browser = SuperController.singleton.fileBrowserUI; browser.defaultPath = _lastBrowseDir; browser.SetTextEntry(false); browser.fileFormat = saveExt; browser.Show(HandleLoadPreset); }); _addAnimatable = new JSONStorableBool("autoSetAnimatable", true); var toggle = CreateToggle(_addAnimatable); toggle.label = "Auto-set 'animatable' on load"; _loadReceiver = new JSONStorableBool("Set 'receiver' on load", true); CreateToggle(_loadReceiver); btn = CreateButton("Save Preset"); btn.button.onClick.AddListener(() => { uFileBrowser.FileBrowser browser = SuperController.singleton.fileBrowserUI; browser.defaultPath = _lastBrowseDir; browser.SetTextEntry(true); browser.fileFormat = saveExt; browser.Show(HandleSavePreset); browser.fileEntryField.text = String.Format("{0}.{1}", ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString(), saveExt); browser.ActivateFileNameField(); }); // set atom to current atom to initialize _atomJSON.val = containingAtom.uid; if (String.IsNullOrEmpty(_lastBrowseDir)) { _lastBrowseDir = SuperController.singleton.mediaFileBrowserUI.defaultPath; } // Create per-randomizer sliders var spacer = CreateSpacer(); spacer.height = 40; var slider = CreateSlider(_displayRandomizer._period, true); slider.label = "Period\nSec between updates"; slider = CreateSlider(_displayRandomizer._periodRandomMin, true); slider.label = "Period min val"; slider = CreateSlider(_displayRandomizer._periodRandomMax, true); slider.label = "Period max val"; slider = CreateSlider(_displayRandomizer._quickness, true); slider.label = "Quickness"; slider = CreateSlider(_displayRandomizer._minVal, true); slider.label = "Random range min val"; slider = CreateSlider(_displayRandomizer._maxVal, true); slider.label = "Random range max val"; slider = CreateSlider(_displayRandomizer._percentage, true); slider.label = "Max target val change %"; slider = CreateSlider(_displayRandomizer._targetVal, true); slider.label = "Target Value"; slider.defaultButtonEnabled = false; slider.quickButtonsEnabled = false; slider = CreateSlider(_displayRandomizer._curVal, true); slider.label = "Current value\nYou can slide manually"; slider.defaultButtonEnabled = false; slider.quickButtonsEnabled = false; var countLabel = CreateTextField(new JSONStorableString("", "")); JSONStorableFloat.SetFloatCallback callback = (float aVal) => { countLabel.text = pluginName + " " + pluginVersion + "\n" + "\n" + "Active randomizers: " + aVal.ToString() + "\n" + "\n" + "Update delay of 0 updates every frame." ; }; _activeRandomizersJson = new JSONStorableFloat("activeRandomizers", -1.0f, callback, 0.0f, 0.0f, false, false); _activeRandomizersJson.val = 0.0f; _updateRate = new JSONStorableFloat("update_rate_ms", 15.0f, 0.0f, 1000f, false); RegisterFloat(_updateRate); slider = CreateSlider(_updateRate); slider.label = "Update Delay (ms)"; spacer = CreateSpacer(); spacer.height = 120; toggle = CreateToggle(_displayRandomizer._enabled); toggle.label = "Enable Randomizer"; } catch (Exception e) { SuperController.LogError("Exception caught: " + e); } }
public JSONStorableFloat CreateSlider(string paramName, string label, float startingValue, float minValue, float maxValue, JSONStorableFloat.SetFloatCallback callback, bool constrain, bool interactable, bool rightSide = false, string valueFormat = "F2") { var storable = _builder.CreateSlider(paramName, label, startingValue, minValue, maxValue, callback, constrain, interactable, rightSide, valueFormat); _objects.Add(storable); return storable; }