-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathStoryboardAnimationRow.cs
More file actions
166 lines (146 loc) · 5.47 KB
/
Copy pathStoryboardAnimationRow.cs
File metadata and controls
166 lines (146 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System;
using System.Linq;
using fluXis.Graphics.Sprites.Icons;
using fluXis.Graphics.Sprites.Text;
using fluXis.Graphics.UserInterface.Color;
using fluXis.Storyboards;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osuTK;
namespace fluXis.Screens.Edit.Tabs.Storyboarding.Animations;
public partial class StoryboardAnimationRow : GridContainer
{
[Resolved]
private EditorClock clock { get; set; }
[Resolved]
private EditorMap map { get; set; }
public readonly StoryboardElement Item;
private readonly StoryboardAnimationType type;
private readonly Colour4 color;
private Container<StoryboardAnimationEntry> entries;
public StoryboardAnimationRow(StoryboardElement item, StoryboardAnimationType type)
{
this.Item = item;
this.type = type;
color = getColor(type);
}
[BackgroundDependencyLoader]
private void load()
{
RelativeSizeAxes = Axes.X;
Height = StoryboardAnimationsList.ROW_HEIGHT;
ColumnDimensions = new Dimension[]
{
new(GridSizeMode.Absolute, StoryboardAnimationsList.SIDE_WIDTH),
new()
};
Content = new[]
{
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new FluXisSpriteText
{
Text = $"{type.GetDescription()}",
WebFontSize = 12,
Margin = new MarginPadding { Horizontal = 8 },
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Colour = color
},
new ClickableContainer
{
Size = new Vector2(StoryboardAnimationsList.ROW_HEIGHT),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Action = addNew,
Child = new FluXisSpriteIcon
{
Icon = Phosphor.Bold.Plus,
Margin = new MarginPadding { Horizontal = 8 },
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(12)
}
},
}
},
entries = new Container<StoryboardAnimationEntry>
{
RelativeSizeAxes = Axes.Both,
Masking = true,
ChildrenEnumerable = Item.Animations.Where(x => x.Type == type).Select(createEntry)
}
}
};
}
private void addNew()
{
var animation = new StoryboardAnimation(Item)
{
StartTime = clock.CurrentTime - Item.StartTime,
UseStartValue = false,
StartValue = getDefault(type),
ValueEnd = getDefault(type),
Type = type
};
Item.Animations.Add(animation);
entries.Add(createEntry(animation));
map.Add(animation);
}
private void remove(StoryboardAnimation animation)
{
var entry = entries.FirstOrDefault(x => x.Animation == animation);
if (entry != null) entries.Remove(entry, true);
Item.Animations.Remove(animation);
map.Remove(animation);
}
private StoryboardAnimationEntry createEntry(StoryboardAnimation anim)
{
// Restore the parent reference lost during json deserialization (because of [JsonIgnore] on ParentElement).
anim.ParentElement ??= Item;
return new StoryboardAnimationEntry(anim, this, color) { RequestRemove = remove };
}
private static string getDefault(StoryboardAnimationType type)
{
switch (type)
{
case StoryboardAnimationType.MoveX:
case StoryboardAnimationType.MoveY:
case StoryboardAnimationType.Width:
case StoryboardAnimationType.Height:
case StoryboardAnimationType.Rotate:
case StoryboardAnimationType.Border:
return "0";
case StoryboardAnimationType.Scale:
case StoryboardAnimationType.Fade:
return "1";
case StoryboardAnimationType.ScaleVector:
return "1,1";
case StoryboardAnimationType.Color:
return "#ffffff";
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
}
private static Colour4 getColor(StoryboardAnimationType type) => type switch
{
StoryboardAnimationType.MoveX => Theme.Red,
StoryboardAnimationType.MoveY => Theme.Orange,
StoryboardAnimationType.Scale => Theme.Yellow,
StoryboardAnimationType.ScaleVector => Theme.Lime,
StoryboardAnimationType.Width => Theme.Green,
StoryboardAnimationType.Height => Theme.Aqua,
StoryboardAnimationType.Rotate => Theme.Cyan,
StoryboardAnimationType.Fade => Theme.Blue,
StoryboardAnimationType.Color => Theme.Purple,
StoryboardAnimationType.Border => Theme.Pink,
_ => Theme.Text
};
}