Skip to content

Commit

Permalink
Add Configurable descriptions as tooltips.
Browse files Browse the repository at this point in the history
  • Loading branch information
Damnae committed Feb 18, 2023
1 parent fbf94ff commit f52554a
Show file tree
Hide file tree
Showing 20 changed files with 99 additions and 28 deletions.
14 changes: 9 additions & 5 deletions common/Scripting/StoryboardObjectGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ private Stream openFile(string path, bool watch)

#region Random

[Configurable(DisplayName = "Random seed")]
public int RandomSeed;
[Group("Common")]
[Description("Changes the result of Random(...) calls.")]
[Configurable] public int RandomSeed;

private Random random;
public int Random(int minValue, int maxValue) => random.Next(minValue, maxValue);
Expand Down Expand Up @@ -228,7 +229,7 @@ public FontGenerator LoadFont(string directory, FontDescription description, par
public FontGenerator LoadFont(string directory, bool asAsset, FontDescription description, params FontEffect[] effects)
{
var assetDirectory = asAsset ? context.ProjectAssetPath : context.MapsetPath;

var fontDirectory = Path.GetFullPath(Path.Combine(assetDirectory, directory));
if (fontDirectories.Contains(fontDirectory))
throw new InvalidOperationException($"This effect already generated a font inside \"{fontDirectory}\"");
Expand Down Expand Up @@ -310,7 +311,7 @@ public void UpdateConfiguration(EffectConfig config)
{
var displayName = configurableField.Attribute.DisplayName;
var initialValue = Convert.ChangeType(configurableField.InitialValue, fieldType, CultureInfo.InvariantCulture);
config.UpdateField(field.Name, displayName, configurableField.Order, fieldType, initialValue, allowedValues, configurableField.BeginsGroup);
config.UpdateField(field.Name, displayName, configurableField.Description, configurableField.Order, fieldType, initialValue, allowedValues, configurableField.BeginsGroup);

var value = config.GetValue(field.Name);
field.SetValue(this, value);
Expand Down Expand Up @@ -361,13 +362,15 @@ private void initializeConfigurableFields()
continue;

var group = field.GetCustomAttribute<GroupAttribute>(true);
var description = field.GetCustomAttribute<DescriptionAttribute>(true);

configurableFields.Add(new ConfigurableField()
{
Field = field,
Attribute = configurable,
InitialValue = field.GetValue(this),
BeginsGroup = group?.Name,
BeginsGroup = group?.Name?.Trim(),
Description = description?.Content?.Trim(),
Order = order++,
});
}
Expand All @@ -379,6 +382,7 @@ private struct ConfigurableField
public ConfigurableAttribute Attribute;
public object InitialValue;
public string BeginsGroup;
public string Description;
public int Order;

public override string ToString() => $"{Field.Name} {InitialValue}";
Expand Down
15 changes: 15 additions & 0 deletions common/Storyboarding/DescriptionAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace StorybrewCommon.Storyboarding
{
[AttributeUsage(AttributeTargets.Field)]
public class DescriptionAttribute : Attribute
{
public string Content { get; set; }

public DescriptionAttribute(string content)
{
Content = content;
}
}
}
6 changes: 5 additions & 1 deletion common/Storyboarding/EffectConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public string[] FieldNames
}
}

public void UpdateField(string name, string displayName, int order, Type fieldType, object defaultValue, NamedValue[] allowedValues, string beginsGroup)
public void UpdateField(string name, string displayName, string description, int order, Type fieldType, object defaultValue, NamedValue[] allowedValues, string beginsGroup)
{
if (fieldType == null)
return;
Expand Down Expand Up @@ -62,6 +62,7 @@ public void UpdateField(string name, string displayName, int order, Type fieldTy
{
Name = name,
DisplayName = displayName,
Description = description?.Trim(),
Value = value,
Type = fieldType,
AllowedValues = allowedValues,
Expand All @@ -84,9 +85,11 @@ public bool SetValue(string name, object value)
{
Name = field.Name,
DisplayName = field.DisplayName,
Description = field.Description,
Value = value,
Type = field.Type,
AllowedValues = field.AllowedValues,
BeginsGroup = field.BeginsGroup,
Order = field.Order,
};
return true;
Expand Down Expand Up @@ -114,6 +117,7 @@ public struct ConfigField
{
public string Name;
public string DisplayName;
public string Description;
public object Value;
public Type Type;
public NamedValue[] AllowedValues;
Expand Down
1 change: 1 addition & 0 deletions common/common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<Compile Include="Storyboarding3d\Sprite3d.cs" />
<Compile Include="Storyboarding\Commands\CommandComparer.cs" />
<Compile Include="Storyboarding\Commands\IFragmentableCommand.cs" />
<Compile Include="Storyboarding\DescriptionAttribute.cs" />
<Compile Include="Storyboarding\GroupAttribute.cs" />
<Compile Include="Storyboarding\OsbAnimationWriter.cs" />
<Compile Include="Storyboarding\OsbSpriteWriter.cs" />
Expand Down
7 changes: 3 additions & 4 deletions editor/Resources/skin_drawables.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,10 @@

"groupBg":
{
_type: "NinePatch",
Texture: "ui-rounded-borders.png",
Borders: [3, 5, 5, 3],
_type: "Sprite",
Texture: "ui-stripes.png",
Color: "@colorGroupBg",
Outset: [2, 2],
ScaleMode: "Fill",
},

"previewBg":
Expand Down
2 changes: 1 addition & 1 deletion editor/Resources/skin_styles.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{
FontSize: "@fontSizeNormal",
Color: "@colorGroupText",
TextAlignment: "Centre",
TextAlignment: "Left",
Background: "groupBg",
},
"listHeader":
Expand Down
2 changes: 2 additions & 0 deletions editor/Resources/ui-stripes-opt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Binary file added editor/Resources/ui-stripes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions editor/Storyboarding/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ private void loadBinary(string path)
Value = allowedValue,
};
}
effect.Config.UpdateField(fieldName, fieldDisplayName, fieldIndex, fieldValue?.GetType(), fieldValue, allowedValues, null);
effect.Config.UpdateField(fieldName, fieldDisplayName, null, fieldIndex, fieldValue?.GetType(), fieldValue, allowedValues, null);
}
}
}
Expand Down Expand Up @@ -792,7 +792,7 @@ private void loadText(string path)
.Select(p => new NamedValue { Name = p.Key, Value = ObjectSerializer.FromString(fieldTypeName, p.Value.Value<string>()), })
.ToArray();

effect.Config.UpdateField(fieldProperty.Key, fieldRoot.Value<string>("DisplayName"), fieldIndex++, fieldValue?.GetType(), fieldValue, allowedValues, beginsGroup);
effect.Config.UpdateField(fieldProperty.Key, fieldRoot.Value<string>("DisplayName"), null, fieldIndex++, fieldValue?.GetType(), fieldValue, allowedValues, beginsGroup);
}

var layersRoot = effectRoot.Value<TinyObject>("Layers");
Expand Down
4 changes: 3 additions & 1 deletion editor/UserInterface/Components/EffectConfigUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ private void updateFields()
if (currentGroup != null)
displayName = Regex.Replace(displayName, $@"^{Regex.Escape(currentGroup)}\s+", "");

var description = $"Variable: {field.Name}";
var description = $"Variable: {field.Name} ({field.Type.Name})";
if (!string.IsNullOrWhiteSpace(field.Description))
description = " " + description + "\n" + field.Description;

configFieldsLayout.Add(new LinearLayout(Manager)
{
Expand Down
4 changes: 4 additions & 0 deletions editor/editor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<Compile Include="Util\OsuHelper.cs" />
<Compile Include="Util\NetHelper.cs" />
<EmbeddedResource Include="Resources\project\vscode_settings.json" />
<EmbeddedResource Include="Resources\ui-stripes-opt.json" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down Expand Up @@ -196,6 +197,9 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\ui-stripes.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
2 changes: 2 additions & 0 deletions scripts/Background.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ namespace StorybrewScripts
{
public class Background : StoryboardObjectGenerator
{
[Group("Timing")]
[Configurable] public int StartTime = 0;
[Configurable] public int EndTime = 0;

[Group("Sprite")]
[Description("Leave empty to automatically use the map's background.")]
[Configurable] public string SpritePath = "";
[Configurable] public double Opacity = 0.2;

Expand Down
1 change: 1 addition & 0 deletions scripts/HitObjectHighlight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace StorybrewScripts
{
public class HitObjectHighlight : StoryboardObjectGenerator
{
[Group("Timing")]
[Configurable] public int StartTime = 0;
[Configurable] public int EndTime = 0;
[Configurable] public int BeatDivisor = 8;
Expand Down
3 changes: 2 additions & 1 deletion scripts/ImportOsb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ namespace StorybrewScripts
{
public class ImportOsb : StoryboardObjectGenerator
{
[Description("Path to the .osb to import, relative to the project folder.")]
[Configurable] public string Path = "storyboard.osb";

private Dictionary<string, string> variables = new Dictionary<string, string>();
private readonly Dictionary<string, string> variables = new Dictionary<string, string>();

public override void Generate()
{
Expand Down
6 changes: 6 additions & 0 deletions scripts/Karaoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ namespace StorybrewScripts
{
public class Karaoke : StoryboardObjectGenerator
{
[Description("Path to a .sbv, .srt, .ass or .ssa file in your project's folder.\nThese can be made with a tool like aegisub.")]
[Configurable] public string SubtitlesPath = "lyrics.srt";
[Configurable] public float SubtitleY = 400;

[Group("Font")]
[Description("The name of a system font, or the path to a font relative to your project's folder.\nIt is preferable to add fonts to the project folder and use their file name rather than installing fonts.")]
[Configurable] public string FontName = "Verdana";
[Description("A path inside your mapset's folder where lyrics images will be generated.")]
[Configurable] public string SpritesPath = "sb/f";
[Description("The Size of the font.\nIncreasing the font size creates larger images.")]
[Configurable] public int FontSize = 26;
[Description("The Scale of the font.\nIncreasing the font scale does not creates larger images, but the result may be blurrier.")]
[Configurable] public float FontScale = 0.5f;
[Configurable] public Color4 FontColor = Color4.White;
[Configurable] public FontStyle FontStyle = FontStyle.Regular;
Expand All @@ -39,6 +44,7 @@ public class Karaoke : StoryboardObjectGenerator
[Group("Misc")]
[Configurable] public bool TrimTransparency = true;
[Configurable] public bool EffectsOnly = false;
[Description("How much extra space is allocated around the text when generating it.\nShould be increased when characters look cut off.")]
[Configurable] public Vector2 Padding = Vector2.Zero;
[Configurable] public OsbOrigin Origin = OsbOrigin.Centre;

Expand Down
6 changes: 6 additions & 0 deletions scripts/Lyrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ namespace StorybrewScripts
{
public class Lyrics : StoryboardObjectGenerator
{
[Description("Path to a .sbv, .srt, .ass or .ssa file in your project's folder.\nThese can be made with a tool like aegisub.")]
[Configurable] public string SubtitlesPath = "lyrics.srt";
[Configurable] public float SubtitleY = 400;

[Group("Font")]
[Description("The name of a system font, or the path to a font relative to your project's folder.\nIt is preferable to add fonts to the project folder and use their file name rather than installing fonts.")]
[Configurable] public string FontName = "Verdana";
[Description("A path inside your mapset's folder where lyrics images will be generated.")]
[Configurable] public string SpritesPath = "sb/f";
[Description("The Size of the font.\nIncreasing the font size creates larger images.")]
[Configurable] public int FontSize = 26;
[Description("The Scale of the font.\nIncreasing the font scale does not creates larger images, but the result may be blurrier.")]
[Configurable] public float FontScale = 0.5f;
[Configurable] public Color4 FontColor = Color4.White;
[Configurable] public FontStyle FontStyle = FontStyle.Regular;
Expand All @@ -39,6 +44,7 @@ public class Lyrics : StoryboardObjectGenerator
[Configurable] public bool PerCharacter = true;
[Configurable] public bool TrimTransparency = true;
[Configurable] public bool EffectsOnly = false;
[Description("How much extra space is allocated around the text when generating it.\nShould be increased when characters look cut off.")]
[Configurable] public Vector2 Padding = Vector2.Zero;
[Configurable] public OsbOrigin Origin = OsbOrigin.Centre;

Expand Down
13 changes: 11 additions & 2 deletions scripts/Particles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,37 @@ namespace StorybrewScripts
{
public class Particles : StoryboardObjectGenerator
{
[Group("Timing")]
[Configurable] public int StartTime;
[Configurable] public int EndTime;
[Configurable] public int ParticleCount = 32;
[Configurable] public float Lifetime = 1000;

[Group("Sprite")]
[Configurable] public string Path = "sb/particle.png";
[Configurable] public OsbOrigin Origin = OsbOrigin.Centre;
[Configurable] public Vector2 Scale = new Vector2(1, 1);
[Description("Rotation of the sprite; does not influences particle motion direction.")]
[Configurable] public float Rotation = 0;
[Configurable] public Color4 Color = Color4.White;
[Description("Varies the saturation and brightness of the selected Color for each particle.")]
[Configurable] public float ColorVariance = 0.6f;
[Configurable] public bool Additive = false;

[Group("Spawn")]
[Configurable] public int ParticleCount = 32;
[Configurable] public float Lifetime = 1000;
[Description("The point around which particles will be created.")]
[Configurable] public Vector2 SpawnOrigin = new Vector2(420, 0);
[Description("The distance around the Spawn Origin point where particles will be created.")]
[Configurable] public float SpawnSpread = 360;

[Group("Motion")]
[Description("The angle in degrees at which particles will be moving.\n0 is to the right, positive values rotate counterclockwise.")]
[Configurable] public float Angle = 110;
[Description("The spread in degrees around Angle.")]
[Configurable] public float AngleSpread = 60;
[Description("The speed at which particles move, in osupixels.")]
[Configurable] public float Speed = 480;
[Description("Eases the motion of particles.")]
[Configurable] public OsbEasing Easing = OsbEasing.None;

public override void Generate()
Expand Down
13 changes: 10 additions & 3 deletions scripts/RadialSpectrum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,27 @@ namespace StorybrewScripts
/// </summary>
public class RadialSpectrum : StoryboardObjectGenerator
{
[Group("Timing")]
[Configurable] public int StartTime = 0;
[Configurable] public int EndTime = 10000;
[Configurable] public Vector2 Position = new Vector2(320, 240);
[Configurable] public int BeatDivisor = 8;
[Configurable] public int BarCount = 20;

[Group("Sprite")]
[Configurable] public string SpritePath = "sb/bar.png";
[Configurable] public OsbOrigin SpriteOrigin = OsbOrigin.Centre;
[Configurable] public Vector2 SpriteScale = Vector2.One;

[Group("Bars")]
[Configurable] public Vector2 Position = new Vector2(320, 240);
[Configurable] public int BarCount = 20;
[Configurable] public int Radius = 50;
[Configurable] public float Scale = 50;
[Configurable] public int LogScale = 600;
[Configurable] public OsbEasing FftEasing = OsbEasing.InExpo;

[Group("Optimization")]
[Configurable] public double Tolerance = 2;
[Configurable] public int CommandDecimals = 0;
[Configurable] public OsbEasing FftEasing = OsbEasing.InExpo;
[Configurable] public int FrequencyCutOff = 16000;

public override void Generate()
Expand Down
Loading

0 comments on commit f52554a

Please sign in to comment.