コード例 #1
0
        private void SessionCreatorComplete_StartInvitingFriend(AsyncLiveOperation op)
        {
            openingSharingRoomMessage.Deactivate();
            openingInviteGuideMessage.Deactivate();

            // We needed to create a session before sending out an invitation to our friend.
            // If we're here, then the session create process is complete.
            UIGridShareFriendElement shareHubElement = op.Param as UIGridShareFriendElement;

            if (op.Succeeded)
            {
                // Session was created, start inviting the friend.

                SessionCreator createOp = op as SessionCreator;

                LiveManager.Session = createOp.Session;
                createOp.Session    = null; // avoid session dispose

                LiveManager.Session.GamerJoined += shared.Session_GamerJoined;
                LiveManager.Session.GamerLeft   += shared.Session_GamerLeft;

                StartInvitingFriend(shareHubElement);
            }
            else
            {
                // TODO: show a message about the failure.
            }
        }
コード例 #2
0
            internal void Session_GamerLeft(object sender, GamerLeftEventArgs e)
            {
                UIGridShareFriendElement elem = FindFriendElement(e.Gamer.Gamertag);

                if (elem != null)
                {
                    elem.Friend.IsJoined = false;
                }
            }
コード例 #3
0
            internal void Session_GamerJoined(object sender, GamerJoinedEventArgs e)
            {
                // If we invited this friend to our session, this is where we detect them arriving while we're at the share hub.
                UIGridShareFriendElement elem = FindFriendElement(e.Gamer.Gamertag);

                if (elem != null)
                {
                    elem.Friend.IsJoining = false;
                    elem.Friend.IsJoined  = true;
                }
            }
コード例 #4
0
        private void StartInvitingFriend(UIGridShareFriendElement shareHubElement)
        {
            Debug.Assert(LiveManager.IsConnected);

            try
            {
                List <Gamer> list = new List <Gamer>();
                list.Add(shareHubElement.Friend.FriendGamer);
                Guide.ShowGameInvite(GamePadInput.LastTouched, list);
                shareHubElement.Friend.InvitingThem = false;
            }
            catch
            {
                // If the controller is not signed into live, we'll get a GamerPriviledgesException.
            }
        }
コード例 #5
0
            internal UIGridShareFriendElement FindFriendElement(string gamertag)
            {
                // Find the menu element for this gamertag.
                for (int i = 0; i < grid.ActualDimensions.Y; ++i)
                {
                    UIGridShareFriendElement elem = grid.Get(0, i) as UIGridShareFriendElement;

                    if (elem == null)
                    {
                        continue;
                    }

                    if (elem.Friend.GamerTag == gamertag)
                    {
                        return(elem);
                    }
                }

                return(null);
            }
コード例 #6
0
        private void FindSessionComplete_Join(AsyncLiveOperation op)
        {
            UIGridShareFriendElement friendElement = op.Param as UIGridShareFriendElement;

            if (op.Succeeded)
            {
                SessionFinder finderOp = op as SessionFinder;

                if (finderOp.AvailableSessions.Count > 0)
                {
                    // We found an available session. Before we can start joining it, we must cancel all pending LIVE
                    // operations. Some of them may be queued attempts to find joinable sessions (incompatible with
                    // joining a session), and the others will be profile updates (no longer relevant as we're leaving
                    // this screen).
                    LiveManager.ClearQueuedOperations(null);

                    openingSharingRoomMessage.Activate();

                    // Start joining the session.
                    AvailableSessionJoiner joinerOp = new AvailableSessionJoiner(finderOp.AvailableSessions[0], JoinSessionComplete_ActivateSharingScreen, op.Param, this);

                    // This operation must start before the network session updates again or
                    // the available sessions collection becomes invalid for some reason.
                    joinerOp.Queue(true);

                    finderOp.AvailableSessions = null;  // prevent dispose, since we passed the available session to the joiner.

                    // TODO: Show joining session message here..
                }
                else
                {
                    // We didn't find the session. Re-enable the share hub's periodic LIVE operations.
                    LiveManager.FriendUpdatesEnabled   = true;
                    LiveManager.JoinableUpdatesEnabled = true;

                    // Session is no longer available, so mark friend as not joinable.
                    // This may change if we detect they are joinable again.
                    if (friendElement != null)
                    {
                        friendElement.Friend.IsJoinable = false;
                    }

                    // Not leaving the share hub anymore, since we failed to join the session.
                    shared.grid.Active = true;
                    openingSharingRoomMessage.Deactivate();
                }
            }
            else
            {
                // We didn't find the session. Re-enable the share hub's periodic LIVE operations.
                LiveManager.FriendUpdatesEnabled   = true;
                LiveManager.JoinableUpdatesEnabled = true;

                // The join operation failed, so mark friend as not joinable.
                // This may change if we detect they are joinable again.
                if (friendElement != null)
                {
                    friendElement.Friend.IsJoinable = false;
                }

                // Not leaving the share hub anymore, since we failed to join the session.
                shared.grid.Active = true;
                openingSharingRoomMessage.Deactivate();
            }
        }
コード例 #7
0
        public void OnSelect(UIGrid grid)
        {
            // User selected a friend.

            grid.Active = true;

            int index = shared.grid.SelectionIndex.Y;

            UIGridShareFriendElement friendElement = shared.grid.Get(0, index) as UIGridShareFriendElement;

            UIGridSharingServerElement serverElement = shared.grid.Get(0, index) as UIGridSharingServerElement;

            if (friendElement != null)
            {
                if (friendElement.Friend.IsOnline)
                {
                    if (friendElement.Friend.InvitedUs || friendElement.Friend.IsJoinable)
                    {
                        // Friend has a joinable session, directly join it ("jump in").
                        StartJumpingIn(friendElement.Friend.GamerTag, friendElement);

                        // Don't allow the user to interact with the share hub while the SessionFinder is running.
                        grid.Active = false;
                    }
                    else if (friendElement.Friend.IsJoined && LiveManager.IsConnected)
                    {
                        // Selected friend has joined our session, just go to the sharing room.

                        ActivateSharingScreen();

                        grid.Active = false;
                    }
                    else if (!friendElement.Friend.InvitedThem)
                    {
                        // Start sending an invitation to this friend.

                        friendElement.Friend.InvitingThem = true;

                        if (!LiveManager.IsConnected)
                        {
                            openingInviteGuideMessage.Activate();

                            LiveManager.ClearQueuedOperations(null);

                            // We must have a session open before we can send an invite.
                            // Start creating the network session.
                            SessionCreator createOp = new SessionCreator(SessionCreatorComplete_StartInvitingFriend, friendElement, this);
                            createOp.Queue();
                        }
                        else
                        {
                            // Session is already open, no need to create it before sending the invite.
                            StartInvitingFriend(friendElement);
                        }
                    }
                }
            }
            else if (serverElement != null)
            {
                if (serverElement.IsOnline)
                {
                    StartJumpingIn(serverElement.GamerTag, serverElement);

                    // Don't allow the user to interact with the share hub while the SessionFinder is running.
                    grid.Active = false;
                }
            }
        }
コード例 #8
0
            public override void Update()
            {
                if (UpdateMessages())
                {
                    return;
                }

                // If we signed out of LIVE, back out to the main menu.
                if (!GamerServices.SignedInToLive)
                {
                    parent.ActivateMainMenu();
                    return;
                }

                // If we are joining a share session by accepting an invite from the Dashboard, bail now; we're just waiting for this
                // operation to complete then we'll open the sharing screen.
                if (LiveManager.JoiningShareInvitation)
                {
                    return;
                }

                // If we are accepting an invite via the Guide interface, start joining the session.
                if (LiveManager.AcceptedShareInvitation)
                {
                    parent.openingSharingRoomMessage.Activate();

                    // Change state from "accepting" to "joining" the invited session.
                    LiveManager.AcceptedShareInvitation = false;
                    LiveManager.JoiningShareInvitation  = true;

                    // Disable the share hub UI.
                    shared.grid.Active = false;

                    // Cancel pending LIVE queries.
                    LiveManager.ClearQueuedOperations(null);

                    // Start joining the invited session.
                    InvitedSessionJoiner joinerOp = new InvitedSessionJoiner(parent.JoinSessionComplete_ActivateSharingScreen, null, parent);
                    joinerOp.Queue();

                    return;
                }

                // Don't do any input processing if the guide is up.
                if (GamerServices.IsGuideVisible)
                {
                    return;
                }

                // Check for mouse press on bottom tile.
                // hit is in pixels in screen coords (before overscan adjustment)
                Vector2 hit = MouseInput.GetAspectRatioAdjustedPosition(shared.camera, true);

                bool openPressed = false;

                if (shared.openBox.LeftPressed(hit))
                {
                    openPressed = true;
                }

                GamePadInput pad = GamePadInput.GetGamePad0();

                if (Actions.StartSharing.WasPressed || openPressed || shared.forceSessionRestart)
                {
                    Actions.StartSharing.ClearAllWasPressedState();

                    shared.forceSessionRestart = false;

                    // User selected "Enter Sharing Room"
                    if (!LiveManager.IsConnected)
                    {
                        LiveManager.FriendUpdatesEnabled   = false;
                        LiveManager.JoinableUpdatesEnabled = false;

                        parent.openingSharingRoomMessage.Activate();

                        LiveManager.ClearQueuedOperations(null);

                        SessionCreator createOp = new SessionCreator(parent.SessionCreatorComplete_ActivateSharingScreen, null, this);
                        createOp.Queue();
                    }
                    else
                    {
                        parent.ActivateSharingScreen();
                    }
                }

                // If we're still active, ensure that the friends list is up to date.
                // We don't want to do this if not active since we'll just end up
                // adding all our friends to the grid which we just cleared...
                if (shared.grid.Active)
                {
                    // We're not accepting or joining an invited session, and we're still logged in to LIVE, so update the friend menu to reflect their current status bits.
                    List <LiveFriend> friends = LiveManager.Friends;

                    bool refreshGrid = false;

                    foreach (LiveFriend friend in friends)
                    {
                        UIGridShareFriendElement elem = shared.FindFriendElement(friend.GamerTag);

                        // Build the menu on the fly.
                        if (elem == null && friend.IsFriend)
                        {
                            elem = new UIGridShareFriendElement(friend);
                            shared.elements.Add(elem);
                            refreshGrid = true;
                        }
                        else if (elem != null && !friend.IsFriend)
                        {
                            shared.elements.Remove(elem);
                            refreshGrid = true;
                        }
                    }

                    // If we've changed the list, call update on the grid again so
                    // that it's in a good state for rendering.
                    if (refreshGrid)
                    {
                        shared.RefreshGrid();
                    }
                }

                Matrix parentMatrix = Matrix.Identity;

                shared.grid.Update(ref parentMatrix);

                // Only care about mouse input on the grid if the grid is not empty.
                if (shared.grid.ActualDimensions != Point.Zero)
                {
                    // Mouse Input.
                    // Scroll wheel is handled by the grid.
                    // Clicking on Invite square should send invite.
                    // Clicking on user tile should bring that user into focus.

                    // Check if mouse hitting current selection object.
                    UIGridElement e     = shared.grid.SelectionElement;
                    Matrix        mat   = Matrix.Invert(e.WorldMatrix);
                    Vector2       hitUV = MouseInput.GetHitUV(shared.camera, ref mat, e.Size.X, e.Size.Y, true);

                    bool focusElementHit = false;
                    if (hitUV.X >= 0 && hitUV.X < 1.25 && hitUV.Y >= 0 && hitUV.Y < 1)
                    {
                        focusElementHit = true;

                        // See if we hit the "invite/join" tile which is
                        // to the right of the main part of the tile.
                        if (hitUV.X > 1)
                        {
                            if (MouseInput.Left.WasPressed)
                            {
                                MouseInput.ClickedOnObject = this;
                            }
                            if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == this)
                            {
                                parent.OnSelect(shared.grid);
                            }
                        }
                    }

                    // If we didn't hit the focus object, see if we hit any of the others.
                    // If so, bring them into focus.
                    if (!focusElementHit && MouseInput.Left.WasPressed)
                    {
                        for (int i = 0; i < shared.grid.ActualDimensions.Y; i++)
                        {
                            if (i == shared.grid.SelectionIndex.Y)
                            {
                                continue;
                            }

                            e     = shared.grid.Get(0, i);
                            mat   = Matrix.Invert(e.WorldMatrix);
                            hitUV = MouseInput.GetHitUV(shared.camera, ref mat, e.Size.X, e.Size.Y, true);

                            if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1)
                            {
                                // We hit an element, so bring it into focus.
                                shared.grid.SelectionIndex = new Point(0, i);

                                break;
                            }
                        }
                    }
                }
            }   // end of Update()
コード例 #9
0
            private void GetSortedGridElements(List <UIGridShareHubElement> list)
            {
                list.Clear();

                // Friends playing Kodu
                foreach (UIGridShareHubElement elem in elements)
                {
                    UIGridShareFriendElement friend = elem as UIGridShareFriendElement;

                    if (friend == null)
                    {
                        continue;
                    }

                    if (!friend.Friend.IsOnline)
                    {
                        continue;
                    }

                    if (!friend.Friend.IsPlayingKodu)
                    {
                        continue;
                    }

                    friend.Friend.Dirty = true;
                    list.Add(elem);
                }

                // Super-friends
                foreach (UIGridShareHubElement elem in elements)
                {
                    UIGridSharingServerElement server = elem as UIGridSharingServerElement;

                    if (server == null)
                    {
                        continue;
                    }

                    if (!server.IsOnline)
                    {
                        continue;
                    }

                    server.Dirty = true;
                    list.Add(elem);
                }

                // Friends online not playing Kodu
                foreach (UIGridShareHubElement elem in elements)
                {
                    UIGridShareFriendElement friend = elem as UIGridShareFriendElement;

                    if (friend == null)
                    {
                        continue;
                    }

                    if (!friend.Friend.IsOnline)
                    {
                        continue;
                    }

                    if (friend.Friend.IsPlayingKodu)
                    {
                        continue;
                    }

                    friend.Friend.Dirty = true;
                    list.Add(elem);
                }

                // Friends offline
                foreach (UIGridShareHubElement elem in elements)
                {
                    UIGridShareFriendElement friend = elem as UIGridShareFriendElement;

                    if (friend == null)
                    {
                        continue;
                    }

                    if (friend.Friend.IsOnline)
                    {
                        continue;
                    }

                    friend.Friend.Dirty = true;
                    list.Add(elem);
                }
            }