generated from vrchat-community/template-package
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add API for declaring custom preview controls (#305)
- Loading branch information
1 parent
6142778
commit f1f0a2f
Showing
10 changed files
with
214 additions
and
60 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
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,43 @@ | ||
using System; | ||
using nadena.dev.ndmf.preview.UI; | ||
|
||
namespace nadena.dev.ndmf.preview | ||
{ | ||
/// <summary> | ||
/// Declares a previewable aspect of this plugin. | ||
/// </summary> | ||
public sealed class TogglablePreviewNode | ||
{ | ||
/// <summary> | ||
/// The name that will be shown to the user. Will be re-invoked on language change. | ||
/// </summary> | ||
public Func<string> DisplayName { get; } | ||
|
||
public PublishedValue<bool> IsEnabled { get; } | ||
|
||
private TogglablePreviewNode(Func<string> displayName, bool initialState) | ||
{ | ||
DisplayName = displayName; | ||
IsEnabled = new PublishedValue<bool>(initialState); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a togglable preview node. Must not be invoked during static initialization. | ||
/// </summary> | ||
/// <param name="displayName">A function which returns the localized display name for this switch</param> | ||
/// <param name="qualifiedName">If not null, a name which will be used to save this configuration</param> | ||
/// <param name="initialState">The initial state for this node; defaults to true</param> | ||
public static TogglablePreviewNode Create(Func<string> displayName, string qualifiedName = null, | ||
bool initialState = true) | ||
{ | ||
if (qualifiedName != null) initialState = PreviewPrefs.instance.GetNodeState(qualifiedName, initialState); | ||
|
||
var node = new TogglablePreviewNode(displayName, initialState); | ||
|
||
if (qualifiedName != null) | ||
node.IsEnabled.OnChange += value => PreviewPrefs.instance.SetNodeState(qualifiedName, value); | ||
|
||
return node; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.