Split out common EditorTable base class

This commit is contained in:
Dean Herbert 2021-04-13 23:05:58 +09:00
parent 1ff4e2076f
commit 0edc1a850d
3 changed files with 63 additions and 82 deletions

View File

@ -0,0 +1,49 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Screens.Edit
{
public abstract class EditorTable : TableContainer
{
private const float horizontal_inset = 20;
protected const float ROW_HEIGHT = 25;
protected const int TEXT_SIZE = 14;
protected readonly FillFlowContainer BackgroundFlow;
protected EditorTable()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Padding = new MarginPadding { Horizontal = horizontal_inset };
RowSize = new Dimension(GridSizeMode.Absolute, ROW_HEIGHT);
AddInternal(BackgroundFlow = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Depth = 1f,
Padding = new MarginPadding { Horizontal = -horizontal_inset },
Margin = new MarginPadding { Top = ROW_HEIGHT }
});
}
protected override Drawable CreateHeader(int index, TableColumn column) => new HeaderText(column?.Header ?? string.Empty);
private class HeaderText : OsuSpriteText
{
public HeaderText(string text)
{
Text = text.ToUpper();
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold);
}
}
}
}

View File

@ -20,47 +20,24 @@ using osuTK.Graphics;
namespace osu.Game.Screens.Edit.Timing namespace osu.Game.Screens.Edit.Timing
{ {
public class ControlPointTable : TableContainer public class ControlPointTable : EditorTable
{ {
private const float horizontal_inset = 20;
private const float row_height = 25;
private const int text_size = 14;
private readonly FillFlowContainer backgroundFlow;
[Resolved] [Resolved]
private Bindable<ControlPointGroup> selectedGroup { get; set; } private Bindable<ControlPointGroup> selectedGroup { get; set; }
public ControlPointTable()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Padding = new MarginPadding { Horizontal = horizontal_inset };
RowSize = new Dimension(GridSizeMode.Absolute, row_height);
AddInternal(backgroundFlow = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Depth = 1f,
Padding = new MarginPadding { Horizontal = -horizontal_inset },
Margin = new MarginPadding { Top = row_height }
});
}
public IEnumerable<ControlPointGroup> ControlGroups public IEnumerable<ControlPointGroup> ControlGroups
{ {
set set
{ {
Content = null; Content = null;
backgroundFlow.Clear(); BackgroundFlow.Clear();
if (value?.Any() != true) if (value?.Any() != true)
return; return;
foreach (var group in value) foreach (var group in value)
{ {
backgroundFlow.Add(new RowBackground(group)); BackgroundFlow.Add(new RowBackground(group));
} }
Columns = createHeaders(); Columns = createHeaders();
@ -86,13 +63,13 @@ namespace osu.Game.Screens.Edit.Timing
new OsuSpriteText new OsuSpriteText
{ {
Text = $"#{index + 1}", Text = $"#{index + 1}",
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold), Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Bold),
Margin = new MarginPadding(10) Margin = new MarginPadding(10)
}, },
new OsuSpriteText new OsuSpriteText
{ {
Text = group.Time.ToEditorFormattedString(), Text = group.Time.ToEditorFormattedString(),
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold) Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Bold)
}, },
null, null,
new ControlGroupAttributes(group), new ControlGroupAttributes(group),
@ -164,17 +141,6 @@ namespace osu.Game.Screens.Edit.Timing
} }
} }
protected override Drawable CreateHeader(int index, TableColumn column) => new HeaderText(column?.Header ?? string.Empty);
private class HeaderText : OsuSpriteText
{
public HeaderText(string text)
{
Text = text.ToUpper();
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold);
}
}
public class RowBackground : OsuClickableContainer public class RowBackground : OsuClickableContainer
{ {
private readonly ControlPointGroup controlGroup; private readonly ControlPointGroup controlGroup;

View File

@ -19,47 +19,24 @@ using osuTK.Graphics;
namespace osu.Game.Screens.Edit.Verify namespace osu.Game.Screens.Edit.Verify
{ {
public class IssueTable : TableContainer public class IssueTable : EditorTable
{ {
private const float horizontal_inset = 20;
private const float row_height = 25;
private const int text_size = 14;
private readonly FillFlowContainer backgroundFlow;
[Resolved] [Resolved]
private Bindable<Issue> selectedIssue { get; set; } private Bindable<Issue> selectedIssue { get; set; }
public IssueTable()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Padding = new MarginPadding { Horizontal = horizontal_inset };
RowSize = new Dimension(GridSizeMode.Absolute, row_height);
AddInternal(backgroundFlow = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Depth = 1f,
Padding = new MarginPadding { Horizontal = -horizontal_inset },
Margin = new MarginPadding { Top = row_height }
});
}
public IEnumerable<Issue> Issues public IEnumerable<Issue> Issues
{ {
set set
{ {
Content = null; Content = null;
backgroundFlow.Clear(); BackgroundFlow.Clear();
if (value == null) if (value == null)
return; return;
foreach (var issue in value) foreach (var issue in value)
{ {
backgroundFlow.Add(new RowBackground(issue)); BackgroundFlow.Add(new RowBackground(issue));
} }
Columns = createHeaders(); Columns = createHeaders();
@ -86,46 +63,35 @@ namespace osu.Game.Screens.Edit.Verify
new OsuSpriteText new OsuSpriteText
{ {
Text = $"#{index + 1}", Text = $"#{index + 1}",
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Medium), Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Medium),
Margin = new MarginPadding { Right = 10 } Margin = new MarginPadding { Right = 10 }
}, },
new OsuSpriteText new OsuSpriteText
{ {
Text = issue.Template.Type.ToString(), Text = issue.Template.Type.ToString(),
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold), Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Bold),
Margin = new MarginPadding { Right = 10 }, Margin = new MarginPadding { Right = 10 },
Colour = issue.Template.Colour Colour = issue.Template.Colour
}, },
new OsuSpriteText new OsuSpriteText
{ {
Text = issue.GetEditorTimestamp(), Text = issue.GetEditorTimestamp(),
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold), Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Bold),
Margin = new MarginPadding { Right = 10 }, Margin = new MarginPadding { Right = 10 },
}, },
new OsuSpriteText new OsuSpriteText
{ {
Text = issue.ToString(), Text = issue.ToString(),
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Medium) Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Medium)
}, },
new OsuSpriteText new OsuSpriteText
{ {
Text = issue.Check.Metadata.Category.ToString(), Text = issue.Check.Metadata.Category.ToString(),
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold), Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Bold),
Margin = new MarginPadding(10) Margin = new MarginPadding(10)
} }
}; };
protected override Drawable CreateHeader(int index, TableColumn column) => new HeaderText(column?.Header ?? string.Empty);
private class HeaderText : OsuSpriteText
{
public HeaderText(string text)
{
Text = text.ToUpper();
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold);
}
}
public class RowBackground : OsuClickableContainer public class RowBackground : OsuClickableContainer
{ {
private readonly Issue issue; private readonly Issue issue;
@ -150,7 +116,7 @@ namespace osu.Game.Screens.Edit.Verify
this.issue = issue; this.issue = issue;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Height = row_height; Height = ROW_HEIGHT;
AlwaysPresent = true; AlwaysPresent = true;
CornerRadius = 3; CornerRadius = 3;
Masking = true; Masking = true;