2021-03-28 23:36:22 +08:00
|
|
|
// 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 System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2021-04-10 19:04:39 +08:00
|
|
|
using osu.Framework.Bindables;
|
2021-03-28 23:36:22 +08:00
|
|
|
using osu.Framework.Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-04-07 20:38:43 +08:00
|
|
|
using osu.Game.Input.Bindings;
|
2021-04-10 19:02:22 +08:00
|
|
|
using osu.Game.Rulesets.Edit.Checks.Components;
|
2021-03-28 23:36:22 +08:00
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Verify
|
|
|
|
{
|
|
|
|
public class IssueTable : TableContainer
|
|
|
|
{
|
|
|
|
private const float horizontal_inset = 20;
|
|
|
|
private const float row_height = 25;
|
|
|
|
private const int text_size = 14;
|
|
|
|
|
|
|
|
private readonly FillFlowContainer backgroundFlow;
|
|
|
|
|
2021-04-10 19:04:39 +08:00
|
|
|
[Resolved]
|
|
|
|
private Bindable<Issue> selectedIssue { get; set; }
|
|
|
|
|
2021-03-28 23:36:22 +08:00
|
|
|
public IssueTable()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
Padding = new MarginPadding { Horizontal = horizontal_inset };
|
|
|
|
RowSize = new Dimension(GridSizeMode.Absolute, row_height);
|
|
|
|
|
2021-04-07 20:38:43 +08:00
|
|
|
Masking = true;
|
|
|
|
CornerRadius = 6;
|
|
|
|
|
2021-03-28 23:36:22 +08:00
|
|
|
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();
|
|
|
|
|
|
|
|
if (value?.Any() != true)
|
|
|
|
return;
|
|
|
|
|
|
|
|
foreach (var issue in value)
|
|
|
|
{
|
2021-04-07 20:38:43 +08:00
|
|
|
backgroundFlow.Add(new RowBackground(issue));
|
2021-03-28 23:36:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Columns = createHeaders();
|
|
|
|
Content = value.Select((g, i) => createContent(i, g)).ToArray().ToRectangular();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private TableColumn[] createHeaders()
|
|
|
|
{
|
|
|
|
var columns = new List<TableColumn>
|
|
|
|
{
|
|
|
|
new TableColumn(string.Empty, Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
2021-04-07 20:38:43 +08:00
|
|
|
new TableColumn("Type", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
2021-03-28 23:36:22 +08:00
|
|
|
new TableColumn("Time", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
2021-04-07 20:38:43 +08:00
|
|
|
new TableColumn("Message", Anchor.CentreLeft),
|
|
|
|
new TableColumn("Category", Anchor.CentreRight, new Dimension(GridSizeMode.AutoSize)),
|
2021-03-28 23:36:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return columns.ToArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Drawable[] createContent(int index, Issue issue) => new Drawable[]
|
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = $"#{index + 1}",
|
2021-04-07 20:38:43 +08:00
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Medium)
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = issue.Template.Type.ToString(),
|
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold),
|
|
|
|
Margin = new MarginPadding { Left = 10 },
|
|
|
|
Colour = issue.Template.TypeColour()
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = issue.GetEditorTimestamp(),
|
2021-03-28 23:36:22 +08:00
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold),
|
|
|
|
Margin = new MarginPadding(10)
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
2021-04-07 20:38:43 +08:00
|
|
|
Text = issue.ToString(),
|
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Medium)
|
2021-03-28 23:36:22 +08:00
|
|
|
},
|
2021-04-07 20:38:43 +08:00
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = issue.Template.Origin.Metadata().Category.ToString(),
|
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold),
|
|
|
|
Margin = new MarginPadding(10)
|
|
|
|
}
|
2021-03-28 23:36:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
public class RowBackground : OsuClickableContainer
|
|
|
|
{
|
2021-04-10 19:04:39 +08:00
|
|
|
private readonly Issue issue;
|
2021-03-28 23:36:22 +08:00
|
|
|
private const int fade_duration = 100;
|
|
|
|
|
|
|
|
private readonly Box hoveredBackground;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private EditorClock clock { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
2021-04-07 20:38:43 +08:00
|
|
|
private Editor editor { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private EditorBeatmap editorBeatmap { get; set; }
|
2021-03-28 23:36:22 +08:00
|
|
|
|
2021-04-10 19:04:39 +08:00
|
|
|
[Resolved]
|
|
|
|
private Bindable<Issue> selectedIssue { get; set; }
|
|
|
|
|
2021-03-28 23:36:22 +08:00
|
|
|
public RowBackground(Issue issue)
|
|
|
|
{
|
2021-04-10 19:04:39 +08:00
|
|
|
this.issue = issue;
|
|
|
|
|
2021-03-28 23:36:22 +08:00
|
|
|
RelativeSizeAxes = Axes.X;
|
2021-04-07 20:38:43 +08:00
|
|
|
Height = row_height;
|
2021-03-28 23:36:22 +08:00
|
|
|
AlwaysPresent = true;
|
|
|
|
CornerRadius = 3;
|
|
|
|
Masking = true;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
hoveredBackground = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
Action = () =>
|
|
|
|
{
|
2021-04-07 20:38:43 +08:00
|
|
|
// Supposed to work like clicking timestamps outside of the game.
|
|
|
|
// TODO: Is there already defined behaviour for this I may be able to call?
|
|
|
|
|
2021-04-10 19:04:39 +08:00
|
|
|
selectedIssue.Value = issue;
|
|
|
|
|
2021-04-07 20:38:43 +08:00
|
|
|
if (issue.Time != null)
|
|
|
|
{
|
|
|
|
clock.Seek(issue.Time.Value);
|
|
|
|
editor.OnPressed(GlobalAction.EditorComposeMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!issue.HitObjects.Any())
|
|
|
|
return;
|
|
|
|
|
|
|
|
editorBeatmap.SelectedHitObjects.Clear();
|
|
|
|
editorBeatmap.SelectedHitObjects.AddRange(issue.HitObjects);
|
2021-03-28 23:36:22 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private Color4 colourHover;
|
2021-04-10 19:04:39 +08:00
|
|
|
private Color4 colourSelected;
|
2021-03-28 23:36:22 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
hoveredBackground.Colour = colourHover = colours.BlueDarker;
|
2021-04-10 19:04:39 +08:00
|
|
|
colourSelected = colours.YellowDarker;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
selectedIssue.BindValueChanged(change => { Selected = issue == change.NewValue; }, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool selected;
|
|
|
|
|
|
|
|
protected bool Selected
|
|
|
|
{
|
|
|
|
get => selected;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == selected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
selected = value;
|
|
|
|
updateState();
|
|
|
|
}
|
2021-03-28 23:36:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
updateState();
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
updateState();
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
2021-04-10 19:04:39 +08:00
|
|
|
hoveredBackground.FadeColour(selected ? colourSelected : colourHover, 450, Easing.OutQuint);
|
2021-03-28 23:36:22 +08:00
|
|
|
|
2021-04-10 19:04:39 +08:00
|
|
|
if (selected || IsHovered)
|
2021-03-28 23:36:22 +08:00
|
|
|
hoveredBackground.FadeIn(fade_duration, Easing.OutQuint);
|
|
|
|
else
|
|
|
|
hoveredBackground.FadeOut(fade_duration, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|