-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e90922a
commit 4c19865
Showing
19 changed files
with
446 additions
and
15 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
170 changes: 170 additions & 0 deletions
170
OngekiFumenEditor/Base/EditorObjects/InterpolatableSoflan.cs
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,170 @@ | ||
using OngekiFumenEditor.Base.OngekiObjects; | ||
using OngekiFumenEditor.Utils; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace OngekiFumenEditor.Base.EditorObjects | ||
{ | ||
public class InterpolatableSoflan : Soflan | ||
{ | ||
public override string IDShortName => "[INTP_SFL]"; | ||
|
||
public class InterpolatableSoflanIndicator : SoflanEndIndicator | ||
{ | ||
private float speed = 1; | ||
public float Speed | ||
{ | ||
get => speed; | ||
set => Set(ref speed, value); | ||
} | ||
|
||
public override string IDShortName => "[INTP_SFL_End]"; | ||
|
||
public override void Copy(OngekiObjectBase from) | ||
{ | ||
base.Copy(from); | ||
|
||
if (from is not InterpolatableSoflanIndicator f) | ||
return; | ||
Speed = f.Speed; | ||
} | ||
} | ||
|
||
public InterpolatableSoflan() : base() | ||
{ | ||
EndIndicator = new InterpolatableSoflanIndicator() { RefSoflan = this }; | ||
EndIndicator.PropertyChanged += EndIndicator_PropertyChanged; | ||
displayables = [this, EndIndicator]; | ||
} | ||
|
||
private void EndIndicator_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) | ||
{ | ||
switch (e.PropertyName) | ||
{ | ||
case nameof(Speed): | ||
NotifyOfPropertyChange(nameof(Speed)); | ||
break; | ||
case nameof(TGrid): | ||
NotifyOfPropertyChange(nameof(EndTGrid)); | ||
break; | ||
default: | ||
NotifyOfPropertyChange(nameof(EndIndicator)); | ||
break; | ||
} | ||
} | ||
|
||
public override void NotifyOfPropertyChange([CallerMemberName] string propertyName = null) | ||
{ | ||
switch (propertyName) | ||
{ | ||
case nameof(Speed): | ||
case nameof(TGrid): | ||
case nameof(InterpolateCountPerResT): | ||
case nameof(EndTGrid): | ||
case nameof(ApplySpeedInDesignMode): | ||
case nameof(Easing): | ||
cachedValid = false; | ||
break; | ||
default: | ||
break; | ||
} | ||
base.NotifyOfPropertyChange(propertyName); | ||
} | ||
|
||
private EasingTypes easing = EasingTypes.None; | ||
public EasingTypes Easing | ||
{ | ||
get => easing; | ||
set => Set(ref easing, value); | ||
} | ||
|
||
private int interpolateCountPerResT = 16; | ||
public int InterpolateCountPerResT | ||
{ | ||
get => interpolateCountPerResT; | ||
set => Set(ref interpolateCountPerResT, value); | ||
} | ||
|
||
public override string ToString() => $"{base.ToString()} --> EndSpeed[{((InterpolatableSoflanIndicator)EndIndicator)?.Speed}x]"; | ||
|
||
public override void CopyEntire(Soflan from) | ||
{ | ||
Copy(from); | ||
|
||
Speed = from.Speed; | ||
ApplySpeedInDesignMode = from.ApplySpeedInDesignMode; | ||
EndIndicator.Copy(from.EndIndicator); | ||
|
||
if (from is not InterpolatableSoflan s) | ||
return; | ||
|
||
Easing = s.Easing; | ||
} | ||
|
||
bool cachedValid = false; | ||
List<Soflan> cachedInterpolatedSoflans = new(); | ||
|
||
public void UpdateCachedInterpolatedSoflans() | ||
{ | ||
cachedInterpolatedSoflans.Clear(); | ||
|
||
var fromTotalGrid = TGrid.TotalGrid; | ||
var toTotalGrid = EndTGrid.TotalGrid; | ||
|
||
var fromSpeed = Speed; | ||
var toSpeed = (EndIndicator as InterpolatableSoflanIndicator).Speed; | ||
|
||
if (fromSpeed == toSpeed || fromTotalGrid == toTotalGrid) | ||
{ | ||
cachedInterpolatedSoflans.Add(new Soflan() | ||
{ | ||
EndTGrid = new TGrid(0, toTotalGrid), | ||
TGrid = new TGrid(0, fromTotalGrid), | ||
Speed = fromSpeed, | ||
ApplySpeedInDesignMode = ApplySpeedInDesignMode | ||
}); | ||
} | ||
else | ||
{ | ||
var stepGridLength = (int)(TGrid.DEFAULT_RES_T / InterpolateCountPerResT); | ||
|
||
for (var curGrid = fromTotalGrid; curGrid < toTotalGrid; curGrid += stepGridLength) | ||
{ | ||
var nextGrid = Math.Min(curGrid + stepGridLength, toTotalGrid); | ||
|
||
var normalized = nextGrid == toTotalGrid ? 1 : (curGrid - fromTotalGrid) * 1.0d / (toTotalGrid - fromTotalGrid); | ||
var transformed = (float)Interpolation.ApplyEasing(Easing, normalized); | ||
|
||
var speed = fromSpeed + transformed * (toSpeed - fromSpeed); | ||
|
||
cachedInterpolatedSoflans.Add(new Soflan() | ||
{ | ||
EndTGrid = new TGrid(0, nextGrid), | ||
TGrid = new TGrid(0, curGrid), | ||
Speed = speed, | ||
ApplySpeedInDesignMode = ApplySpeedInDesignMode | ||
}); | ||
} | ||
} | ||
cachedValid = true; | ||
} | ||
|
||
public IReadOnlyList<Soflan> GetInterpolatedSoflans() | ||
{ | ||
if (!cachedValid) | ||
UpdateCachedInterpolatedSoflans(); | ||
return cachedInterpolatedSoflans; | ||
} | ||
|
||
public double CalculateSpeed(TGrid t) | ||
{ | ||
var list = GetInterpolatedSoflans(); | ||
var r = list.LastOrDefaultByBinarySearch(t, x => x.TGrid); | ||
return r.Speed; | ||
} | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
...rtyBrowser/UIGenerator/ObjectOperationImplement/InterpolatableSoflanOperationGenerator.cs
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,26 @@ | ||
using OngekiFumenEditor.Base; | ||
using OngekiFumenEditor.Base.EditorObjects; | ||
using OngekiFumenEditor.Base.OngekiObjects; | ||
using OngekiFumenEditor.Modules.FumenObjectPropertyBrowser.ViewModels; | ||
using OngekiFumenEditor.UI.Controls.ObjectInspector.UIGenerator; | ||
using OngekiFumenEditor.Utils; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.Composition; | ||
using System.Windows; | ||
|
||
namespace OngekiFumenEditor.Modules.FumenObjectPropertyBrowser.UIGenerator.ObjectOperationImplement | ||
{ | ||
[Export(typeof(IOngekiObjectOperationGenerator))] | ||
public class InterpolatableSoflanOperationGenerator : IOngekiObjectOperationGenerator | ||
{ | ||
public IEnumerable<Type> SupportOngekiTypes { get; } = new[] { | ||
typeof(InterpolatableSoflan), | ||
}; | ||
|
||
public UIElement Generate(OngekiObjectBase obj) | ||
{ | ||
return ViewHelper.CreateViewByViewModelType(() => new InterpolatableSoflanOperationViewModel(obj as InterpolatableSoflan)); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...r/Modules/FumenObjectPropertyBrowser/ViewModels/InterpolatableSoflanOperationViewModel.cs
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,42 @@ | ||
using Caliburn.Micro; | ||
using Gemini.Modules.Toolbox; | ||
using OngekiFumenEditor.Base.EditorObjects; | ||
using OngekiFumenEditor.Base.OngekiObjects; | ||
using OngekiFumenEditor.Modules.FumenVisualEditor.Base; | ||
using OngekiFumenEditor.Modules.FumenVisualEditor.Base.DropActions; | ||
using System; | ||
using System.Linq; | ||
using System.Windows; | ||
using System.Windows.Input; | ||
|
||
namespace OngekiFumenEditor.Modules.FumenObjectPropertyBrowser.ViewModels | ||
{ | ||
public class InterpolatableSoflanOperationViewModel : PropertyChangedBase | ||
{ | ||
private InterpolatableSoflan soflan; | ||
|
||
public InterpolatableSoflanOperationViewModel(InterpolatableSoflan obj) | ||
{ | ||
soflan = obj; | ||
} | ||
|
||
public void Interpolate(ActionExecutionContext e) | ||
{ | ||
var list = soflan.GetInterpolatedSoflans().ToArray(); | ||
var editor = IoC.Get<IFumenObjectPropertyBrowser>().Editor; | ||
|
||
if (editor == null) | ||
return; | ||
|
||
editor.UndoRedoManager.ExecuteAction(LambdaUndoAction.Create("插值生成Soflan物件", () => | ||
{ | ||
editor.Fumen.AddObjects(list); | ||
editor.Fumen.RemoveObject(soflan); | ||
}, () => | ||
{ | ||
editor.Fumen.AddObject(soflan); | ||
editor.Fumen.RemoveObjects(list); | ||
})); | ||
} | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...menEditor/Modules/FumenObjectPropertyBrowser/Views/InterpolatableSoflanOperationView.xaml
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,21 @@ | ||
<UserControl | ||
x:Class="OngekiFumenEditor.Modules.FumenObjectPropertyBrowser.Views.InterpolatableSoflanOperationView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:cal="http://caliburnmicro.com" | ||
xmlns:controls="clr-namespace:OngekiFumenEditor.Modules.FumenObjectPropertyBrowser.UI.Controls" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
d:Background="White" | ||
mc:Ignorable="d"> | ||
<StackPanel Margin="21,5,0,0"> | ||
<controls:CommonOperationButton | ||
Width="150" | ||
Margin="0,10,0,0" | ||
HorizontalAlignment="Left" | ||
cal:Message.Attach="[Event MouseLeftButtonDown] = [Action Interpolate($executionContext)];" | ||
DecoratorBrush="DarkSalmon" | ||
Text="插值生成Soflan物件" | ||
ToolTip="生成已经插值好的一堆Soflan物件" /> | ||
</StackPanel> | ||
</UserControl> |
Oops, something went wrong.