forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonoGameGamerServicesHelper.cs
151 lines (120 loc) · 4.51 KB
/
MonoGameGamerServicesHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using Microsoft.Xna.Framework.Graphics;
namespace Microsoft.Xna.Framework.GamerServices
{
internal class MonoGameGamerServicesHelper
{
private static MonoLiveGuide guide = null;
public static void ShowSigninSheet()
{
guide.Enabled = true;
guide.Visible = true;
Guide.IsVisible = true;
}
internal static void Initialise(Game game)
{
if (guide == null)
{
guide = new MonoLiveGuide(game);
game.Components.Add(guide);
}
}}
internal class MonoLiveGuide : DrawableGameComponent
{
SpriteBatch spriteBatch;
Texture2D signInProgress;
Color alphaColor = new Color(128, 128, 128, 0);
byte startalpha = 0;
public MonoLiveGuide(Game game)
: base(game)
{
this.Enabled = false;
this.Visible = false;
//Guide.IsVisible = false;
this.DrawOrder = Int32.MaxValue;
}
public override void Initialize()
{
base.Initialize();
}
Texture2D Circle(GraphicsDevice graphics, int radius)
{
int aDiameter = radius * 2;
Vector2 aCenter = new Vector2(radius, radius);
Texture2D aCircle = new Texture2D(graphics, aDiameter, aDiameter, false, SurfaceFormat.Color);
Color[] aColors = new Color[aDiameter * aDiameter];
for (int i = 0; i < aColors.Length; i++)
{
int x = (i + 1) % aDiameter;
int y = (i + 1) / aDiameter;
Vector2 aDistance = new Vector2(Math.Abs(aCenter.X - x), Math.Abs(aCenter.Y - y));
if (Math.Sqrt((aDistance.X * aDistance.X) + (aDistance.Y * aDistance.Y)) > radius)
{
aColors[i] = Color.Transparent;
}
else
{
aColors[i] = Color.White;
}
}
aCircle.SetData<Color>(aColors);
return aCircle;
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(this.Game.GraphicsDevice);
signInProgress = Circle(this.Game.GraphicsDevice, 10);
base.LoadContent();
}
protected override void UnloadContent()
{
base.UnloadContent();
}
public override void Draw(GameTime gameTime)
{
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
Vector2 center = new Vector2(this.Game.GraphicsDevice.PresentationParameters.BackBufferWidth / 2, this.Game.GraphicsDevice.PresentationParameters.BackBufferHeight - 100);
Vector2 loc = Vector2.Zero;
alphaColor.A = startalpha;
for (int i = 0; i < 12; i++)
{
float angle = (float)(i / 12.0 * Math.PI * 2);
loc = new Vector2(center.X + (float)Math.Cos(angle) * 50, center.Y + (float)Math.Sin(angle) * 50);
spriteBatch.Draw(signInProgress, loc, alphaColor);
alphaColor.A += 255 / 12;
if (alphaColor.A > 255) alphaColor.A = 0;
}
spriteBatch.End();
base.Draw(gameTime);
}
TimeSpan gt = TimeSpan.Zero;
TimeSpan last = TimeSpan.Zero;
public override void Update(GameTime gameTime)
{
if (gt == TimeSpan.Zero) gt = last = gameTime.TotalGameTime;
if ((gameTime.TotalGameTime - last).Milliseconds > 100)
{
last = gameTime.TotalGameTime;
startalpha += 255 / 12;
}
if ((gameTime.TotalGameTime - gt).TotalSeconds > 5) // close after 10 seconds
{
string strUsr = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
if (strUsr.Contains(@"\"))
{
int idx = strUsr.IndexOf(@"\") + 1;
strUsr = strUsr.Substring(idx, strUsr.Length - idx);
}
SignedInGamer sig = new SignedInGamer();
sig.DisplayName = strUsr;
sig.Gamertag = strUsr;
Gamer.SignedInGamers.Add(sig);
this.Visible = false;
this.Enabled = false;
//Guide.IsVisible = false;
gt = TimeSpan.Zero;
}
base.Update(gameTime);
}
}
}