mirror of
https://github.com/ppy/osu
synced 2025-01-04 13:22:08 +00:00
Implement CancellableCommentEditor
This commit is contained in:
parent
730c115f49
commit
c022cf72b5
@ -8,6 +8,7 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Comments;
|
using osu.Game.Overlays.Comments;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
@ -16,6 +17,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
{
|
{
|
||||||
typeof(CommentEditor),
|
typeof(CommentEditor),
|
||||||
|
typeof(CancellableCommentEditor),
|
||||||
};
|
};
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
@ -23,13 +25,19 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
|
|
||||||
public TestSceneCommentEditor()
|
public TestSceneCommentEditor()
|
||||||
{
|
{
|
||||||
Add(new Container
|
Add(new FillFlowContainer
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Width = 800,
|
Width = 800,
|
||||||
Child = new TestCommentEditor()
|
Direction = FillDirection.Vertical,
|
||||||
|
Spacing = new Vector2(0, 20),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new TestCommentEditor(),
|
||||||
|
new TestCancellableCommentEditor()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,5 +49,14 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
|
|
||||||
protected override string TextboxPlaceholderText => @"This textbox is empty";
|
protected override string TextboxPlaceholderText => @"This textbox is empty";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class TestCancellableCommentEditor : CancellableCommentEditor
|
||||||
|
{
|
||||||
|
protected override string FooterText => @"Wow, another one. Sicc";
|
||||||
|
|
||||||
|
protected override string CommitButtonText => @"Save";
|
||||||
|
|
||||||
|
protected override string TextboxPlaceholderText => @"Miltiline textboxes soon";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
71
osu.Game/Overlays/Comments/CancellableCommentEditor.cs
Normal file
71
osu.Game/Overlays/Comments/CancellableCommentEditor.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
// 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;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Comments
|
||||||
|
{
|
||||||
|
public abstract class CancellableCommentEditor : CommentEditor
|
||||||
|
{
|
||||||
|
public Action OnCancel;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
ButtonsContainer.Add(new CancelButton
|
||||||
|
{
|
||||||
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
Action = () => OnCancel?.Invoke()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private class CancelButton : OsuHoverContainer
|
||||||
|
{
|
||||||
|
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
|
||||||
|
|
||||||
|
private readonly Box background;
|
||||||
|
|
||||||
|
public CancelButton()
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
Child = new CircularContainer
|
||||||
|
{
|
||||||
|
Masking = true,
|
||||||
|
Height = 25,
|
||||||
|
AutoSizeAxes = Axes.X,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
background = new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
|
||||||
|
Margin = new MarginPadding { Horizontal = 20 },
|
||||||
|
Text = @"Cancel"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OverlayColourProvider colourProvider)
|
||||||
|
{
|
||||||
|
IdleColour = colourProvider.GetColour(0.5f, 0.45f);
|
||||||
|
HoverColour = colourProvider.GetColour(0.5f, 0.6f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,8 @@ namespace osu.Game.Overlays.Comments
|
|||||||
|
|
||||||
protected abstract string TextboxPlaceholderText { get; }
|
protected abstract string TextboxPlaceholderText { get; }
|
||||||
|
|
||||||
|
protected FillFlowContainer ButtonsContainer;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OverlayColourProvider colourProvider)
|
private void load(OverlayColourProvider colourProvider)
|
||||||
{
|
{
|
||||||
@ -67,6 +69,14 @@ namespace osu.Game.Overlays.Comments
|
|||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
|
||||||
Text = FooterText
|
Text = FooterText
|
||||||
|
},
|
||||||
|
ButtonsContainer = new FillFlowContainer
|
||||||
|
{
|
||||||
|
Name = "Buttons",
|
||||||
|
Anchor = Anchor.CentreRight,
|
||||||
|
Origin = Anchor.CentreRight,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,28 +16,28 @@ namespace osu.Game.Overlays
|
|||||||
this.colourScheme = colourScheme;
|
this.colourScheme = colourScheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color4 Highlight1 => getColour(1, 0.7f);
|
public Color4 Highlight1 => GetColour(1, 0.7f);
|
||||||
public Color4 Content1 => getColour(0.4f, 1);
|
public Color4 Content1 => GetColour(0.4f, 1);
|
||||||
public Color4 Content2 => getColour(0.4f, 0.9f);
|
public Color4 Content2 => GetColour(0.4f, 0.9f);
|
||||||
public Color4 Light1 => getColour(0.4f, 0.8f);
|
public Color4 Light1 => GetColour(0.4f, 0.8f);
|
||||||
public Color4 Light2 => getColour(0.4f, 0.75f);
|
public Color4 Light2 => GetColour(0.4f, 0.75f);
|
||||||
public Color4 Light3 => getColour(0.4f, 0.7f);
|
public Color4 Light3 => GetColour(0.4f, 0.7f);
|
||||||
public Color4 Light4 => getColour(0.4f, 0.5f);
|
public Color4 Light4 => GetColour(0.4f, 0.5f);
|
||||||
public Color4 Dark1 => getColour(0.2f, 0.35f);
|
public Color4 Dark1 => GetColour(0.2f, 0.35f);
|
||||||
public Color4 Dark2 => getColour(0.2f, 0.3f);
|
public Color4 Dark2 => GetColour(0.2f, 0.3f);
|
||||||
public Color4 Dark3 => getColour(0.2f, 0.25f);
|
public Color4 Dark3 => GetColour(0.2f, 0.25f);
|
||||||
public Color4 Dark4 => getColour(0.2f, 0.2f);
|
public Color4 Dark4 => GetColour(0.2f, 0.2f);
|
||||||
public Color4 Dark5 => getColour(0.2f, 0.15f);
|
public Color4 Dark5 => GetColour(0.2f, 0.15f);
|
||||||
public Color4 Dark6 => getColour(0.2f, 0.1f);
|
public Color4 Dark6 => GetColour(0.2f, 0.1f);
|
||||||
public Color4 Foreground1 => getColour(0.1f, 0.6f);
|
public Color4 Foreground1 => GetColour(0.1f, 0.6f);
|
||||||
public Color4 Background1 => getColour(0.1f, 0.4f);
|
public Color4 Background1 => GetColour(0.1f, 0.4f);
|
||||||
public Color4 Background2 => getColour(0.1f, 0.3f);
|
public Color4 Background2 => GetColour(0.1f, 0.3f);
|
||||||
public Color4 Background3 => getColour(0.1f, 0.25f);
|
public Color4 Background3 => GetColour(0.1f, 0.25f);
|
||||||
public Color4 Background4 => getColour(0.1f, 0.2f);
|
public Color4 Background4 => GetColour(0.1f, 0.2f);
|
||||||
public Color4 Background5 => getColour(0.1f, 0.15f);
|
public Color4 Background5 => GetColour(0.1f, 0.15f);
|
||||||
public Color4 Background6 => getColour(0.1f, 0.1f);
|
public Color4 Background6 => GetColour(0.1f, 0.1f);
|
||||||
|
|
||||||
private Color4 getColour(float saturation, float lightness) => Color4.FromHsl(new Vector4(getBaseHue(colourScheme), saturation, lightness, 1));
|
public Color4 GetColour(float saturation, float lightness) => Color4.FromHsl(new Vector4(getBaseHue(colourScheme), saturation, lightness, 1));
|
||||||
|
|
||||||
// See https://github.com/ppy/osu-web/blob/4218c288292d7c810b619075471eaea8bbb8f9d8/app/helpers.php#L1463
|
// See https://github.com/ppy/osu-web/blob/4218c288292d7c810b619075471eaea8bbb8f9d8/app/helpers.php#L1463
|
||||||
private static float getBaseHue(OverlayColourScheme colourScheme)
|
private static float getBaseHue(OverlayColourScheme colourScheme)
|
||||||
|
Loading…
Reference in New Issue
Block a user