1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-23 18:10:01 +08:00

Merge remote-tracking branch 'upstream/master' into inter-column-movements

This commit is contained in:
Dean Herbert 2018-11-30 11:57:53 +09:00
commit 5254b07680
32 changed files with 1136 additions and 112 deletions

View File

@ -0,0 +1,18 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Mania.Edit.Blueprints;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
namespace osu.Game.Rulesets.Mania.Tests
{
public class TestCaseHoldNotePlacementBlueprint : ManiaPlacementBlueprintTestCase
{
protected override DrawableHitObject CreateHitObject(HitObject hitObject) => new DrawableHoldNote((HoldNote)hitObject);
protected override PlacementBlueprint CreateBlueprint() => new HoldNotePlacementBlueprint();
}
}

View File

@ -0,0 +1,21 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Game.Graphics;
using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
namespace osu.Game.Rulesets.Mania.Edit.Blueprints.Components
{
public class EditBodyPiece : BodyPiece
{
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AccentColour = colours.Yellow;
Background.Alpha = 0.5f;
Foreground.Alpha = 0;
}
}
}

View File

@ -0,0 +1,74 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Mania.Edit.Blueprints.Components;
using osu.Game.Rulesets.Mania.Objects;
using osuTK;
namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{
public class HoldNotePlacementBlueprint : ManiaPlacementBlueprint<HoldNote>
{
private readonly EditBodyPiece bodyPiece;
private readonly EditNotePiece headPiece;
private readonly EditNotePiece tailPiece;
public HoldNotePlacementBlueprint()
: base(new HoldNote())
{
RelativeSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
bodyPiece = new EditBodyPiece { Origin = Anchor.TopCentre },
headPiece = new EditNotePiece { Origin = Anchor.Centre },
tailPiece = new EditNotePiece { Origin = Anchor.Centre }
};
}
protected override void Update()
{
base.Update();
if (Column != null)
{
headPiece.Y = PositionAt(HitObject.StartTime);
tailPiece.Y = PositionAt(HitObject.EndTime);
}
var topPosition = new Vector2(headPiece.DrawPosition.X, Math.Min(headPiece.DrawPosition.Y, tailPiece.DrawPosition.Y));
var bottomPosition = new Vector2(headPiece.DrawPosition.X, Math.Max(headPiece.DrawPosition.Y, tailPiece.DrawPosition.Y));
bodyPiece.Position = topPosition;
bodyPiece.Width = headPiece.Width;
bodyPiece.Height = (bottomPosition - topPosition).Y;
}
private double originalStartTime;
protected override bool OnMouseMove(MouseMoveEvent e)
{
base.OnMouseMove(e);
if (PlacementBegun)
{
var endTime = TimeAt(e.ScreenSpaceMousePosition);
HitObject.StartTime = endTime < originalStartTime ? endTime : originalStartTime;
HitObject.Duration = Math.Abs(endTime - originalStartTime);
}
else
{
headPiece.Width = tailPiece.Width = SnappedWidth;
headPiece.X = tailPiece.X = SnappedMousePosition.X;
originalStartTime = HitObject.StartTime = TimeAt(e.ScreenSpaceMousePosition);
}
return true;
}
}
}

View File

@ -3,6 +3,7 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Input;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Mania.Objects;
@ -13,11 +14,14 @@ using osuTK;
namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{
public abstract class ManiaPlacementBlueprint<T> : PlacementBlueprint
public abstract class ManiaPlacementBlueprint<T> : PlacementBlueprint,
IRequireHighFrequencyMousePosition // the playfield could be moving behind us
where T : ManiaHitObject
{
protected new T HitObject => (T)base.HitObject;
protected Column Column;
/// <summary>
/// The current mouse position, snapped to the closest column.
/// </summary>
@ -40,35 +44,49 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
RelativeSizeAxes = Axes.None;
}
protected override bool OnMouseDown(MouseDownEvent e)
{
if (Column == null)
return base.OnMouseDown(e);
HitObject.StartTime = TimeAt(e.ScreenSpaceMousePosition);
HitObject.Column = Column.Index;
BeginPlacement();
return true;
}
protected override bool OnMouseUp(MouseUpEvent e)
{
EndPlacement();
return base.OnMouseUp(e);
}
protected override bool OnMouseMove(MouseMoveEvent e)
{
Column column = ColumnAt(e.ScreenSpaceMousePosition);
if (!PlacementBegun)
Column = ColumnAt(e.ScreenSpaceMousePosition);
if (column == null)
SnappedMousePosition = e.MousePosition;
else
{
SnappedWidth = column.DrawWidth;
if (Column == null) return false;
// Snap to the column
var parentPos = Parent.ToLocalSpace(column.ToScreenSpace(new Vector2(column.DrawWidth / 2, 0)));
SnappedMousePosition = new Vector2(parentPos.X, e.MousePosition.Y);
}
SnappedWidth = Column.DrawWidth;
// Snap to the column
var parentPos = Parent.ToLocalSpace(Column.ToScreenSpace(new Vector2(Column.DrawWidth / 2, 0)));
SnappedMousePosition = new Vector2(parentPos.X, e.MousePosition.Y);
return true;
}
protected double TimeAt(Vector2 screenSpacePosition)
{
var column = ColumnAt(screenSpacePosition);
if (column == null)
if (Column == null)
return 0;
var hitObjectContainer = column.HitObjectContainer;
var hitObjectContainer = Column.HitObjectContainer;
// If we're scrolling downwards, a position of 0 is actually further away from the hit target
// so we need to flip the vertical coordinate in the hitobject container's space
var hitObjectPos = column.HitObjectContainer.ToLocalSpace(applyPositionOffset(screenSpacePosition)).Y;
var hitObjectPos = Column.HitObjectContainer.ToLocalSpace(applyPositionOffset(screenSpacePosition, false)).Y;
if (scrollingInfo.Direction.Value == ScrollingDirection.Down)
hitObjectPos = hitObjectContainer.DrawHeight - hitObjectPos;
@ -78,21 +96,22 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
hitObjectContainer.DrawHeight);
}
protected Column ColumnAt(Vector2 screenSpacePosition)
=> composer.ColumnAt(applyPositionOffset(screenSpacePosition));
private Vector2 applyPositionOffset(Vector2 position)
protected float PositionAt(double time)
{
switch (scrollingInfo.Direction.Value)
{
case ScrollingDirection.Up:
position.Y -= NotePiece.NOTE_HEIGHT / 2;
break;
case ScrollingDirection.Down:
position.Y += NotePiece.NOTE_HEIGHT / 2;
break;
}
var pos = scrollingInfo.Algorithm.PositionAt(time,
EditorClock.CurrentTime,
scrollingInfo.TimeRange.Value,
Column.HitObjectContainer.DrawHeight);
return applyPositionOffset(Column.HitObjectContainer.ToSpaceOfOtherDrawable(new Vector2(0, pos), Parent), true).Y;
}
protected Column ColumnAt(Vector2 screenSpacePosition)
=> composer.ColumnAt(applyPositionOffset(screenSpacePosition, false));
private Vector2 applyPositionOffset(Vector2 position, bool reverse)
{
position.Y += (scrollingInfo.Direction.Value == ScrollingDirection.Up && !reverse ? -1 : 1) * NotePiece.NOTE_HEIGHT / 2;
return position;
}
}

View File

@ -2,10 +2,8 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Mania.Edit.Blueprints.Components;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.UI;
namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{
@ -28,19 +26,5 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
Width = SnappedWidth;
Position = SnappedMousePosition;
}
protected override bool OnClick(ClickEvent e)
{
Column column;
if ((column = ColumnAt(e.ScreenSpaceMousePosition)) == null)
return base.OnClick(e);
HitObject.StartTime = TimeAt(e.ScreenSpaceMousePosition);
HitObject.Column = column.Index;
EndPlacement();
return true;
}
}
}

View File

@ -0,0 +1,19 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Tools;
using osu.Game.Rulesets.Mania.Edit.Blueprints;
namespace osu.Game.Rulesets.Mania.Edit
{
public class HoldNoteCompositionTool : HitObjectCompositionTool
{
public HoldNoteCompositionTool()
: base("Hold")
{
}
public override PlacementBlueprint CreatePlacementBlueprint() => new HoldNotePlacementBlueprint();
}
}

View File

@ -53,7 +53,8 @@ namespace osu.Game.Rulesets.Mania.Edit
protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => new HitObjectCompositionTool[]
{
new NoteCompositionTool()
new NoteCompositionTool(),
new HoldNoteCompositionTool()
};
public override SelectionHandler CreateSelectionHandler() => new ManiaSelectionHandler();

View File

@ -15,12 +15,12 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables.Pieces
/// <summary>
/// Represents length-wise portion of a hold note.
/// </summary>
internal class BodyPiece : Container, IHasAccentColour
public class BodyPiece : Container, IHasAccentColour
{
private readonly Container subtractionLayer;
private readonly Drawable background;
private readonly BufferedContainer foreground;
protected readonly Drawable Background;
protected readonly BufferedContainer Foreground;
private readonly BufferedContainer subtractionContainer;
public BodyPiece()
@ -29,8 +29,8 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables.Pieces
Children = new[]
{
background = new Box { RelativeSizeAxes = Axes.Both },
foreground = new BufferedContainer
Background = new Box { RelativeSizeAxes = Axes.Both },
Foreground = new BufferedContainer
{
Blending = BlendingMode.Additive,
RelativeSizeAxes = Axes.Both,
@ -123,7 +123,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables.Pieces
Radius = DrawWidth
};
foreground.ForceRedraw();
Foreground.ForceRedraw();
subtractionContainer.ForceRedraw();
subtractionCache.Validate();
@ -137,18 +137,18 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables.Pieces
if (!IsLoaded)
return;
foreground.Colour = AccentColour.Opacity(0.5f);
background.Colour = AccentColour.Opacity(0.7f);
Foreground.Colour = AccentColour.Opacity(0.5f);
Background.Colour = AccentColour.Opacity(0.7f);
const float animation_length = 50;
foreground.ClearTransforms(false, nameof(foreground.Colour));
Foreground.ClearTransforms(false, nameof(Foreground.Colour));
if (hitting)
{
// wait for the next sync point
double synchronisedOffset = animation_length * 2 - Time.Current % (animation_length * 2);
using (foreground.BeginDelayedSequence(synchronisedOffset))
foreground.FadeColour(AccentColour.Lighten(0.2f), animation_length).Then().FadeColour(foreground.Colour, animation_length).Loop();
using (Foreground.BeginDelayedSequence(synchronisedOffset))
Foreground.FadeColour(AccentColour.Lighten(0.2f), animation_length).Then().FadeColour(Foreground.Colour, animation_length).Loop();
}
subtractionCache.Invalidate();

View File

@ -185,6 +185,6 @@ namespace osu.Game.Rulesets.Mania.UI
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)
// This probably shouldn't exist as is, but the columns in the stage are separated by a 1px border
=> DrawRectangle.Inflate(new Vector2(1, 0)).Contains(ToLocalSpace(screenSpacePos));
=> DrawRectangle.Inflate(new Vector2(ManiaStage.COLUMN_SPACING / 2, 0)).Contains(ToLocalSpace(screenSpacePos));
}
}

View File

@ -18,6 +18,8 @@ namespace osu.Game.Rulesets.Mania.UI
{
private readonly List<ManiaStage> stages = new List<ManiaStage>();
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => stages.Any(s => s.ReceivePositionalInputAt(screenSpacePos));
public ManiaPlayfield(List<StageDefinition> stageDefinitions)
{
if (stageDefinitions == null)
@ -53,6 +55,8 @@ namespace osu.Game.Rulesets.Mania.UI
public override void Add(DrawableHitObject h) => getStageByColumn(((ManiaHitObject)h.HitObject).Column).Add(h);
public override bool Remove(DrawableHitObject h) => getStageByColumn(((ManiaHitObject)h.HitObject).Column).Remove(h);
public void Add(BarLine barline) => stages.ForEach(s => s.Add(barline));
/// <summary>

View File

@ -25,6 +25,8 @@ namespace osu.Game.Rulesets.Mania.UI
/// </summary>
public class ManiaStage : ScrollingPlayfield
{
public const float COLUMN_SPACING = 1;
public const float HIT_TARGET_POSITION = 50;
public IReadOnlyList<Column> Columns => columnFlow.Children;
@ -40,6 +42,8 @@ namespace osu.Game.Rulesets.Mania.UI
private List<Color4> normalColumnColours = new List<Color4>();
private Color4 specialColumnColour;
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Columns.Any(c => c.ReceivePositionalInputAt(screenSpacePos));
private readonly int firstColumnIndex;
public ManiaStage(int firstColumnIndex, StageDefinition definition, ref ManiaAction normalColumnStartAction, ref ManiaAction specialColumnStartAction)
@ -84,8 +88,8 @@ namespace osu.Game.Rulesets.Mania.UI
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Direction = FillDirection.Horizontal,
Padding = new MarginPadding { Left = 1, Right = 1 },
Spacing = new Vector2(1, 0)
Padding = new MarginPadding { Left = COLUMN_SPACING, Right = COLUMN_SPACING },
Spacing = new Vector2(COLUMN_SPACING, 0)
},
}
},
@ -167,6 +171,16 @@ namespace osu.Game.Rulesets.Mania.UI
h.OnNewResult += OnNewResult;
}
public override bool Remove(DrawableHitObject h)
{
var maniaObject = (ManiaHitObject)h.HitObject;
int columnIndex = maniaObject.Column - firstColumnIndex;
Columns.ElementAt(columnIndex).Remove(h);
h.OnNewResult -= OnNewResult;
return true;
}
public void Add(BarLine barline) => base.Add(new DrawableBarLine(barline));
internal void OnNewResult(DrawableHitObject judgedObject, JudgementResult result)

View File

@ -16,8 +16,6 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public class DrawableOsuHitObject : DrawableHitObject<OsuHitObject>
{
public override bool IsPresent => base.IsPresent || State.Value == ArmedState.Idle && Clock?.CurrentTime >= HitObject.StartTime - HitObject.TimePreempt;
private readonly ShakeContainer shakeContainer;
protected DrawableOsuHitObject(OsuHitObject hitObject)

View File

@ -217,6 +217,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
switch (state)
{
case ArmedState.Idle:
Expire(true);
break;
case ArmedState.Hit:
sequence.ScaleTo(Scale * 1.2f, 320, Easing.Out);
break;

View File

@ -16,6 +16,7 @@ using NUnit.Framework;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osu.Framework.Configuration;
namespace osu.Game.Tests.Visual
{
@ -54,8 +55,9 @@ namespace osu.Game.Tests.Visual
linkColour = colours.Blue;
var chatManager = new ChannelManager();
chatManager.AvailableChannels.Add(new Channel { Name = "#english"});
chatManager.AvailableChannels.Add(new Channel { Name = "#japanese" });
BindableCollection<Channel> availableChannels = (BindableCollection<Channel>)chatManager.AvailableChannels;
availableChannels.Add(new Channel { Name = "#english"});
availableChannels.Add(new Channel { Name = "#japanese" });
Dependencies.Cache(chatManager);
Dependencies.Cache(new ChatOverlay());

View File

@ -0,0 +1,135 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Input;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual
{
[TestFixture]
public class TestCaseIdleTracker : ManualInputManagerTestCase
{
private readonly IdleTrackingBox box1;
private readonly IdleTrackingBox box2;
private readonly IdleTrackingBox box3;
private readonly IdleTrackingBox box4;
public TestCaseIdleTracker()
{
Children = new Drawable[]
{
box1 = new IdleTrackingBox(1000)
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Red,
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
},
box2 = new IdleTrackingBox(2000)
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Green,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
},
box3 = new IdleTrackingBox(3000)
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Blue,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
},
box4 = new IdleTrackingBox(4000)
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Orange,
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
},
};
}
[Test]
public void TestNudge()
{
AddStep("move mouse to top left", () => InputManager.MoveMouseTo(box1.ScreenSpaceDrawQuad.Centre));
AddUntilStep(() => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle, "Wait for all idle");
AddStep("nudge mouse", () => InputManager.MoveMouseTo(box1.ScreenSpaceDrawQuad.Centre + new Vector2(1)));
AddAssert("check not idle", () => !box1.IsIdle);
AddAssert("check idle", () => box2.IsIdle);
AddAssert("check idle", () => box3.IsIdle);
AddAssert("check idle", () => box4.IsIdle);
}
[Test]
public void TestMovement()
{
AddStep("move mouse", () => InputManager.MoveMouseTo(box2.ScreenSpaceDrawQuad.Centre));
AddAssert("check not idle", () => box1.IsIdle);
AddAssert("check not idle", () => !box2.IsIdle);
AddAssert("check idle", () => box3.IsIdle);
AddAssert("check idle", () => box4.IsIdle);
AddStep("move mouse", () => InputManager.MoveMouseTo(box3.ScreenSpaceDrawQuad.Centre));
AddStep("move mouse", () => InputManager.MoveMouseTo(box4.ScreenSpaceDrawQuad.Centre));
AddAssert("check not idle", () => box1.IsIdle);
AddAssert("check not idle", () => !box2.IsIdle);
AddAssert("check idle", () => !box3.IsIdle);
AddAssert("check idle", () => !box4.IsIdle);
AddUntilStep(() => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle, "Wait for all idle");
}
[Test]
public void TestTimings()
{
AddStep("move mouse", () => InputManager.MoveMouseTo(ScreenSpaceDrawQuad.Centre));
AddAssert("check not idle", () => !box1.IsIdle && !box2.IsIdle && !box3.IsIdle && !box4.IsIdle);
AddUntilStep(() => box1.IsIdle, "Wait for idle");
AddAssert("check not idle", () => !box2.IsIdle && !box3.IsIdle && !box4.IsIdle);
AddUntilStep(() => box2.IsIdle, "Wait for idle");
AddAssert("check not idle", () => !box3.IsIdle && !box4.IsIdle);
AddUntilStep(() => box3.IsIdle, "Wait for idle");
AddUntilStep(() => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle, "Wait for all idle");
}
private class IdleTrackingBox : CompositeDrawable
{
private readonly IdleTracker idleTracker;
public bool IsIdle => idleTracker.IsIdle.Value;
public IdleTrackingBox(double timeToIdle)
{
Box box;
Alpha = 0.6f;
Scale = new Vector2(0.6f);
InternalChildren = new Drawable[]
{
idleTracker = new IdleTracker(timeToIdle),
box = new Box
{
Colour = Color4.White,
RelativeSizeAxes = Axes.Both,
},
};
idleTracker.IsIdle.BindValueChanged(idle => box.Colour = idle ? Color4.White : Color4.Black, true);
}
}
}
}

View File

@ -0,0 +1,119 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Testing.Input;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi.Screens.Match.Settings;
using osuTK.Input;
namespace osu.Game.Tests.Visual
{
[TestFixture]
public class TestCaseRoomSettings : ManualInputManagerTestCase
{
private readonly Room room;
private readonly TestRoomSettingsOverlay overlay;
public TestCaseRoomSettings()
{
room = new Room
{
Name = { Value = "One Testing Room" },
Availability = { Value = RoomAvailability.Public },
Type = { Value = new GameTypeTeamVersus() },
MaxParticipants = { Value = 10 },
};
Add(overlay = new TestRoomSettingsOverlay(room)
{
RelativeSizeAxes = Axes.Both,
Height = 0.75f,
});
AddStep(@"show", overlay.Show);
assertAll();
AddStep(@"set name", () => overlay.CurrentName = @"Two Testing Room");
AddStep(@"set max", () => overlay.CurrentMaxParticipants = null);
AddStep(@"set availability", () => overlay.CurrentAvailability = RoomAvailability.InviteOnly);
AddStep(@"set type", () => overlay.CurrentType = new GameTypeTagTeam());
apply();
assertAll();
AddStep(@"show", overlay.Show);
AddStep(@"set room name", () => room.Name.Value = @"Room Changed Name!");
AddStep(@"set room availability", () => room.Availability.Value = RoomAvailability.Public);
AddStep(@"set room type", () => room.Type.Value = new GameTypeTag());
AddStep(@"set room max", () => room.MaxParticipants.Value = 100);
assertAll();
AddStep(@"set name", () => overlay.CurrentName = @"Unsaved Testing Room");
AddStep(@"set max", () => overlay.CurrentMaxParticipants = 20);
AddStep(@"set availability", () => overlay.CurrentAvailability = RoomAvailability.FriendsOnly);
AddStep(@"set type", () => overlay.CurrentType = new GameTypeVersus());
AddStep(@"hide", overlay.Hide);
AddWaitStep(5);
AddStep(@"show", overlay.Show);
assertAll();
AddStep(@"hide", overlay.Hide);
}
private void apply()
{
AddStep(@"apply", () =>
{
overlay.ClickApplyButton(InputManager);
});
}
private void assertAll()
{
AddAssert(@"name == room name", () => overlay.CurrentName == room.Name.Value);
AddAssert(@"max == room max", () => overlay.CurrentMaxParticipants == room.MaxParticipants.Value);
AddAssert(@"availability == room availability", () => overlay.CurrentAvailability == room.Availability.Value);
AddAssert(@"type == room type", () => Equals(overlay.CurrentType, room.Type.Value));
}
private class TestRoomSettingsOverlay : RoomSettingsOverlay
{
public string CurrentName
{
get => NameField.Text;
set => NameField.Text = value;
}
public int? CurrentMaxParticipants
{
get
{
if (int.TryParse(MaxParticipantsField.Text, out int max))
return max;
return null;
}
set => MaxParticipantsField.Text = value?.ToString();
}
public RoomAvailability CurrentAvailability
{
get => AvailabilityPicker.Current.Value;
set => AvailabilityPicker.Current.Value = value;
}
public GameType CurrentType
{
get => TypePicker.Current.Value;
set => TypePicker.Current.Value = value;
}
public TestRoomSettingsOverlay(Room room) : base(room)
{
}
public void ClickApplyButton(ManualInputManager inputManager)
{
inputManager.MoveMouseTo(ApplyButton);
inputManager.Click(MouseButton.Left);
}
}
}
}

View File

@ -0,0 +1,71 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
namespace osu.Game.Input
{
/// <summary>
/// Track whether the end-user is in an idle state, based on their last interaction with the game.
/// </summary>
public class IdleTracker : Component, IKeyBindingHandler<PlatformAction>, IHandleGlobalInput
{
private readonly double timeToIdle;
private double lastInteractionTime;
protected double TimeSpentIdle => Clock.CurrentTime - lastInteractionTime;
/// <summary>
/// Whether the user is currently in an idle state.
/// </summary>
public IBindable<bool> IsIdle => isIdle;
private readonly BindableBool isIdle = new BindableBool();
/// <summary>
/// Intstantiate a new <see cref="IdleTracker"/>.
/// </summary>
/// <param name="timeToIdle">The length in milliseconds until an idle state should be assumed.</param>
public IdleTracker(double timeToIdle)
{
this.timeToIdle = timeToIdle;
RelativeSizeAxes = Axes.Both;
}
protected override void Update()
{
base.Update();
isIdle.Value = TimeSpentIdle > timeToIdle;
}
public bool OnPressed(PlatformAction action) => updateLastInteractionTime();
public bool OnReleased(PlatformAction action) => updateLastInteractionTime();
protected override bool Handle(UIEvent e)
{
switch (e)
{
case KeyDownEvent _:
case KeyUpEvent _:
case MouseDownEvent _:
case MouseUpEvent _:
case MouseMoveEvent _:
return updateLastInteractionTime();
default:
return base.Handle(e);
}
}
private bool updateLastInteractionTime()
{
lastInteractionTime = Clock.CurrentTime;
return false;
}
}
}

View File

@ -178,6 +178,7 @@ namespace osu.Game.Online.API
AddParameter("grant_type", GrantType);
AddParameter("client_id", ClientId);
AddParameter("client_secret", ClientSecret);
AddParameter("scope", "*");
base.PrePerform();
}

View File

@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
@ -31,6 +30,9 @@ namespace osu.Game.Online.Chat
@"#lobby"
};
private readonly BindableCollection<Channel> availableChannels = new BindableCollection<Channel>();
private readonly BindableCollection<Channel> joinedChannels = new BindableCollection<Channel>();
/// <summary>
/// The currently opened channel
/// </summary>
@ -39,12 +41,12 @@ namespace osu.Game.Online.Chat
/// <summary>
/// The Channels the player has joined
/// </summary>
public ObservableCollection<Channel> JoinedChannels { get; } = new ObservableCollection<Channel>(); //todo: should be publicly readonly
public IBindableCollection<Channel> JoinedChannels => joinedChannels;
/// <summary>
/// The channels available for the player to join
/// </summary>
public ObservableCollection<Channel> AvailableChannels { get; } = new ObservableCollection<Channel>(); //todo: should be publicly readonly
public IBindableCollection<Channel> AvailableChannels => availableChannels;
private IAPIProvider api;
private ScheduledDelegate fetchMessagesScheduleder;
@ -293,8 +295,8 @@ namespace osu.Game.Online.Chat
found.Users.Remove(foundSelf);
}
if (joined == null && addToJoined) JoinedChannels.Add(found);
if (available == null && addToAvailable) AvailableChannels.Add(found);
if (joined == null && addToJoined) joinedChannels.Add(found);
if (available == null && addToAvailable) availableChannels.Add(found);
return found;
}
@ -346,9 +348,10 @@ namespace osu.Game.Online.Chat
{
if (channel == null) return;
if (channel == CurrentChannel.Value) CurrentChannel.Value = null;
if (channel == CurrentChannel.Value)
CurrentChannel.Value = null;
JoinedChannels.Remove(channel);
joinedChannels.Remove(channel);
if (channel.Joined.Value)
{

View File

@ -14,6 +14,9 @@ namespace osu.Game.Online.Multiplayer
{
public abstract string Name { get; }
public abstract Drawable GetIcon(OsuColour colours, float size);
public override int GetHashCode() => GetType().GetHashCode();
public override bool Equals(object obj) => GetType() == obj?.GetType();
}
public class GameTypeTag : GameType

View File

@ -26,6 +26,7 @@ using osu.Framework.Platform;
using osu.Framework.Threading;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Input;
using osu.Game.Rulesets.Scoring;
using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets;
@ -88,6 +89,8 @@ namespace osu.Game
public float ToolbarOffset => Toolbar.Position.Y + Toolbar.DrawHeight;
private IdleTracker idleTracker;
public readonly Bindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>();
private OsuScreen screenStack;
@ -316,6 +319,7 @@ namespace osu.Game
},
mainContent = new Container { RelativeSizeAxes = Axes.Both },
overlayContent = new Container { RelativeSizeAxes = Axes.Both, Depth = float.MinValue },
idleTracker = new IdleTracker(6000)
});
loadComponentSingleFile(screenStack = new Loader(), d =>
@ -373,6 +377,7 @@ namespace osu.Game
Depth = -6,
}, overlayContent.Add);
dependencies.Cache(idleTracker);
dependencies.Cache(settings);
dependencies.Cache(onscreenDisplay);
dependencies.Cache(social);

View File

@ -2,7 +2,6 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using System.Collections.Specialized;
using osuTK;
using osuTK.Graphics;
using osu.Framework.Allocation;
@ -181,28 +180,6 @@ namespace osu.Game.Overlays
channelSelection.OnRequestLeave = channel => channelManager.LeaveChannel(channel);
}
private void joinedChannelsChanged(object sender, NotifyCollectionChangedEventArgs args)
{
switch (args.Action)
{
case NotifyCollectionChangedAction.Add:
foreach (Channel newChannel in args.NewItems)
{
channelTabControl.AddChannel(newChannel);
}
break;
case NotifyCollectionChangedAction.Remove:
foreach (Channel removedChannel in args.OldItems)
{
channelTabControl.RemoveChannel(removedChannel);
loadedChannels.Remove(loadedChannels.Find(c => c.Channel == removedChannel));
}
break;
}
}
private void currentChannelChanged(Channel channel)
{
if (channel == null)
@ -322,19 +299,35 @@ namespace osu.Game.Overlays
this.channelManager = channelManager;
channelManager.CurrentChannel.ValueChanged += currentChannelChanged;
channelManager.JoinedChannels.CollectionChanged += joinedChannelsChanged;
channelManager.AvailableChannels.CollectionChanged += availableChannelsChanged;
channelManager.JoinedChannels.ItemsAdded += onChannelAddedToJoinedChannels;
channelManager.JoinedChannels.ItemsRemoved += onChannelRemovedFromJoinedChannels;
channelManager.AvailableChannels.ItemsAdded += availableChannelsChanged;
channelManager.AvailableChannels.ItemsRemoved += availableChannelsChanged;
//for the case that channelmanager was faster at fetching the channels than our attachment to CollectionChanged.
channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels);
joinedChannelsChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, channelManager.JoinedChannels));
foreach (Channel channel in channelManager.JoinedChannels)
channelTabControl.AddChannel(channel);
}
private void availableChannelsChanged(object sender, NotifyCollectionChangedEventArgs e)
private void onChannelAddedToJoinedChannels(IEnumerable<Channel> channels)
{
channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels);
foreach (Channel channel in channels)
channelTabControl.AddChannel(channel);
}
private void onChannelRemovedFromJoinedChannels(IEnumerable<Channel> channels)
{
foreach (Channel channel in channels)
{
channelTabControl.RemoveChannel(channel);
loadedChannels.Remove(loadedChannels.Find(c => c.Channel == channel));
}
}
private void availableChannelsChanged(IEnumerable<Channel> channels)
=> channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels);
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
@ -342,8 +335,10 @@ namespace osu.Game.Overlays
if (channelManager != null)
{
channelManager.CurrentChannel.ValueChanged -= currentChannelChanged;
channelManager.JoinedChannels.CollectionChanged -= joinedChannelsChanged;
channelManager.AvailableChannels.CollectionChanged -= availableChannelsChanged;
channelManager.JoinedChannels.ItemsAdded -= onChannelAddedToJoinedChannels;
channelManager.JoinedChannels.ItemsRemoved -= onChannelRemovedFromJoinedChannels;
channelManager.AvailableChannels.ItemsAdded -= availableChannelsChanged;
channelManager.AvailableChannels.ItemsRemoved -= availableChannelsChanged;
}
}

View File

@ -25,7 +25,7 @@ namespace osu.Game.Overlays.Volume
private CircularProgress volumeCircle;
private CircularProgress volumeCircleGlow;
public BindableDouble Bindable { get; } = new BindableDouble { MinValue = 0, MaxValue = 1 };
public BindableDouble Bindable { get; } = new BindableDouble { MinValue = 0, MaxValue = 1, Precision = 0.01 };
private readonly float circleSize;
private readonly Color4 meterColour;
private readonly string name;
@ -222,7 +222,7 @@ namespace osu.Game.Overlays.Volume
private set => Bindable.Value = value;
}
private const float adjust_step = 0.05f;
private const double adjust_step = 0.05;
public void Increase(double amount = 1, bool isPrecise = false) => adjust(amount, isPrecise);
public void Decrease(double amount = 1, bool isPrecise = false) => adjust(-amount, isPrecise);
@ -236,7 +236,7 @@ namespace osu.Game.Overlays.Volume
var precision = Bindable.Precision;
while (Math.Abs(scrollAccumulation) > precision)
while (Precision.AlmostBigger(Math.Abs(scrollAccumulation), precision))
{
Volume += Math.Sign(scrollAccumulation) * precision;
scrollAccumulation = scrollAccumulation < 0 ? Math.Min(0, scrollAccumulation + precision) : Math.Max(0, scrollAccumulation - precision);

View File

@ -91,8 +91,8 @@ namespace osu.Game.Rulesets.Edit
// Process the beatmap
var processor = ruleset.CreateBeatmapProcessor(beatmap);
processor.PreProcess();
processor.PostProcess();
processor?.PreProcess();
processor?.PostProcess();
// Remove visual representation
var drawableObject = Playfield.AllHitObjects.Single(d => d.HitObject == hitObject);

View File

@ -7,7 +7,6 @@ using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Input.Events;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
@ -20,7 +19,7 @@ namespace osu.Game.Rulesets.Edit
/// <summary>
/// A blueprint which governs the creation of a new <see cref="HitObject"/> to actualisation.
/// </summary>
public abstract class PlacementBlueprint : CompositeDrawable, IStateful<PlacementState>, IRequireHighFrequencyMousePosition
public abstract class PlacementBlueprint : CompositeDrawable, IStateful<PlacementState>
{
/// <summary>
/// Invoked when <see cref="State"/> has changed.
@ -50,6 +49,10 @@ namespace osu.Game.Rulesets.Edit
RelativeSizeAxes = Axes.Both;
// This is required to allow the blueprint's position to be updated via OnMouseMove/Handle
// on the same frame it is made visible via a PlacementState change.
AlwaysPresent = true;
Alpha = 0;
}

View File

@ -84,6 +84,8 @@ namespace osu.Game.Rulesets.Objects.Drawables
public override bool RemoveCompletedTransforms => false;
protected override bool RequiresChildrenUpdate => true;
public override bool IsPresent => base.IsPresent || State.Value == ArmedState.Idle && Clock?.CurrentTime >= LifetimeStart;
public readonly Bindable<ArmedState> State = new Bindable<ArmedState>();
protected DrawableHitObject(HitObject hitObject)

View File

@ -8,12 +8,14 @@ using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
using osu.Framework.Logging;
using osu.Framework.Threading;
using osu.Game.Graphics;
using osu.Game.Input;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
using osuTK;
@ -26,6 +28,8 @@ namespace osu.Game.Screens.Menu
{
public event Action<ButtonSystemState> StateChanged;
private readonly IBindable<bool> isIdle = new BindableBool();
public Action OnEdit;
public Action OnExit;
public Action OnDirect;
@ -102,12 +106,22 @@ namespace osu.Game.Screens.Menu
private OsuGame game;
[BackgroundDependencyLoader(true)]
private void load(AudioManager audio, OsuGame game)
private void load(AudioManager audio, OsuGame game, IdleTracker idleTracker)
{
this.game = game;
isIdle.ValueChanged += updateIdleState;
if (idleTracker != null) isIdle.BindTo(idleTracker.IsIdle);
sampleBack = audio.Sample.Get(@"Menu/button-back-select");
}
private void updateIdleState(bool isIdle)
{
if (isIdle && State != ButtonSystemState.Exit)
State = ButtonSystemState.Initial;
}
public bool OnPressed(GlobalAction action)
{
switch (action)
@ -266,9 +280,6 @@ namespace osu.Game.Screens.Menu
protected override void Update()
{
//if (OsuGame.IdleTime > 6000 && State != MenuState.Exit)
// State = MenuState.Initial;
base.Update();
if (logo != null)

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi.Screens.Match.Settings;
using osu.Game.Screens.Select;
using osu.Game.Users;
@ -34,11 +35,15 @@ namespace osu.Game.Screens.Multi.Screens.Match
{
this.room = room;
Header header;
RoomSettingsOverlay settings;
Info info;
Children = new Drawable[]
{
header = new Header(),
header = new Header
{
Depth = -1,
},
info = new Info
{
Margin = new MarginPadding { Top = Header.HEIGHT },
@ -48,6 +53,16 @@ namespace osu.Game.Screens.Multi.Screens.Match
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = Header.HEIGHT + Info.HEIGHT },
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = Header.HEIGHT },
Child = settings = new RoomSettingsOverlay(room)
{
RelativeSizeAxes = Axes.Both,
Height = 0.9f,
},
},
};
header.OnRequestSelectBeatmap = () => Push(new MatchSongSelect());
@ -59,6 +74,20 @@ namespace osu.Game.Screens.Multi.Screens.Match
info.Beatmap = b;
}, true);
header.Tabs.Current.ValueChanged += t =>
{
if (t == MatchHeaderPage.Settings)
settings.Show();
else
settings.Hide();
};
settings.StateChanged += s =>
{
if (s == Visibility.Hidden)
header.Tabs.Current.Value = MatchHeaderPage.Room;
};
nameBind.BindTo(room.Name);
nameBind.BindValueChanged(n => info.Name = n, true);

View File

@ -0,0 +1,110 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi.Components;
using osuTK;
namespace osu.Game.Screens.Multi.Screens.Match.Settings
{
public class GameTypePicker : TabControl<GameType>
{
private const float height = 40;
private const float selection_width = 3;
protected override TabItem<GameType> CreateTabItem(GameType value) => new GameTypePickerItem(value);
protected override Dropdown<GameType> CreateDropdown() => null;
public GameTypePicker()
{
Height = height + selection_width * 2;
TabContainer.Spacing = new Vector2(10 - selection_width * 2);
AddItem(new GameTypeTag());
AddItem(new GameTypeVersus());
AddItem(new GameTypeTagTeam());
AddItem(new GameTypeTeamVersus());
}
private class GameTypePickerItem : TabItem<GameType>
{
private const float transition_duration = 200;
private readonly CircularContainer hover, selection;
public GameTypePickerItem(GameType value) : base(value)
{
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
{
selection = new CircularContainer
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Alpha = 0,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
},
},
new DrawableGameType(Value)
{
Size = new Vector2(height),
Margin = new MarginPadding(selection_width),
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(selection_width),
Child = hover = new CircularContainer
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Alpha = 0,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
},
},
},
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
selection.Colour = colours.Yellow;
}
protected override bool OnHover(HoverEvent e)
{
hover.FadeTo(0.05f, transition_duration, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
hover.FadeOut(transition_duration, Easing.OutQuint);
base.OnHoverLost(e);
}
protected override void OnActivated()
{
selection.FadeIn(transition_duration, Easing.OutQuint);
}
protected override void OnDeactivated()
{
selection.FadeOut(transition_duration, Easing.OutQuint);
}
}
}
}

View File

@ -0,0 +1,105 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Multiplayer;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Multi.Screens.Match.Settings
{
public class RoomAvailabilityPicker : TabControl<RoomAvailability>
{
protected override TabItem<RoomAvailability> CreateTabItem(RoomAvailability value) => new RoomAvailabilityPickerItem(value);
protected override Dropdown<RoomAvailability> CreateDropdown() => null;
public RoomAvailabilityPicker()
{
RelativeSizeAxes = Axes.X;
Height = 35;
TabContainer.Spacing = new Vector2(10);
AddItem(RoomAvailability.Public);
AddItem(RoomAvailability.FriendsOnly);
AddItem(RoomAvailability.InviteOnly);
}
private class RoomAvailabilityPickerItem : TabItem<RoomAvailability>
{
private const float transition_duration = 200;
private readonly Box hover, selection;
public RoomAvailabilityPickerItem(RoomAvailability value) : base(value)
{
RelativeSizeAxes = Axes.Y;
Width = 120;
Masking = true;
CornerRadius = 5;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"3d3943"),
},
selection = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
},
hover = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White,
Alpha = 0,
},
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = @"Exo2.0-Bold",
Text = value.GetDescription(),
},
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
selection.Colour = colours.GreenLight;
}
protected override bool OnHover(HoverEvent e)
{
hover.FadeTo(0.05f, transition_duration, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
hover.FadeOut(transition_duration, Easing.OutQuint);
base.OnHoverLost(e);
}
protected override void OnActivated()
{
selection.FadeIn(transition_duration, Easing.OutQuint);
}
protected override void OnDeactivated()
{
selection.FadeOut(transition_duration, Easing.OutQuint);
}
}
}
}

View File

@ -0,0 +1,270 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Multiplayer;
using osu.Game.Overlays.SearchableList;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Multi.Screens.Match.Settings
{
public class RoomSettingsOverlay : FocusedOverlayContainer
{
private const float transition_duration = 350;
private const float field_padding = 45;
private readonly Bindable<string> nameBind = new Bindable<string>();
private readonly Bindable<RoomAvailability> availabilityBind = new Bindable<RoomAvailability>();
private readonly Bindable<GameType> typeBind = new Bindable<GameType>();
private readonly Bindable<int?> maxParticipantsBind = new Bindable<int?>();
private readonly Container content;
private readonly OsuSpriteText typeLabel;
protected readonly OsuTextBox NameField, MaxParticipantsField;
protected readonly RoomAvailabilityPicker AvailabilityPicker;
protected readonly GameTypePicker TypePicker;
protected readonly TriangleButton ApplyButton;
public RoomSettingsOverlay(Room room)
{
Masking = true;
Child = content = new Container
{
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Y,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"28242d"),
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 35, Bottom = 75, Horizontal = SearchableListOverlay.WIDTH_PADDING },
Children = new[]
{
new SectionContainer
{
Padding = new MarginPadding { Right = field_padding / 2 },
Children = new[]
{
new Section("ROOM NAME")
{
Child = NameField = new SettingsTextBox
{
RelativeSizeAxes = Axes.X,
TabbableContentContainer = this,
OnCommit = (sender, text) => apply(),
},
},
new Section("ROOM VISIBILITY")
{
Child = AvailabilityPicker = new RoomAvailabilityPicker(),
},
new Section("GAME TYPE")
{
Child = new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
Spacing = new Vector2(7),
Children = new Drawable[]
{
TypePicker = new GameTypePicker
{
RelativeSizeAxes = Axes.X,
},
typeLabel = new OsuSpriteText
{
TextSize = 14,
},
},
},
},
},
},
new SectionContainer
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Padding = new MarginPadding { Left = field_padding / 2 },
Children = new[]
{
new Section("MAX PARTICIPANTS")
{
Child = MaxParticipantsField = new SettingsNumberTextBox
{
RelativeSizeAxes = Axes.X,
TabbableContentContainer = this,
OnCommit = (sender, text) => apply(),
},
},
new Section("PASSWORD (OPTIONAL)")
{
Child = new SettingsPasswordTextBox
{
RelativeSizeAxes = Axes.X,
TabbableContentContainer = this,
OnCommit = (sender, text) => apply(),
},
},
},
},
},
},
ApplyButton = new ApplySettingsButton
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Size = new Vector2(230, 35),
Margin = new MarginPadding { Bottom = 20 },
Action = apply,
},
},
};
TypePicker.Current.ValueChanged += t => typeLabel.Text = t.Name;
nameBind.ValueChanged += n => NameField.Text = n;
availabilityBind.ValueChanged += a => AvailabilityPicker.Current.Value = a;
typeBind.ValueChanged += t => TypePicker.Current.Value = t;
maxParticipantsBind.ValueChanged += m => MaxParticipantsField.Text = m?.ToString();
nameBind.BindTo(room.Name);
availabilityBind.BindTo(room.Availability);
typeBind.BindTo(room.Type);
maxParticipantsBind.BindTo(room.MaxParticipants);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
typeLabel.Colour = colours.Yellow;
}
protected override void PopIn()
{
// reapply the rooms values if the overlay was completely closed
if (content.Y == -1)
{
nameBind.TriggerChange();
availabilityBind.TriggerChange();
typeBind.TriggerChange();
maxParticipantsBind.TriggerChange();
}
content.MoveToY(0, transition_duration, Easing.OutQuint);
}
protected override void PopOut()
{
content.MoveToY(-1, transition_duration, Easing.InSine);
}
private void apply()
{
nameBind.Value = NameField.Text;
availabilityBind.Value = AvailabilityPicker.Current.Value;
typeBind.Value = TypePicker.Current.Value;
if (int.TryParse(MaxParticipantsField.Text, out int max))
maxParticipantsBind.Value = max;
else
maxParticipantsBind.Value = null;
Hide();
}
private class SettingsTextBox : OsuTextBox
{
protected override Color4 BackgroundUnfocused => Color4.Black;
protected override Color4 BackgroundFocused => Color4.Black;
}
private class SettingsNumberTextBox : SettingsTextBox
{
protected override bool CanAddCharacter(char character) => char.IsNumber(character);
}
private class SettingsPasswordTextBox : OsuPasswordTextBox
{
protected override Color4 BackgroundUnfocused => Color4.Black;
protected override Color4 BackgroundFocused => Color4.Black;
}
private class SectionContainer : FillFlowContainer<Section>
{
public SectionContainer()
{
RelativeSizeAxes = Axes.Both;
Width = 0.5f;
Direction = FillDirection.Vertical;
Spacing = new Vector2(field_padding);
}
}
private class Section : Container
{
private readonly Container content;
protected override Container<Drawable> Content => content;
public Section(string title)
{
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
InternalChild = new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
Spacing = new Vector2(5),
Children = new Drawable[]
{
new OsuSpriteText
{
TextSize = 12,
Font = @"Exo2.0-Bold",
Text = title.ToUpper(),
},
content = new Container
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
},
},
};
}
}
private class ApplySettingsButton : TriangleButton
{
public ApplySettingsButton()
{
Text = "Apply";
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
BackgroundColour = colours.Yellow;
Triangles.ColourLight = colours.YellowLight;
Triangles.ColourDark = colours.YellowDark;
}
}
}
}

View File

@ -24,4 +24,9 @@
<PackageReference Include="SharpRaven" Version="2.4.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="osu.Game, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\osu.Game.Rulesets.Osu.Tests\bin\Debug\netcoreapp2.1\osu.Game.dll</HintPath>
</Reference>
</ItemGroup>
</Project>