Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use virtualised list container to replace edit table. #2264

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private partial class IssueTablePopover : OsuPopover
{
private readonly IReadOnlyDependencyContainer dependencyContainer;

public IssueTablePopover(IReadOnlyDependencyContainer dependencyContainer, IReadOnlyCollection<Issue> issues)
public IssueTablePopover(IReadOnlyDependencyContainer dependencyContainer, IBindableList<Issue> issues)
{
this.dependencyContainer = dependencyContainer;

Expand All @@ -131,7 +131,7 @@ public IssueTablePopover(IReadOnlyDependencyContainer dependencyContainer, IRead
{
new SingleLyricIssueTable
{
Issues = issues,
Issues = { BindTarget = issues, },
},
new IconButton
{
Expand Down Expand Up @@ -166,30 +166,43 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl

private partial class SingleLyricIssueTable : LyricEditorIssueTable
{
protected override TableColumn[] CreateHeaders() => new[]
protected override Dimension[] CreateDimensions() => new[]
{
new TableColumn(string.Empty, Anchor.CentreLeft, new Dimension(GridSizeMode.AutoSize, minSize: 30)),
new TableColumn("Message", Anchor.CentreLeft),
new Dimension(GridSizeMode.AutoSize, minSize: 30),
new Dimension(),
};

protected override Drawable[] CreateContent(Issue issue) =>
new Drawable[]
protected override IssueTableHeaderText[] CreateHeaders() => new[]
{
new IssueTableHeaderText(string.Empty, Anchor.CentreLeft),
new IssueTableHeaderText("Message", Anchor.CentreLeft),
};

protected override Tuple<Drawable[], Action<Issue>> CreateContent()
{
IssueIcon issueIcon;
TruncatingSpriteText issueSpriteText;

return new Tuple<Drawable[], Action<Issue>>(new Drawable[]
{
new IssueIcon
issueIcon = new IssueIcon
{
Origin = Anchor.Centre,
Size = new Vector2(10),
Margin = new MarginPadding { Left = 10 },
Issue = issue,
},
new TruncatingSpriteText
issueSpriteText = new TruncatingSpriteText
{
Text = issue.ToString(),
RelativeSizeAxes = Axes.X,
Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Medium),
ShowTooltip = false,
},
};
}, issue =>
{
issueIcon.Issue = issue;
issueSpriteText.Text = issue.ToString();
});
}

protected override void OnIssueClicked(Issue issue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public IssueSection()
},
});

issueTable.Issues.BindTo(bindableIssues);
bindableIssues.BindCollectionChanged((_, _) =>
{
bool hasIssue = bindableIssues.Any();
Expand All @@ -72,7 +73,6 @@ public IssueSection()

reloadButton.Alpha = hasIssue ? 1 : 0;
issueTable.Alpha = hasIssue ? 1 : 0;
issueTable.Issues = bindableIssues.Take(100);
}, true);
}

Expand Down Expand Up @@ -152,28 +152,41 @@ public SingleLyricIssueTable()
ShowHeaders = false;
}

protected override TableColumn[] CreateHeaders() => new[]
protected override Dimension[] CreateDimensions() => new[]
{
new TableColumn(string.Empty, Anchor.CentreLeft, new Dimension(GridSizeMode.AutoSize, minSize: 30)),
new TableColumn("Message", Anchor.CentreLeft),
new Dimension(GridSizeMode.AutoSize, minSize: 30),
new Dimension(),
};

protected override Drawable[] CreateContent(Issue issue) =>
new Drawable[]
protected override IssueTableHeaderText[] CreateHeaders() => new[]
{
new IssueTableHeaderText(string.Empty, Anchor.CentreLeft),
new IssueTableHeaderText("Message", Anchor.CentreLeft),
};

protected override Tuple<Drawable[], Action<Issue>> CreateContent()
{
IssueIcon issueIcon;
TruncatingSpriteText issueSpriteText;

return new Tuple<Drawable[], Action<Issue>>(new Drawable[]
{
new IssueIcon
issueIcon = new IssueIcon
{
Origin = Anchor.Centre,
Size = new Vector2(10),
Margin = new MarginPadding { Left = 10 },
Issue = issue,
},
new TruncatingSpriteText
issueSpriteText = new TruncatingSpriteText
{
Text = issue.ToString(),
RelativeSizeAxes = Axes.X,
Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Medium),
},
};
}, issue =>
{
issueIcon.Issue = issue;
issueSpriteText.Text = issue.ToString();
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit.Checks.Components;
using osuTK.Graphics;

Expand All @@ -16,75 +12,23 @@ public abstract partial class LyricEditorIssueTable : IssueTable
[Resolved]
private IIssueNavigator issueNavigator { get; set; } = null!;

public new bool ShowHeaders
private Color4 colourHover;
private Color4 colourSelected;

[BackgroundDependencyLoader]
private void load(LyricEditorColourProvider colourProvider, ILyricEditorState state)
{
get => base.ShowHeaders;
set
{
base.ShowHeaders = value;
BackgroundFlow.Margin = new MarginPadding { Top = value ? ROW_HEIGHT : 0 };
}
colourHover = colourProvider.Background1(state.Mode);
colourSelected = colourProvider.Colour3(state.Mode);
}

protected override void OnIssueClicked(Issue issue)
protected sealed override Color4 GetBackgroundColour(bool selected)
{
issueNavigator.Navigate(issue);
return selected ? colourSelected : colourHover;
}

protected override RowBackground CreateRowBackground(Issue issue)
=> new IssueTableRowBackground(issue);

/// <summary>
/// Inherit the class just for able to override the colour.
/// </summary>
protected partial class IssueTableRowBackground : RowBackground
protected override void OnIssueClicked(Issue issue)
{
private const int fade_duration = 100;

private readonly Box hoveredBackground;

public IssueTableRowBackground(object item)
: base(item)
{
hoveredBackground = Children.OfType<Box>().First();
}

private Color4 colourHover;
private Color4 colourSelected;

[BackgroundDependencyLoader]
private void load(LyricEditorColourProvider colourProvider, ILyricEditorState state)
{
colourHover = colourProvider.Background1(state.Mode);
colourSelected = colourProvider.Colour3(state.Mode);

Schedule(() =>
{
hoveredBackground.Colour = colourHover;
});
}

protected override bool OnHover(HoverEvent e)
{
bool hover = base.OnHover(e);
updateState();
return hover;
}

protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
updateState();
}

private void updateState()
{
hoveredBackground.FadeColour(Selected ? colourSelected : colourHover, 450, Easing.OutQuint);

if (Selected || IsHovered)
hoveredBackground.FadeIn(fade_duration, Easing.OutQuint);
else
hoveredBackground.FadeOut(fade_duration, Easing.OutQuint);
}
issueNavigator.Navigate(issue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,60 @@ public partial class LanguageIssueSection : LyricEditorIssueSection

private partial class LanguageIssueTable : LyricsIssueTable
{
protected override TableColumn[] CreateHeaders() => new[]
protected override Dimension[] CreateDimensions() => new[]
{
new TableColumn(string.Empty, Anchor.CentreLeft, new Dimension(GridSizeMode.AutoSize, minSize: 30)),
new TableColumn("Lyric", Anchor.CentreLeft, new Dimension(GridSizeMode.AutoSize, minSize: 40)),
new TableColumn("Message", Anchor.CentreLeft),
new Dimension(GridSizeMode.AutoSize, minSize: 30),
new Dimension(GridSizeMode.AutoSize, minSize: 40),
new Dimension(),
};

protected override Drawable[] CreateContent(Issue issue)
protected override IssueTableHeaderText[] CreateHeaders() => new[]
{
var lyric = getInvalidByIssue(issue);
new IssueTableHeaderText(string.Empty, Anchor.CentreLeft),
new IssueTableHeaderText("Lyric", Anchor.CentreLeft),
new IssueTableHeaderText("Message", Anchor.CentreLeft),
};

protected override Tuple<Drawable[], Action<Issue>> CreateContent()
{
IssueIcon issueIcon;
OsuSpriteText orderSpriteText;
TruncatingSpriteText issueSpriteText;

return new Drawable[]
return new Tuple<Drawable[], Action<Issue>>(new Drawable[]
{
new IssueIcon
issueIcon = new IssueIcon
{
Origin = Anchor.Centre,
Size = new Vector2(10),
Margin = new MarginPadding { Left = 10 },
Issue = issue,
},
new OsuSpriteText
orderSpriteText = new OsuSpriteText
{
Text = $"#{lyric.Order}",
Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Bold),
Margin = new MarginPadding { Right = 10 },
},
new TruncatingSpriteText
issueSpriteText = new TruncatingSpriteText
{
Text = issue.ToString(),
RelativeSizeAxes = Axes.X,
Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Medium),
},
};
}
}, issue =>
{
var lyric = getInvalidByIssue(issue);

private Lyric getInvalidByIssue(Issue issue)
{
if (issue is not LyricIssue lyricIssue)
throw new InvalidCastException();
issueIcon.Issue = issue;
orderSpriteText.Text = $"#{lyric.Order}";
issueSpriteText.Text = issue.ToString();
});

static Lyric getInvalidByIssue(Issue issue)
{
if (issue is not LyricIssue lyricIssue)
throw new InvalidCastException();

return lyricIssue.Lyric;
return lyricIssue.Lyric;
}
}
}
}
Loading