Skip to content

Commit

Permalink
Merge WindowsGL and Linux Net files
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-cpp committed May 11, 2015
1 parent 985c42e commit b6686e3
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 155 deletions.
24 changes: 12 additions & 12 deletions Build/Projects/MonoGame.Framework.Net.definition
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@
<ExcludePlatforms>WindowsPhone</ExcludePlatforms>
</Compile>
<Compile Include="GamerServices\GuideAlreadyVisibleException.cs">
<Platforms>Android,MacOS,Ouya,Windows,WindowsGL</Platforms>
<Platforms>Android,MacOS,Ouya,Windows,WindowsGL,Linux</Platforms>
</Compile>
<Compile Include="GamerServices\GamerServicesDispatcher.cs">
<Platforms>MacOS,Windows,WindowsGL</Platforms>
<Platforms>MacOS,Windows,WindowsGL,Linux</Platforms>
</Compile>
<Compile Include="GamerServices\GamerServicesComponent.cs">
<Platforms>Android,iOS,Linux,MacOS,Ouya,PSMobile,Windows,WindowsGL</Platforms>
Expand Down Expand Up @@ -255,15 +255,15 @@
<Platforms>iOS</Platforms>
</Compile>

<!-- Linux Platform -->
<Compile Include="Linux\GamerServices\Guide.cs">
<Platforms>Linux</Platforms>
<!-- DesktopGL Platform -->
<Compile Include="DesktopGL\GamerServices\Guide.cs">
<Platforms>WindowsGL,Linux</Platforms>
</Compile>
<Compile Include="Linux\GamerServices\MonoGameGamerServicesHelper.cs">
<Platforms>Linux</Platforms>
<Compile Include="DesktopGL\GamerServices\MonoGameGamerServicesHelper.cs">
<Platforms>WindowsGL,Linux</Platforms>
</Compile>
<Compile Include="Linux\GamerServices\SignedInGamer.cs">
<Platforms>Linux</Platforms>
<Compile Include="DesktopGL\GamerServices\SignedInGamer.cs">
<Platforms>WindowsGL,Linux</Platforms>
</Compile>


Expand Down Expand Up @@ -304,13 +304,13 @@

<!-- Windows Desktop Platform -->
<Compile Include="Windows\GamerServices\Guide.cs">
<Platforms>Windows8,Windows,WindowsGL,WindowsPhone,WindowsPhone81</Platforms>
<Platforms>Windows8,Windows,WindowsPhone,WindowsPhone81</Platforms>
</Compile>
<Compile Include="Windows\GamerServices\MonoGameGamerServicesHelper.cs">
<Platforms>Windows,WindowsGL</Platforms>
<Platforms>Windows</Platforms>
</Compile>
<Compile Include="Windows\GamerServices\SignedInGamer.cs">
<Platforms>Windows,WindowsGL</Platforms>
<Platforms>Windows</Platforms>
</Compile>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,7 @@ public static string ShowKeyboardInput(
string defaultText,
bool usePasswordMode)
{
string result = defaultText;

//TextFieldAlertView myAlertView = new TextFieldAlertView(usePasswordMode, title, defaultText);


//myAlertView.Title = title;
//myAlertView.Message = description;

//myAlertView.Clicked += delegate(object sender, UIButtonEventArgs e)
// {
// if (e.ButtonIndex == 1)
// {
// result = ((UIAlertView) sender).Subviews.OfType<UITextField>().Single().Text;
// }
// };
//myAlertView.Transform = MonoTouch.CoreGraphics.CGAffineTransform.MakeTranslation (0f, 110f);
//myAlertView.Show();

return result;
throw new NotImplementedException();
}

public static IAsyncResult BeginShowKeyboardInput (
Expand All @@ -116,25 +98,14 @@ public static IAsyncResult BeginShowKeyboardInput (
Object state,
bool usePasswordMode)
{
isVisible = true;

ShowKeyboardInputDelegate ski = ShowKeyboardInput;

return ski.BeginInvoke(player, title, description, defaultText, usePasswordMode, callback, ski);
return BeginShowKeyboardInput(player, title, description, defaultText, callback, state, false );
}

public static string EndShowKeyboardInput (IAsyncResult result)
{
try
{
ShowKeyboardInputDelegate ski = (ShowKeyboardInputDelegate)result.AsyncState;
{
ShowKeyboardInputDelegate ski = (ShowKeyboardInputDelegate)result.AsyncState;

return ski.EndInvoke(result);
}
finally
{
isVisible = false;
}
return ski.EndInvoke(result);
}

delegate Nullable<int> ShowMessageBoxDelegate( string title,
Expand All @@ -148,12 +119,12 @@ public static Nullable<int> ShowMessageBox( string title,
IEnumerable<string> buttons,
int focusButton,
MessageBoxIcon icon)
{
Nullable<int> result = null;


{
int? result = null;
IsVisible = true;

return result;
IsVisible = false;
return result;
}

public static IAsyncResult BeginShowMessageBox(
Expand All @@ -167,11 +138,21 @@ public static IAsyncResult BeginShowMessageBox(
Object state
)
{
isVisible = true;
if (IsVisible)
throw new Exception("The function cannot be completed at this time: the Guide UI is already active. Wait until Guide.IsVisible is false before issuing this call.");

ShowMessageBoxDelegate smb = ShowMessageBox;
if (player != PlayerIndex.One)
throw new ArgumentOutOfRangeException("player", "Specified argument was out of the range of valid values.");
if (title == null)
throw new ArgumentNullException("title", "This string cannot be null or empty, and must be less than 256 characters long.");
if (text == null)
throw new ArgumentNullException("text", "This string cannot be null or empty, and must be less than 256 characters long.");
if (buttons == null)
throw new ArgumentNullException("buttons", "Value can not be null.");

return smb.BeginInvoke(title, text, buttons, focusButton, icon, callback, smb);
ShowMessageBoxDelegate smb = ShowMessageBox;

return smb.BeginInvoke(title, text, buttons, focusButton, icon, callback, smb);
}

public static IAsyncResult BeginShowMessageBox (
Expand All @@ -188,17 +169,8 @@ Object state
}

public static Nullable<int> EndShowMessageBox (IAsyncResult result)
{
try
{
ShowMessageBoxDelegate smbd = (ShowMessageBoxDelegate)result.AsyncState;

return smbd.EndInvoke(result);
}
finally
{
isVisible = false;
}
{
return ((ShowMessageBoxDelegate)result.AsyncState).EndInvoke(result);
}


Expand Down Expand Up @@ -326,11 +298,7 @@ public static bool IsTrialMode
{
get
{
return isTrialMode;
}
set
{
isTrialMode = value;
return simulateTrialMode || isTrialMode;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}

}
}
Loading

0 comments on commit b6686e3

Please sign in to comment.