Skip to content

Commit

Permalink
Merge pull request #1808 from andy840119/make-auto-genreate-section-m…
Browse files Browse the repository at this point in the history
…ore-generic

Make auto-generate section more generic
  • Loading branch information
andy840119 authored Dec 22, 2022
2 parents 8b86d64 + bc0187c commit 9f95526
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 244 deletions.
21 changes: 21 additions & 0 deletions osu.Game.Rulesets.Karaoke/Screens/Edit/AutoGenerateSection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.Localisation;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit;

public abstract partial class AutoGenerateSection : EditorSection
{
protected sealed override LocalisableString Title => "Auto generate";

protected AutoGenerateSection()
{
Children = new[]
{
CreateAutoGenerateSubsection()
};
}

protected abstract AutoGenerateSubsection CreateAutoGenerateSubsection();
}
152 changes: 152 additions & 0 deletions osu.Game.Rulesets.Karaoke/Screens/Edit/AutoGenerateSubsection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Components.Markdown;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit;

public abstract partial class AutoGenerateSubsection : FillFlowContainer
{
private const int horizontal_padding = 20;

protected AutoGenerateSubsection()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
}

[BackgroundDependencyLoader]
private void load()
{
// should wait until BDL in the parent class has been loaded.
Schedule(() =>
{
Children = new Drawable[]
{
new GridContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
ColumnDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.Absolute, 5),
new Dimension(GridSizeMode.Absolute, 36)
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize)
},
Content = new[]
{
new Drawable?[]
{
CreateGenerateButton(),
null,
CreateConfigButton().With(x =>
{
x.Anchor = Anchor.Centre;
x.Origin = Anchor.Centre;
x.Size = new Vector2(36);
})
}
},
},
CreateDescriptionTextFlowContainer().With(x =>
{
x.RelativeSizeAxes = Axes.X;
x.AutoSizeAxes = Axes.Y;
x.Padding = new MarginPadding { Horizontal = horizontal_padding };
x.Description = CreateInvalidLyricDescriptionFormat();
})
};
});
}

protected abstract OsuButton CreateGenerateButton();

protected virtual DescriptionTextFlowContainer CreateDescriptionTextFlowContainer() => new();

protected abstract DescriptionFormat CreateInvalidLyricDescriptionFormat();

protected abstract ConfigButton CreateConfigButton();

protected abstract partial class ConfigButton : IconButton, IHasPopover
{
protected ConfigButton()
{
Icon = FontAwesome.Solid.Cog;
Action = openConfigSetting;

void openConfigSetting()
=> this.ShowPopover();
}

public abstract Popover GetPopover();
}

protected abstract partial class MultiConfigButton : ConfigButton
{
private KaraokeRulesetEditGeneratorSetting? selectedSetting;

protected MultiConfigButton()
{
Action = this.ShowPopover;
}

public override Popover GetPopover()
{
if (selectedSetting == null)
return createSelectionPopover();

return GetPopoverBySettingType(selectedSetting.Value);
}

protected abstract IEnumerable<KaraokeRulesetEditGeneratorSetting> AvailableSettings { get; }

protected abstract string GetDisplayName(KaraokeRulesetEditGeneratorSetting setting);

protected abstract Popover GetPopoverBySettingType(KaraokeRulesetEditGeneratorSetting setting);

private Popover createSelectionPopover()
=> new OsuPopover
{
Child = new FillFlowContainer<OsuButton>
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
Children = AvailableSettings.Select(x =>
{
string name = GetDisplayName(x);
return new OsuButton
{
Text = name,
Width = 150,
Action = () =>
{
selectedSetting = x;
this.ShowPopover();

// after show config pop-over, should make the state back for able to show this dialog next time.
selectedSetting = null;
},
};
}).ToList()
}
};
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.Language
{
public partial class LanguageAutoGenerateSubsection : AutoGenerateSubsection
public partial class LanguageAutoGenerateSubsection : LyricEditorAutoGenerateSubsection
{
private const string typing_mode = "TYPING_MODE";

Expand Down
Loading

0 comments on commit 9f95526

Please sign in to comment.