mirror of
https://github.com/osukey/osukey.git
synced 2025-05-26 07:57:32 +09:00
Move nested classes to own files
This commit is contained in:
parent
4ddf3cb1d9
commit
ab8db3b7dc
159
osu.Game/Overlays/Toolbar/AnalogClockDisplay.cs
Normal file
159
osu.Game/Overlays/Toolbar/AnalogClockDisplay.cs
Normal file
@ -0,0 +1,159 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Toolbar
|
||||
{
|
||||
public class AnalogClockDisplay : ClockDisplay
|
||||
{
|
||||
private const float hand_thickness = 2.4f;
|
||||
|
||||
private Drawable hour;
|
||||
private Drawable minute;
|
||||
private Drawable second;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Size = new Vector2(22);
|
||||
|
||||
InternalChildren = new[]
|
||||
{
|
||||
new CircularContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
BorderThickness = 2,
|
||||
BorderColour = Color4.White,
|
||||
Child = new Box
|
||||
{
|
||||
AlwaysPresent = true,
|
||||
Alpha = 0,
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
},
|
||||
hour = new LargeHand(0.34f),
|
||||
minute = new LargeHand(0.48f),
|
||||
second = new SecondHand(),
|
||||
new CentreCircle
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override void UpdateDisplay(DateTimeOffset now)
|
||||
{
|
||||
float secondFractional = now.Second / 60f;
|
||||
float minuteFractional = (now.Minute + secondFractional) / 60f;
|
||||
float hourFractional = ((minuteFractional + now.Hour) % 12) / 12f;
|
||||
|
||||
updateRotation(hour, hourFractional);
|
||||
updateRotation(minute, minuteFractional);
|
||||
updateRotation(second, secondFractional);
|
||||
}
|
||||
|
||||
private void updateRotation(Drawable hand, float fraction)
|
||||
{
|
||||
const float duration = 320;
|
||||
|
||||
float rotation = fraction * 360 - 90;
|
||||
|
||||
if (Math.Abs(hand.Rotation - rotation) > 180)
|
||||
hand.RotateTo(rotation);
|
||||
else
|
||||
hand.RotateTo(rotation, duration, Easing.OutElastic);
|
||||
}
|
||||
|
||||
private class CentreCircle : CompositeDrawable
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Circle
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(hand_thickness),
|
||||
Colour = Color4.White,
|
||||
},
|
||||
new Circle
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(hand_thickness * 0.7f),
|
||||
Colour = colours.PinkLight,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private class SecondHand : CompositeDrawable
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Width = 0.66f;
|
||||
|
||||
Height = hand_thickness * 0.7f;
|
||||
Anchor = Anchor.Centre;
|
||||
Origin = Anchor.Custom;
|
||||
|
||||
OriginPosition = new Vector2(Height * 2, Height / 2);
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Circle
|
||||
{
|
||||
Colour = colours.PinkLight,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private class LargeHand : CompositeDrawable
|
||||
{
|
||||
public LargeHand(float length)
|
||||
{
|
||||
Width = length;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
Anchor = Anchor.Centre;
|
||||
Origin = Anchor.CentreLeft;
|
||||
|
||||
Origin = Anchor.Custom;
|
||||
OriginPosition = new Vector2(hand_thickness / 2); // offset x also, to ensure the centre of the line is centered on the face.
|
||||
Height = hand_thickness;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Circle
|
||||
{
|
||||
Colour = Color4.White,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
BorderThickness = 0.7f,
|
||||
BorderColour = colours.Gray2,
|
||||
},
|
||||
};
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
28
osu.Game/Overlays/Toolbar/ClockDisplay.cs
Normal file
28
osu.Game/Overlays/Toolbar/ClockDisplay.cs
Normal file
@ -0,0 +1,28 @@
|
||||
// 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 osu.Framework.Graphics.Containers;
|
||||
|
||||
namespace osu.Game.Overlays.Toolbar
|
||||
{
|
||||
public abstract class ClockDisplay : CompositeDrawable
|
||||
{
|
||||
private int? lastSecond;
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
var now = DateTimeOffset.Now;
|
||||
|
||||
if (now.Second != lastSecond)
|
||||
{
|
||||
lastSecond = now.Second;
|
||||
UpdateDisplay(now);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void UpdateDisplay(DateTimeOffset now);
|
||||
}
|
||||
}
|
64
osu.Game/Overlays/Toolbar/DigitalClockDisplay.cs
Normal file
64
osu.Game/Overlays/Toolbar/DigitalClockDisplay.cs
Normal file
@ -0,0 +1,64 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays.Toolbar
|
||||
{
|
||||
public class DigitalClockDisplay : ClockDisplay
|
||||
{
|
||||
private OsuSpriteText realTime;
|
||||
private OsuSpriteText gameTime;
|
||||
|
||||
private bool showRuntime = true;
|
||||
|
||||
public bool ShowRuntime
|
||||
{
|
||||
get => showRuntime;
|
||||
set
|
||||
{
|
||||
if (showRuntime == value)
|
||||
return;
|
||||
|
||||
showRuntime = value;
|
||||
updateMetrics();
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
AutoSizeAxes = Axes.Y;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
realTime = new OsuSpriteText(),
|
||||
gameTime = new OsuSpriteText
|
||||
{
|
||||
Y = 14,
|
||||
Colour = colours.PinkLight,
|
||||
Scale = new Vector2(0.6f)
|
||||
}
|
||||
};
|
||||
|
||||
updateMetrics();
|
||||
}
|
||||
|
||||
protected override void UpdateDisplay(DateTimeOffset now)
|
||||
{
|
||||
realTime.Text = $"{now:HH:mm:ss}";
|
||||
gameTime.Text = $"running {new TimeSpan(TimeSpan.TicksPerSecond * (int)(Clock.CurrentTime / 1000)):c}";
|
||||
}
|
||||
|
||||
private void updateMetrics()
|
||||
{
|
||||
Width = showRuntime ? 66 : 45; // Allows for space for game time up to 99 days (in the padding area since this is quite rare).
|
||||
gameTime.FadeTo(showRuntime ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +1,13 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Toolbar
|
||||
{
|
||||
@ -20,10 +15,8 @@ namespace osu.Game.Overlays.Toolbar
|
||||
{
|
||||
private Bindable<ToolbarClockDisplayMode> clockDisplayMode;
|
||||
|
||||
private DigitalDisplay digital;
|
||||
private AnalogDisplay analog;
|
||||
|
||||
private const float hand_thickness = 2.4f;
|
||||
private DigitalClockDisplay digital;
|
||||
private AnalogClockDisplay analog;
|
||||
|
||||
public ToolbarClock()
|
||||
{
|
||||
@ -46,12 +39,12 @@ namespace osu.Game.Overlays.Toolbar
|
||||
Spacing = new Vector2(5),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
analog = new AnalogDisplay
|
||||
analog = new AnalogClockDisplay
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
},
|
||||
digital = new DigitalDisplay
|
||||
digital = new DigitalClockDisplay
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
@ -104,220 +97,5 @@ namespace osu.Game.Overlays.Toolbar
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private class DigitalDisplay : ClockDisplay
|
||||
{
|
||||
private OsuSpriteText realTime;
|
||||
private OsuSpriteText gameTime;
|
||||
|
||||
private bool showRuntime = true;
|
||||
|
||||
public bool ShowRuntime
|
||||
{
|
||||
get => showRuntime;
|
||||
set
|
||||
{
|
||||
if (showRuntime == value)
|
||||
return;
|
||||
|
||||
showRuntime = value;
|
||||
updateMetrics();
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
AutoSizeAxes = Axes.Y;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
realTime = new OsuSpriteText(),
|
||||
gameTime = new OsuSpriteText
|
||||
{
|
||||
Y = 14,
|
||||
Colour = colours.PinkLight,
|
||||
Scale = new Vector2(0.6f)
|
||||
}
|
||||
};
|
||||
|
||||
updateMetrics();
|
||||
}
|
||||
|
||||
protected override void UpdateDisplay(DateTimeOffset now)
|
||||
{
|
||||
realTime.Text = $"{now:HH:mm:ss}";
|
||||
gameTime.Text = $"running {new TimeSpan(TimeSpan.TicksPerSecond * (int)(Clock.CurrentTime / 1000)):c}";
|
||||
}
|
||||
|
||||
private void updateMetrics()
|
||||
{
|
||||
Width = showRuntime ? 66 : 45; // Allows for space for game time up to 99 days (in the padding area since this is quite rare).
|
||||
gameTime.FadeTo(showRuntime ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
private class AnalogDisplay : ClockDisplay
|
||||
{
|
||||
private Drawable hour;
|
||||
private Drawable minute;
|
||||
private Drawable second;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Size = new Vector2(22);
|
||||
|
||||
InternalChildren = new[]
|
||||
{
|
||||
new CircularContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
BorderThickness = 2,
|
||||
BorderColour = Color4.White,
|
||||
Child = new Box
|
||||
{
|
||||
AlwaysPresent = true,
|
||||
Alpha = 0,
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
},
|
||||
hour = new LargeHand(0.34f),
|
||||
minute = new LargeHand(0.48f),
|
||||
second = new SecondHand(),
|
||||
new CentreCircle
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private class CentreCircle : CompositeDrawable
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Circle
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(hand_thickness),
|
||||
Colour = Color4.White,
|
||||
},
|
||||
new Circle
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(hand_thickness * 0.7f),
|
||||
Colour = colours.PinkLight,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private class SecondHand : CompositeDrawable
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Width = 0.66f;
|
||||
|
||||
Height = hand_thickness * 0.7f;
|
||||
Anchor = Anchor.Centre;
|
||||
Origin = Anchor.Custom;
|
||||
|
||||
OriginPosition = new Vector2(Height * 2, Height / 2);
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Circle
|
||||
{
|
||||
Colour = colours.PinkLight,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private class LargeHand : CompositeDrawable
|
||||
{
|
||||
public LargeHand(float length)
|
||||
{
|
||||
Width = length;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
Anchor = Anchor.Centre;
|
||||
Origin = Anchor.CentreLeft;
|
||||
|
||||
Origin = Anchor.Custom;
|
||||
OriginPosition = new Vector2(hand_thickness / 2); // offset x also, to ensure the centre of the line is centered on the face.
|
||||
Height = hand_thickness;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Circle
|
||||
{
|
||||
Colour = Color4.White,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
BorderThickness = 0.7f,
|
||||
BorderColour = colours.Gray2,
|
||||
},
|
||||
};
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void UpdateDisplay(DateTimeOffset now)
|
||||
{
|
||||
float secondFractional = now.Second / 60f;
|
||||
float minuteFractional = (now.Minute + secondFractional) / 60f;
|
||||
float hourFractional = ((minuteFractional + now.Hour) % 12) / 12f;
|
||||
|
||||
updateRotation(hour, hourFractional);
|
||||
updateRotation(minute, minuteFractional);
|
||||
updateRotation(second, secondFractional);
|
||||
}
|
||||
|
||||
private void updateRotation(Drawable hand, float fraction)
|
||||
{
|
||||
const float duration = 320;
|
||||
|
||||
float rotation = fraction * 360 - 90;
|
||||
|
||||
if (Math.Abs(hand.Rotation - rotation) > 180)
|
||||
hand.RotateTo(rotation);
|
||||
else
|
||||
hand.RotateTo(rotation, duration, Easing.OutElastic);
|
||||
}
|
||||
}
|
||||
|
||||
private abstract class ClockDisplay : CompositeDrawable
|
||||
{
|
||||
private int? lastSecond;
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
var now = DateTimeOffset.Now;
|
||||
|
||||
if (now.Second != lastSecond)
|
||||
{
|
||||
lastSecond = now.Second;
|
||||
UpdateDisplay(now);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void UpdateDisplay(DateTimeOffset now);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user