예제 #1
0
        }   // end of MainMenu c'tor

        private void ActivateMainMenu()
        {
            // Backing out to main menu kills the session we're in.
            // If we're the host, everyone is disconnected.
            LiveManager.CloseSession();

            // Cancel pending profile updates, joinable session finds, etc.
            LiveManager.ClearQueuedOperations(this);

            // Activate main menu.
            Deactivate();
            BokuGame.bokuGame.mainMenu.Activate();
        }
예제 #2
0
            internal void Deactivate()
            {
                LiveManager.FriendUpdatesEnabled   = false;
                LiveManager.JoinableUpdatesEnabled = false;

                if (LiveManager.IsConnected)
                {
                    LiveManager.Session.GamerJoined -= Session_GamerJoined;
                    LiveManager.Session.GamerLeft   -= Session_GamerLeft;
                }

                LiveManager.ClearQueuedOperations(null);

                grid.Active = false;

                // We rebuild the grid each time the share hub is activated, to reflect the dynamic nature of the friend list.
                BokuGame.Unload(grid);
                grid.Clear();

                elements.Clear();
            }
예제 #3
0
        private void StartJumpingIn(string gamerTag, object param)
        {
            // Turn off background updates to friend profiles.
            LiveManager.FriendUpdatesEnabled = false;
            // Turn off background updates to friend joinable states.
            LiveManager.JoinableUpdatesEnabled = false;

            // TODO: Warn of potentially "destructive" action. Player may have invited people to join their session.
            // This action closes the local session, invalidating the invites.
            LiveManager.CloseSession();

            // Cancel pending friend profile and joinable state queries.
            LiveManager.ClearQueuedOperations(null);

            // Show the "initializing sharing room" notification dialog.
            openingSharingRoomMessage.Activate();

            // Start finding our friend's network session.
            SessionFinder finderOp = new SessionFinder(gamerTag, FindSessionComplete_Join, param, this);

            finderOp.Queue();
        }
예제 #4
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();
            }
        }
예제 #5
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;
                }
            }
        }
예제 #6
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()