Exemplo n.º 1
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;
                }
            }
        }
Exemplo n.º 2
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()