Exemplo n.º 1
0
            public override void Render(Camera camera)
            {
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

                HelpOverlay.RefreshTexture();

                RenderTarget2D rt         = UI2D.Shared.RenderTargetDepthStencil1280_720;
                Vector2        screenSize = BokuGame.ScreenSize;
                Vector2        rtSize     = new Vector2(rt.Width, rt.Height);

                if (skipFrames > 0 || shared.waitingForStorage)
                {
                    InGame.Clear(Color.Black);
                    --skipFrames;
                    return;
                }

                shared.liveFeed.FeedSize = shared.liveFeed.ResetScrollBoxSize;
                InGame.SetRenderTarget(rt);

                // Clear the screen & z-buffer.
                InGame.Clear(Color.Black);

                // Apply the background.
                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                Vector2 position = Vector2.Zero;

                quad.Render(shared.backgroundTexture, position, rtSize, @"TexturedNoAlpha");

                Color textColor = new Color(21, 125, 178);

                if (parent.newWorldDialog.Active)
                {
                    // Hide the dialog if auth UI is active.  Just keeps things cleaner.
                    if (!AuthUI.IsModalActive)
                    {
                        // If options menu is active, render instead of main menu.
                        parent.newWorldDialog.Render(new Vector2(rt.Width, rt.Height));
                    }
                }
                else if (shared.optionsMenu.Active)
                {
                    // Hide the menu if auth UI is active.  Just keeps things cleaner.
                    if (!AuthUI.IsModalActive)
                    {
                        // If options menu is active, render instead of main menu.
                        shared.optionsMenu.Render();
                    }
                }
                else
                {
                    // Render url
                    SpriteBatch         batch = UI2D.Shared.SpriteBatch;
                    UI2D.Shared.GetFont Font  = UI2D.Shared.GetGameFont24;
                    Vector2             size  = Font().MeasureString(shared.screenUrl);
                    Vector2             pos   = new Vector2(rt.Width / 2 - size.X / 2, 586);
                    batch.Begin();
                    TextHelper.DrawString(Font, shared.screenUrl, pos, textColor);
                    batch.End();
                    shared.urlBox.Set(pos, pos + size);

                    // Hide the menu if auth UI is active.  Just keeps things cleaner.
                    if (!AuthUI.IsModalActive)
                    {
                        // Render menu using local cameras.
                        ShaderGlobals.SetCamera(shared.camera);
                        shared.menu.WorldMatrix = Matrix.CreateTranslation(0.0f, -0.3f, 0.0f);
                        shared.menu.Render(shared.camera);
                    }

                    // Render Boku.
                    ShaderGlobals.SetCamera(shared.bokuCamera);
                    string oldRig = BokuGame.bokuGame.shaderGlobals.PushLightRig(ShaderGlobals.GreeterRigName);

                    // TODO (****) How to temporarily disable point lights???
                    // Do we really need to?
                    //Luz.SetToEffect(true); // disable scene point lights

                    if (BokuGame.bMarsMode)
                    {
                        shared.boku.Movement.Position = new Vector3(-0.0f, 0.25f, -0.5f);
                        shared.boku.ReScale           = 0.50f;

                        //quad = ScreenSpaceQuad.GetInstance();
                        //float wid=shared.jplTexture.Width/2;
                        //position = new Vector2(1250-(wid), 20);
                        //quad.Render(shared.jplTexture, position, new Vector2(wid, shared.jplTexture.Height/2), @"TexturedRegularAlpha");
                    }
                    else
                    {
                        shared.boku.Movement.Position = new Vector3(0.0f, 0.0f, 0.0f);
                    }
                    fVal += 0.01f;

                    // Be sure to set the right camera so the env map looks correct.
                    ShaderGlobals.SetCamera(shared.bokuCamera);

                    shared.boku.RenderObject.Render(shared.bokuCamera);

                    // TODO (****) How to temporarily disable point lights???
                    //Luz.SetToEffect(false); // re-enable scene point lights
                    BokuGame.bokuGame.shaderGlobals.PopLightRig(oldRig);
                }

                InGame.RestoreRenderTarget();

                InGame.Clear(new Color(20, 20, 20));
                InGame.SetViewportToScreen();

                // Copy the rendered scene to the backbuffer.
                {
                    ScreenWarp.FitRtToScreen(rtSize);

                    quad.Render(rt, ScreenWarp.RenderPosition, ScreenWarp.RenderSize, @"TexturedNoAlpha");
                }

                // Render news feed.
                if (!shared.optionsMenu.Active)
                {
                    shared.liveFeed.Render();
                }

                // Hide overlay if auth UI is active.
                if (!AuthUI.IsModalActive)
                {
                    HelpOverlay.Render();
                }

                // Render text dialogs if being shown by OptionsMenu.
                // TODO (****) Need to get rid of rendering to RTs where possible.
                // TODO (****) Need to split OptionsMenu from MainMenu.
                if (shared.optionsMenu.Active)
                {
                    InGame.inGame.shared.smallTextDisplay.Render();
                    InGame.inGame.shared.scrollableTextDisplay.Render();
                }

                MainMenu.Instance.prevSessionCrashedMessage.Render();
                MainMenu.Instance.noCommunityMessage.Render();
                MainMenu.Instance.noSharingMessage.Render();
            }   // end of Render()
Exemplo n.º 2
0
        }   // end of OnSaveLevelDialogButton()

        /// <summary>
        /// OnSelect method used by mini-hub grid.  If the level is dirty and needs to
        /// be saved the SaveChagesDialog will be activated.  Upon its deactivation
        /// the level should no longer be marked dirty and OnSelect() will get called
        /// again allowing the user's action to be executed.
        /// </summary>
        /// <param name="grid"></param>
        public void OnSelect(ModularMenu menu)
        {
            // Prevent the button pressed from leaking into runtime.
            GamePadInput.IgnoreUntilReleased(Buttons.A);

            // In every case, we need to reset the level to its starting state.
            InGame.inGame.ResetSim(preserveScores: false, removeCreatablesFromScene: false, keepPersistentScores: false);
            // Resetting the sim just started up all game audio, let's pause it down again.
            // It will be resumed when we go back into sim mode.
            BokuGame.Audio.PauseGameAudio();

            // Flag to let us know if the level needs saving.  If the save changes
            // dialog has already been activated then just set this to false.
            bool needToSaveLevel = (InGame.IsLevelDirty || InGame.AutoSaved) && !saveChangesActivated;

            // Does the current world belong to the user.  Required to share to community.
            // Test the genre flag and also special case look at empty world.
            bool isMyWorld = false;

            if (InGame.XmlWorldData != null)
            {
                bool genreTest    = ((int)InGame.XmlWorldData.genres & (int)Genres.MyWorlds) != 0;
                bool newWorldTest = InGame.XmlWorldData.Filename == emptyWorldFileName;
                if (genreTest && !newWorldTest)
                {
                    isMyWorld = true;
                }
            }

            // Normally there would be a switch here but if we compare strings
            // we proof ourselves against changes in the order of the elements.
            if (menu.CurString == Strings.Localize("miniHub.reset"))
            {
                // Reset.
                // We've already done a Reset, so force to RunSim mode if we already aren't.
                Deactivate();
                InGame.inGame.Activate();
                InGame.inGame.CurrentUpdateMode = InGame.UpdateMode.RunSim;
                InGame.inGame.RestorePlayModeCamera();

                // The ResetSim above doesn't ApplyInlining since it's generally
                // meant for resetting into the editor.  In this case we're going
                // into RunSim mode so be sure to apply inlining first.
                InGame.ApplyInlining();

                if (InGame.inGame.PreGame != null)
                {
                    InGame.inGame.PreGame.Active = true;
                }
            }
            else if (menu.CurString == Strings.Localize("miniHub.edit"))
            {
                // Edit level.
                Deactivate();
                InGame.inGame.Activate();
                InGame.inGame.CurrentUpdateMode = InGame.UpdateMode.ToolMenu;
            }
            else if (menu.CurString == Strings.Localize("miniHub.save"))
            {
                // Save
                saveLevelDialog.Activate();
            }
            else if (menu.CurString == Strings.Localize("miniHub.publish"))
            {
                // Offer to save first.  Need to save if world has changed or is world doesn't belong to user.
                if (needToSaveLevel || !isMyWorld)
                {
                    saveChangesActivated = true;
                    saveChangesMessage.Activate();
                }
                else
                {
                    var level = LevelMetadata.CreateFromXml(InGame.XmlWorldData);

                    shared.communityShareMenu.Activate(level);
                }
            }
            else if (menu.CurString == Strings.Localize("miniHub.load"))
            {
                // Load.

                // If we're back here and saveChangesActivated is true then the
                // user was given the option to save changes and chose Discard.
                // So don't offer to save again.
                if (!saveChangesActivated && needToSaveLevel)
                {
                    saveChangesActivated = true;
                    saveChangesWithDiscardMessage.Activate();
                }
                else
                {
                    saveChangesActivated = false;

                    // Deactivate mini-hub and bring up loading menu.
                    Deactivate();
                    //InGame.inGame.DiscardTerrain();
                    BokuGame.bokuGame.loadLevelMenu.LocalLevelMode = LoadLevelMenu.LocalLevelModes.General;
                    BokuGame.bokuGame.loadLevelMenu.ReturnToMenu   = LoadLevelMenu.ReturnTo.MiniHub;
                    BokuGame.bokuGame.loadLevelMenu.Activate();
                }
            }
            else if (menu.CurString == Strings.Localize("miniHub.emptyLevel"))
            {
                // Empty Level.
                // If saveChangesActivated is already true then user chose Discard and
                // we can ignore the needToSaveLevel flag.
                if (!saveChangesActivated && needToSaveLevel)
                {
                    saveChangesActivated = true;
                    saveChangesWithDiscardMessage.Activate();
                }
                else
                {
                    saveChangesActivated = false;

                    // Undo any previous warping.
                    ScreenWarp.FitRtToScreen(BokuGame.ScreenSize);

                    newWorldDialog.Active = true;
                }
            }
            else if (menu.CurString == Strings.Localize("miniHub.print"))
            {
                Print.PrintProgramming();

                // We don't want to exit the mini-hub so re-activate the menu.
                shared.menu.Active = true;
            }
            else if (menu.CurString == Strings.Localize("miniHub.quit"))
            {
                // Exit to main menu.
                // If we're back here and saveChangesActivated is true then the
                // user was given the option to save changes and chose Discard.
                // So don't offer to save again.
                if (!saveChangesActivated && needToSaveLevel)
                {
                    saveChangesActivated = true;
                    saveChangesWithDiscardMessage.Activate();
                }
                else
                {
                    saveChangesActivated = false;

                    // Wave bye, bye.  Go back to the main menu
                    Deactivate();
                    InGame.inGame.StopAllSounds();
                    BokuGame.bokuGame.mainMenu.Activate();
                }
            }
        }   // end of MiniHub OnSelect()
Exemplo n.º 3
0
        public void PreRender()
        {
            RenderTarget2D rt = Shared.RenderTargetDepthStencil1280_720;

            Vector2 rtSize = new Vector2(rt.Width, rt.Height);

            ScreenWarp.FitRtToScreen(rtSize);

            // Render the scene to our rendertarget.
            InGame.SetRenderTarget(rt);
            InGame.Clear(Color.Transparent);

            // Set up params for rendering UI with this camera.
            ShaderGlobals.SetCamera(camera);

            ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

            SpriteBatch batch = Shared.SpriteBatch;

            var center    = new Vector2(640, 360);
            var dialogMin = center - new Vector2(dialogWidth / 2, dialogHeight / 2);
            var dialogMax = center + new Vector2(dialogWidth / 2, dialogHeight / 2);


            // Top and bottom of dialog.
            var     size = new Vector2(dialogWidth, whiteTop.Height);
            Vector2 pos  = dialogMin;

            quad.Render(whiteTop, new Vector4(0, 0, 0, 1), pos, size, "TexturedRegularAlpha");
            pos += new Vector2(0, dialogHeight - 16);
            quad.Render(whiteBottom, new Vector4(0, 0, 0, 1), pos, size, "TexturedRegularAlpha");

            //dialog center
            size    = new Vector2(dialogWidth, dialogHeight);
            pos     = dialogMin;
            pos.Y  += 16;
            size.Y  = dialogHeight - 32;
            pos.X  += 1; //to match size of top and bottom pieces
            size.X -= 2; //
            quad.Render(new Vector4(0, 0, 0, 1), pos, size);

            //top and bottom highlights
            int highlightMargin = 3;

            pos    = dialogMin + new Vector2(highlightMargin, 2);
            size.X = dialogWidth - 2 * highlightMargin;
            size.Y = 30;
            quad.Render(blackHighlight, new Vector4(1, 1, 1, 0.2f), pos, size, "AdditiveBlendWithAlpha");

            pos    = dialogMin + new Vector2(highlightMargin, dialogHeight - 60);
            size.X = dialogWidth - 2 * highlightMargin;
            size.Y = 30;
            quad.Render(blackHighlight, new Vector4(1, 1, 1, 0.2f), pos, size, "AdditiveBlendWithAlpha");

            batch.Begin();

            //Dialog title.
            TextHelper.DrawString(Shared.GetGameFont20, title, dialogMin + new Vector2(10, 10 + 5), Color.White);

            //Ok and Cancel buttons
            var buttonSize = cancelButton.GetSize();

            pos = dialogMax - buttonSize - new Vector2(10, 10);
            cancelButton.Render(pos);

            buttonSize = okButton.GetSize();
            pos       -= new Vector2(buttonSize.X + 20, 0);
            okButton.Render(pos);

            batch.End();

            // Render text box
            textLineEditor.Render(camera);

            InGame.RestoreRenderTarget();

            InGame.SetViewportToScreen();
        }   // end of Render()