(1762f02b3) Merge branch 'dev' into human-ai

This commit is contained in:
Joonas Rikkonen
2019-05-16 05:08:22 +03:00
parent 4797f6b0d3
commit 454dda56c7
91 changed files with 1138 additions and 744 deletions
@@ -18,9 +18,7 @@ namespace Barotrauma
private GUITextBox inputBox;
private GUIButton toggleButton;
private GUIButton radioButton;
private Point screenResolution;
private bool isSinglePlayer;
@@ -60,12 +58,7 @@ namespace Barotrauma
{
get { return guiFrame; }
}
public GUIButton RadioButton
{
get { return radioButton; }
}
public GUITextBox InputBox
{
get { return inputBox; }
@@ -109,31 +102,7 @@ namespace Barotrauma
{
gui.Text = "";
};
radioButton = new GUIButton(new RectTransform(new Vector2(0.1f, 2.0f), inputBox.RectTransform,
HUDLayoutSettings.ChatBoxAlignment == Alignment.Right ? Anchor.BottomRight : Anchor.BottomLeft,
HUDLayoutSettings.ChatBoxAlignment == Alignment.Right ? Pivot.TopRight : Pivot.TopLeft),
style: null);
new GUIImage(new RectTransform(Vector2.One, radioButton.RectTransform), radioIcon, scaleToFit: true);
radioButton.OnClicked = (GUIButton btn, object userData) =>
{
if (inputBox.Selected)
{
inputBox.Text = "";
inputBox.Deselect();
}
else
{
inputBox.Select();
var radioItem = Character.Controlled?.Inventory?.Items.FirstOrDefault(i => i?.GetComponent<WifiComponent>() != null);
if (radioItem != null && Character.Controlled.HasEquippedItem(radioItem) && radioItem.GetComponent<WifiComponent>().CanTransmit())
{
inputBox.Text = "r; ";
}
}
return true;
};
ToggleOpen = GameMain.Config.ChatOpen;
}
@@ -368,7 +337,6 @@ namespace Barotrauma
}
openState = MathHelper.Clamp(openState, 0.0f, 1.0f);
int hiddenBoxOffset = guiFrame.Rect.Width + toggleButton.Rect.Width;
if (radioButton != null) hiddenBoxOffset += (int)(radioButton.Rect.Width * 1.5f);
guiFrame.RectTransform.AbsoluteOffset =
new Point((int)MathHelper.SmoothStep(hiddenBoxOffset * (HUDLayoutSettings.ChatBoxAlignment == Alignment.Left ? -1 : 1), 0, openState), 0);
}
@@ -154,6 +154,8 @@ namespace Barotrauma
public bool IgnoreLayoutGroups;
public bool IgnoreLayoutGroups;
public virtual ScalableFont Font
{
get;
@@ -511,10 +511,8 @@ namespace Barotrauma
pos = 0;
totalSize += child.Rect.Width + spacing;
}
else
{
pos += child.Rect.Height + spacing;
}
pos += child.Rect.Height + spacing;
if (child == children.Last())
{
totalSize += child.Rect.Width + spacing;
@@ -527,10 +525,7 @@ namespace Barotrauma
pos = 0;
totalSize += child.Rect.Height + spacing;
}
else
{
pos += child.Rect.Width + spacing;
}
pos += child.Rect.Width + spacing;
if (child == children.Last())
{
@@ -113,6 +113,12 @@ namespace Barotrauma
Content = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.85f), InnerFrame.RectTransform, Anchor.Center)) { AbsoluteSpacing = 5 };
Tag = tag;
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);
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
@@ -9,6 +10,8 @@ namespace Barotrauma
{
private Dictionary<string, GUIComponentStyle> componentStyles;
private XElement configElement;
public ScalableFont Font { get; private set; }
public ScalableFont SmallFont { get; private set; }
public ScalableFont LargeFont { get; private set; }
@@ -45,24 +48,6 @@ namespace Barotrauma
{
switch (subElement.Name.ToString().ToLowerInvariant())
{
case "font":
Font = new ScalableFont(subElement, graphicsDevice);
break;
case "smallfont":
SmallFont = new ScalableFont(subElement, graphicsDevice);
break;
case "largefont":
LargeFont = new ScalableFont(subElement, graphicsDevice);
break;
case "objectivetitle":
ObjectiveTitleFont = new ScalableFont(subElement, graphicsDevice);
break;
case "objectivename":
ObjectiveNameFont = new ScalableFont(subElement, graphicsDevice);
break;
case "videotitle":
VideoTitleFont = new ScalableFont(subElement, graphicsDevice);
break;
case "cursor":
CursorSprite = new Sprite(subElement);
break;
@@ -72,12 +57,58 @@ namespace Barotrauma
case "focusindicator":
FocusIndicator = new SpriteSheet(subElement);
break;
case "font":
Font = LoadFont(subElement, graphicsDevice);
break;
case "smallfont":
SmallFont = LoadFont(subElement, graphicsDevice);
break;
case "largefont":
LargeFont = LoadFont(subElement, graphicsDevice);
break;
case "objectivetitle":
ObjectiveTitleFont = LoadFont(subElement, graphicsDevice);
break;
case "objectivename":
ObjectiveNameFont = LoadFont(subElement, graphicsDevice);
break;
case "videotitle":
VideoTitleFont = LoadFont(subElement, graphicsDevice);
break;
default:
GUIComponentStyle componentStyle = new GUIComponentStyle(subElement);
componentStyles.Add(subElement.Name.ToString().ToLowerInvariant(), componentStyle);
break;
}
}
}
private void RescaleFonts()
{
foreach (XElement subElement in configElement.Elements())
{
switch (subElement.Name.ToString().ToLowerInvariant())
{
case "font":
Font.Size = GetFontSize(subElement);
break;
case "smallfont":
SmallFont.Size = GetFontSize(subElement);
break;
case "largefont":
LargeFont.Size = GetFontSize(subElement);
break;
case "objectivetitle":
ObjectiveTitleFont.Size = GetFontSize(subElement);
break;
case "objectivename":
ObjectiveNameFont.Size = GetFontSize(subElement);
break;
case "videotitle":
VideoTitleFont.Size = GetFontSize(subElement);
break;
}
}
return element.GetAttributeBool("dynamicloading", false);
}
@@ -159,6 +190,32 @@ namespace Barotrauma
return style;
}
private ScalableFont LoadFont(XElement element, GraphicsDevice graphicsDevice)
{
string file = element.GetAttributeString("file", "");
uint size = GetFontSize(element);
return new ScalableFont(file, size, graphicsDevice);
}
private uint GetFontSize(XElement element)
{
foreach (XElement subElement in element.Elements())
{
Point maxResolution = subElement.GetAttributePoint("maxresolution", new Point(int.MaxValue, int.MaxValue));
if (GameMain.GraphicsWidth <= maxResolution.X && GameMain.GraphicsHeight <= maxResolution.Y)
{
return (uint)subElement.GetAttributeInt("size", 14);
}
}
return 14;
}
public GUIComponentStyle GetComponentStyle(string name)
{
componentStyles.TryGetValue(name.ToLowerInvariant(), out GUIComponentStyle style);
return style;
}
public void Apply(GUIComponent targetComponent, string styleName = "", GUIComponent parent = null)
{
GUIComponentStyle componentStyle = null;
@@ -333,7 +333,7 @@ namespace Barotrauma
{
spriteBatch.End();
spriteBatch.GraphicsDevice.ScissorRectangle = prevScissorRect;
spriteBatch.Begin(SpriteSortMode.Deferred);
spriteBatch.Begin(SpriteSortMode.Deferred, rasterizerState: GameMain.ScissorTestEnable);
}
if (OutlineColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, OutlineColor * (currColor.A / 255.0f), false);
@@ -123,6 +123,12 @@ namespace Barotrauma
}
}
public bool OverflowClip
{
get { return textBlock.OverflowClip; }
set { textBlock.OverflowClip = value; }
}
public override bool Enabled
{
get { return enabled; }
@@ -318,7 +324,7 @@ namespace Barotrauma
for (int i = 0; i <= textBlock.Text.Length; i++)
{
Vector2 textSize = Font.MeasureString(textBlock.Text.Substring(0, i));
Vector2 indexPos = new Vector2(textSize.X + textBlock.Padding.X, textSize.Y + textBlock.Padding.Y);
Vector2 indexPos = new Vector2(textSize.X + textBlock.Padding.X, textSize.Y + textBlock.Padding.Y) + textBlock.TextPos - textBlock.Origin;
//DebugConsole.NewMessage($"index: {i}, pos: {indexPos}", Color.WhiteSmoke);
positions.Add(new Tuple<Vector2, int>(textBlock.Rect.Location.ToVector2() + indexPos, i));
}
@@ -405,7 +411,7 @@ namespace Barotrauma
{
isSelecting = PlayerInput.KeyDown(Keys.LeftShift) || PlayerInput.KeyDown(Keys.RightShift);
}
if (CaretEnabled)
{
if (textBlock.OverflowClipActive)
@@ -428,7 +434,7 @@ namespace Barotrauma
CalculateCaretPos();
}
}
if (GUI.KeyboardDispatcher.Subscriber == this)
{
state = ComponentState.Selected;
@@ -547,15 +553,7 @@ namespace Barotrauma
public void ReceiveTextInput(char inputChar)
{
if (selectedCharacters > 0)
{
RemoveSelectedText();
}
if (SetText(Text.Insert(CaretIndex, inputChar.ToString())))
{
CaretIndex = Math.Min(Text.Length, CaretIndex + 1);
OnTextChanged?.Invoke(this, Text);
}
ReceiveTextInput(inputChar.ToString());
}
public void ReceiveTextInput(string input)
@@ -564,10 +562,16 @@ namespace Barotrauma
{
RemoveSelectedText();
}
Vector2 textPos = textBlock.TextPos;
bool wasOverflowClipActive = textBlock.OverflowClipActive;
if (SetText(Text.Insert(CaretIndex, input)))
{
CaretIndex = Math.Min(Text.Length, CaretIndex + input.Length);
OnTextChanged?.Invoke(this, Text);
if (textBlock.OverflowClipActive && wasOverflowClipActive && !MathUtils.NearlyEqual(textBlock.TextPos, textPos))
{
textBlock.TextPos = textPos + Vector2.UnitX * Font.MeasureString(input).X;
}
}
}