(c1468d39d) Overhauled docking interface (WIP)

This commit is contained in:
Joonas Rikkonen
2019-05-03 13:39:54 +03:00
parent 7eb0972d16
commit b551ae7999
101 changed files with 1249 additions and 2246 deletions
@@ -129,8 +129,6 @@ namespace Barotrauma
get { return pauseMenuOpen; }
}
public static bool PreventPauseMenuToggle = false;
public static Color ScreenOverlayColor
{
get;
@@ -1415,7 +1413,6 @@ namespace Barotrauma
public static void TogglePauseMenu()
{
if (Screen.Selected == GameMain.MainMenuScreen) return;
if (PreventPauseMenuToggle) return;
settingsMenuOpen = false;
@@ -1549,9 +1546,9 @@ namespace Barotrauma
if (GameMain.GameSession != null)
{
if (Tutorial.Initialized)
if (ContextualTutorial.Initialized && GameMain.GameSession.GameMode is SinglePlayerCampaign)
{
((TutorialMode)GameMain.GameSession.GameMode).Tutorial.Stop();
((SinglePlayerCampaign)GameMain.GameSession.GameMode).ContextualTutorial.Stop();
}
if (GameSettings.SendUserStatistics)
@@ -168,11 +168,6 @@ namespace Barotrauma
if (frame != null) frame.ApplyStyle(style);
}
public override void Flash(Color? color = null, float flashDuration = 1.5f, bool useRectangleFlash = false, Vector2? flashRectInflate = null)
{
Frame.Flash(color, flashDuration, useRectangleFlash, flashRectInflate);
}
protected override void Draw(SpriteBatch spriteBatch)
{
//do nothing
@@ -121,22 +121,17 @@ namespace Barotrauma
protected Color selectedColor;
protected Color pressedColor;
private CoroutineHandle pulsateCoroutine;
protected ComponentState state;
protected Color flashColor;
protected float flashDuration = 1.5f;
private bool useRectangleFlash;
public float FlashTimer
{
get { return flashTimer; }
}
protected float flashTimer;
private Vector2 flashRectInflate;
public bool IgnoreLayoutGroups;
public bool IgnoreLayoutGroups;
public virtual ScalableFont Font
{
get;
@@ -269,8 +264,6 @@ namespace Barotrauma
set { pressedColor = value; }
}
public bool ExternalHighlight = false;
private RectTransform rectTransform;
public RectTransform RectTransform
{
@@ -445,21 +438,11 @@ namespace Barotrauma
int flashCycleCount = (int)Math.Max(flashDuration, 1);
float flashCycleDuration = flashDuration / flashCycleCount;
Rectangle flashRect = Rect;
flashRect.Inflate(flashRectInflate.X, flashRectInflate.Y);
//MathHelper.Pi * 0.8f -> the curve goes from 144 deg to 0,
//i.e. quickly bumps up from almost full brightness to full and then fades out
if (!useRectangleFlash)
{
GUI.UIGlow.Draw(spriteBatch,
flashRect,
flashColor * (float)Math.Sin(flashTimer % flashCycleDuration / flashCycleDuration * MathHelper.Pi * 0.8f));
}
else
{
GUI.DrawRectangle(spriteBatch, flashRect, flashColor * (float)Math.Sin(flashTimer % flashCycleDuration / flashCycleDuration * MathHelper.Pi * 0.8f), true);
}
GUI.UIGlow.Draw(spriteBatch,
rect,
flashColor * (float)Math.Sin(flashTimer % flashCycleDuration / flashCycleDuration * MathHelper.Pi * 0.8f));
}
}
@@ -507,11 +490,9 @@ namespace Barotrauma
color = new Color(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, a);
}
public virtual void Flash(Color? color = null, float flashDuration = 1.5f, bool useRectangleFlash = false, Vector2? flashRectInflate = null)
public virtual void Flash(Color? color = null, float flashDuration = 1.5f)
{
flashTimer = flashDuration;
this.flashRectInflate = flashRectInflate ?? Vector2.Zero;
this.useRectangleFlash = useRectangleFlash;
this.flashDuration = flashDuration;
flashColor = (color == null) ? Color.Red : (Color)color;
}
@@ -529,7 +510,9 @@ namespace Barotrauma
while (t < duration)
{
t += CoroutineManager.DeltaTime;
SetAlpha(MathHelper.Lerp(startA, to, t / duration));
yield return CoroutineStatus.Running;
}
@@ -542,30 +525,9 @@ namespace Barotrauma
yield return CoroutineStatus.Success;
}
#endregion
public void Pulsate(Vector2 startScale, Vector2 endScale, float duration)
{
if (CoroutineManager.IsCoroutineRunning(pulsateCoroutine))
{
return;
}
pulsateCoroutine = CoroutineManager.StartCoroutine(DoPulsate(startScale, endScale, duration), "Pulsate" + ToString());
}
private IEnumerable<object> DoPulsate(Vector2 startScale, Vector2 endScale, float duration)
{
float t = 0.0f;
while (t < duration)
{
t += CoroutineManager.DeltaTime;
RectTransform.LocalScale = Vector2.Lerp(startScale, endScale, (float)Math.Sin(t / duration * MathHelper.Pi));
yield return CoroutineStatus.Running;
}
RectTransform.LocalScale = startScale;
yield return CoroutineStatus.Success;
}
public virtual void ApplyStyle(GUIComponentStyle style)
protected virtual void SetAlpha(float a)
{
if (style == null) return;
@@ -578,7 +540,13 @@ namespace Barotrauma
OutlineColor = style.OutlineColor;
this.style = style;
public virtual void Flash(Color? color = null, float flashDuration = 1.5f, bool useRectangleFlash = false, Vector2? flashRectInflate = null)
{
flashTimer = flashDuration;
this.flashRectInflate = flashRectInflate ?? Vector2.Zero;
this.useRectangleFlash = useRectangleFlash;
this.flashDuration = flashDuration;
flashColor = (color == null) ? Color.Red : (Color)color;
}
}
}
@@ -41,22 +41,33 @@ namespace Barotrauma
InnerFrame = new GUIFrame(new RectTransform(new Point(width, height), RectTransform, Anchor.Center) { IsFixedSize = false }, style: null);
GUI.Style.Apply(InnerFrame, "", this);
InnerFrame = new GUIFrame(new RectTransform(new Point(width, height), RectTransform, Anchor.Center) { IsFixedSize = false }, style: null);
GUI.Style.Apply(InnerFrame, "", this);
Content = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.85f), InnerFrame.RectTransform, Anchor.Center)) { AbsoluteSpacing = 5 };
Tag = tag;
if (height == 0)
{
string wrappedText = ToolBox.WrapText(text, Content.Rect.Width, GUI.Font);
string[] lines = wrappedText.Split('\n');
foreach (string line in lines)
{
height += (int)GUI.Font.MeasureString(line).Y;
}
height += string.IsNullOrWhiteSpace(headerText) ? 220 : 220 - headerHeight;
}
InnerFrame.RectTransform.NonScaledSize = new Point(InnerFrame.Rect.Width, height);
Header = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), Content.RectTransform),
headerText, textAlignment: Alignment.Center, wrap: true);
GUI.Style.Apply(Header, "", this);
Header.RectTransform.MinSize = new Point(0, Header.Rect.Height);
GUI.Style.Apply(Header, "", this);
if (!string.IsNullOrWhiteSpace(text))
if (height == 0)
{
Text = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), Content.RectTransform),
text, textAlignment: textAlignment, wrap: true);
GUI.Style.Apply(Text, "", this);
Text.RectTransform.NonScaledSize = Text.RectTransform.MinSize = Text.RectTransform.MaxSize =
new Point(Text.Rect.Width, Text.Rect.Height);
Text.RectTransform.IsFixedSize = true;
}
var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), Content.RectTransform, Anchor.BottomCenter, maxSize: new Point(1000, 50)),
@@ -65,22 +76,7 @@ namespace Barotrauma
AbsoluteSpacing = 5,
IgnoreLayoutGroups = true
};
buttonContainer.RectTransform.NonScaledSize = buttonContainer.RectTransform.MinSize = buttonContainer.RectTransform.MaxSize =
new Point(buttonContainer.Rect.Width, (int)(30 * GUI.Scale));
buttonContainer.RectTransform.IsFixedSize = true;
if (height == 0)
{
height += Header.Rect.Height + Content.AbsoluteSpacing;
height += (Text == null ? 0 : Text.Rect.Height) + Content.AbsoluteSpacing;
height += buttonContainer.Rect.Height;
InnerFrame.RectTransform.NonScaledSize =
new Point(InnerFrame.Rect.Width, (int)Math.Max(height / Content.RectTransform.RelativeSize.Y, height + 50));
Content.RectTransform.NonScaledSize =
new Point(Content.Rect.Width, height);
}
Buttons = new List<GUIButton>(buttons.Length);
for (int i = 0; i < buttons.Length; i++)
{
@@ -1,8 +1,6 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
@@ -249,7 +247,7 @@ namespace Barotrauma
return;
}
textPos = new Vector2(padding.X + (rect.Width - padding.Z - padding.X) / 2.0f, padding.Y + (rect.Height - padding.Y - padding.W) / 2.0f);
textPos = new Vector2(rect.Width / 2.0f, rect.Height / 2.0f);
origin = TextSize * 0.5f;
if (textAlignment.HasFlag(Alignment.Left) && !overflowClipActive)
@@ -365,9 +365,9 @@ namespace Barotrauma
OnDeselected?.Invoke(this, Keys.None);
}
public override void Flash(Color? color = null, float flashDuration = 1.5f, bool useRectangleFlash = false, Vector2? flashRectOffset = null)
public override void Flash(Color? color = null, float flashDuration = 1.5f)
{
textBlock.Flash(color, flashDuration, useRectangleFlash, flashRectOffset);
textBlock.Flash(color, flashDuration);
}
protected override void Update(float deltaTime)
@@ -44,11 +44,10 @@ namespace Barotrauma
public Color TextColor
{
get { return text.TextColor; }
set { text.TextColor = value; }
get { return box; }
}
public override Rectangle MouseRect
public GUITextBlock TextBlock
{
get
{
@@ -57,17 +56,14 @@ namespace Barotrauma
}
}
public override ScalableFont Font
public override string ToolTip
{
get
{
return base.Font;
}
get { return base.ToolTip; }
set
{
base.Font = value;
if (text != null) text.Font = value;
base.ToolTip = value;
box.ToolTip = value;
text.ToolTip = value;
}
}
@@ -76,11 +72,6 @@ namespace Barotrauma
get { return box; }
}
public GUITextBlock TextBlock
{
get { return text; }
}
public override string ToolTip
{
get { return base.ToolTip; }
@@ -128,7 +119,6 @@ namespace Barotrauma
private void ResizeBox()
{
box.RectTransform.NonScaledSize = new Point(RectTransform.NonScaledSize.Y);
text.RectTransform.NonScaledSize = new Point(Rect.Width - box.Rect.Width, text.Rect.Height);
text.RectTransform.AbsoluteOffset = new Point(box.Rect.Width, 0);
}
@@ -10,10 +10,9 @@ namespace Barotrauma
{
class VideoPlayer
{
public bool IsPlaying;
private Video currentVideo;
private string filePath;
private bool isPlaying;
private GUIFrame background, videoFrame, textFrame;
private GUITextBlock title, textContent, objectiveTitle, objectiveText;
@@ -25,14 +24,12 @@ namespace Barotrauma
private Point scaledVideoResolution;
private readonly int borderSize = 20;
private readonly Point buttonSize = new Point(120, 30);
private readonly Point buttonSize = new Point(160, 50);
private readonly int titleHeight = 30;
private readonly int objectiveFrameHeight = 60;
private readonly int textHeight = 25;
private bool useTextOnRightSide = false;
public class TextSettings
public struct TextSettings
{
public string Text;
public int Width;
@@ -44,7 +41,7 @@ namespace Barotrauma
}
}
public class VideoSettings
public struct VideoSettings
{
public string File;
@@ -65,14 +62,7 @@ namespace Barotrauma
background = new GUIFrame(new RectTransform(Point.Zero, GUI.Canvas, Anchor.Center), "InnerFrame", backgroundColor);
videoFrame = new GUIFrame(new RectTransform(Point.Zero, background.RectTransform, Anchor.Center, Pivot.Center), "SonarFrame");
if (useTextOnRightSide)
{
textFrame = new GUIFrame(new RectTransform(Point.Zero, videoFrame.RectTransform, Anchor.CenterLeft, Pivot.CenterLeft), "TextFrame");
}
else
{
textFrame = new GUIFrame(new RectTransform(Point.Zero, videoFrame.RectTransform, Anchor.TopCenter, Pivot.TopCenter), "TextFrame");
}
textFrame = new GUIFrame(new RectTransform(Point.Zero, videoFrame.RectTransform, Anchor.CenterLeft, Pivot.CenterLeft), "TextFrame");
videoView = new GUICustomComponent(new RectTransform(Point.Zero, videoFrame.RectTransform, Anchor.Center), (spriteBatch, guiCustomComponent) => { DrawVideo(spriteBatch, guiCustomComponent.Rect); });
title = new GUITextBlock(new RectTransform(Point.Zero, textFrame.RectTransform, Anchor.TopLeft, Pivot.TopLeft), string.Empty, font: GUI.VideoTitleFont, textColor: new Color(253, 174, 0), textAlignment: Alignment.Left);
@@ -80,7 +70,7 @@ namespace Barotrauma
textContent = new GUITextBlock(new RectTransform(Point.Zero, textFrame.RectTransform, Anchor.TopLeft, Pivot.TopLeft), string.Empty, font: GUI.Font, textAlignment: Alignment.TopLeft);
objectiveTitle = new GUITextBlock(new RectTransform(new Vector2(1f, 0f), textFrame.RectTransform, Anchor.TopCenter, Pivot.TopCenter), string.Empty, font: GUI.ObjectiveTitleFont, textAlignment: Alignment.CenterRight, textColor: Color.White);
objectiveTitle.Text = TextManager.Get("Tutorial.NewObjective");
objectiveTitle.Text = TextManager.Get("NewObjective");
objectiveText = new GUITextBlock(new RectTransform(Point.Zero, textFrame.RectTransform, Anchor.TopCenter, Pivot.TopCenter), string.Empty, font: GUI.ObjectiveNameFont, textColor: new Color(4, 180, 108), textAlignment: Alignment.CenterRight);
objectiveTitle.Visible = objectiveText.Visible = false;
@@ -88,12 +78,12 @@ namespace Barotrauma
public void Play()
{
IsPlaying = true;
isPlaying = true;
}
public void Stop()
{
IsPlaying = false;
isPlaying = false;
if (currentVideo == null) return;
currentVideo.Dispose();
currentVideo = null;
@@ -109,6 +99,13 @@ namespace Barotrauma
public void Update()
{
if (currentVideo == null) return;
if (PlayerInput.KeyHit(Keys.Enter) || PlayerInput.KeyHit(Keys.Escape))
{
DisposeVideo(null, null);
return;
}
if (currentVideo.IsPlaying) return;
currentVideo.Dispose();
@@ -118,7 +115,7 @@ namespace Barotrauma
public void AddToGUIUpdateList(bool ignoreChildren = false, int order = 0)
{
if (!IsPlaying) return;
if (!isPlaying) return;
background.AddToGUIUpdateList(ignoreChildren, order);
}
@@ -142,7 +139,7 @@ namespace Barotrauma
currentVideo = CreateVideo(scaledVideoResolution);
title.Text = TextManager.Get(contentId);
textContent.Text = textSettings != null ? textSettings.Text : string.Empty;
textContent.Text = textSettings.Text;
objectiveText.Text = objective;
AdjustFrames(videoSettings, textSettings);
@@ -168,8 +165,7 @@ namespace Barotrauma
title.TextScale = textContent.TextScale = objectiveText.TextScale = objectiveTitle.TextScale = GUI.Scale;
int scaledBorderSize = (int)(borderSize * GUI.Scale);
int scaledTextWidth = 0;
if (textSettings != null) scaledTextWidth = useTextOnRightSide ? (int)(textSettings.Width * GUI.Scale) : scaledVideoResolution.X / 2;
int scaledTextWidth = (int)(textSettings.Width * GUI.Scale);
int scaledTitleHeight = (int)(titleHeight * GUI.Scale);
int scaledTextHeight = (int)(textHeight * GUI.Scale);
int scaledObjectiveFrameHeight = (int)(objectiveFrameHeight * GUI.Scale);
@@ -184,21 +180,13 @@ namespace Barotrauma
title.RectTransform.NonScaledSize += new Point(scaledTextWidth, scaledTitleHeight);
title.RectTransform.AbsoluteOffset = new Point((int)(5 * GUI.Scale), (int)(10 * GUI.Scale));
if (textSettings != null && !string.IsNullOrEmpty(textSettings.Text))
if (!string.IsNullOrEmpty(textSettings.Text))
{
textSettings.Text = ToolBox.WrapText(textSettings.Text, scaledTextWidth, GUI.Font);
int wrappedHeight = textSettings.Text.Split('\n').Length * scaledTextHeight;
textFrame.RectTransform.NonScaledSize += new Point(scaledTextWidth + scaledBorderSize, wrappedHeight + scaledBorderSize + scaledButtonSize.Y + scaledTitleHeight);
if (useTextOnRightSide)
{
textFrame.RectTransform.AbsoluteOffset = new Point(scaledVideoResolution.X + scaledBorderSize * 2, 0);
}
else
{
textFrame.RectTransform.AbsoluteOffset = new Point(0, scaledVideoResolution.Y + scaledBorderSize * 2);
}
textFrame.RectTransform.AbsoluteOffset = new Point(scaledVideoResolution.X + scaledBorderSize * 2, 0);
textContent.RectTransform.NonScaledSize += new Point(scaledTextWidth, wrappedHeight);
textContent.RectTransform.AbsoluteOffset = new Point(0, scaledBorderSize + scaledTitleHeight);
@@ -221,41 +209,22 @@ namespace Barotrauma
objectiveTitle.Visible = objectiveText.Visible = false;
}
int totalFrameWidth = videoFrame.Rect.Width + textFrame.Rect.Width + scaledBorderSize * 2;
int xOffset = videoFrame.Rect.Width / 2 + scaledBorderSize - (videoFrame.Rect.Width / 2 - textFrame.Rect.Width / 2);
videoFrame.RectTransform.AbsoluteOffset = new Point(-xOffset, (int)(50 * GUI.Scale));
if (okButton != null)
{
textFrame.RemoveChild(okButton);
okButton = null;
}
if (textSettings != null)
okButton = new GUIButton(new RectTransform(scaledButtonSize, textFrame.RectTransform, Anchor.BottomRight, Pivot.BottomRight) { AbsoluteOffset = new Point(scaledBorderSize, scaledBorderSize) }, TextManager.Get("OK"))
{
if (useTextOnRightSide)
{
int totalFrameWidth = videoFrame.Rect.Width + textFrame.Rect.Width + scaledBorderSize * 2;
int xOffset = videoFrame.Rect.Width / 2 + scaledBorderSize - (videoFrame.Rect.Width / 2 - textFrame.Rect.Width / 2);
videoFrame.RectTransform.AbsoluteOffset = new Point(-xOffset, (int)(50 * GUI.Scale));
}
else
{
int totalFrameHeight = videoFrame.Rect.Height + textFrame.Rect.Height + scaledBorderSize * 2;
int yOffset = videoFrame.Rect.Height / 2 + scaledBorderSize - (videoFrame.Rect.Height / 2 - textFrame.Rect.Height / 2);
videoFrame.RectTransform.AbsoluteOffset = new Point(0, -yOffset);
}
okButton = new GUIButton(new RectTransform(scaledButtonSize, textFrame.RectTransform, Anchor.BottomRight, Pivot.BottomRight) { AbsoluteOffset = new Point(scaledBorderSize, scaledBorderSize) }, TextManager.Get("OK"))
{
OnClicked = DisposeVideo
};
}
else
{
videoFrame.RectTransform.AbsoluteOffset = new Point(0, (int)(100 * GUI.Scale));
okButton = new GUIButton(new RectTransform(scaledButtonSize, videoFrame.RectTransform, Anchor.TopLeft, Pivot.TopLeft) { AbsoluteOffset = new Point(scaledBorderSize, scaledBorderSize) }, TextManager.Get("Back"))
{
OnClicked = DisposeVideo
};
}
OnClicked = DisposeVideo
};
}
private Video CreateVideo(Point resolution)
@@ -276,7 +245,7 @@ namespace Barotrauma
private void DrawVideo(SpriteBatch spriteBatch, Rectangle rect)
{
if (!IsPlaying) return;
if (!isPlaying) return;
spriteBatch.Draw(currentVideo.GetTexture(), rect, Color.White);
}