(3dc4135ce) v0.9.5.1

This commit is contained in:
Regalis
2019-11-21 18:22:25 +01:00
parent b39922a074
commit 5c95c53118
287 changed files with 12655 additions and 5048 deletions
@@ -1,4 +1,5 @@
using Barotrauma.Items.Components;
using Barotrauma.Extensions;
using Barotrauma.Items.Components;
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -52,6 +53,8 @@ namespace Barotrauma
public GUIButton ToggleButton { get; private set; }
private GUIButton showNewMessagesButton;
public ChatBox(GUIComponent parent, bool isSinglePlayer)
{
this.IsSinglePlayer = isSinglePlayer;
@@ -65,8 +68,9 @@ namespace Barotrauma
int toggleButtonWidth = (int)(30 * GUI.Scale);
GUIFrame = new GUIFrame(HUDLayoutSettings.ToRectTransform(HUDLayoutSettings.ChatBoxArea, parent.RectTransform), style: null);
var chatBoxHolder = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.9f), GUIFrame.RectTransform), style: "ChatBox");
var chatBoxHolder = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.875f), GUIFrame.RectTransform), style: "ChatBox");
chatBox = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.95f), chatBoxHolder.RectTransform, Anchor.CenterRight), style: null);
ToggleButton = new GUIButton(new RectTransform(new Point(toggleButtonWidth, HUDLayoutSettings.ChatBoxArea.Height), parent.RectTransform),
style: "UIToggleButton");
@@ -76,7 +80,7 @@ namespace Barotrauma
return true;
};
InputBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.1f), GUIFrame.RectTransform, Anchor.BottomCenter),
InputBox = new GUITextBox(new RectTransform(new Vector2(0.925f, 0.125f), GUIFrame.RectTransform, Anchor.BottomLeft),
style: "ChatTextBox")
{
Font = GUI.SmallFont,
@@ -84,9 +88,25 @@ namespace Barotrauma
};
InputBox.OnDeselected += (gui, Keys) =>
{
gui.Text = "";
//gui.Text = "";
};
var chatSendButton = new GUIButton(new RectTransform(new Vector2(0.075f, 0.125f), GUIFrame.RectTransform, Anchor.BottomRight) { RelativeOffset = new Vector2(0.0f, -0.01f) }, ">");
chatSendButton.OnClicked += (GUIButton btn, object userdata) =>
{
InputBox.OnEnterPressed(InputBox, InputBox.Text);
return true;
};
showNewMessagesButton = new GUIButton(new RectTransform(new Vector2(1f, 0.125f), GUIFrame.RectTransform, Anchor.BottomCenter) { RelativeOffset = new Vector2(0.0f, -0.125f) }, TextManager.Get("chat.shownewmessages"));
showNewMessagesButton.OnClicked += (GUIButton btn, object userdata) =>
{
chatBox.ScrollBar.BarScrollValue = 1f;
showNewMessagesButton.Visible = false;
return true;
};
showNewMessagesButton.Visible = false;
ToggleOpen = GameMain.Config.ChatOpen;
}
@@ -133,7 +153,7 @@ namespace Barotrauma
public void AddMessage(ChatMessage message)
{
while (chatBox.Content.CountChildren > 20)
while (chatBox.Content.CountChildren > 60)
{
chatBox.RemoveChild(chatBox.Content.Children.First());
}
@@ -155,18 +175,21 @@ namespace Barotrauma
var msgHolder = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.0f), chatBox.Content.RectTransform, Anchor.TopCenter), style: null,
color: ((chatBox.Content.CountChildren % 2) == 0) ? Color.Transparent : Color.Black * 0.1f);
GUITextBlock senderNameBlock = null;
GUITextBlock senderNameBlock = new GUITextBlock(new RectTransform(new Vector2(0.98f, 0.0f), msgHolder.RectTransform) { AbsoluteOffset = new Point((int)(5 * GUI.Scale), 0) },
ChatMessage.GetTimeStamp(), textColor: Color.LightGray, font: GUI.SmallFont, textAlignment: Alignment.TopLeft, style: null)
{
CanBeFocused = true
};
if (!string.IsNullOrEmpty(senderName))
{
senderNameBlock = new GUITextBlock(new RectTransform(new Vector2(0.98f, 0.0f), msgHolder.RectTransform)
{ AbsoluteOffset = new Point((int)(5 * GUI.Scale), 0) },
new GUITextBlock(new RectTransform(new Vector2(0.8f, 1.0f), senderNameBlock.RectTransform) { AbsoluteOffset = new Point((int)(senderNameBlock.TextSize.X), 0) },
senderName, textColor: senderColor, font: GUI.SmallFont, textAlignment: Alignment.TopLeft, style: null)
{
CanBeFocused = true
};
}
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), msgHolder.RectTransform)
var msgText =new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), msgHolder.RectTransform)
{ AbsoluteOffset = new Point((int)(10 * GUI.Scale), senderNameBlock == null ? 0 : senderNameBlock.Rect.Height) },
displayedText, textColor: message.Color, font: GUI.SmallFont, textAlignment: Alignment.TopLeft, style: null, wrap: true,
color: ((chatBox.Content.CountChildren % 2) == 0) ? Color.Transparent : Color.Black * 0.1f)
@@ -185,12 +208,28 @@ namespace Barotrauma
{
msgHolder.Flash(Color.Yellow * 0.6f);
}
//resize the holder to match the size of the message and add some spacing
msgHolder.RectTransform.Resize(new Point(msgHolder.Rect.Width, msgHolder.Children.Sum(c => c.Rect.Height) + (int)(10 * GUI.Scale)), resizeChildren: false);
msgHolder.RectTransform.SizeChanged += Recalculate;
Recalculate();
void Recalculate()
{
msgHolder.RectTransform.SizeChanged -= Recalculate;
//resize the holder to match the size of the message and add some spacing
msgText.RectTransform.MaxSize = new Point(msgHolder.Rect.Width - msgText.RectTransform.AbsoluteOffset.X, int.MaxValue);
senderNameBlock.RectTransform.MaxSize = new Point(msgHolder.Rect.Width - senderNameBlock.RectTransform.AbsoluteOffset.X, int.MaxValue);
msgHolder.Children.ForEach(c => (c as GUITextBlock)?.CalculateHeightFromText());
msgHolder.RectTransform.Resize(new Point(msgHolder.Rect.Width, msgHolder.Children.Sum(c => c.Rect.Height) + (int)(10 * GUI.Scale)), resizeChildren: false);
msgHolder.RectTransform.SizeChanged += Recalculate;
chatBox.RecalculateChildren();
}
CoroutineManager.StartCoroutine(UpdateMessageAnimation(msgHolder, 0.5f));
chatBox.UpdateScrollBarSize();
if (chatBox.ScrollBar.Visible && chatBox.ScrollBar.BarScroll < 1f)
{
showNewMessagesButton.Visible = true;
}
if (!ToggleOpen)
{
@@ -203,16 +242,16 @@ namespace Barotrauma
{
CanBeFocused = false
};
var msgText = new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.0f), popupMsg.RectTransform, Anchor.TopRight)
var msgPopupText = new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.0f), popupMsg.RectTransform, Anchor.TopRight)
{ AbsoluteOffset = new Point(0, senderText.Rect.Height) },
displayedText, textColor: message.Color, font: GUI.SmallFont, textAlignment: Alignment.TopRight, style: null, wrap: true)
{
CanBeFocused = false
};
int textWidth = (int)Math.Max(
msgText.Font.MeasureString(msgText.WrappedText).X,
msgPopupText.Font.MeasureString(msgPopupText.WrappedText).X,
senderText.Font.MeasureString(senderText.WrappedText).X);
popupMsg.RectTransform.Resize(new Point(textWidth + 20, msgText.Rect.Bottom - senderText.Rect.Y), resizeChildren: false);
popupMsg.RectTransform.Resize(new Point(textWidth + 20, msgPopupText.Rect.Bottom - senderText.Rect.Y), resizeChildren: false);
popupMessages.Enqueue(popupMsg);
}
@@ -277,6 +316,11 @@ namespace Barotrauma
prevUIScale = GUI.Scale;
}
if (showNewMessagesButton.Visible && chatBox.ScrollBar.BarScroll == 1f)
{
showNewMessagesButton.Visible = false;
}
if (ToggleOpen || (InputBox != null && InputBox.Selected))
{
openState += deltaTime * 5.0f;
@@ -19,12 +19,16 @@ namespace Barotrauma
public readonly Color OutlineColor;
public readonly XElement Element;
public readonly Dictionary<GUIComponent.ComponentState, List<UISprite>> Sprites;
public Dictionary<string, GUIComponentStyle> ChildStyles;
public GUIComponentStyle(XElement element)
{
Element = element;
Sprites = new Dictionary<GUIComponent.ComponentState, List<UISprite>>();
foreach (GUIComponent.ComponentState state in Enum.GetValues(typeof(GUIComponent.ComponentState)))
{
+41 -36
View File
@@ -29,6 +29,35 @@ namespace Barotrauma
{
public static GUICanvas Canvas => GUICanvas.Instance;
public static readonly SamplerState SamplerState = new SamplerState()
{
Filter = TextureFilter.Linear,
AddressU = TextureAddressMode.Wrap,
AddressV = TextureAddressMode.Wrap,
AddressW = TextureAddressMode.Wrap,
BorderColor = Color.White,
MaxAnisotropy = 4,
MaxMipLevel = 0,
MipMapLevelOfDetailBias = -0.8f,
ComparisonFunction = CompareFunction.Never,
FilterMode = TextureFilterMode.Default,
};
public static readonly SamplerState SamplerStateClamp = new SamplerState()
{
Filter = TextureFilter.Linear,
AddressU = TextureAddressMode.Clamp,
AddressV = TextureAddressMode.Clamp,
AddressW = TextureAddressMode.Clamp,
BorderColor = Color.White,
MaxAnisotropy = 4,
MaxMipLevel = 0,
MipMapLevelOfDetailBias = -0.8f,
ComparisonFunction = CompareFunction.Never,
FilterMode = TextureFilterMode.Default,
};
public static readonly string[] vectorComponentLabels = { "X", "Y", "Z", "W" };
public static readonly string[] rectComponentLabels = { "X", "Y", "W", "H" };
public static readonly string[] colorComponentLabels = { "R", "G", "B", "A" };
@@ -455,7 +484,11 @@ namespace Barotrauma
if (GameMain.WindowActive)
{
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerStateClamp, rasterizerState: GameMain.ScissorTestEnable);
Cursor.Draw(spriteBatch, PlayerInput.LatestMousePosition, 0, Scale / 2f);
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
}
}
@@ -664,6 +697,7 @@ namespace Barotrauma
/// </summary>
public static GUIComponent UpdateMouseOn()
{
GUIComponent prevMouseOn = MouseOn;
MouseOn = null;
int inventoryIndex = -1;
if (Inventory.IsMouseOnInventory())
@@ -673,9 +707,13 @@ namespace Barotrauma
for (int i = updateList.Count - 1; i > inventoryIndex; i--)
{
GUIComponent c = updateList[i];
if (!c.CanBeFocused) { continue; }
if (c.MouseRect.Contains(PlayerInput.MousePosition))
{
MouseOn = c;
if ((!PlayerInput.LeftButtonHeld() && !PlayerInput.LeftButtonClicked()) || c == prevMouseOn)
{
MouseOn = c;
}
break;
}
}
@@ -1629,42 +1667,9 @@ namespace Barotrauma
return true;
}
private static bool QuitClicked(GUIButton button, object obj)
public static bool QuitClicked(GUIButton button, object obj)
{
bool save = button.UserData as string == "save";
if (save)
{
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
}
if (GameMain.Client != null)
{
GameMain.Client.Disconnect();
GameMain.Client = null;
}
CoroutineManager.StopCoroutines("EndCinematic");
if (GameMain.GameSession != null)
{
if (Tutorial.Initialized)
{
((TutorialMode)GameMain.GameSession.GameMode).Tutorial.Stop();
}
if (GameSettings.SendUserStatistics)
{
Mission mission = GameMain.GameSession.Mission;
GameAnalyticsManager.AddDesignEvent("QuitRound:" + (save ? "Save" : "NoSave"));
GameAnalyticsManager.AddDesignEvent("EndRound:" + (mission == null ? "NoMission" : (mission.Completed ? "MissionCompleted" : "MissionFailed")));
}
GameMain.GameSession = null;
}
GUIMessageBox.CloseAll();
GameMain.MainMenuScreen.Select();
GameMain.QuitToMainMenu(button.UserData as string == "save");
return true;
}
@@ -153,15 +153,18 @@ namespace Barotrauma
public GUIButton(RectTransform rectT, string text = "", Alignment textAlignment = Alignment.Center, string style = "", Color? color = null) : base(style, rectT)
{
CanBeFocused = true;
if (color.HasValue)
{
this.color = color.Value;
}
frame = new GUIFrame(new RectTransform(Vector2.One, rectT), style);
frame = new GUIFrame(new RectTransform(Vector2.One, rectT), style) { CanBeFocused = false };
if (style != null) GUI.Style.Apply(frame, style == "" ? "GUIButton" : style);
textBlock = new GUITextBlock(new RectTransform(Vector2.One, rectT), text, textAlignment: textAlignment, style: null)
{
TextColor = this.style == null ? Color.Black : this.style.textColor
TextColor = this.style == null ? Color.Black : this.style.textColor,
CanBeFocused = false
};
if (rectT.Rect.Height == 0 && !string.IsNullOrEmpty(text))
{
@@ -106,11 +106,21 @@ namespace Barotrauma
return Children.Where(c => c.userData == userData);
}
public IEnumerable<GUIComponent> FindChildren(Func<GUIComponent, bool> predicate)
{
return Children.Where(c => predicate(c));
}
public virtual void ClearChildren()
{
RectTransform.ClearChildren();
}
public void SetAsFirstChild()
{
RectTransform.SetAsFirstChild();
}
public void SetAsLastChild()
{
RectTransform.SetAsLastChild();
@@ -319,7 +329,7 @@ namespace Barotrauma
Font = GUI.Font;
CanBeFocused = true;
CanBeFocused = true; //TODO: change default to false?
if (style != null)
GUI.Style.Apply(this, style);
@@ -729,9 +739,10 @@ namespace Barotrauma
private static GUITextBlock LoadGUITextBlock(XElement element, RectTransform parent, string overrideText = null, Anchor? anchor = null)
{
string text = element.Attribute("text") == null ?
element.ElementInnerText() :
element.GetAttributeString("text", "");
string text = overrideText ??
(element.Attribute("text") == null ?
element.ElementInnerText() :
element.GetAttributeString("text", ""));
text = text.Replace(@"\n", "\n");
string style = element.GetAttributeString("style", "");
@@ -29,7 +29,7 @@ namespace Barotrauma
{
spriteBatch.End();
spriteBatch.GraphicsDevice.ScissorRectangle = Rectangle.Intersect(prevScissorRect, Rect);
spriteBatch.Begin(SpriteSortMode.Deferred, rasterizerState: GameMain.ScissorTestEnable);
spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
}
OnDraw?.Invoke(spriteBatch, this);
@@ -38,7 +38,7 @@ namespace Barotrauma
{
spriteBatch.End();
spriteBatch.GraphicsDevice.ScissorRectangle = prevScissorRect;
spriteBatch.Begin(SpriteSortMode.Deferred, rasterizerState: GameMain.ScissorTestEnable);
spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
}
}
@@ -16,7 +16,7 @@ namespace Barotrauma
private GUIButton button;
private GUIListBox listBox;
private RectTransform currentListBoxParent;
private RectTransform currentHighestParent;
private List<RectTransform> parentHierarchy = new List<RectTransform>();
private bool selectMultiple;
@@ -141,6 +141,8 @@ namespace Barotrauma
public GUIDropDown(RectTransform rectT, string text = "", int elementCount = 4, string style = "", bool selectMultiple = false) : base(style, rectT)
{
CanBeFocused = true;
this.selectMultiple = selectMultiple;
button = new GUIButton(new RectTransform(Vector2.One, rectT), text, Alignment.CenterLeft, style: "GUIDropDown")
@@ -149,7 +151,7 @@ namespace Barotrauma
};
GUI.Style.Apply(button, "", this);
listBox = new GUIListBox(new RectTransform(new Point(Rect.Width, Rect.Height * MathHelper.Clamp(elementCount, 2, 10)), rectT, Anchor.BottomLeft, Pivot.TopLeft)
listBox = new GUIListBox(new RectTransform(new Point(Rect.Width, Rect.Height * MathHelper.Clamp(elementCount, 2, 10)), rectT, Anchor.BottomCenter, Pivot.TopCenter)
{ IsFixedSize = false }, style: null)
{
Enabled = !selectMultiple,
@@ -157,48 +159,55 @@ namespace Barotrauma
};
GUI.Style.Apply(listBox.Content, "GUIListBox", this);
currentListBoxParent = FindListBoxParent();
currentListBoxParent.GUIComponent.OnAddedToGUIUpdateList += AddListBoxToGUIUpdateList;
currentHighestParent = FindHighestParent();
currentHighestParent.GUIComponent.OnAddedToGUIUpdateList += AddListBoxToGUIUpdateList;
rectT.ParentChanged += (RectTransform newParent) =>
{
currentListBoxParent.GUIComponent.OnAddedToGUIUpdateList -= AddListBoxToGUIUpdateList;
currentHighestParent.GUIComponent.OnAddedToGUIUpdateList -= AddListBoxToGUIUpdateList;
if (newParent != null)
{
currentListBoxParent = FindListBoxParent();
currentListBoxParent.GUIComponent.OnAddedToGUIUpdateList += AddListBoxToGUIUpdateList;
currentHighestParent = FindHighestParent();
currentHighestParent.GUIComponent.OnAddedToGUIUpdateList += AddListBoxToGUIUpdateList;
}
};
}
/// <summary>
/// Finds the component after which the listbox should be drawn. Usually the parent of the dropdown, but if the dropdown
/// is the child of another GUIListBox, we need to draw our listbox after that because listboxes clip everything outside their rect.
/// Finds the component after which the listbox should be drawn
/// //(= the component highest in the hierarchy, to get the listbox
/// //to be rendered on top of all of it's children)
/// </summary>
private RectTransform FindListBoxParent()
private RectTransform FindHighestParent()
{
parentHierarchy.Clear();
//collect entire parent hierarchy to a list
parentHierarchy = new List<RectTransform>() { RectTransform.Parent };
while (parentHierarchy.Last().Parent != null)
RectTransform parent = parentHierarchy.Last();
while (parent?.Parent != null)
{
parentHierarchy.Add(parentHierarchy.Last().Parent);
parentHierarchy.Add(parent.Parent);
parent = parent.Parent;
}
//find the parent GUIListBox highest in the hierarchy
for (int i = parentHierarchy.Count - 1; i >= 0; i--)
//find the highest parent that has a guicomponent with a style
//(and so should be rendered and not just some empty parent/root element used for constructing a layout)
for (int i = parentHierarchy.Count - 1; i > 0; i--)
{
if (parentHierarchy[i].GUIComponent is GUIListBox)
if (parentHierarchy[i] is GUICanvas ||
parentHierarchy[i].GUIComponent == null ||
parentHierarchy[i].GUIComponent.Style == null ||
parentHierarchy[i].GUIComponent == Screen.Selected?.Frame)
{
if (parentHierarchy[i].Parent != null && parentHierarchy[i].Parent.GUIComponent != null)
{
return parentHierarchy[i].Parent;
}
return parentHierarchy[i];
parentHierarchy.RemoveAt(i);
}
else
{
break;
}
}
//or just go with the direct parent if there are no listboxes in the hierarchy
parentHierarchy.Clear();
parentHierarchy.Add(RectTransform.Parent);
return RectTransform.Parent;
return parentHierarchy.Last();
}
public void AddItem(string text, object userData = null, string toolTip = "")
@@ -20,7 +20,7 @@ namespace Barotrauma
Color currColor = GetCurrentColor(state);
if (sprites == null || !sprites.Any()) GUI.DrawRectangle(spriteBatch, Rect, currColor * (currColor.A/255.0f), true);
if (sprites == null || !sprites.Any(s => s.Value.Any())) GUI.DrawRectangle(spriteBatch, Rect, currColor * (currColor.A/255.0f), true);
base.Draw(spriteBatch);
if (OutlineColor != Color.Transparent)
@@ -1,6 +1,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Linq;
namespace Barotrauma
{
@@ -57,6 +58,10 @@ namespace Barotrauma
}
}
public BlendState BlendState;
public ComponentState? OverrideState = null;
public GUIImage(RectTransform rectT, string style, bool scaleToFit = false)
: this(rectT, null, null, scaleToFit, style)
{
@@ -82,9 +87,7 @@ namespace Barotrauma
}
if (style == null)
{
color = Color.White;
hoverColor = Color.White;
selectedColor = Color.White;
color = hoverColor = selectedColor = pressedColor = Color.White;
}
if (!scaleToFit)
{
@@ -99,7 +102,17 @@ namespace Barotrauma
protected override void Draw(SpriteBatch spriteBatch)
{
if (!Visible) return;
if (Parent != null) { state = Parent.State; }
if (OverrideState != null) { state = OverrideState.Value; }
Color currColor = GetCurrentColor(state);
if (BlendState != null)
{
spriteBatch.End();
spriteBatch.Begin(blendState: BlendState, samplerState: GUI.SamplerState);
}
if (style != null)
{
foreach (UISprite uiSprite in style.Sprites[state])
@@ -121,6 +134,12 @@ namespace Barotrauma
spriteBatch.Draw(sprite.Texture, Rect.Center.ToVector2(), sourceRect, currColor * (currColor.A / 255.0f), Rotation, sprite.size / 2,
Scale, SpriteEffects, 0.0f);
}
if (BlendState != null)
{
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
}
}
private void RecalculateScale()
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using System;
using System.Linq;
namespace Barotrauma
@@ -71,6 +72,8 @@ namespace Barotrauma
public GUILayoutGroup(RectTransform rectT, bool isHorizontal = false, Anchor childAnchor = Anchor.TopLeft) : base(null, rectT)
{
CanBeFocused = false;
this.isHorizontal = isHorizontal;
this.childAnchor = childAnchor;
rectT.ChildrenChanged += (child) => needsToRecalculate = true;
@@ -83,17 +86,25 @@ namespace Barotrauma
float stretchFactor = 1.0f;
if (stretch && RectTransform.Children.Count() > 0)
{
float minSize = RectTransform.Children
.Where(c => !c.GUIComponent.IgnoreLayoutGroups)
.Sum(c => isHorizontal ? c.MinSize.X : c.MinSize.Y);
float totalSize = RectTransform.Children
.Where(c => !c.GUIComponent.IgnoreLayoutGroups)
.Sum(c => isHorizontal ?
MathHelper.Clamp(c.Rect.Width, c.MinSize.X, c.MaxSize.X) :
MathHelper.Clamp(c.Rect.Height, c.MinSize.Y, c.MaxSize.Y));
float thisSize = (isHorizontal ? Rect.Width : Rect.Height);
totalSize +=
(RectTransform.Children.Count() - 1) *
(absoluteSpacing + relativeSpacing * (isHorizontal ? Rect.Width : Rect.Height));
(absoluteSpacing + relativeSpacing * thisSize);
stretchFactor = totalSize <= 0.0f ? 1.0f : (isHorizontal ? Rect.Width: Rect.Height) / totalSize;
stretchFactor = totalSize <= 0.0f || minSize >= thisSize ?
1.0f :
(thisSize - minSize) / (totalSize - minSize);
}
int absPos = 0;
@@ -106,7 +117,7 @@ namespace Barotrauma
{
child.RelativeOffset = new Vector2(relPos, child.RelativeOffset.Y);
child.AbsoluteOffset = new Point(absPos, child.AbsoluteOffset.Y);
absPos += (int)((child.Rect.Width + absoluteSpacing) * stretchFactor);
absPos += (int)Math.Max((child.Rect.Width + absoluteSpacing) * stretchFactor, child.MinSize.X);
if (stretch)
{
child.RelativeSize = new Vector2(child.RelativeSize.X * stretchFactor, child.RelativeSize.Y);
@@ -116,7 +127,7 @@ namespace Barotrauma
{
child.RelativeOffset = new Vector2(child.RelativeOffset.X, relPos);
child.AbsoluteOffset = new Point(child.AbsoluteOffset.X, absPos);
absPos += (int)((child.Rect.Height + absoluteSpacing) * stretchFactor);
absPos += (int)Math.Max((child.Rect.Height + absoluteSpacing) * stretchFactor, child.MinSize.Y);
if (stretch)
{
child.RelativeSize = new Vector2(child.RelativeSize.X, child.RelativeSize.Y * stretchFactor);
@@ -135,6 +135,8 @@ namespace Barotrauma
public GUIListBox(RectTransform rectT, bool isHorizontal = false, Color? color = null, string style = "") : base(style, rectT)
{
CanBeFocused = true;
selected = new List<GUIComponent>();
Point frameSize = isHorizontal ?
@@ -176,7 +178,7 @@ namespace Barotrauma
private void UpdateDimensions()
{
if (!ScrollBarEnabled)
if (!ScrollBar.Visible)
{
Content.RectTransform.NonScaledSize = Rect.Size;
}
@@ -295,7 +297,7 @@ namespace Barotrauma
if (child == null) continue;
// selecting
if (Enabled && child.CanBeFocused && (GUI.IsMouseOn(child)) && child.Rect.Contains(PlayerInput.MousePosition))
if (Enabled && CanBeFocused && child.CanBeFocused && (GUI.IsMouseOn(child)) && child.Rect.Contains(PlayerInput.MousePosition))
{
child.State = ComponentState.Hover;
if (PlayerInput.LeftButtonClicked())
@@ -322,6 +324,15 @@ namespace Barotrauma
public override void AddToGUIUpdateList(bool ignoreChildren = false, int order = 0)
{
if (!Visible) { return; }
if (!ignoreChildren)
{
foreach (GUIComponent child in Children)
{
if (child == Content || child == ScrollBar) { continue; }
child.AddToGUIUpdateList(ignoreChildren, order);
}
}
foreach (GUIComponent child in Content.Children)
{
@@ -406,12 +417,16 @@ namespace Barotrauma
scrollBarNeedsRecalculation = false;
}
bool prevScrollBarVisible = ScrollBar.Visible;
ScrollBar.Enabled = ScrollBarEnabled && ScrollBar.BarSize < 1.0f;
if (AutoHideScrollBar)
{
ScrollBar.Visible = ScrollBar.BarSize < 1.0f;
}
if (ScrollBar.Visible != prevScrollBarVisible) { UpdateDimensions(); }
if ((GUI.IsMouseOn(this) || GUI.IsMouseOn(ScrollBar)) && PlayerInput.ScrollWheelSpeed != 0)
{
ScrollBar.BarScroll -= (PlayerInput.ScrollWheelSpeed / 500.0f) * BarSize;
@@ -594,7 +609,7 @@ namespace Barotrauma
{
spriteBatch.End();
spriteBatch.GraphicsDevice.ScissorRectangle = Rectangle.Intersect(prevScissorRect, Content.Rect);
spriteBatch.Begin(SpriteSortMode.Deferred, rasterizerState: GameMain.ScissorTestEnable);
spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
}
var children = Content.Children;
@@ -618,7 +633,7 @@ namespace Barotrauma
{
spriteBatch.End();
spriteBatch.GraphicsDevice.ScissorRectangle = prevScissorRect;
spriteBatch.Begin(SpriteSortMode.Deferred, rasterizerState: prevRasterizerState);
spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: prevRasterizerState);
}
if (ScrollBar.Visible) ScrollBar.DrawManually(spriteBatch, alsoChildren: true, recursive: true);
@@ -119,6 +119,19 @@ namespace Barotrauma
}
}
public override ScalableFont Font
{
get
{
return base.Font;
}
set
{
base.Font = value;
if (TextBox != null) { TextBox.Font = value; }
}
}
public GUILayoutGroup LayoutGroup
{
get;
@@ -147,11 +160,11 @@ namespace Barotrauma
};
TextBox.OnTextChanged += TextChanged;
var buttonArea = new GUIFrame(new RectTransform(new Vector2(_relativeButtonAreaWidth, 1.0f), LayoutGroup.RectTransform, Anchor.CenterRight), style: null);
if (!relativeButtonAreaWidth.HasValue)
/*if (!relativeButtonAreaWidth.HasValue)
{
// Not sure what's the point of this
buttonArea.RectTransform.MinSize = new Point(Rect.Height, 0);
}
}*/
PlusButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.5f), buttonArea.RectTransform), "+");
PlusButton.OnButtonDown += () =>
{
@@ -94,7 +94,7 @@ namespace Barotrauma
{
spriteBatch.End();
spriteBatch.GraphicsDevice.ScissorRectangle = Rectangle.Intersect(prevScissorRect, sliderRect);
spriteBatch.Begin(SpriteSortMode.Deferred, rasterizerState: GameMain.ScissorTestEnable);
spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
}
Color currColor = GetCurrentColor(state);
@@ -9,11 +9,12 @@ namespace Barotrauma
{
public class GUIRadioButtonGroup : GUIComponent
{
private Dictionary<Enum, GUITickBox> radioButtons; //TODO: use children list instead?
private Dictionary<int, GUITickBox> radioButtons; //TODO: use children list instead?
public GUIRadioButtonGroup() : base("GUIFrame")
public GUIRadioButtonGroup() : base(null)
{
radioButtons = new Dictionary<Enum, GUITickBox>();
radioButtons = new Dictionary<int, GUITickBox>();
selected = null;
}
public override bool Enabled
@@ -22,28 +23,28 @@ namespace Barotrauma
set
{
base.Enabled = value;
foreach(KeyValuePair<Enum, GUITickBox> rbPair in radioButtons)
foreach(KeyValuePair<int, GUITickBox> rbPair in radioButtons)
{
rbPair.Value.Enabled = value;
}
}
}
public void AddRadioButton(Enum key, GUITickBox radioButton)
public void AddRadioButton(int key, GUITickBox radioButton)
{
if (selected == key) radioButton.Selected = true;
else if (radioButton.Selected) selected = key;
radioButton.SetRadioButtonGroup(this);
radioButtons.Add(key, radioButton);
radioButtons.Add((int)key, radioButton);
}
public delegate void RadioButtonGroupDelegate(GUIRadioButtonGroup rbg, Enum val);
public delegate void RadioButtonGroupDelegate(GUIRadioButtonGroup rbg, int? val);
public RadioButtonGroupDelegate OnSelect = null;
public void SelectRadioButton(GUITickBox radioButton)
{
foreach (KeyValuePair<Enum, GUITickBox> rbPair in radioButtons)
foreach (KeyValuePair<int, GUITickBox> rbPair in radioButtons)
{
if (radioButton == rbPair.Value)
{
@@ -53,8 +54,8 @@ namespace Barotrauma
}
}
private Enum selected;
public Enum Selected
private int? selected;
public int? Selected
{
get
{
@@ -63,11 +64,11 @@ namespace Barotrauma
set
{
OnSelect?.Invoke(this, value);
if (selected != null && selected.Equals((Enum)value)) return;
if (selected != null && selected.Equals(value)) return;
selected = value;
foreach (KeyValuePair<Enum, GUITickBox> radioButton in radioButtons)
foreach (KeyValuePair<int, GUITickBox> radioButton in radioButtons)
{
if (radioButton.Key.Equals((Enum)value))
if (radioButton.Key.Equals(value))
{
radioButton.Value.Selected = true;
}
@@ -80,7 +81,7 @@ namespace Barotrauma
{
get
{
return radioButtons[selected];
return selected.HasValue ? radioButtons[selected.Value] : null;
}
}
}
@@ -17,6 +17,8 @@ namespace Barotrauma
private float barScroll;
private float step;
private Vector2? dragStartPos;
public delegate bool OnMovedHandler(GUIScrollBar scrollBar, float barScroll);
public OnMovedHandler OnMoved;
@@ -162,6 +164,18 @@ namespace Barotrauma
}
}
public float StepValue
{
get
{
return step * (Range.Y - Range.X);
}
set
{
Step = value / (Range.Y - Range.X);
}
}
public float BarSize
{
get { return barSize; }
@@ -174,6 +188,8 @@ namespace Barotrauma
public GUIScrollBar(RectTransform rectT, float barSize = 1, Color? color = null, string style = "", bool? isHorizontal = null) : base(style, rectT)
{
CanBeFocused = true;
this.isHorizontal = isHorizontal ?? (Rect.Width > Rect.Height);
Frame = new GUIFrame(new RectTransform(Vector2.One, rectT));
GUI.Style.Apply(Frame, IsHorizontal ? "GUIFrameHorizontal" : "GUIFrameVertical", this);
@@ -201,11 +217,11 @@ namespace Barotrauma
protected override void Update(float deltaTime)
{
if (!Visible) return;
if (!Visible) { return; }
base.Update(deltaTime);
if (!enabled) return;
if (!enabled) { return; }
if (IsBooleanSwitch &&
(!PlayerInput.LeftButtonHeld() || (GUI.MouseOn != this && !IsParentOf(GUI.MouseOn))))
@@ -221,10 +237,19 @@ namespace Barotrauma
if (draggingBar == this)
{
if (dragStartPos == null) { dragStartPos = PlayerInput.MousePosition; }
if (!PlayerInput.LeftButtonHeld())
{
if (IsBooleanSwitch && GUI.MouseOn == Bar && Vector2.Distance(dragStartPos.Value, PlayerInput.MousePosition) < 5)
{
BarScroll = BarScroll > 0.5f ? 0.0f : 1.0f;
OnMoved?.Invoke(this, BarScroll);
}
OnReleased?.Invoke(this, BarScroll);
draggingBar = null;
dragStartPos = null;
}
if ((isHorizontal && PlayerInput.MousePosition.X > Rect.X && PlayerInput.MousePosition.X < Rect.Right) ||
(!isHorizontal && PlayerInput.MousePosition.Y > Rect.Y && PlayerInput.MousePosition.Y < Rect.Bottom))
@@ -237,9 +262,18 @@ namespace Barotrauma
if (PlayerInput.LeftButtonClicked())
{
draggingBar?.OnReleased?.Invoke(draggingBar, draggingBar.BarScroll);
MoveButton(new Vector2(
Math.Sign(PlayerInput.MousePosition.X - Bar.Rect.Center.X) * Bar.Rect.Width,
Math.Sign(PlayerInput.MousePosition.Y - Bar.Rect.Center.Y) * Bar.Rect.Height));
if (IsBooleanSwitch)
{
MoveButton(new Vector2(
Math.Sign(PlayerInput.MousePosition.X - Bar.Rect.Center.X) * Rect.Width,
Math.Sign(PlayerInput.MousePosition.Y - Bar.Rect.Center.Y) * Rect.Height));
}
else
{
MoveButton(new Vector2(
Math.Sign(PlayerInput.MousePosition.X - Bar.Rect.Center.X) * Bar.Rect.Width,
Math.Sign(PlayerInput.MousePosition.Y - Bar.Rect.Center.Y) * Bar.Rect.Height));
}
}
}
}
@@ -270,7 +304,7 @@ namespace Barotrauma
BarScroll = newScroll;
if (moveAmount != Vector2.Zero && OnMoved != null) OnMoved(this, BarScroll);
if (moveAmount != Vector2.Zero && OnMoved != null) { OnMoved(this, BarScroll); }
}
}
}
@@ -242,10 +242,10 @@ namespace Barotrauma
Censor = false;
}
public void CalculateHeightFromText()
public void CalculateHeightFromText(int padding = 0)
{
if (wrappedText == null) { return; }
RectTransform.Resize(new Point(RectTransform.Rect.Width, (int)Font.MeasureString(wrappedText).Y));
RectTransform.Resize(new Point(RectTransform.Rect.Width, (int)Font.MeasureString(wrappedText).Y + padding));
}
public override void ApplyStyle(GUIComponentStyle style)
@@ -262,7 +262,7 @@ namespace Barotrauma
if (text == null) return;
censoredText = "";
for (int i=0;i<text.Length;i++)
for (int i = 0; i < text.Length; i++)
{
censoredText += "\u2022";
}
@@ -367,7 +367,7 @@ namespace Barotrauma
spriteBatch.End();
Rectangle scissorRect = new Rectangle(rect.X + (int)padding.X, rect.Y, rect.Width - (int)padding.X - (int)padding.Z, rect.Height);
spriteBatch.GraphicsDevice.ScissorRectangle = scissorRect;
spriteBatch.Begin(SpriteSortMode.Deferred, rasterizerState: GameMain.ScissorTestEnable);
spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
}
if (!string.IsNullOrEmpty(text))
@@ -391,7 +391,7 @@ namespace Barotrauma
{
spriteBatch.End();
spriteBatch.GraphicsDevice.ScissorRectangle = prevScissorRect;
spriteBatch.Begin(SpriteSortMode.Deferred, rasterizerState: GameMain.ScissorTestEnable);
spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
}
if (OutlineColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, OutlineColor * (currColor.A / 255.0f), false);
@@ -9,9 +9,9 @@ using System.Linq;
namespace Barotrauma
{
delegate void TextBoxEvent(GUITextBox sender, Keys key);
public delegate void TextBoxEvent(GUITextBox sender, Keys key);
class GUITextBox : GUIComponent, IKeyboardSubscriber
public class GUITextBox : GUIComponent, IKeyboardSubscriber
{
public event TextBoxEvent OnSelected;
public event TextBoxEvent OnDeselected;
@@ -38,6 +38,7 @@ namespace Barotrauma
public bool CaretEnabled { get; set; }
public Color? CaretColor { get; set; }
public bool DeselectAfterMessage = true;
private int? maxTextLength;
@@ -232,6 +233,8 @@ namespace Barotrauma
Alignment textAlignment = Alignment.Left, bool wrap = false, string style = "", Color? color = null)
: base(style, rectT)
{
CanBeFocused = true;
Enabled = true;
this.color = color ?? Color.White;
frame = new GUIFrame(new RectTransform(Vector2.One, rectT, Anchor.Center), style, color);
@@ -477,7 +480,7 @@ namespace Barotrauma
}
else
{
if (PlayerInput.LeftButtonClicked() && selected) Deselect();
if ((PlayerInput.LeftButtonClicked() || PlayerInput.RightButtonClicked()) && selected) Deselect();
isSelecting = false;
state = ComponentState.None;
}
@@ -656,7 +659,12 @@ namespace Barotrauma
switch (command)
{
case '\b': //backspace
if (selectedCharacters > 0)
if (PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl))
{
SetText(string.Empty, false);
CaretIndex = Text.Length;
}
else if (selectedCharacters > 0)
{
RemoveSelectedText();
}
@@ -692,6 +700,7 @@ namespace Barotrauma
text = memento.Undo();
if (text != Text)
{
ClearSelection();
SetText(text, false);
CaretIndex = Text.Length;
OnTextChanged?.Invoke(this, Text);
@@ -701,6 +710,7 @@ namespace Barotrauma
text = memento.Redo();
if (text != Text)
{
ClearSelection();
SetText(text, false);
CaretIndex = Text.Length;
OnTextChanged?.Invoke(this, Text);
@@ -860,16 +870,12 @@ namespace Barotrauma
private void RemoveSelectedText()
{
if (selectedText.Length == 0) { return; }
if (IsLeftToRight)
{
SetText(Text.Remove(selectionStartIndex, selectedText.Length));
CaretIndex = Math.Min(Text.Length, selectionStartIndex);
}
else
{
SetText(Text.Remove(selectionEndIndex, selectedText.Length));
CaretIndex = Math.Min(Text.Length, selectionEndIndex);
}
selectionStartIndex = Math.Max(0, Math.Min(selectionEndIndex, Math.Min(selectionStartIndex, Text.Length - 1)));
int selectionLength = Math.Min(Text.Length - selectionStartIndex, selectedText.Length);
SetText(Text.Remove(selectionStartIndex, selectionLength));
CaretIndex = Math.Min(Text.Length, selectionStartIndex);
ClearSelection();
OnTextChanged?.Invoke(this, Text);
}
@@ -1,11 +1,13 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
namespace Barotrauma
{
public class GUITickBox : GUIComponent
{
private GUILayoutGroup layoutGroup;
private GUIFrame box;
private GUITextBlock text;
@@ -69,14 +71,19 @@ namespace Barotrauma
set { text.TextColor = value; }
}
public override Rectangle MouseRect
/*public override Rectangle MouseRect
{
get
{
if (!CanBeFocused) return Rectangle.Empty;
return ClampMouseRectToParent ? ClampRect(box.Rect) : box.Rect;
Rectangle union = Rectangle.Union(box.Rect, TextBlock.Rect);
Vector2 textPos = TextBlock.Rect.Location.ToVector2() + TextBlock.TextPos + TextBlock.TextOffset;
Vector2 textSize = TextBlock.Font.MeasureString(TextBlock.Text);
union = Rectangle.Union(union, new Rectangle(textPos.ToPoint(), textSize.ToPoint()));
union = Rectangle.Union(union, Rect);
return ClampMouseRectToParent ? ClampRect(union) : union;
}
}
}*/
public override ScalableFont Font
{
@@ -121,7 +128,11 @@ namespace Barotrauma
public GUITickBox(RectTransform rectT, string label, ScalableFont font = null, string style = "") : base(null, rectT)
{
box = new GUIFrame(new RectTransform(new Point(rectT.Rect.Height, rectT.Rect.Height), rectT, Anchor.CenterLeft)
CanBeFocused = true;
layoutGroup = new GUILayoutGroup(new RectTransform(Vector2.One, rectT), true);
box = new GUIFrame(new RectTransform(Vector2.One, layoutGroup.RectTransform, scaleBasis: ScaleBasis.BothHeight)
{
IsFixedSize = false
}, string.Empty, Color.DarkGray)
@@ -131,7 +142,11 @@ namespace Barotrauma
CanBeFocused = false
};
GUI.Style.Apply(box, style == "" ? "GUITickBox" : style);
text = new GUITextBlock(new RectTransform(Vector2.One, rectT, Anchor.CenterLeft) { AbsoluteOffset = new Point(box.Rect.Width, 0) }, label, font: font, textAlignment: Alignment.CenterLeft);
Vector2 textBlockScale = new Vector2((float)(Rect.Width - Rect.Height) / (float)Math.Max(Rect.Width, 1.0), 1.0f);
text = new GUITextBlock(new RectTransform(textBlockScale, layoutGroup.RectTransform), label, font: font, textAlignment: Alignment.CenterLeft)
{
CanBeFocused = false
};
GUI.Style.Apply(text, "GUIButtonHorizontal", this);
Enabled = true;
@@ -148,9 +163,9 @@ 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);
Vector2 textBlockScale = new Vector2(Math.Max(Rect.Width - box.Rect.Width, 0.0f) / Math.Max(Rect.Width, 1.0f), 1.0f);
text.RectTransform.RelativeSize = textBlockScale;
text.SetTextPos();
}
protected override void Update(float deltaTime)
@@ -21,11 +21,11 @@ namespace Barotrauma
private Video currSplashScreen;
private DateTime videoStartTime;
private Queue<Pair<string, Point>> pendingSplashScreens = new Queue<Pair<string, Point>>();
private Queue<Triplet<string, Point, float>> pendingSplashScreens = new Queue<Triplet<string, Point, float>>();
/// <summary>
/// Pair.first = filepath, Pair.second = resolution
/// Triplet.first = filepath, Triplet.second = resolution, Triplet.third = audio gain
/// </summary>
public Queue<Pair<string, Point>> PendingSplashScreens
public Queue<Triplet<string, Point, float>> PendingSplashScreens
{
get
{
@@ -49,7 +49,7 @@ namespace Barotrauma
{
lock (loadMutex)
{
return currSplashScreen != null;
return currSplashScreen != null || pendingSplashScreens.Count > 0;
}
}
}
@@ -149,7 +149,7 @@ namespace Barotrauma
TitlePosition = new Vector2(GameMain.GraphicsWidth * 0.5f, GameMain.GraphicsHeight * 0.45f);
}
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, samplerState: GUI.SamplerState);
graphics.Clear(Color.Black);
spriteBatch.Draw(backgroundTexture, BackgroundPosition, null, Color.White * Math.Min(state / 5.0f, 1.0f), 0.0f,
@@ -168,7 +168,7 @@ namespace Barotrauma
WaterRenderer.Instance.RenderWater(spriteBatch, renderTarget, null);
}
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, samplerState: GUI.SamplerState);
titleSprite?.Draw(spriteBatch, TitlePosition, Color.White * Math.Min((state - 1.0f) / 5.0f, 1.0f), scale: titleScale);
@@ -280,6 +280,7 @@ namespace Barotrauma
try
{
currSplashScreen = new Video(graphics, GameMain.SoundManager, fileName, (uint)resolution.X, (uint)resolution.Y);
currSplashScreen.AudioGain = newSplashScreen.Third;
videoStartTime = DateTime.Now;
}
catch (Exception e)