From 04563a724202ee9d8abc45d12316e635d9ffd86e Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 28 Jun 2026 10:42:57 +0900 Subject: [PATCH] =?UTF-8?q?--track/--check/--color=E3=81=AB=E5=BF=9C?= =?UTF-8?q?=E3=81=98=E3=81=9F=E5=8B=95=E7=9A=84UI=E3=82=92LuaScriptEffect?= =?UTF-8?q?=E3=81=AB=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript/LuaScriptEffect.cs | 105 ++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/LuaScript/LuaScriptEffect.cs b/LuaScript/LuaScriptEffect.cs index 7e3e01c..c645e9e 100644 --- a/LuaScript/LuaScriptEffect.cs +++ b/LuaScript/LuaScriptEffect.cs @@ -1,8 +1,12 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Windows.Media; +using LuaScript.Compat; +using Newtonsoft.Json; using YukkuriMovieMaker.Commons; using YukkuriMovieMaker.Controls; using YukkuriMovieMaker.Exo; +using YukkuriMovieMaker.ItemEditor.CustomVisibilityAttributes; using YukkuriMovieMaker.Player.Video; using YukkuriMovieMaker.Plugin; using YukkuriMovieMaker.Plugin.Effects; @@ -27,27 +31,126 @@ namespace LuaScript [Display(GroupName = nameof(Texts.ScriptGroup), ResourceType = typeof(Texts))] [CodeEditor(Language = "pack://application:,,,/LuaScript;component/Resources/SyntaxDefinitions/Lua-{theme}.xshd", FoldingStrategyType = typeof(LuaFoldingStrategy), AutoCompletionStrategyType = typeof(LuaAutoCompletionStrategy), ToolBarStrategyType = typeof(EmptyToolBarStrategy), PropertyEditorSize = PropertyEditorSize.FullWidth)] - public string Script { get => _script; set => Set(ref _script, value); } + public string Script + { + get => _script; + set { if (Set(ref _script, value)) UpdateLayout(); } + } string _script = DefaultScript; string IScriptProvider.DefaultScript => DefaultScript; + internal AviUtlParameterLayout Layout { get; private set; } = AviUtlParameterLayout.Parse(DefaultScript); + [Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Track0), Description = nameof(Texts.TrackDesc), ResourceType = typeof(Texts))] [AnimationSlider("F2", "", -100, 100)] + [ShowPropertyEditorWhen(nameof(IsTrack0Visible), true)] public Animation Track0 { get; } = new Animation(0, YMM4Constants.VerySmallValue, YMM4Constants.VeryLargeValue); [Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Track1), Description = nameof(Texts.TrackDesc), ResourceType = typeof(Texts))] [AnimationSlider("F2", "", -100, 100)] + [ShowPropertyEditorWhen(nameof(IsTrack1Visible), true)] public Animation Track1 { get; } = new Animation(0, YMM4Constants.VerySmallValue, YMM4Constants.VeryLargeValue); [Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Track2), Description = nameof(Texts.TrackDesc), ResourceType = typeof(Texts))] [AnimationSlider("F2", "", -100, 100)] + [ShowPropertyEditorWhen(nameof(IsTrack2Visible), true)] public Animation Track2 { get; } = new Animation(0, YMM4Constants.VerySmallValue, YMM4Constants.VeryLargeValue); [Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Track3), Description = nameof(Texts.TrackDesc), ResourceType = typeof(Texts))] [AnimationSlider("F2", "", -100, 100)] + [ShowPropertyEditorWhen(nameof(IsTrack3Visible), true)] public Animation Track3 { get; } = new Animation(0, YMM4Constants.VerySmallValue, YMM4Constants.VeryLargeValue); + [Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Check0), Description = nameof(Texts.CheckDesc), ResourceType = typeof(Texts))] + [ToggleSlider] + [ShowPropertyEditorWhen(nameof(IsCheck0Visible), true)] + public bool Check0 { get => _check0; set => Set(ref _check0, value); } + bool _check0; + + [Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Check1), Description = nameof(Texts.CheckDesc), ResourceType = typeof(Texts))] + [ToggleSlider] + [ShowPropertyEditorWhen(nameof(IsCheck1Visible), true)] + public bool Check1 { get => _check1; set => Set(ref _check1, value); } + bool _check1; + + [Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Check2), Description = nameof(Texts.CheckDesc), ResourceType = typeof(Texts))] + [ToggleSlider] + [ShowPropertyEditorWhen(nameof(IsCheck2Visible), true)] + public bool Check2 { get => _check2; set => Set(ref _check2, value); } + bool _check2; + + [Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Check3), Description = nameof(Texts.CheckDesc), ResourceType = typeof(Texts))] + [ToggleSlider] + [ShowPropertyEditorWhen(nameof(IsCheck3Visible), true)] + public bool Check3 { get => _check3; set => Set(ref _check3, value); } + bool _check3; + + [Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Color), Description = nameof(Texts.ColorDesc), ResourceType = typeof(Texts))] + [ColorPicker] + [ShowPropertyEditorWhen(nameof(IsColorVisible), true)] + public Color Color { get => _color; set => Set(ref _color, value); } + Color _color = Colors.White; + + [JsonIgnore] public bool IsTrack0Visible { get => _isTrack0Visible; private set => Set(ref _isTrack0Visible, value); } + [JsonIgnore] public bool IsTrack1Visible { get => _isTrack1Visible; private set => Set(ref _isTrack1Visible, value); } + [JsonIgnore] public bool IsTrack2Visible { get => _isTrack2Visible; private set => Set(ref _isTrack2Visible, value); } + [JsonIgnore] public bool IsTrack3Visible { get => _isTrack3Visible; private set => Set(ref _isTrack3Visible, value); } + [JsonIgnore] public bool IsCheck0Visible { get => _isCheck0Visible; private set => Set(ref _isCheck0Visible, value); } + [JsonIgnore] public bool IsCheck1Visible { get => _isCheck1Visible; private set => Set(ref _isCheck1Visible, value); } + [JsonIgnore] public bool IsCheck2Visible { get => _isCheck2Visible; private set => Set(ref _isCheck2Visible, value); } + [JsonIgnore] public bool IsCheck3Visible { get => _isCheck3Visible; private set => Set(ref _isCheck3Visible, value); } + [JsonIgnore] public bool IsColorVisible { get => _isColorVisible; private set => Set(ref _isColorVisible, value); } + + bool _isTrack0Visible = true; + bool _isTrack1Visible = true; + bool _isTrack2Visible = true; + bool _isTrack3Visible = true; + bool _isCheck0Visible; + bool _isCheck1Visible; + bool _isCheck2Visible; + bool _isCheck3Visible; + bool _isColorVisible; + + private void UpdateLayout() + { + var layout = AviUtlParameterLayout.Parse(_script); + Layout = layout; + + bool hasAny = layout.HasAny; + + IsTrack0Visible = !hasAny || layout.HasTrack(0); + IsTrack1Visible = !hasAny || layout.HasTrack(1); + IsTrack2Visible = !hasAny || layout.HasTrack(2); + IsTrack3Visible = !hasAny || layout.HasTrack(3); + IsCheck0Visible = layout.HasCheck(0); + IsCheck1Visible = layout.HasCheck(1); + IsCheck2Visible = layout.HasCheck(2); + IsCheck3Visible = layout.HasCheck(3); + IsColorVisible = layout.HasColor; + + SeedDefaults(layout); + } + + private void SeedDefaults(AviUtlParameterLayout layout) + { + if (layout.GetCheck(0) is { Default: true } && !_check0) Check0 = true; + if (layout.GetCheck(1) is { Default: true } && !_check1) Check1 = true; + if (layout.GetCheck(2) is { Default: true } && !_check2) Check2 = true; + if (layout.GetCheck(3) is { Default: true } && !_check3) Check3 = true; + + if (layout.Color is { } color && _color == Colors.White) + Color = ToMediaColor(color.Default); + } + + private static Color ToMediaColor(int rgb) + { + byte r = (byte)((rgb >> 16) & 0xFF); + byte g = (byte)((rgb >> 8) & 0xFF); + byte b = (byte)(rgb & 0xFF); + return Color.FromRgb(r, g, b); + } + public override IEnumerable CreateExoVideoFilters(int keyFrameIndex, ExoOutputDescription exoOutputDescription) => []; public override IVideoEffectProcessor CreateVideoEffect(IGraphicsDevicesAndContext devices)