} // end of GetGridFromCurTab() #endregion #region Internal /// <summary> /// Updates the texture to be rendered to the bottom bar based on the number of worlds and the current sort order. /// </summary> public void UpdateBottomBarTexture() { UIGrid grid = GetGridFromCurTab(); int worldCount = grid != null ? grid.ActualDimensions.Y : 0; if (numWorlds != worldCount || bottomBarDirty) { numWorlds = worldCount; bottomBarDirty = false; GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; // Render into the diffuse texture. RenderTarget2D diffuse = bottomBar.Diffuse; InGame.SetRenderTarget(diffuse); InGame.Clear(Color.TransparentBlack); BitmapFont font = BokuGame.fontBerlinSansFBDemiBold20; // Render the label text into the texture. const int dpi = 128; const float buttonSpacing = 0.1f; // Magic number gotten through trial and error. No other reason. int x = diffuse.Width / 2 + (int)((xButtonPosition.X - bottomBar.Position.X + buttonSpacing) * dpi); int h = (int)(dpi * bottomBar.Height); int y = (int)((h - font.LineHeight) / 2.0f) - 2; // Only show delete option for MyWorlds and Downloads. if (parent.curTab == Tab.MyWorlds || parent.curTab == Tab.Downloads) { x += DrawText(Strings.Instance.loadLevelMenu.deleteWorld, x, y, bottomBar.TextColor); } // Sort options. x = diffuse.Width / 2 + (int)((yButtonPosition.X - bottomBar.Position.X + buttonSpacing) * dpi); x += DrawText(Strings.Instance.loadLevelMenu.oldSortBy, x, y, bottomBar.TextColor); if (curSortOrder == LevelSort.SortBy.WorldName) { x += DrawText(Strings.Instance.loadLevelMenu.world, x, y, Color.Yellow); } else { x += DrawText(Strings.Instance.loadLevelMenu.world, x, y, bottomBar.TextColor); } x += DrawText(Strings.Instance.loadLevelMenu.separator, x, y, bottomBar.TextColor); if (curSortOrder == LevelSort.SortBy.Creator) { x += DrawText(Strings.Instance.loadLevelMenu.oldCreator, x, y, Color.Yellow); } else { x += DrawText(Strings.Instance.loadLevelMenu.oldCreator, x, y, bottomBar.TextColor); } x += DrawText(Strings.Instance.loadLevelMenu.separator, x, y, bottomBar.TextColor); if (curSortOrder == LevelSort.SortBy.Rating) { x += DrawText(Strings.Instance.loadLevelMenu.rating, x, y, Color.Yellow); } else { x += DrawText(Strings.Instance.loadLevelMenu.rating, x, y, bottomBar.TextColor); } x += DrawText(Strings.Instance.loadLevelMenu.separator, x, y, bottomBar.TextColor); if (curSortOrder == LevelSort.SortBy.Date) { x += DrawText(Strings.Instance.loadLevelMenu.date, x, y, Color.Yellow); } else { x += DrawText(Strings.Instance.loadLevelMenu.date, x, y, bottomBar.TextColor); } string str = numWorlds.ToString() + (numWorlds == 1 ? Strings.Instance.loadLevelMenu.worldCount : Strings.Instance.loadLevelMenu.worldsCount); x = diffuse.Width - font.MeasureString(str) - 50; x += DrawText(str, x, y, bottomBar.TextColor); // Note: // The button graphics are rendered on the fly in the Render() // call rather than being rendered into the texture so they // don't get washed out by the specular highlights. // Restore backbuffer. InGame.RestoreRenderTarget(); } } // end of UpdateBottomBarTexture()
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()
} // end of Render() /// <summary> /// If the text being displayed has changed, we need to refresh the texture. /// Note this requires changing the rendertarget so this should no be called /// during the normal rendering loop. /// </summary> public void RefreshTexture() { if (shared.dirty) { GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; SpriteBatch batch = UI2D.Shared.SpriteBatch; UI2D.Shared.GetFont Font20 = UI2D.Shared.GetGameFont20; UI2D.Shared.GetFont Font24 = UI2D.Shared.GetGameFont24; InGame.SetRenderTarget(diffuse); InGame.Clear(Color.Transparent); TextBlob blob = new TextBlob(UI2D.Shared.GetGameFont20, shared.Prompt, (int)(diffuse.Width - 2.0f * margin)); // Render the backdrop. ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance(); ssquad.Render(background, Vector2.Zero, new Vector2(512, 256), @"TexturedPreMultAlpha"); // Render the prompt. if (shared.Prompt != null && shared.Prompt.Length > 0) { // Render the prompt text into the texture. Vector2 promptPos = new Vector2(margin, margin); int textWidth = (int)Font20().MeasureString(shared.Prompt).X; blob.RenderWithButtons(promptPos, shared.textColor, shared.shadowColor, new Vector2(1, 1), maxLines: 3); //TextHelper.DrawStringWithShadow(Font20, batch, x, y, shared.Prompt, shared.textColor, shared.shadowColor, false); } batch.Begin(); Vector2 glyphSize = new Vector2(64f, 64f); // Pre-measure the button strip so we can align it. int stripWidth = 0; if (0 != (shared.parent.Buttons & TextDialogButtons.Accept)) { string text = shared.parent.ButtonText(TextDialogButtons.Accept); stripWidth += ((int)glyphSize.X * 7 / 6) + (int)Font20().MeasureString(text).X; } if (0 != (shared.parent.Buttons & TextDialogButtons.Discard)) { string text = shared.parent.ButtonText(TextDialogButtons.Discard); stripWidth += ((int)glyphSize.X * 7 / 6) + (int)Font20().MeasureString(text).X; } if (0 != (shared.parent.Buttons & TextDialogButtons.Cancel)) { string text = shared.parent.ButtonText(TextDialogButtons.Cancel); stripWidth += ((int)glyphSize.X * 7 / 6) + (int)Font20().MeasureString(text).X; } // Render the buttons and the text that goes with them. Point position = new Point(); position.X = (backgroundWidth - stripWidth) / 2; position.Y = backgroundHeight - margin - 40; ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); if (0 != (shared.parent.Buttons & TextDialogButtons.Accept)) { string text = shared.parent.ButtonText(TextDialogButtons.Accept); quad.Render(ButtonTextures.AButton, new Vector2(position.X, position.Y - 2), glyphSize, @"TexturedRegularAlpha"); position.X += (int)glyphSize.X * 2 / 3; TextHelper.DrawStringWithShadow(Font20, batch, position.X, position.Y, text, Color.White, Color.Black, false); position.X += (int)glyphSize.X / 2 + (int)Font20().MeasureString(text).X; } if (0 != (shared.parent.Buttons & TextDialogButtons.Discard)) { string text = shared.parent.ButtonText(TextDialogButtons.Discard); quad.Render(ButtonTextures.XButton, new Vector2(position.X, position.Y - 2), glyphSize, @"TexturedRegularAlpha"); position.X += (int)glyphSize.X * 2 / 3; TextHelper.DrawStringWithShadow(Font20, batch, position.X, position.Y, text, Color.White, Color.Black, false); position.X += (int)glyphSize.X / 2 + (int)Font20().MeasureString(text).X; } if (0 != (shared.parent.Buttons & TextDialogButtons.Cancel)) { string text = shared.parent.ButtonText(TextDialogButtons.Cancel); quad.Render(ButtonTextures.BButton, new Vector2(position.X, position.Y - 2), glyphSize, @"TexturedRegularAlpha"); position.X += (int)glyphSize.X * 2 / 3; TextHelper.DrawStringWithShadow(Font20, batch, position.X, position.Y, text, Color.White, Color.Black, false); position.X += (int)glyphSize.X / 2 + (int)Font20().MeasureString(text).X; } // Render the user text. // Position user text in the vertical center of the tile. position.X = margin; position.Y = margin + blob.NumLines * blob.TotalSpacing; position.Y += (backgroundHeight - position.Y) / 2 - Font24().LineSpacing - Font24().LineSpacing / 2; // Calc the cursor position. string tmpText = shared.curString.Substring(0, shared.cursorPosition); int width = (int)Font24().MeasureString(tmpText).X; float cursorHeight = Font24().LineSpacing + 4.0f; Vector2 cursorTop = new Vector2(position.X + width, position.Y); Vector2 cursorBottom = cursorTop; cursorBottom.Y += cursorHeight; // Render the user text with cursor. Vector2 pos = new Vector2(position.X, position.Y); TextHelper.DrawString(Font24, shared.curString, pos, Color.Black); Utils.Draw2DLine(cursorTop, cursorBottom, Color.Black.ToVector4()); pos += new Vector2(1, -1); TextHelper.DrawString(Font24, shared.curString, pos, Color.White); cursorTop += new Vector2(1.0f, -1.0f); cursorBottom += new Vector2(1.0f, -1.0f); Utils.Draw2DLine(cursorTop, cursorBottom, Color.White.ToVector4()); batch.End(); // Restore backbuffer. InGame.RestoreRenderTarget(); //shared.dirty = false; } } // end of TextDialog RenderObj RefreshTexture()
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()
public void Activate(GameActor thinker, string text, UIGridElement.Justification justification, bool useBackgroundThumbnail, bool useRtCoords) { if (text == null) { return; } if (state != States.Active) { this.useBackgroundThumbnail = useBackgroundThumbnail; this.useRtCoords = useRtCoords; // Do stack handling here. If we do it in the update object we have no // clue which order things get pushed and popped and madness ensues. CommandStack.Push(commandMap); state = States.Active; // Get the current scene thumbnail. If we're using this from the main menu (options) // then use the title screen image instead. if (InGame.inGame.State == InGame.States.Inactive) { thumbnail = BokuGame.bokuGame.mainMenu.BackgroundTexture; } else { thumbnail = InGame.inGame.SmallThumbNail; } // Tell InGame we're using the thumbnail so no need to do full render. prevRenderWorldAsThumbnail = InGame.inGame.RenderWorldAsThumbnail; if (!prevRenderWorldAsThumbnail) { InGame.inGame.RenderWorldAsThumbnail = true; } Time.Paused = true; HelpOverlay.Push(@"TextDisplay"); // Get text string. if (thinker != null) { text = TextHelper.ApplyStringSubstitutions(text, thinker as GameActor); } rawText = text; text = TextHelper.RemoveTags(text); blob = new TextBlob(Font, text, textWidth); blob.Justification = justification; this.thinker = thinker; // Render text into RT. RenderTarget2D rt = UI2D.Shared.RenderTarget512_512; InGame.SetRenderTarget(rt); InGame.Clear(Color.Transparent); Color greyTextColor = new Color(127, 127, 127); blob.RenderWithButtons(textPosition, greyTextColor); InGame.RestoreRenderTarget(); activationTime = Time.WallClockTotalSeconds; } } // end of Activate