(5670a7c58) Don't get stuck if cannot use the button.

This commit is contained in:
Joonas Rikkonen
2019-05-16 05:44:48 +03:00
parent 96b2d953d2
commit f8090d470e
87 changed files with 1711 additions and 2564 deletions
@@ -5,19 +5,15 @@ using System;
using System.Collections.Generic;
using System.Xml.Linq;
using Barotrauma.Media;
using System.Linq;
namespace Barotrauma
{
class LoadingScreen
{
private Texture2D backgroundTexture;
private Texture2D backgroundTexture, monsterTexture, titleTexture;
private RenderTarget2D renderTarget;
private Sprite languageSelectionCursor;
private ScalableFont languageSelectionFont;
private Video splashScreen;
public Video SplashScreen
{
@@ -41,6 +37,35 @@ namespace Barotrauma
private string selectedTip;
public Vector2 CenterPosition;
public Vector2 TitlePosition;
private object loadMutex = new object();
private float? loadState;
public Vector2 TitleSize
{
get
{
lock (loadMutex)
{
return splashScreen;
}
}
set
{
lock (loadMutex)
{
splashScreen = value;
}
}
}
private float state;
private string selectedTip;
public Vector2 BackgroundPosition;
public Vector2 TitlePosition;
@@ -74,17 +99,11 @@ namespace Barotrauma
}
public bool WaitForLanguageSelection
{
get;
set;
}
public LoadingScreen(GraphicsDevice graphics)
{
backgroundTexture = TextureLoader.FromFile("Content/UI/titleBackground.png");
renderTarget = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
GameMain.Instance.OnResolutionChanged += () =>
GameMain.Instance.OnResolutionChanged += () =>
{
renderTarget?.Dispose();
renderTarget = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
@@ -101,7 +120,7 @@ namespace Barotrauma
try
{
DrawSplashScreen(spriteBatch);
if (SplashScreen != null && SplashScreen.IsPlaying) return;
if (SplashScreen!=null && SplashScreen.IsPlaying) return;
}
catch (Exception e)
{
@@ -109,27 +128,20 @@ namespace Barotrauma
GameMain.Config.EnableSplashScreen = false;
}
}
var titleStyle = GUI.Style?.GetComponentStyle("TitleText");
Sprite titleSprite = null;
if (!WaitForLanguageSelection && titleStyle != null && titleStyle.Sprites.ContainsKey(GUIComponent.ComponentState.None))
{
titleSprite = titleStyle.Sprites[GUIComponent.ComponentState.None].First()?.Sprite;
}
drawn = true;
graphics.SetRenderTarget(renderTarget);
float backgroundScale = GameMain.GraphicsHeight / 1500.0f;
float titleScale = MathHelper.SmoothStep(0.8f, 1.0f, state / 10.0f) * GameMain.GraphicsHeight / 1000.0f;
Scale = GameMain.GraphicsHeight / 1500.0f;
state += deltaTime;
if (DrawLoadingText)
{
BackgroundPosition = new Vector2(GameMain.GraphicsWidth * 0.3f, GameMain.GraphicsHeight * 0.45f);
TitlePosition = new Vector2(GameMain.GraphicsWidth * 0.5f, GameMain.GraphicsHeight * 0.45f);
CenterPosition = new Vector2(GameMain.GraphicsWidth * 0.3f, GameMain.GraphicsHeight / 2.0f);
TitlePosition = CenterPosition + new Vector2(-0.0f + (float)Math.Sqrt(state) * 220.0f, 0.0f) * Scale;
TitlePosition.X = Math.Min(TitlePosition.X, (float)GameMain.GraphicsWidth / 2.0f);
}
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
@@ -137,10 +149,16 @@ namespace Barotrauma
spriteBatch.Draw(backgroundTexture, BackgroundPosition, null, Color.White * Math.Min(state / 5.0f, 1.0f), 0.0f,
new Vector2(backgroundTexture.Width / 2.0f, backgroundTexture.Height / 2.0f),
backgroundScale * 1.5f, SpriteEffects.None, 0.2f);
titleSprite?.Draw(spriteBatch, TitlePosition, Color.White * Math.Min((state - 1.0f) / 5.0f, 1.0f), scale: titleScale);
Scale * 1.5f, SpriteEffects.None, 0.2f);
spriteBatch.Draw(monsterTexture,
CenterPosition + new Vector2((state % 40) * 100.0f - 1800.0f, (state % 40) * 30.0f - 200.0f) * Scale, null,
Color.White, 0.0f, Vector2.Zero, Scale, SpriteEffects.None, 0.1f);
spriteBatch.Draw(titleTexture,
TitlePosition, null,
Color.White * Math.Min((state - 1.0f) / 5.0f, 1.0f), 0.0f, new Vector2(titleTexture.Width / 2.0f, titleTexture.Height / 2.0f), Scale, SpriteEffects.None, 0.0f);
spriteBatch.End();
graphics.SetRenderTarget(null);
@@ -153,6 +171,10 @@ namespace Barotrauma
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
spriteBatch.Draw(titleTexture,
TitlePosition, null,
Color.White * Math.Min((state - 3.0f) / 5.0f, 1.0f), 0.0f, new Vector2(titleTexture.Width / 2.0f, titleTexture.Height / 2.0f), Scale, SpriteEffects.None, 0.0f);
titleSprite?.Draw(spriteBatch, TitlePosition, Color.White * Math.Min((state - 1.0f) / 5.0f, 1.0f), scale: titleScale);
if (WaitForLanguageSelection)
@@ -197,28 +219,6 @@ namespace Barotrauma
spriteBatch.End();
}
private void DrawLanguageSelectionPrompt(SpriteBatch spriteBatch, GraphicsDevice graphicsDevice)
{
if (languageSelectionFont == null)
{
languageSelectionFont = new ScalableFont("Content/Fonts/BebasNeue-Regular.otf", 28, graphicsDevice);
}
if (languageSelectionCursor == null)
{
languageSelectionCursor = new Sprite("Content/UI/cursor.png", Vector2.Zero);
}
Vector2 textPos = new Vector2(GameMain.GraphicsWidth / 2, GameMain.GraphicsHeight * 0.25f);
Vector2 textSpacing = new Vector2(0.0f, (GameMain.GraphicsHeight * 0.5f) / TextManager.AvailableLanguages.Count());
foreach (string language in TextManager.AvailableLanguages)
{
languageSelectionFont.DrawString(spriteBatch, language, textPos - languageSelectionFont.MeasureString(language) / 2, Color.White * 0.8f);
textPos += textSpacing;
}
languageSelectionCursor.Draw(spriteBatch, PlayerInput.LatestMousePosition);
}
private void DrawSplashScreen(SpriteBatch spriteBatch)
{
if (SplashScreen != null)