1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 12:32:56 +08:00

Refactor with constants and better method names

This commit is contained in:
Dean Herbert 2019-04-01 13:13:56 +09:00
parent 698e38c4e0
commit 2b3c70b2d2
2 changed files with 13 additions and 16 deletions

View File

@ -18,6 +18,7 @@ using osu.Game.Users;
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
namespace osu.Game.Screens.Menu namespace osu.Game.Screens.Menu
{ {
@ -86,10 +87,8 @@ namespace osu.Game.Screens.Menu
user = api.LocalUser.GetBoundCopy(); user = api.LocalUser.GetBoundCopy();
skin = skinManager.CurrentSkin.GetBoundCopy(); skin = skinManager.CurrentSkin.GetBoundCopy();
user.ValueChanged += _ => changeColour(); user.ValueChanged += _ => updateColour();
skin.ValueChanged += _ => changeColour(); skin.BindValueChanged(_ => updateColour(), true);
changeColour();
} }
private void updateAmplitudes() private void updateAmplitudes()
@ -119,12 +118,14 @@ namespace osu.Game.Screens.Menu
Scheduler.AddDelayed(updateAmplitudes, time_between_updates); Scheduler.AddDelayed(updateAmplitudes, time_between_updates);
} }
private void changeColour() private void updateColour()
{ {
Color4 defaultColour = Color4.White.Opacity(0.2f);
if (user.Value?.IsSupporter ?? false) if (user.Value?.IsSupporter ?? false)
AccentColour = skin.Value.GetValue<SkinConfiguration, Color4?>(s => s.CustomColours.ContainsKey("MenuGlow") ? s.CustomColours["MenuGlow"] : (Color4?)null) ?? new Color4(1, 1, 1, 0.2f); AccentColour = skin.Value.GetValue<SkinConfiguration, Color4?>(s => s.CustomColours.ContainsKey("MenuGlow") ? s.CustomColours["MenuGlow"] : (Color4?)null) ?? defaultColour;
else else
AccentColour = new Color4(1, 1, 1, 0.2f); AccentColour = defaultColour;
} }
protected override void LoadComplete() protected override void LoadComplete()

View File

@ -58,9 +58,6 @@ namespace osu.Game.Screens.Menu
user = api.LocalUser.GetBoundCopy(); user = api.LocalUser.GetBoundCopy();
skin = skinManager.CurrentSkin.GetBoundCopy(); skin = skinManager.CurrentSkin.GetBoundCopy();
user.ValueChanged += _ => changeColour();
skin.ValueChanged += _ => changeColour();
Children = new Drawable[] Children = new Drawable[]
{ {
leftBox = new Box leftBox = new Box
@ -88,7 +85,8 @@ namespace osu.Game.Screens.Menu
} }
}; };
changeColour(); user.ValueChanged += _ => updateColour();
skin.BindValueChanged(_ => updateColour(), true);
} }
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes) protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes)
@ -109,14 +107,12 @@ namespace osu.Game.Screens.Menu
.FadeOut(beatLength, Easing.In); .FadeOut(beatLength, Easing.In);
} }
private void changeColour() private void updateColour()
{ {
Color4 baseColour; Color4 baseColour = colours.Blue;
if (user.Value?.IsSupporter ?? false) if (user.Value?.IsSupporter ?? false)
baseColour = skin.Value.GetValue<SkinConfiguration, Color4?>(s => s.CustomColours.ContainsKey("MenuGlow") ? s.CustomColours["MenuGlow"] : (Color4?)null) ?? colours.Blue; baseColour = skin.Value.GetValue<SkinConfiguration, Color4?>(s => s.CustomColours.ContainsKey("MenuGlow") ? s.CustomColours["MenuGlow"] : (Color4?)null) ?? baseColour;
else
baseColour = colours.Blue;
// linear colour looks better in this case, so let's use it for now. // linear colour looks better in this case, so let's use it for now.
Color4 gradientDark = baseColour.Opacity(0).ToLinear(); Color4 gradientDark = baseColour.Opacity(0).ToLinear();