Skip to content

Commit

Permalink
Adjust the style.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Oct 9, 2024
1 parent d0cd252 commit 65adbfc
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,82 @@
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays;
using osu.Game.Rulesets.Karaoke.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Utils;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Edit.Setup.Components;

/// <summary>
/// A component which displays a collection of <see cref="CultureInfo"/>
/// </summary>
public partial class LanguageList : CompositeDrawable
public partial class FormLanguageList : CompositeDrawable
{
public BindableList<CultureInfo> Languages { get; } = new();

private FillFlowContainer languages = null!;
public LocalisableString Caption { get; init; }

private const int fade_duration = 200;
public LocalisableString HintText { get; init; }

private Box background = null!;
private FormFieldCaption caption = null!;
private FillFlowContainer flow = null!;

[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;

[BackgroundDependencyLoader]
private void load()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
AutoSizeDuration = fade_duration;
AutoSizeEasing = Easing.OutQuint;

InternalChild = languages = new FillFlowContainer
Masking = true;
CornerRadius = 5;

AddLanguageButton button;

InternalChildren = new Drawable[]
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(8),
Direction = FillDirection.Full,
background = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background5,
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(9),
Spacing = new Vector2(7),
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
caption = new FormFieldCaption
{
Caption = Caption,
TooltipText = HintText,
},
flow = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Full,
Spacing = new Vector2(5),
Child = button = new AddLanguageButton
{
Action = languageInsertionRequested,
},
},
},
},
};

flow.SetLayoutPosition(button, float.MaxValue);
}

protected override void LoadComplete()
Expand All @@ -57,28 +98,46 @@ protected override void LoadComplete()
Languages.BindCollectionChanged((_, args) =>
{
if (args.Action != NotifyCollectionChangedAction.Replace)
updateSingers();
updateLanguages();
}, true);
FinishTransforms(true);
updateState();
}

private void updateSingers()
protected override bool OnHover(HoverEvent e)
{
languages.Clear();
updateState();
return true;
}

foreach (CultureInfo language in Languages)
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
updateState();
}

private void updateState()
{
background.Colour = colourProvider.Background5;
caption.Colour = colourProvider.Content2;

BorderThickness = IsHovered ? 2 : 0;

if (IsHovered)
BorderColour = colourProvider.Light4;
}

private void updateLanguages()
{
flow.RemoveAll(d => d is LanguageDisplay, true);

foreach (var language in Languages)
{
languages.Add(new LanguageDisplay
flow.Add(new LanguageDisplay
{
Current = { Value = language },
DeleteRequested = languageDeletionRequested,
});
}

languages.Add(new AddLanguageButton
{
Action = languageInsertionRequested,
});
}

private void languageInsertionRequested(CultureInfo language)
Expand Down Expand Up @@ -162,6 +221,8 @@ internal partial class AddLanguageButton : CompositeDrawable, IHasPopover

public AddLanguageButton()
{
Size = new Vector2(35);

InternalChild = new IconButton
{
Action = this.ShowPopover,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
Expand All @@ -15,10 +13,13 @@
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas;
using osu.Game.Rulesets.Karaoke.Beatmaps.Utils;
using osu.Game.Rulesets.Karaoke.Graphics.Cursor;
Expand All @@ -28,30 +29,69 @@

namespace osu.Game.Rulesets.Karaoke.Edit.Setup.Components;

/// <summary>
/// A component which displays a collection of singers in individual <see cref="SingerDisplay"/>s.
/// </summary>
public partial class SingerList : CompositeDrawable
public partial class FormSingerList : CompositeDrawable
{
public BindableList<Singer> Singers { get; } = new();
public BindableList<Singer> Singers { get; } = new();

private FillFlowContainer singers = null!;
public LocalisableString Caption { get; init; }

public LocalisableString HintText { get; init; }

private Box background = null!;
private FormFieldCaption caption = null!;
private FillFlowContainer flow = null!;

[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;

[BackgroundDependencyLoader]
private void load()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
AutoSizeDuration = fade_duration;
AutoSizeEasing = Easing.OutQuint;

InternalChild = singers = new FillFlowContainer
Masking = true;
CornerRadius = 5;

AddSingerButton button;

InternalChildren = new Drawable[]
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(10),
Direction = FillDirection.Full,
background = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background5,
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(9),
Spacing = new Vector2(7),
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
caption = new FormFieldCaption
{
Caption = Caption,
TooltipText = HintText,
},
flow = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Full,
Spacing = new Vector2(10),
Child = button = new AddSingerButton
{
Action = singerInsertionRequested,
},
},
},
},
};

flow.SetLayoutPosition(button, float.MaxValue);
}

protected override void LoadComplete()
Expand All @@ -63,35 +103,56 @@ protected override void LoadComplete()
if (args.Action != NotifyCollectionChangedAction.Replace)
updateSingers();
}, true);
FinishTransforms(true);
updateState();
}

protected override bool OnHover(HoverEvent e)
{
updateState();
return true;
}

private const int fade_duration = 200;
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
updateState();
}

private void updateState()
{
background.Colour = colourProvider.Background5;
caption.Colour = colourProvider.Content2;

BorderThickness = IsHovered ? 2 : 0;

if (IsHovered)
BorderColour = colourProvider.Light4;
}

private void updateSingers()
{
singers.Clear();
flow.RemoveAll(d => d is SingerDisplay, true);

foreach (var singer in Singers)
{
singers.Add(new SingerDisplay
flow.Add(new SingerDisplay
{
Current = { Value = singer },
DeleteRequested = singerDeletionRequested,
DeleteRequested = languageDeletionRequested,
});
}
}

singers.Add(new AddSingerButton
private void singerInsertionRequested()
{
var singer = new Singer
{
Action = () => Singers.Add(new Singer
{
Name = "New singer",
}),
});
Name = "New singer",
};
Singers.Add(singer);
}

// todo : might have dialog to ask should delete singer or not if contains lyric.
private void singerDeletionRequested(Singer singer) => Singers.Remove(singer);
private void languageDeletionRequested(Singer singer) => Singers.Remove(singer);

/// <summary>
/// A component which displays a singer along with related description text.
Expand All @@ -118,7 +179,7 @@ public Bindable<Singer> Current
private void load()
{
AutoSizeAxes = Axes.Y;
Width = 100;
Width = 50;

InternalChild = new FillFlowContainer
{
Expand Down Expand Up @@ -169,8 +230,9 @@ private partial class SingerCircle : Container, IHasCustomTooltip<Singer>
public SingerCircle()
{
RelativeSizeAxes = Axes.X;
Height = 100;
CornerRadius = 50;
Height = 50;

CornerRadius = 25;
Masking = true;
BorderThickness = 5;

Expand Down Expand Up @@ -216,7 +278,7 @@ public Action Action
public AddSingerButton()
{
AutoSizeAxes = Axes.Y;
Width = 100;
Width = 50;

InternalChild = new FillFlowContainer
{
Expand All @@ -229,8 +291,8 @@ public AddSingerButton()
circularButton = new OsuClickableContainer
{
RelativeSizeAxes = Axes.X,
Height = 100,
CornerRadius = 50,
Height = 50,
CornerRadius = 25,
Masking = true,
BorderThickness = 5,
Children = new Drawable[]
Expand Down
Loading

0 comments on commit 65adbfc

Please sign in to comment.