Created
March 5, 2015 18:21
-
-
Save fpruitt/cd81937c6622e688c1ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Collections.Generic; | |
using Windows.UI.Xaml; | |
using Windows.UI.Popups; | |
using Windows.UI.Xaml.Controls; | |
using Windows.UI.Xaml.Media.Imaging; | |
using Windows.UI.Xaml.Media.Animation; | |
using Microsoft.Xbox.Services; | |
using Microsoft.Xbox.Services.System; | |
using Microsoft.Xbox.Services.Social; | |
using Microsoft.Xbox.Services.Presence; | |
using Microsoft.Xbox.Services.Achievements; | |
using XboxLiveQuickStart; | |
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 | |
namespace XboxLiveQuickstart | |
{ | |
/// <summary> | |
/// An empty page that can be used on its own or navigated to within a Frame. | |
/// </summary> | |
public sealed partial class MainPage : Page | |
{ | |
public MainPage() | |
{ | |
this.InitializeComponent(); | |
this.Loaded += MainPage_Loaded; ; | |
} | |
private async void MainPage_Loaded(object sender, RoutedEventArgs e) | |
{ | |
try | |
{ | |
User user = await User.SignInAsync(Window.Current.Dispatcher); | |
XboxLiveContext context = new XboxLiveContext(user); | |
XboxUserProfile profile = await context.ProfileService.GetUserProfileAsync(user.XboxUserId); | |
Gamertag.Text = profile.Gamertag; | |
Gamerscore.Text = profile.Gamerscore; | |
Gamerpic.Source = new BitmapImage(profile.GameDisplayPictureResizeUri); | |
GamercardProgress.IsActive = false; | |
GamercardProgress.Visibility = Visibility.Collapsed; | |
IReadOnlyList<XboxUserProfile> profiles = await | |
context.ProfileService.GetUserProfilesForSocialGroupAsync("People"); | |
IReadOnlyList<PresenceRecord> presenceRecords = await context.PresenceService.GetPresenceForSocialGroupAsync("People"); | |
XboxSocialRelationshipResult relationships = await context.SocialService.GetSocialRelationshipsAsync(); | |
List<UserDisplay> userDisplayList = new List<UserDisplay>(); | |
foreach (XboxUserProfile userProfile in profiles) | |
{ | |
UserDisplay ud = new UserDisplay(); | |
ud.Gamertag = userProfile.Gamertag; | |
ud.GamerpicUri = userProfile.GameDisplayPictureResizeUri; | |
ud.Gamerscore = userProfile.Gamerscore; | |
ud.IsFavorite = (from r in relationships.Items where r.XboxUserId == userProfile.XboxUserId select r.IsFavorite).FirstOrDefault(); | |
ud.IsOnline = (from p in presenceRecords where p.XboxUserId == userProfile.XboxUserId select p.UserState == UserPresenceState.Online) | |
.FirstOrDefault(); | |
userDisplayList.Add(ud); | |
} | |
FriendsCount.Text = profiles.Count.ToString(); FollowersCount.Text = (from r in relationships.Items where r.IsFollowingCaller select r).Count().ToString(); | |
FriendsList.ItemsSource = userDisplayList; | |
FriendsProgress.IsActive = false; | |
FriendsProgress.Visibility = Visibility.Collapsed; | |
AchievementsResult achievements = await context.AchievementService.GetAchievementsForTitleIdAsync(user.XboxUserId, 0x389FE325, AchievementType.All, false, AchievementOrderBy.Default, 0, 10); | |
List<AchievementDisplay> achievementDisplayList = new List<AchievementDisplay>(); | |
foreach (Achievement achievement in achievements.Items) | |
{ | |
AchievementDisplay ad = new AchievementDisplay(); ad.Name = achievement.Name; ad.Description = achievement.LockedDescription; ad.Score = achievement.Rewards[0].Data; ad.IsAchieved = achievement.ProgressState == AchievementProgressState.Achieved; ad.ImageUri = new Uri(achievement.MediaAssets[0].Url); achievementDisplayList.Add(ad); | |
} | |
AchievementsList.ItemsSource = achievementDisplayList; | |
AchievementsProgress.IsActive = false; | |
AchievementsProgress.Visibility = Visibility.Collapsed; | |
} | |
catch (Exception ex) | |
{ | |
await new MessageDialog(ex.ToString()).ShowAsync(); | |
} | |
} | |
#region XAML events | |
private void Canvas_Loaded(object sender, RoutedEventArgs e) | |
{ | |
starsScrolling.Begin(); | |
} | |
private void btnFriends_Click(object sender, RoutedEventArgs e) | |
{ | |
canvasPanelAchievements.Visibility = Visibility.Collapsed; | |
canvasPanelFriends.Visibility = Visibility.Visible; | |
slideToSecondaryScreen.FillBehavior = FillBehavior.Stop; | |
slideToSecondaryScreen.Begin(); | |
} | |
private void btnAchievements_Click(object sender, RoutedEventArgs e) | |
{ | |
canvasPanelAchievements.Visibility = Visibility.Visible; | |
canvasPanelFriends.Visibility = Visibility.Collapsed; | |
slideToSecondaryScreen.FillBehavior = FillBehavior.Stop; | |
slideToSecondaryScreen.Begin(); | |
} | |
private void btnBack_Click(object sender, RoutedEventArgs e) | |
{ | |
slideToSecondaryScreen.FillBehavior = FillBehavior.Stop; | |
slideToPrimaryScreen.Begin(); | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment