(eba811de) Unstable 0.9.703.0

This commit is contained in:
Juan Pablo Arce
2020-02-04 11:54:57 -03:00
parent 15499cb704
commit 08ab6185c4
100 changed files with 2162 additions and 1520 deletions
@@ -12,7 +12,8 @@ namespace Barotrauma
{
class ChatBox
{
private static Sprite radioIcon;
public const string RadioChatString = "r; ";
private GUIListBox chatBox;
private Point screenResolution;
@@ -26,8 +27,8 @@ namespace Barotrauma
get { return _toggleOpen; }
set
{
if (_toggleOpen == value) { return; }
_toggleOpen = GameMain.Config.ChatOpen = value;
if (value) hideableElements.Visible = true;
foreach (GUIComponent child in ToggleButton.Children)
{
child.SpriteEffects = _toggleOpen ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
@@ -65,11 +66,6 @@ namespace Barotrauma
public ChatBox(GUIComponent parent, bool isSinglePlayer)
{
this.IsSinglePlayer = isSinglePlayer;
if (radioIcon == null)
{
radioIcon = new Sprite("Content/UI/inventoryAtlas.png", new Rectangle(527, 952, 38, 52), null);
radioIcon.Origin = radioIcon.size / 2;
}
screenResolution = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
@@ -105,7 +101,7 @@ namespace Barotrauma
//gui.Text = "";
};
var chatSendButton = new GUIButton(new RectTransform(new Vector2(0.2f, 0.7f), InputBox.RectTransform, Anchor.CenterRight, scaleBasis: ScaleBasis.BothHeight), style: "GUIButtonToggleRight");
var chatSendButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.7f), InputBox.RectTransform, Anchor.CenterRight, scaleBasis: ScaleBasis.BothHeight), style: "GUIButtonToggleRight");
chatSendButton.OnClicked += (GUIButton btn, object userdata) =>
{
InputBox.OnEnterPressed(InputBox, InputBox.Text);
@@ -339,7 +335,7 @@ namespace Barotrauma
showNewMessagesButton.Visible = false;
}
if (ToggleOpen || (InputBox != null && InputBox.Selected))
if (ToggleOpen)
{
openState += deltaTime * 5.0f;
//delete all popup messages when the chatbox is open
@@ -133,7 +133,16 @@ namespace Barotrauma
case "size":
break;
default:
ChildStyles.Add(subElement.Name.ToString().ToLowerInvariant(), new GUIComponentStyle(subElement, style));
string styleName = subElement.Name.ToString().ToLowerInvariant();
if (ChildStyles.ContainsKey(styleName))
{
DebugConsole.ThrowError("UI style \"" + element.Name.ToString() + "\" contains multiple child styles with the same name (\"" + styleName + "\")!");
ChildStyles[styleName] = new GUIComponentStyle(subElement, style);
}
else
{
ChildStyles.Add(styleName, new GUIComponentStyle(subElement, style));
}
break;
}
}
@@ -78,19 +78,26 @@ namespace Barotrauma
public static readonly string[] rectComponentLabels = { "X", "Y", "W", "H" };
public static readonly string[] colorComponentLabels = { "R", "G", "B", "A" };
public static float Scale
{
get { return (GameMain.GraphicsWidth / 1920.0f + GameMain.GraphicsHeight / 1080.0f) / 2.0f * GameSettings.HUDScale; }
}
public static Vector2 ReferenceResolution => new Vector2(1920f, 1080f);
public static float Scale => (GameMain.GraphicsWidth / ReferenceResolution.X + GameMain.GraphicsHeight / ReferenceResolution.Y) / 2.0f * GameSettings.HUDScale;
public static float xScale => GameMain.GraphicsWidth / ReferenceResolution.X * GameSettings.HUDScale;
public static float yScale => GameMain.GraphicsHeight / ReferenceResolution.Y * GameSettings.HUDScale;
public static float HorizontalAspectRatio => GameMain.GraphicsWidth / (float)GameMain.GraphicsHeight;
public static float VerticalAspectRatio => GameMain.GraphicsHeight / (float)GameMain.GraphicsWidth;
public static float RelativeHorizontalAspectRatio => HorizontalAspectRatio / (ReferenceResolution.X / ReferenceResolution.Y);
public static float RelativeVerticalAspectRatio => VerticalAspectRatio / (ReferenceResolution.Y / ReferenceResolution.X);
public static float xScale
public static float SlicedSpriteScale
{
get { return GameMain.GraphicsWidth / 1920.0f * GameSettings.HUDScale; }
}
public static float yScale
{
get { return GameMain.GraphicsHeight / 1080.0f * GameSettings.HUDScale; }
get
{
if (Math.Abs(1.0f - Scale) < 0.1f)
{
//don't scale if very close to the "reference resolution"
return 1.0f;
}
return Scale;
}
}
public static GUIStyle Style;
@@ -106,7 +113,7 @@ namespace Barotrauma
private static Sound[] sounds;
private static bool pauseMenuOpen, settingsMenuOpen;
public static GUIFrame PauseMenu { get; private set; }
private static Sprite arrow, lockIcon, checkmarkIcon, timerIcon;
private static Sprite arrow;
public static bool HideCursor;
@@ -155,21 +162,6 @@ namespace Barotrauma
get { return arrow; }
}
public static Sprite CheckmarkIcon
{
get { return checkmarkIcon; }
}
public static Sprite LockIcon
{
get { return lockIcon; }
}
public static Sprite TimerIcon
{
get { return timerIcon; }
}
public static Sprite InfoAreaBackground;
public static bool SettingsMenuOpen
@@ -263,13 +255,10 @@ namespace Barotrauma
t.SetData(new Color[] { Color.White });// fill the texture with white
});
SubmarineIcon = new Sprite("Content/UI/IconAtlas.png", new Rectangle(452, 385, 182, 81), new Vector2(0.5f, 0.5f));
arrow = new Sprite("Content/UI/IconAtlas.png", new Rectangle(392, 393, 49, 45), new Vector2(0.5f, 0.5f));
SpeechBubbleIcon = new Sprite("Content/UI/IconAtlas.png", new Rectangle(385, 449, 66, 60), new Vector2(0.5f, 0.5f));
BrokenIcon = new Sprite("Content/UI/IconAtlas.png", new Rectangle(898, 386, 123, 123), new Vector2(0.5f, 0.5f));
lockIcon = new Sprite("Content/UI/UI_Atlas.png", new Rectangle(996, 677, 21, 25), new Vector2(0.5f, 0.5f));
checkmarkIcon = new Sprite("Content/UI/UI_Atlas.png", new Rectangle(932, 398, 33, 28), new Vector2(0.5f, 0.5f));
timerIcon = new Sprite("Content/UI/UI_Atlas.png", new Rectangle(997, 653, 18, 21), new Vector2(0.5f, 0.5f));
SubmarineIcon = new Sprite("Content/UI/MainIconsAtlas.png", new Rectangle(452, 385, 182, 81), new Vector2(0.5f, 0.5f));
arrow = new Sprite("Content/UI/MainIconsAtlas.png", new Rectangle(392, 393, 49, 45), new Vector2(0.5f, 0.5f));
SpeechBubbleIcon = new Sprite("Content/UI/MainIconsAtlas.png", new Rectangle(385, 449, 66, 60), new Vector2(0.5f, 0.5f));
BrokenIcon = new Sprite("Content/UI/MainIconsAtlas.png", new Rectangle(898, 386, 123, 123), new Vector2(0.5f, 0.5f));
InfoAreaBackground = new Sprite("Content/UI/InventoryUIAtlas.png", new Rectangle(290, 320, 400, 300), new Vector2(0.0f, 0.0f));
}
@@ -300,17 +289,33 @@ namespace Barotrauma
string line1 = "Barotrauma Unstable v" + GameMain.Version;
string line2 = "(" + AssemblyInfo.GetBuildString() + ", branch " + AssemblyInfo.GetGitBranch() + ", revision " + AssemblyInfo.GetGitRevision() + ")";
Rectangle watermarkRect = new Rectangle(-50, GameMain.GraphicsHeight - 80, 50 + (int)(Math.Max(LargeFont.MeasureString(line1).X, Font.MeasureString(line2).X) * 1.2f), 100);
float alpha = 1.0f;
int yOffset = 0;
if (Screen.Selected == GameMain.GameScreen)
{
yOffset = -HUDLayoutSettings.ChatBoxArea.Height;
watermarkRect.Y += yOffset;
}
if (Screen.Selected == GameMain.GameScreen || Screen.Selected == GameMain.SubEditorScreen)
{
alpha = 0.2f;
}
Style.GetComponentStyle("OuterGlow").Sprites[GUIComponent.ComponentState.None][0].Draw(
spriteBatch, new Rectangle(-50, GameMain.GraphicsHeight - 80, 50 + (int)(Math.Max(LargeFont.MeasureString(line1).X, Font.MeasureString(line2).X) * 1.2f), 100), Color.Black * 0.8f);
spriteBatch, watermarkRect, Color.Black * 0.8f * alpha);
LargeFont.DrawString(spriteBatch, line1,
new Vector2(10, GameMain.GraphicsHeight - 30 - LargeFont.MeasureString(line1).Y), Color.White * 0.6f);
new Vector2(10, GameMain.GraphicsHeight - 30 - LargeFont.MeasureString(line1).Y + yOffset), Color.White * 0.6f * alpha);
Font.DrawString(spriteBatch, line2,
new Vector2(10, GameMain.GraphicsHeight - 30), Color.White * 0.6f);
new Vector2(10, GameMain.GraphicsHeight - 30 + yOffset), Color.White * 0.6f * alpha);
if (Screen.Selected != GameMain.GameScreen)
{
var buttonRect =
new Rectangle(20 + (int)Math.Max(LargeFont.MeasureString(line1).X, Font.MeasureString(line2).X), GameMain.GraphicsHeight - (int)(45 * Scale), (int)(150 * Scale), (int)(40 * Scale));
new Rectangle(20 + (int)Math.Max(LargeFont.MeasureString(line1).X, Font.MeasureString(line2).X), GameMain.GraphicsHeight - (int)(45 * Scale) + yOffset, (int)(150 * Scale), (int)(40 * Scale));
if (DrawButton(spriteBatch, buttonRect, "Report Bug", Style.GetComponentStyle("GUIBugButton").Color * 0.8f))
{
GameMain.Instance.ShowBugReporter();
@@ -521,7 +526,7 @@ namespace Barotrauma
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: SamplerStateClamp, rasterizerState: GameMain.ScissorTestEnable);
var sprite = MouseCursorSprites[(int) MouseCursor];
var sprite = MouseCursorSprites[(int) MouseCursor] ?? MouseCursorSprites[(int)CursorState.Default];
sprite.Draw(spriteBatch, PlayerInput.LatestMousePosition, Color.White, sprite.Origin, 0f, Scale / 1.5f);
spriteBatch.End();
@@ -1761,6 +1766,18 @@ namespace Barotrauma
//move the interfaces away from each other, in a random direction if they're at the same position
Vector2 moveAmount = centerDiff == Point.Zero ? Rand.Vector(1.0f) : Vector2.Normalize(centerDiff.ToVector2());
//if the horizontal move amount is much larger than vertical, only move horizontally
//(= attempt to place the elements side-by-side if they're more apart horizontally than vertically)
if (Math.Abs(moveAmount.X) > Math.Abs(moveAmount.Y) * 5.0f)
{
moveAmount.Y = 0.0f;
}
//same for the y-axis
else if (Math.Abs(moveAmount.Y) > Math.Abs(moveAmount.X) * 5.0f)
{
moveAmount.X = 0.0f;
}
//make sure we don't move the interfaces out of the screen
Vector2 moveAmount1 = ClampMoveAmount(rect1, area, moveAmount * 20.0f * rect1Area / (rect1Area + rect2Area));
Vector2 moveAmount2 = ClampMoveAmount(rect2, area, -moveAmount * 20.0f * rect1Area / (rect1Area + rect2Area));
@@ -656,18 +656,18 @@ namespace Barotrauma
public static void DrawToolTip(SpriteBatch spriteBatch, string toolTip, Rectangle targetElement, List<ColorData> colorData = null)
{
if (Tutorials.Tutorial.ContentRunning) return;
if (Tutorials.Tutorial.ContentRunning) { return; }
int width = (int)(400 * GUI.Scale);
int height = (int)(18 * GUI.Scale);
Point padding = new Point((int)(20 * GUI.Scale), (int)(7 * GUI.Scale));
Point padding = new Point((int)(10 * GUI.Scale));
if (toolTipBlock == null || (string)toolTipBlock.userData != toolTip)
{
toolTipBlock = new GUITextBlock(new RectTransform(new Point(width, height), null), colorData, toolTip, font: GUI.SmallFont, wrap: true, style: "GUIToolTip");
toolTipBlock.RectTransform.NonScaledSize = new Point(
(int)(GUI.SmallFont.MeasureString(toolTipBlock.WrappedText).X + padding.X),
(int)(GUI.SmallFont.MeasureString(toolTipBlock.WrappedText).Y + padding.Y));
(int)(GUI.SmallFont.MeasureString(toolTipBlock.WrappedText).X + padding.X + toolTipBlock.Padding.X + toolTipBlock.Padding.Z),
(int)(GUI.SmallFont.MeasureString(toolTipBlock.WrappedText).Y + padding.Y + toolTipBlock.Padding.Y + toolTipBlock.Padding.W));
toolTipBlock.userData = toolTip;
}
@@ -41,7 +41,17 @@ namespace Barotrauma
private bool dimensionsNeedsRecalculation;
// TODO: Define in styles?
private int scrollBarSize = 25;
private int ScrollBarSize
{
get
{
//use the average of the "desired" size and the scaled size
//scaling the bar linearly with the resolution tends to make them too large on large resolutions
float desiredSize = 25.0f;
float scaledSize = desiredSize * GUI.Scale;
return (int)((desiredSize + scaledSize) / 2.0f);
}
}
public bool SelectMultiple;
@@ -162,7 +172,7 @@ namespace Barotrauma
/// Automatically hides the scroll bar when the content fits in.
/// </summary>
public bool AutoHideScrollBar { get; set; } = true;
private bool IsScrollBarOnDefaultSide { get; set; }
public bool CanDragElements { get; set; } = false;
private GUIComponent draggedElement;
@@ -171,7 +181,8 @@ namespace Barotrauma
public GUIComponent DraggedElement => draggedElement;
public GUIListBox(RectTransform rectT, bool isHorizontal = false, Color? color = null, string style = "") : base(style, rectT)
/// <param name="isScrollBarOnDefaultSide">For horizontal listbox, default side is on the bottom. For vertical, it's on the right.</param>
public GUIListBox(RectTransform rectT, bool isHorizontal = false, Color? color = null, string style = "", bool isScrollBarOnDefaultSide = true) : base(style, rectT)
{
CanBeFocused = true;
selected = new List<GUIComponent>();
@@ -196,20 +207,27 @@ namespace Barotrauma
{
this.color = color.Value;
}
IsScrollBarOnDefaultSide = isScrollBarOnDefaultSide;
Point size;
Anchor anchor;
if (isHorizontal)
{
size = new Point((int)(Rect.Width - Padding.X - Padding.Z), (int)(scrollBarSize * GUI.Scale));
anchor = Anchor.BottomCenter;
size = new Point((int)(Rect.Width - Padding.X - Padding.Z), (int)(ScrollBarSize * GUI.Scale));
anchor = isScrollBarOnDefaultSide ? Anchor.BottomCenter : Anchor.TopCenter;
}
else
{
size = new Point((int)(scrollBarSize * GUI.Scale), (int)(Rect.Height - Padding.Y - Padding.W));
anchor = Anchor.CenterRight;
// TODO: Should this be multiplied by the GUI.Scale as well?
size = new Point(ScrollBarSize, (int)(Rect.Height - Padding.Y - Padding.W));
anchor = isScrollBarOnDefaultSide ? Anchor.CenterRight : Anchor.CenterLeft;
}
ScrollBar = new GUIScrollBar(new RectTransform(size, rectT, anchor)
{ AbsoluteOffset = isHorizontal ? new Point(0, (int)Padding.W) : new Point((int)Padding.Z, 0) },
ScrollBar = new GUIScrollBar(
new RectTransform(size, rectT, anchor)
{
AbsoluteOffset = isHorizontal ?
new Point(0, IsScrollBarOnDefaultSide ? (int)Padding.W : (int)Padding.Y) :
new Point(IsScrollBarOnDefaultSide ? (int)Padding.Z : (int)Padding.X, 0)
},
isHorizontal: isHorizontal);
UpdateScrollBarSize();
Enabled = true;
@@ -224,12 +242,15 @@ namespace Barotrauma
dimensionsNeedsRecalculation = false;
ContentBackground.RectTransform.Resize(Rect.Size);
bool reduceScrollbarSize = KeepSpaceForScrollBar ? ScrollBarEnabled : ScrollBarVisible;
Point contentSize = reduceScrollbarSize ? CalculateFrameSize(ScrollBar.IsHorizontal, scrollBarSize) : Rect.Size;
Point contentSize = reduceScrollbarSize ? CalculateFrameSize(ScrollBar.IsHorizontal, ScrollBarSize) : Rect.Size;
Content.RectTransform.Resize(new Point((int)(contentSize.X - Padding.X - Padding.Z), (int)(contentSize.Y - Padding.Y - Padding.W)));
Content.RectTransform.AbsoluteOffset = new Point((int)Padding.X, (int)Padding.Y);
if (!IsScrollBarOnDefaultSide) { Content.RectTransform.SetPosition(Anchor.BottomRight); }
Content.RectTransform.AbsoluteOffset = new Point(
IsScrollBarOnDefaultSide ? (int)Padding.X : (int)Padding.Z,
IsScrollBarOnDefaultSide ? (int)Padding.Y : (int)Padding.W);
ScrollBar.RectTransform.Resize(ScrollBar.IsHorizontal ?
new Point((int)(Rect.Width - Padding.X - Padding.Z), (int)(scrollBarSize * GUI.Scale)) :
new Point((int)(scrollBarSize * GUI.Scale), (int)(Rect.Height - Padding.Y - Padding.W)));
new Point((int)(Rect.Width - Padding.X - Padding.Z), ScrollBarSize) :
new Point(ScrollBarSize, (int)(Rect.Height - Padding.Y - Padding.W)));
ScrollBar.RectTransform.AbsoluteOffset = ScrollBar.IsHorizontal ?
new Point(0, (int)Padding.W) :
new Point((int)Padding.Z, 0);
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using Barotrauma.Extensions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
@@ -62,8 +63,8 @@ namespace Barotrauma
public Color TextColorDark { get; private set; } = Color.Black * 0.9f;
public Color TextColorDim { get; private set; } = Color.White * 0.6f;
public static Point ItemFrameMargin = new Point(50, 56);
public static Point ItemFrameOffset = new Point(0, 3);
public static Point ItemFrameMargin = new Point(50, 56).Multiply(GUI.SlicedSpriteScale);
public static Point ItemFrameOffset = new Point(0, 3).Multiply(GUI.SlicedSpriteScale);
public GUIStyle(XElement element, GraphicsDevice graphicsDevice)
{
@@ -76,10 +77,17 @@ namespace Barotrauma
switch (name)
{
case "cursor":
foreach (var children in subElement.Descendants())
if (subElement.HasElements)
{
var index = children.GetAttributeInt("state", (int) CursorState.Default);
CursorSprite[index] = new Sprite(children);
foreach (var children in subElement.Descendants())
{
var index = children.GetAttributeInt("state", (int)CursorState.Default);
CursorSprite[index] = new Sprite(children);
}
}
else
{
CursorSprite[(int)CursorState.Default] = new Sprite(subElement);
}
break;
case "green":
@@ -85,7 +85,7 @@ namespace Barotrauma
if (Text == newText) { return; }
//reset scale, it gets recalculated in SetTextPos
if (autoScale) { textScale = 1.0f; }
if (autoScaleHorizontal || autoScaleVertical) { textScale = 1.0f; }
text = newText;
wrappedText = newText;
@@ -132,19 +132,36 @@ namespace Barotrauma
}
}
private bool autoScale;
private bool autoScaleHorizontal, autoScaleVertical;
/// <summary>
/// When enabled, the text is automatically scaled down to fit the textblock.
/// When enabled, the text is automatically scaled down to fit the textblock horizontally.
/// </summary>
public bool AutoScale
public bool AutoScaleHorizontal
{
get { return autoScale; }
get { return autoScaleHorizontal; }
set
{
if (autoScale == value) return;
autoScale = value;
if (autoScale)
if (autoScaleHorizontal == value) { return; }
autoScaleHorizontal = value;
if (autoScaleHorizontal)
{
SetTextPos();
}
}
}
/// <summary>
/// When enabled, the text is automatically scaled down to fit the textblock vertically.
/// </summary>
public bool AutoScaleVertical
{
get { return autoScaleVertical; }
set
{
if (autoScaleVertical == value) { return; }
autoScaleVertical = value;
if (autoScaleVertical)
{
SetTextPos();
}
@@ -309,7 +326,7 @@ namespace Barotrauma
public void SetTextPos()
{
if (text == null) return;
if (text == null) { return; }
censoredText = "";
for (int i = 0; i < text.Length; i++)
@@ -337,12 +354,13 @@ namespace Barotrauma
Vector2 minSize = new Vector2(
Math.Max(rect.Width - padding.X - padding.Z, 5.0f),
Math.Max(rect.Height - padding.Y - padding.W, 5.0f));
if (autoScale && textScale > 0.1f &&
if (!autoScaleHorizontal) { minSize.X = float.MaxValue; }
if (!Wrap && !autoScaleVertical) { minSize.Y = float.MaxValue; }
if ((autoScaleHorizontal || autoScaleVertical) && textScale > 0.1f &&
(TextSize.X * textScale > minSize.X || TextSize.Y * textScale > minSize.Y))
{
TextScale = Math.Max(0.1f, Math.Min(
(rect.Width - padding.X - padding.Z) / TextSize.X,
(rect.Height - padding.Y - padding.W) / TextSize.Y)) - 0.01f;
TextScale = Math.Max(0.1f, Math.Min(minSize.X / TextSize.X, minSize.Y / TextSize.Y)) - 0.01f;
return;
}
@@ -490,20 +508,30 @@ namespace Barotrauma
/// <summary>
/// Set the text scale of the GUITextBlocks so that they all use the same scale and can fit the text within the block.
/// </summary>
public static void AutoScaleAndNormalize(IEnumerable<GUITextBlock> textBlocks, float? defaultScale = null)
public static void AutoScaleAndNormalize(bool scaleHorizontal = true, bool scaleVertical = false, params GUITextBlock[] textBlocks)
{
AutoScaleAndNormalize(textBlocks.AsEnumerable<GUITextBlock>(), scaleHorizontal, scaleVertical);
}
/// <summary>
/// Set the text scale of the GUITextBlocks so that they all use the same scale and can fit the text within the block.
/// </summary>
public static void AutoScaleAndNormalize(IEnumerable<GUITextBlock> textBlocks, bool scaleHorizontal = true, bool scaleVertical = false, float? defaultScale = null)
{
if (!textBlocks.Any()) { return; }
float minScale = Math.Max(textBlocks.First().TextScale, 1.0f);
foreach (GUITextBlock textBlock in textBlocks)
{
if (defaultScale.HasValue) { textBlock.TextScale = defaultScale.Value; }
textBlock.AutoScale = true;
textBlock.AutoScaleHorizontal = scaleHorizontal;
textBlock.AutoScaleVertical = scaleVertical;
minScale = Math.Min(textBlock.TextScale, minScale);
}
foreach (GUITextBlock textBlock in textBlocks)
{
textBlock.AutoScale = false;
textBlock.AutoScaleHorizontal = false;
textBlock.AutoScaleVertical = false;
textBlock.TextScale = minScale;
}
}
@@ -75,9 +75,8 @@ namespace Barotrauma
set { textBlock.TextGetter = value; }
}
// TODO: fix implicit hiding
private bool selected;
public bool Selected
private new bool selected;
public new bool Selected
{
get
{
@@ -457,13 +456,13 @@ namespace Barotrauma
return currPosition != null ? currPosition.Item2 : textBlock.Text.Length;
}
public void Select()
public void Select(int forcedCaretIndex = -1)
{
if (memento.Current == null)
{
memento.Store(Text);
}
CaretIndex = GetCaretIndexFromScreenPos(PlayerInput.MousePosition);
CaretIndex = forcedCaretIndex == - 1 ? GetCaretIndexFromScreenPos(PlayerInput.MousePosition) : forcedCaretIndex;
ClearSelection();
selected = true;
GUI.KeyboardDispatcher.Subscriber = this;
@@ -30,10 +30,6 @@ namespace Barotrauma
get; private set;
}
public static Rectangle InventoryAreaUpper
{
get; private set;
}
public static Rectangle CrewArea
{
@@ -110,7 +106,7 @@ namespace Barotrauma
{
Padding = (int)(10 * GUI.Scale);
if (inventoryTopY == 0) inventoryTopY = GameMain.GraphicsHeight;
if (inventoryTopY == 0) { inventoryTopY = GameMain.GraphicsHeight - 30; }
//slice from the top of the screen for misc buttons (info, end round, server controls)
ButtonAreaTop = new Rectangle(Padding, Padding, GameMain.GraphicsWidth - Padding * 2, (int)(50 * GUI.Scale));
@@ -124,7 +120,7 @@ namespace Barotrauma
int healthBarHeight = (int)Math.Max(15f * GUI.Scale, 12.5f);
int afflictionAreaHeight = (int)(50 * GUI.Scale);
HealthBarAreaLeft = new Rectangle(PortraitArea.X, PortraitArea.Y + Padding / 2 + portraitSize, healthBarWidth, healthBarHeight);
AfflictionAreaLeft = new Rectangle(Padding, HealthBarAreaLeft.Y - afflictionAreaHeight - Padding, healthBarWidth, afflictionAreaHeight);
AfflictionAreaLeft = new Rectangle(PortraitArea.X, HealthBarAreaLeft.Y + healthBarHeight + Padding, healthBarWidth, afflictionAreaHeight);
//HealthBarAreaRight = new Rectangle(Padding, GameMain.GraphicsHeight - healthBarHeight - Padding, healthBarWidth, healthBarHeight);
/*if (HealthBarAreaRight.Y + healthBarHeight * 0.75f < PortraitArea.Y)
@@ -136,14 +132,6 @@ namespace Barotrauma
int messageAreaWidth = GameMain.GraphicsWidth / 3;
MessageAreaTop = new Rectangle((GameMain.GraphicsWidth - messageAreaWidth) / 2, ButtonAreaTop.Bottom, messageAreaWidth, ButtonAreaTop.Height);
CrewArea = new Rectangle(HealthBarAreaLeft.Right + Padding, MessageAreaTop.Bottom + Padding,
GameMain.GraphicsWidth - HealthBarAreaLeft.Right - 2 * Padding, (int)(0.6f * portraitSize));
//slice for the upper slots of the inventory (clothes, id card, headset)
int inventoryAreaUpperWidth = (int)(GameMain.GraphicsWidth * 0.2f);
int inventoryAreaUpperHeight = (int)(GameMain.GraphicsHeight * 0.2f);
InventoryAreaUpper = new Rectangle(GameMain.GraphicsWidth - inventoryAreaUpperWidth - Padding, CrewArea.Y, inventoryAreaUpperWidth, inventoryAreaUpperHeight);
int toggleButtonWidth = (int)(ChatBox.ToggleButtonWidthRaw * GUI.Scale);
int chatBoxWidth = (int)(475 * GUI.Scale);
int chatBoxHeight = (int)Math.Max(GameMain.GraphicsHeight * 0.22f, 150);
@@ -153,8 +141,11 @@ namespace Barotrauma
int objectiveAnchorOffsetY = (int)(150 * GUI.Scale);
ObjectiveAnchor = new Rectangle(Padding, ChatBoxArea.Y - objectiveAnchorOffsetY, objectiveAnchorWidth, 0);
int lowerAreaHeight = (int)Math.Min(GameMain.GraphicsHeight * 0.25f, 280);
InventoryAreaLower = new Rectangle(Padding, GameMain.GraphicsHeight - lowerAreaHeight, GameMain.GraphicsWidth - Padding * 2, lowerAreaHeight);
var crewAreaY = AfflictionAreaLeft.Bottom + Padding;
var crewAreaHeight = ObjectiveAnchor.Top - Padding - crewAreaY;
CrewArea = new Rectangle(Padding, crewAreaY, (int)Math.Max(400 * GUI.Scale, 400), crewAreaHeight);
InventoryAreaLower = new Rectangle(Padding, inventoryTopY, GameMain.GraphicsWidth - Padding * 2, GameMain.GraphicsHeight - inventoryTopY);
int healthWindowWidth = (int)(GameMain.GraphicsWidth * 0.5f);
int healthWindowHeight = (int)(GameMain.GraphicsWidth * 0.5f * 0.65f);
@@ -168,7 +159,6 @@ namespace Barotrauma
{
GUI.DrawRectangle(spriteBatch, ButtonAreaTop, Color.White * 0.5f);
GUI.DrawRectangle(spriteBatch, MessageAreaTop, GUI.Style.Orange * 0.5f);
GUI.DrawRectangle(spriteBatch, InventoryAreaUpper, Color.Yellow * 0.5f);
GUI.DrawRectangle(spriteBatch, CrewArea, Color.Blue * 0.5f);
GUI.DrawRectangle(spriteBatch, ChatBoxArea, Color.Cyan * 0.5f);
GUI.DrawRectangle(spriteBatch, HealthBarAreaLeft, Color.Red * 0.5f);
@@ -293,10 +293,15 @@ namespace Barotrauma
}
}
private ScaleBasis _scaleBasis;
public ScaleBasis ScaleBasis
{
get;
private set;
get { return _scaleBasis; }
set
{
_scaleBasis = value;
RecalculateAbsoluteSize();
}
}
public bool IsLastChild
@@ -336,7 +341,7 @@ namespace Barotrauma
public RectTransform(Vector2 relativeSize, RectTransform parent, Anchor anchor = Anchor.TopLeft, Pivot? pivot = null, Point? minSize = null, Point? maxSize = null, ScaleBasis scaleBasis = ScaleBasis.Normal)
{
Init(parent, anchor, pivot);
this.ScaleBasis = scaleBasis;
_scaleBasis = scaleBasis;
this.relativeSize = relativeSize;
this.minSize = minSize;
this.maxSize = maxSize;
@@ -348,19 +353,23 @@ namespace Barotrauma
}
/// <summary>
/// By default, elements defined with an absolute size (in pixels), will be treated as fixed sized.
/// This can be changed by setting IsFixedSize to false.
/// By default, elements defined with an absolute size (in pixels) will scale with the parent.
/// This can be changed by setting IsFixedSize to true.
/// </summary>
public RectTransform(Point absoluteSize, RectTransform parent = null, Anchor anchor = Anchor.TopLeft, Pivot? pivot = null)
public RectTransform(Point absoluteSize, RectTransform parent = null, Anchor anchor = Anchor.TopLeft, Pivot? pivot = null, ScaleBasis scaleBasis = ScaleBasis.Normal, bool isFixedSize = false)
{
Init(parent, anchor, pivot);
this.ScaleBasis = ScaleBasis.Normal;
_scaleBasis = scaleBasis;
this.nonScaledSize = absoluteSize;
RecalculateScale();
RecalculateRelativeSize();
RecalculateRelativeSize();
if (scaleBasis != ScaleBasis.Normal)
{
RecalculateAbsoluteSize();
}
RecalculateAnchorPoint();
RecalculatePivotOffset();
IsFixedSize = true;
IsFixedSize = isFixedSize;
parent?.ChildrenChanged?.Invoke(this);
}
@@ -370,6 +379,7 @@ namespace Barotrauma
Enum.TryParse(element.GetAttributeString("pivot", anchor.ToString()), out Pivot pivot);
Point? minSize = null, maxSize = null;
ScaleBasis scaleBasis = ScaleBasis.Normal;
if (element.Attribute("minsize") != null)
{
minSize = element.GetAttributePoint("minsize", Point.Zero);
@@ -378,11 +388,15 @@ namespace Barotrauma
{
maxSize = element.GetAttributePoint("maxsize", new Point(1000, 1000));
}
string sb = element.GetAttributeString("scalebasis", null);
if (sb != null)
{
Enum.TryParse(sb, ignoreCase: true, out scaleBasis);
}
RectTransform rectTransform;
if (element.Attribute("absolutesize") != null)
{
rectTransform = new RectTransform(element.GetAttributePoint("absolutesize", new Point(1000, 1000)), parent, anchor, pivot)
rectTransform = new RectTransform(element.GetAttributePoint("absolutesize", new Point(1000, 1000)), parent, anchor, pivot, scaleBasis)
{
minSize = minSize,
maxSize = maxSize
@@ -390,7 +404,7 @@ namespace Barotrauma
}
else
{
rectTransform = new RectTransform(element.GetAttributeVector2("relativesize", Vector2.One), parent, anchor, pivot, minSize, maxSize);
rectTransform = new RectTransform(element.GetAttributeVector2("relativesize", Vector2.One), parent, anchor, pivot, minSize, maxSize, scaleBasis);
}
rectTransform.RelativeOffset = element.GetAttributeVector2("relativeoffset", Vector2.Zero);
rectTransform.AbsoluteOffset = element.GetAttributePoint("absoluteoffset", Point.Zero);
@@ -438,37 +452,37 @@ namespace Barotrauma
protected void RecalculateAbsoluteSize()
{
Point size = NonScaledParentRect.Size;
if (ScaleBasis == ScaleBasis.BothWidth)
switch (ScaleBasis)
{
size.Y = size.X;
}
else if (ScaleBasis == ScaleBasis.BothHeight)
{
size.X = size.Y;
}
else if (ScaleBasis == ScaleBasis.Smallest)
{
if (size.X < size.Y)
{
case ScaleBasis.BothWidth:
size.Y = size.X;
}
else
{
break;
case ScaleBasis.BothHeight:
size.X = size.Y;
}
break;
case ScaleBasis.Smallest:
if (size.X < size.Y)
{
size.Y = size.X;
}
else
{
size.X = size.Y;
}
break;
case ScaleBasis.Largest:
if (size.X > size.Y)
{
size.Y = size.X;
}
else
{
size.X = size.Y;
}
break;
}
else if (ScaleBasis == ScaleBasis.Largest)
{
if (size.X > size.Y)
{
size.Y = size.X;
}
else
{
size.X = size.Y;
}
}
nonScaledSize = size.Multiply(RelativeSize).Clamp(MinSize, MaxSize);
size = size.Multiply(RelativeSize);
nonScaledSize = size.Clamp(MinSize, MaxSize);
recalculateRect = true;
SizeChanged?.Invoke();
}
@@ -684,6 +698,44 @@ namespace Barotrauma
children[i].GUIComponent.AddToGUIUpdateList(ignoreChildren, order);
}
}
public void MatchPivotToAnchor() => MatchPivotToAnchor(Anchor);
public void MoveOverTime(Point targetPos, float duration)
{
CoroutineManager.StartCoroutine(DoMoveAnimation(targetPos, duration));
}
public void ScaleOverTime(Point targetSize, float duration)
{
CoroutineManager.StartCoroutine(DoScaleAnimation(targetSize, duration));
}
private IEnumerable<object> DoMoveAnimation(Point targetPos, float duration)
{
Vector2 startPos = AbsoluteOffset.ToVector2();
float t = 0.0f;
while (t < duration && duration > 0.0f)
{
t += CoroutineManager.DeltaTime;
AbsoluteOffset = Vector2.SmoothStep(startPos, targetPos.ToVector2(), t / duration).ToPoint();
yield return CoroutineStatus.Running;
}
AbsoluteOffset = targetPos;
yield return CoroutineStatus.Success;
}
private IEnumerable<object> DoScaleAnimation(Point targetSize, float duration)
{
Vector2 startSize = NonScaledSize.ToVector2();
float t = 0.0f;
while (t < duration && duration > 0.0f)
{
t += CoroutineManager.DeltaTime;
NonScaledSize = Vector2.SmoothStep(startSize, targetSize.ToVector2(), t / duration).ToPoint();
yield return CoroutineStatus.Running;
}
NonScaledSize = targetSize;
yield return CoroutineStatus.Success;
}
#endregion
#region Static methods
@@ -101,10 +101,9 @@ namespace Barotrauma
Vector2 scale = Vector2.One;
scale.Y = MathHelper.Clamp((float)rect.Height / (Slices[0].Height + Slices[6].Height), 0, 1);
scale.X = MathHelper.Clamp((float)rect.Width / (Slices[0].Width + Slices[2].Width), 0, 1);
scale.X = scale.Y = Math.Min(scale.X, scale.Y);
scale.X = scale.Y = Math.Min(Math.Min(scale.X, scale.Y), GUI.SlicedSpriteScale);
int centerHeight = rect.Height - (int)((Slices[0].Height + Slices[6].Height) * scale.Y);
int centerWidth = rect.Width - (int)((Slices[0].Width + Slices[2].Width) * scale.X);
@@ -20,7 +20,7 @@ namespace Barotrauma
private GUICustomComponent videoView;
private GUIButton okButton;
private Color backgroundColor = new Color(0f, 0f, 0f, 1f);
private Color backgroundColor = new Color(0f, 0f, 0f, 0.8f);
private Action callbackOnStop;
private Point scaledVideoResolution;
@@ -62,8 +62,8 @@ namespace Barotrauma
int width = scaledVideoResolution.X;
int height = scaledVideoResolution.Y;
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");
background = new GUIFrame(new RectTransform(Point.Zero, GUI.Canvas, Anchor.Center), style: null, color: backgroundColor);
videoFrame = new GUIFrame(new RectTransform(Point.Zero, background.RectTransform, Anchor.Center, Pivot.Center), style: "InnerFrame");
if (useTextOnRightSide)
{