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 @@
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]
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
{
set
{
Content = null;
backgroundFlow.Clear();
BackgroundFlow.Clear();
if (value?.Any() != true)
return;
foreach (var group in value)
{
backgroundFlow.Add(new RowBackground(group));
BackgroundFlow.Add(new RowBackground(group));
}
Columns = createHeaders();
@ -86,13 +63,13 @@ private TableColumn[] createHeaders()
new OsuSpriteText
{
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)
},
new OsuSpriteText
{
Text = group.Time.ToEditorFormattedString(),
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold)
Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Bold)
},
null,
new ControlGroupAttributes(group),
@ -164,17 +141,6 @@ private Drawable createAttribute(ControlPoint controlPoint)
}
}
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
{
private readonly ControlPointGroup controlGroup;

View File

@ -19,47 +19,24 @@
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]
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
{
set
{
Content = null;
backgroundFlow.Clear();
BackgroundFlow.Clear();
if (value == null)
return;
foreach (var issue in value)
{
backgroundFlow.Add(new RowBackground(issue));
BackgroundFlow.Add(new RowBackground(issue));
}
Columns = createHeaders();
@ -86,46 +63,35 @@ private TableColumn[] createHeaders()
new OsuSpriteText
{
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 }
},
new OsuSpriteText
{
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 },
Colour = issue.Template.Colour
},
new OsuSpriteText
{
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 },
},
new OsuSpriteText
{
Text = issue.ToString(),
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Medium)
Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Medium)
},
new OsuSpriteText
{
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)
}
};
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
{
private readonly Issue issue;
@ -150,7 +116,7 @@ public RowBackground(Issue issue)
this.issue = issue;
RelativeSizeAxes = Axes.X;
Height = row_height;
Height = ROW_HEIGHT;
AlwaysPresent = true;
CornerRadius = 3;
Masking = true;