(98ad00fa2) v0.9.1.0
This commit is contained in:
@@ -1394,8 +1394,8 @@ namespace Barotrauma
|
||||
Vector2 moveAmount = centerDiff == Point.Zero ? Rand.Vector(1.0f) : Vector2.Normalize(centerDiff.ToVector2());
|
||||
|
||||
//make sure we don't move the interfaces out of the screen
|
||||
Vector2 moveAmount1 = ClampMoveAmount(rect1, area, moveAmount * 10.0f * rect1Area / (rect1Area + rect2Area));
|
||||
Vector2 moveAmount2 = ClampMoveAmount(rect2, area, -moveAmount * 10.0f * rect1Area / (rect1Area + rect2Area));
|
||||
Vector2 moveAmount1 = ClampMoveAmount(rect1, area, moveAmount * 20.0f * rect1Area / (rect1Area + rect2Area));
|
||||
Vector2 moveAmount2 = ClampMoveAmount(rect2, area, -moveAmount * 20.0f * rect1Area / (rect1Area + rect2Area));
|
||||
|
||||
//move by 10 units in the desired direction and repeat until nothing overlaps
|
||||
//(or after 100 iterations, in which case we'll just give up and let them overlap)
|
||||
|
||||
@@ -148,7 +148,14 @@ namespace Barotrauma
|
||||
//find the parent GUIListBox highest in the hierarchy
|
||||
for (int i = parentHierarchy.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (parentHierarchy[i].GUIComponent is GUIListBox) return parentHierarchy[i];
|
||||
if (parentHierarchy[i].GUIComponent is GUIListBox)
|
||||
{
|
||||
if (parentHierarchy[i].Parent != null && parentHierarchy[i].Parent.GUIComponent != null)
|
||||
{
|
||||
return parentHierarchy[i].Parent;
|
||||
}
|
||||
return parentHierarchy[i];
|
||||
}
|
||||
}
|
||||
//or just go with the direct parent if there are no listboxes in the hierarchy
|
||||
parentHierarchy.Clear();
|
||||
|
||||
@@ -57,8 +57,8 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public GUIImage(RectTransform rectT, string style)
|
||||
: this(rectT, null, null, false, style)
|
||||
public GUIImage(RectTransform rectT, string style, bool scaleToFit = false)
|
||||
: this(rectT, null, null, scaleToFit, style)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -131,13 +131,13 @@ namespace Barotrauma
|
||||
private float pressedDelay = 0.5f;
|
||||
private bool IsPressedTimerRunning { get { return pressedTimer > 0; } }
|
||||
|
||||
public GUINumberInput(RectTransform rectT, NumberType inputType, string style = "", Alignment textAlignment = Alignment.Center) : base(style, rectT)
|
||||
public GUINumberInput(RectTransform rectT, NumberType inputType, string style = "", Alignment textAlignment = Alignment.Center, float? relativeButtonAreaWidth = null) : base(style, rectT)
|
||||
{
|
||||
LayoutGroup = new GUILayoutGroup(new RectTransform(Vector2.One, rectT), isHorizontal: true) { Stretch = true };
|
||||
|
||||
float relativeButtonAreaWidth = MathHelper.Clamp(Rect.Height / (float)Rect.Width, 0.1f, 0.5f);
|
||||
float _relativeButtonAreaWidth = relativeButtonAreaWidth ?? MathHelper.Clamp(Rect.Height / (float)Rect.Width, 0.1f, 0.5f);
|
||||
|
||||
TextBox = new GUITextBox(new RectTransform(new Vector2(1.0f - relativeButtonAreaWidth, 1.0f), LayoutGroup.RectTransform), textAlignment: textAlignment, style: style)
|
||||
TextBox = new GUITextBox(new RectTransform(new Vector2(1.0f - _relativeButtonAreaWidth, 1.0f), LayoutGroup.RectTransform), textAlignment: textAlignment, style: style)
|
||||
{
|
||||
ClampText = false,
|
||||
// For some reason the caret in the number inputs is dimmer than it should.
|
||||
@@ -146,7 +146,12 @@ namespace Barotrauma
|
||||
CaretColor = Color.White
|
||||
};
|
||||
TextBox.OnTextChanged += TextChanged;
|
||||
var buttonArea = new GUIFrame(new RectTransform(new Vector2(relativeButtonAreaWidth, 1.0f), LayoutGroup.RectTransform, Anchor.CenterRight) { MinSize = new Point(Rect.Height, 0) }, style: null);
|
||||
var buttonArea = new GUIFrame(new RectTransform(new Vector2(_relativeButtonAreaWidth, 1.0f), LayoutGroup.RectTransform, Anchor.CenterRight), style: null);
|
||||
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 += () =>
|
||||
{
|
||||
|
||||
@@ -246,14 +246,12 @@ namespace Barotrauma
|
||||
|
||||
private bool SelectBar()
|
||||
{
|
||||
if (!enabled) return false;
|
||||
// This doesn't work
|
||||
if (barSize == 1.0f) return false;
|
||||
if (!enabled || !PlayerInput.LeftButtonDown()) { return false; }
|
||||
if (barSize >= 1.0f) { return false; }
|
||||
|
||||
draggingBar = this;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public void MoveButton(Vector2 moveAmount)
|
||||
|
||||
@@ -40,6 +40,9 @@ namespace Barotrauma
|
||||
{
|
||||
ToolBox.IsProperFilenameCase(file);
|
||||
doc = XDocument.Load(file, LoadOptions.SetBaseUri);
|
||||
if (doc == null) { throw new Exception("doc is null"); }
|
||||
if (doc.Root == null) { throw new Exception("doc.Root is null"); }
|
||||
if (doc.Root.Elements() == null) { throw new Exception("doc.Root.Elements() is null"); }
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -113,26 +116,34 @@ namespace Barotrauma
|
||||
|
||||
private void RescaleFonts()
|
||||
{
|
||||
if (configElement == null) { return; }
|
||||
if (configElement.Elements() == null) { return; }
|
||||
foreach (XElement subElement in configElement.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "font":
|
||||
if (Font == null) { continue; }
|
||||
Font.Size = GetFontSize(subElement);
|
||||
break;
|
||||
case "smallfont":
|
||||
if (SmallFont == null) { continue; }
|
||||
SmallFont.Size = GetFontSize(subElement);
|
||||
break;
|
||||
case "largefont":
|
||||
if (LargeFont == null) { continue; }
|
||||
LargeFont.Size = GetFontSize(subElement);
|
||||
break;
|
||||
case "objectivetitle":
|
||||
if (ObjectiveTitleFont == null) { continue; }
|
||||
ObjectiveTitleFont.Size = GetFontSize(subElement);
|
||||
break;
|
||||
case "objectivename":
|
||||
if (ObjectiveNameFont == null) { continue; }
|
||||
ObjectiveNameFont.Size = GetFontSize(subElement);
|
||||
break;
|
||||
case "videotitle":
|
||||
if (VideoTitleFont == null) { continue; }
|
||||
VideoTitleFont.Size = GetFontSize(subElement);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ namespace Barotrauma
|
||||
public static void AutoScaleAndNormalize(IEnumerable<GUITextBlock> textBlocks)
|
||||
{
|
||||
if (!textBlocks.Any()) { return; }
|
||||
float minScale = textBlocks.First().TextScale;
|
||||
float minScale = Math.Max(textBlocks.First().TextScale, 1.0f);
|
||||
foreach (GUITextBlock textBlock in textBlocks)
|
||||
{
|
||||
textBlock.AutoScale = true;
|
||||
|
||||
@@ -41,7 +41,28 @@ namespace Barotrauma
|
||||
OnSelected?.Invoke(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Color? defaultTextColor;
|
||||
|
||||
public override bool Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value == enabled) { return; }
|
||||
enabled = value;
|
||||
if (color.A == 0)
|
||||
{
|
||||
if (defaultTextColor == null) { defaultTextColor = TextBlock.TextColor; }
|
||||
TextBlock.TextColor = enabled ? defaultTextColor.Value : defaultTextColor.Value * 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Color TextColor
|
||||
{
|
||||
get { return text.TextColor; }
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public GUIComponent Parent { get; private set; }
|
||||
public GUIListBox EditorBox { get; private set; }
|
||||
/// <summary>
|
||||
/// Uses Linq queries. Don't use too frequently or reimplement.
|
||||
@@ -29,13 +30,12 @@ namespace Barotrauma
|
||||
|
||||
public GUIListBox CreateEditorBox(RectTransform rectT = null)
|
||||
{
|
||||
rectT = rectT ?? new RectTransform(new Vector2(0.25f, 0.95f), GUI.Canvas) { MinSize = new Point(340, GameMain.GraphicsHeight) };
|
||||
rectT = rectT ?? new RectTransform(new Vector2(0.25f, 1f), GUI.Canvas) { MinSize = new Point(340, GameMain.GraphicsHeight) };
|
||||
rectT.SetPosition(Anchor.TopRight);
|
||||
rectT.RelativeOffset = new Vector2(0.16f, 0);
|
||||
EditorBox = new GUIListBox(rectT)
|
||||
Parent = new GUIFrame(rectT, null, new Color(20, 20, 20, 255));
|
||||
EditorBox = new GUIListBox(new RectTransform(Vector2.One * 0.98f, rectT, Anchor.Center), color: Color.Black, style: null)
|
||||
{
|
||||
Spacing = 10,
|
||||
Color = Color.Black
|
||||
Spacing = 10
|
||||
};
|
||||
return EditorBox;
|
||||
}
|
||||
|
||||
@@ -1,274 +0,0 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class SpriteSheetPlayer
|
||||
{
|
||||
private SpriteSheet[] playingSheets;
|
||||
private SpriteSheet currentSheet;
|
||||
private List<PreloadedContent> preloadedSheets;
|
||||
|
||||
private GUIFrame background, videoFrame;
|
||||
private GUITextBlock title;
|
||||
private GUICustomComponent sheetView;
|
||||
|
||||
private float totalElapsed = 0;
|
||||
private float animationSpeed = 0.1f;
|
||||
private float loopTimer = 0.0f;
|
||||
private float loopDelay = 0.0f;
|
||||
|
||||
private int currentSheetIndex = 0;
|
||||
private int currentFrameIndex = 0;
|
||||
|
||||
private Color backgroundColor = new Color(0f, 0f, 0f, 1f);
|
||||
private Action callbackOnStop;
|
||||
|
||||
private bool isPlaying;
|
||||
public bool IsPlaying
|
||||
{
|
||||
get { return isPlaying; }
|
||||
private set
|
||||
{
|
||||
if (isPlaying == value) return;
|
||||
isPlaying = value;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Vector2 defaultResolution = new Vector2(520, 300);
|
||||
private readonly int borderSize = 20;
|
||||
|
||||
private class PreloadedContent
|
||||
{
|
||||
public string ContentName;
|
||||
public string ContentTag;
|
||||
public SpriteSheet[] Sheets;
|
||||
|
||||
public PreloadedContent(string name, string tag, SpriteSheet[] sheets)
|
||||
{
|
||||
ContentName = name;
|
||||
ContentTag = tag;
|
||||
Sheets = sheets;
|
||||
}
|
||||
}
|
||||
|
||||
public SpriteSheetPlayer()
|
||||
{
|
||||
int width = (int)defaultResolution.X;
|
||||
int height = (int)defaultResolution.Y;
|
||||
|
||||
background = new GUIFrame(new RectTransform(new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight), GUI.Canvas, Anchor.Center), "InnerFrame", backgroundColor);
|
||||
videoFrame = new GUIFrame(new RectTransform(new Point(width + borderSize, height + borderSize), background.RectTransform, Anchor.Center), "SonarFrame");
|
||||
sheetView = new GUICustomComponent(new RectTransform(new Point(width, height), videoFrame.RectTransform, Anchor.Center),
|
||||
(spriteBatch, guiCustomComponent) => { DrawSheetView(spriteBatch, guiCustomComponent.Rect); }, UpdateSheetView);
|
||||
title = new GUITextBlock(new RectTransform(new Vector2(1f, 0f), videoFrame.RectTransform, Anchor.TopCenter, Pivot.BottomCenter), string.Empty, font: GUI.LargeFont, textAlignment: Alignment.Center);
|
||||
|
||||
preloadedSheets = new List<PreloadedContent>();
|
||||
}
|
||||
|
||||
public void PreloadContent(string contentPath, string contentTag, string contentId, XElement contentElement)
|
||||
{
|
||||
if (preloadedSheets.Find(s => s.ContentName == contentId) != null) return; // Already loaded
|
||||
preloadedSheets.Add(new PreloadedContent(contentId, contentTag, CreateSpriteSheets(contentPath, contentElement)));
|
||||
}
|
||||
|
||||
public void RemoveAllPreloaded()
|
||||
{
|
||||
if (preloadedSheets == null || preloadedSheets.Count == 0) return;
|
||||
|
||||
for (int i = 0; i < preloadedSheets.Count; i++)
|
||||
{
|
||||
for (int j = 0; j < preloadedSheets[i].Sheets.Length; j++)
|
||||
{
|
||||
preloadedSheets[i].Sheets[j].Remove();
|
||||
}
|
||||
}
|
||||
|
||||
preloadedSheets.Clear();
|
||||
}
|
||||
|
||||
public void RemovePreloadedByTag(string tag)
|
||||
{
|
||||
if (preloadedSheets == null || preloadedSheets.Count == 0) return;
|
||||
|
||||
for (int i = 0; i < preloadedSheets.Count; i++)
|
||||
{
|
||||
if (preloadedSheets[i].ContentTag != tag) continue;
|
||||
for (int j = 0; j < preloadedSheets[i].Sheets.Length; j++)
|
||||
{
|
||||
preloadedSheets[i].Sheets[j].Remove();
|
||||
}
|
||||
|
||||
preloadedSheets[i] = null;
|
||||
preloadedSheets.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
isPlaying = true;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
isPlaying = false;
|
||||
}
|
||||
|
||||
private bool OKButtonClicked(GUIButton button, object userData)
|
||||
{
|
||||
Stop();
|
||||
callbackOnStop?.Invoke();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AddToGUIUpdateList()
|
||||
{
|
||||
if (!isPlaying) return;
|
||||
background.AddToGUIUpdateList();
|
||||
}
|
||||
|
||||
public void LoadContent(string contentPath, XElement videoElement, string contentId, bool startPlayback, bool hasButton, Action callback = null)
|
||||
{
|
||||
totalElapsed = loopTimer = 0.0f;
|
||||
animationSpeed = videoElement.GetAttributeFloat("animationspeed", 0.1f);
|
||||
loopDelay = videoElement.GetAttributeFloat("loopdelay", 0.0f);
|
||||
|
||||
if (playingSheets != null)
|
||||
{
|
||||
foreach (SpriteSheet existingSheet in playingSheets)
|
||||
{
|
||||
existingSheet.Remove();
|
||||
}
|
||||
playingSheets = null;
|
||||
}
|
||||
|
||||
playingSheets = preloadedSheets.Find(s => s.ContentName == contentId).Sheets;
|
||||
|
||||
if (playingSheets == null) // No preloaded sheets found, create sheets
|
||||
{
|
||||
playingSheets = CreateSpriteSheets(contentPath, videoElement);
|
||||
}
|
||||
|
||||
currentSheet = playingSheets[0];
|
||||
|
||||
Point resolution = currentSheet.FrameSize;
|
||||
|
||||
videoFrame.RectTransform.NonScaledSize = resolution + new Point(borderSize, borderSize);
|
||||
sheetView.RectTransform.NonScaledSize = resolution;
|
||||
|
||||
title.Text = TextManager.Get(contentId);
|
||||
title.RectTransform.NonScaledSize = new Point(resolution.X, 30);
|
||||
|
||||
callbackOnStop = callback;
|
||||
|
||||
if (hasButton)
|
||||
{
|
||||
var okButton = new GUIButton(new RectTransform(new Point(160, 50), videoFrame.RectTransform, Anchor.BottomCenter, Pivot.TopCenter) { AbsoluteOffset = new Point(0, -10) },
|
||||
TextManager.Get("OK"))
|
||||
{
|
||||
OnClicked = OKButtonClicked
|
||||
};
|
||||
}
|
||||
|
||||
if (startPlayback) Play();
|
||||
}
|
||||
|
||||
private SpriteSheet[] CreateSpriteSheets(string contentPath, XElement videoElement)
|
||||
{
|
||||
SpriteSheet[] sheets = null;
|
||||
|
||||
try
|
||||
{
|
||||
List<XElement> sheetElements = new List<XElement>();
|
||||
|
||||
foreach (var sheetElement in videoElement.Elements("Sheet"))
|
||||
{
|
||||
sheetElements.Add(sheetElement);
|
||||
}
|
||||
|
||||
sheets = new SpriteSheet[sheetElements.Count];
|
||||
|
||||
for (int i = 0; i < sheetElements.Count; i++)
|
||||
{
|
||||
sheets[i] = new SpriteSheet(sheetElements[i], contentPath, sheetElements[i].GetAttributeString("path", ""), sheetElements[i].GetAttributeInt("empty", 0));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Error loading sprite sheet content " + contentPath + "!", e);
|
||||
}
|
||||
|
||||
return sheets;
|
||||
}
|
||||
|
||||
private void UpdateSheetView(float deltaTime, GUICustomComponent viewContainer)
|
||||
{
|
||||
if (!isPlaying) return;
|
||||
if (loopTimer > 0.0f)
|
||||
{
|
||||
loopTimer -= deltaTime;
|
||||
|
||||
if (loopTimer <= 0.0f)
|
||||
{
|
||||
currentSheetIndex = 0;
|
||||
currentFrameIndex = 0;
|
||||
currentSheet = playingSheets[currentSheetIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
totalElapsed += deltaTime;
|
||||
if (totalElapsed > animationSpeed)
|
||||
{
|
||||
totalElapsed -= animationSpeed;
|
||||
currentFrameIndex++;
|
||||
|
||||
if (currentFrameIndex > currentSheet.FrameCount - 1)
|
||||
{
|
||||
currentSheetIndex++;
|
||||
|
||||
if (currentSheetIndex > playingSheets.Length - 1)
|
||||
{
|
||||
if (loopDelay > 0.0f)
|
||||
{
|
||||
loopTimer = loopDelay;
|
||||
return;
|
||||
}
|
||||
|
||||
currentSheetIndex = 0;
|
||||
}
|
||||
|
||||
currentFrameIndex = 0;
|
||||
currentSheet = playingSheets[currentSheetIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawSheetView(SpriteBatch spriteBatch, Rectangle rect)
|
||||
{
|
||||
if (!isPlaying) return;
|
||||
currentSheet.Draw(spriteBatch, currentFrameIndex, rect.Center.ToVector2(), Color.White, currentSheet.Origin, 0f, Vector2.One);
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
if (playingSheets != null)
|
||||
{
|
||||
foreach (SpriteSheet existingSheet in playingSheets)
|
||||
{
|
||||
existingSheet.Remove();
|
||||
}
|
||||
playingSheets = null;
|
||||
}
|
||||
|
||||
RemoveAllPreloaded();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user