Skip to content

Commit

Permalink
Merge pull request #286 from andy840119/lyric-editor/implement-time-d…
Browse files Browse the repository at this point in the history
…isplay-and-language-selection

Implement time and language display.
  • Loading branch information
andy840119 authored Dec 6, 2020
2 parents 5794828 + bfc710a commit 9c94a8f
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Game.Graphics;
using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Badges
{
public class LanguageInfoBadge : Badge
{
public LanguageInfoBadge(Lyric lyric)
: base(lyric)
{
lyric.LanguageBindable.BindValueChanged(value =>
{
var language = value.NewValue;

if (language == null)
BadgeText = "None";
else
BadgeText = language.DisplayName;
}, true);
}

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
BadgeColour = colours.BlueDarker;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Extensions;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Infos
{
public class TimeInfoContainer : Container
{
private readonly Box background;
private readonly OsuSpriteText timeRange;

public TimeInfoContainer(Lyric lyric)
{
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both
},
timeRange = new OsuSpriteText
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Font = OsuFont.GetFont(size: 16, fixedWidth: true),
Padding = new MarginPadding(10),
}
};

// todo : might move to another function for updating time.
var startTime = lyric.StartTime.ToEditorFormattedString();
var endTime = lyric.EndTime.ToEditorFormattedString();
timeRange.Text = startTime + " - " + endTime;
}

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
background.Colour = colours.Gray4;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics
{
public class DrawableLyricEditList : OsuRearrangeableListContainer<Lyric>
{
public const int SPACING = 2;

protected override OsuRearrangeableListItem<Lyric> CreateOsuDrawable(Lyric item)
=> new DrawableLyricEditListItem(item);
}
Expand Down
57 changes: 44 additions & 13 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Badges;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Infos;
using osu.Game.Rulesets.Karaoke.Objects;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics
{
public class DrawableLyricEditListItem : OsuRearrangeableListItem<Lyric>
{
private const int continuous_spacing = 20;
private const int info_part_spacing = 200;
private const int min_height = 75;
private const int max_height = 120;

private Box background;
private Box dragAlert;
private Box headerBackground;
Expand All @@ -28,12 +34,21 @@ public DrawableLyricEditListItem(Lyric item)

protected override Drawable CreateContent()
{
// todo : need to refactor this part.
var isContinuous = Model.LayoutIndex == -1;
var continuousSpacing = isContinuous ? continuous_spacing : 0;

return new Container
{
Masking = true,
CornerRadius = 5,
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Margin = new MarginPadding
{
Left = continuousSpacing,
Top = DrawableLyricEditList.SPACING,
},
Children = new Drawable[]
{
background = new Box
Expand All @@ -50,33 +65,51 @@ protected override Drawable CreateContent()
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, info_part_spacing - continuousSpacing),
new Dimension(GridSizeMode.Distributed)
},
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize, minSize: min_height, maxSize: max_height) },
Content = new[]
{
new[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
// todo : cannot use relative size to both because it will cause size cannot roll-back if make lyric smaller.
RelativeSizeAxes = Axes.X,
Height = min_height,
Children = new Drawable[]
{
headerBackground = new Box
{
RelativeSizeAxes = Axes.Both,
RelativeSizeAxes = Axes.X,
Height = max_height,
Alpha = 0.7f
},
new BadgeFillFlowContainer
{
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Both,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Spacing = new Vector2(5),
Padding = new MarginPadding(10),
Children = new Badge[]
Children = new Drawable[]
{
new TimeInfoBadge(Model),
new StyleInfoBadge(Model),
new LayoutInfoBadge(Model),
new TimeInfoContainer(Model)
{
RelativeSizeAxes = Axes.X,
Height = 36,
},

// todo : in small display size use badge.
// in larger size should use real icon.
new LanguageInfoBadge(Model)
{
Margin = new MarginPadding{ Right = 5 }
}
}
},
}
Expand All @@ -87,9 +120,7 @@ protected override Drawable CreateContent()
RelativeSizeAxes = Axes.X,
}
}
},
ColumnDimensions = new[] { new Dimension(GridSizeMode.Absolute, 200) },
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }
}
}
}
};
Expand Down Expand Up @@ -118,9 +149,9 @@ protected override void OnDragEnd(DragEndEvent e)
base.OnDragEnd(e);
}

public class BadgeFillFlowContainer : FillFlowContainer<Badge>
public class BadgeFillFlowContainer : FillFlowContainer
{
public override void Add(Badge drawable)
public override void Add(Drawable drawable)
{
drawable.Anchor = Anchor.TopRight;
drawable.Origin = Anchor.TopRight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps;
using osu.Game.Extensions;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
Expand Down Expand Up @@ -167,8 +168,8 @@ private Drawable[][] createContent(EditorBeatmap editorBeatmap, Bindable<Beatmap

private Drawable createTimeDrawable(Lyric lyric)
{
var startTime = TimeSpan.FromMilliseconds(lyric.StartTime).ToString(@"mm\:ss\:fff");
var endTime = TimeSpan.FromMilliseconds(lyric.EndTime).ToString(@"mm\:ss\:fff");
var startTime = lyric.StartTime.ToEditorFormattedString();
var endTime = lyric.EndTime.ToEditorFormattedString();
return new OsuSpriteText
{
Text = startTime + " - " + endTime,
Expand Down
14 changes: 12 additions & 2 deletions osu.Game.Rulesets.Karaoke/Objects/Lyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,23 @@ public int LayoutIndex
[JsonIgnore]
public readonly Bindable<string> TranslateTextBindable = new Bindable<string>();

public CultureInfo Language { get; set; }

/// <summary>
/// Translates
/// </summary>
public IDictionary<int, string> Translates { get; set; } = new Dictionary<int, string>();

[JsonIgnore]
public readonly Bindable<CultureInfo> LanguageBindable = new Bindable<CultureInfo>();

/// <summary>
/// Language
/// </summary>
public CultureInfo Language
{
get => LanguageBindable.Value;
set => LanguageBindable.Value = value;
}

/// <summary>
/// Display target translate
/// </summary>
Expand Down

0 comments on commit 9c94a8f

Please sign in to comment.