osu/osu.Desktop/Overlays/VersionManager.cs

140 lines
4.9 KiB
C#
Raw Normal View History

// 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.
2018-04-13 09:19:50 +00:00
2018-06-19 11:19:52 +00:00
using System;
2018-04-13 09:19:50 +00:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
2018-06-19 11:19:52 +00:00
using osu.Framework.Platform;
2018-04-13 09:19:50 +00:00
using osu.Game;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
2018-06-06 12:29:45 +00:00
using osu.Game.Utils;
2018-11-20 07:51:59 +00:00
using osuTK;
using osuTK.Graphics;
2018-04-13 09:19:50 +00:00
namespace osu.Desktop.Overlays
{
public class VersionManager : OverlayContainer
{
private OsuConfigManager config;
private OsuGameBase game;
private NotificationOverlay notificationOverlay;
2018-06-19 11:19:52 +00:00
private GameHost host;
2018-04-13 09:19:50 +00:00
[BackgroundDependencyLoader]
2018-08-30 22:04:40 +00:00
private void load(NotificationOverlay notification, OsuColour colours, TextureStore textures, OsuGameBase game, OsuConfigManager config, GameHost host)
2018-04-13 09:19:50 +00:00
{
notificationOverlay = notification;
this.config = config;
this.game = game;
2018-06-19 11:19:52 +00:00
this.host = host;
2018-04-13 09:19:50 +00:00
AutoSizeAxes = Axes.Both;
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
Alpha = 0;
Children = new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Children = new Drawable[]
{
new OsuSpriteText
{
Font = OsuFont.GetFont(weight: FontWeight.Bold),
2018-04-13 09:19:50 +00:00
Text = game.Name
},
new OsuSpriteText
{
Colour = DebugUtils.IsDebug ? colours.Red : Color4.White,
Text = game.Version
},
}
},
new OsuSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Font = OsuFont.Numeric.With(size: 12),
2018-04-13 09:19:50 +00:00
Colour = colours.Yellow,
Text = @"Development Build"
},
new Sprite
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
2018-08-30 22:04:40 +00:00
Texture = textures.Get(@"Menu/dev-build-footer"),
2018-04-13 09:19:50 +00:00
},
}
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
var version = game.Version;
var lastVersion = config.Get<string>(OsuSetting.Version);
2019-04-01 03:16:05 +00:00
2018-04-13 09:19:50 +00:00
if (game.IsDeployedBuild && version != lastVersion)
{
config.Set(OsuSetting.Version, version);
// only show a notification if we've previously saved a version to the config file (ie. not the first run).
if (!string.IsNullOrEmpty(lastVersion))
2018-06-19 11:19:52 +00:00
notificationOverlay.Post(new UpdateCompleteNotification(version, host.OpenUrlExternally));
2018-04-13 09:19:50 +00:00
}
}
private class UpdateCompleteNotification : SimpleNotification
{
2018-06-19 11:19:52 +00:00
public UpdateCompleteNotification(string version, Action<string> openUrl = null)
2018-04-13 09:19:50 +00:00
{
Text = $"You are now running osu!lazer {version}.\nClick to see what's new!";
Icon = FontAwesome.CheckSquare;
2018-04-13 09:19:50 +00:00
Activated = delegate
{
2018-06-19 11:19:52 +00:00
openUrl?.Invoke($"https://osu.ppy.sh/home/changelog/lazer/{version}");
2018-04-13 09:19:50 +00:00
return true;
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
IconBackgound.Colour = colours.BlueDark;
}
}
protected override void PopIn()
{
2018-12-27 10:22:24 +00:00
this.FadeIn(1400, Easing.OutQuint);
2018-04-13 09:19:50 +00:00
}
protected override void PopOut()
{
2018-12-27 10:22:24 +00:00
this.FadeOut(500, Easing.OutQuint);
2018-04-13 09:19:50 +00:00
}
}
}