(a410fd46c) Trying to help the merge script through a jungle of merges

This commit is contained in:
Joonas Rikkonen
2019-06-04 16:19:53 +03:00
parent 5208b922d8
commit bea7b58ff3
84 changed files with 1720 additions and 929 deletions
@@ -39,10 +39,14 @@ namespace Barotrauma
else if (Entity is Item)
{
color = Color.CadetBlue;
// disable the indicators for items, because they clutter the debug view
return;
}
else
{
color = Color.WhiteSmoke;
// disable the indicators for structures, because they clutter the debug view
return;
}
ShapeExtensions.DrawCircle(spriteBatch, pos, SightRange, 100, color, thickness: 1 / Screen.Selected.Cam.Zoom);
ShapeExtensions.DrawCircle(spriteBatch, pos, 6, 8, color, thickness: 2 / Screen.Selected.Cam.Zoom);
@@ -219,7 +219,7 @@ namespace Barotrauma
{
//hull subs don't match => teleport the camera to the other sub
character.Submarine = serverHull.Submarine;
character.CurrentHull = currentHull = serverHull;
character.CurrentHull = CurrentHull = serverHull;
SetPosition(serverPos.Position);
character.MemLocalState.Clear();
}
@@ -369,11 +369,11 @@ namespace Barotrauma
LimbJoints.ForEach(j => j.UpdateDeformations(deltaTime));
foreach (var deformation in SpriteDeformations)
{
if (character.IsDead && deformation.DeformationParams.StopWhenHostIsDead) { continue; }
if (deformation.DeformationParams.UseMovementSine)
{
if (this is AnimController animator)
{
//deformation.Phase = MathUtils.WrapAngleTwoPi(animator.WalkPos + MathHelper.Pi);
deformation.Phase = MathUtils.WrapAngleTwoPi(animator.WalkPos * deformation.DeformationParams.Frequency + MathHelper.Pi * deformation.DeformationParams.SineOffset);
}
}
@@ -538,13 +538,10 @@ namespace Barotrauma
if (wearable.InheritLimbDepth)
{
depth = ActiveSprite.Depth - depthStep;
if (wearable.DepthLimb != LimbType.None)
Limb depthLimb = (wearable.DepthLimb == LimbType.None) ? this : character.AnimController.GetLimb(wearable.DepthLimb);
if (depthLimb != null)
{
Limb depthLimb = character.AnimController.GetLimb(wearable.DepthLimb);
if (depthLimb != null)
{
depth = depthLimb.ActiveSprite.Depth - depthStep;
}
depth = depthLimb.ActiveSprite.Depth - depthStep;
}
}
var wearableItemComponent = wearable.WearableComponent;
@@ -62,9 +62,21 @@ namespace Barotrauma
{
frame = new GUIFrame(new RectTransform(new Vector2(0.5f, 0.45f), GUI.Canvas) { MinSize = new Point(400, 300), AbsoluteOffset = new Point(10, 10) },
color: new Color(0.4f, 0.4f, 0.4f, 0.8f));
var paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.9f), frame.RectTransform, Anchor.Center), style: null);
listBox = new GUIListBox(new RectTransform(new Point(paddedFrame.Rect.Width, paddedFrame.Rect.Height - 30), paddedFrame.RectTransform)
var toggleText = new GUITextBlock(new RectTransform(new Point(paddedFrame.Rect.Width-30, 20), paddedFrame.RectTransform, Anchor.TopLeft), TextManager.Get("DebugConsoleHelpText"), new Color(150,150,200,255), GUI.SmallFont, Alignment.CenterLeft, style: null);
var closeButton = new GUIButton(new RectTransform(new Point(20, 20), paddedFrame.RectTransform, Anchor.TopRight), "X", color: Color.Red);
closeButton.OnClicked += (btn, userdata) =>
{
isOpen = false;
GUI.ForceMouseOn(null);
textBox.Deselect();
return true;
};
listBox = new GUIListBox(new RectTransform(new Point(paddedFrame.Rect.Width, paddedFrame.Rect.Height - 50), paddedFrame.RectTransform, Anchor.Center)
{
IsFixedSize = false
}, color: Color.Black * 0.9f);
@@ -80,9 +92,6 @@ namespace Barotrauma
ResetAutoComplete();
}
};
NewMessage("Press F3 to open/close the debug console", Color.Cyan);
NewMessage("Enter \"help\" for a list of available console commands", Color.Cyan);
}
public static void AddToGUIUpdateList()
@@ -130,6 +139,12 @@ namespace Barotrauma
textBox.Deselect();
}
}
else if (isOpen && PlayerInput.KeyHit(Keys.Escape))
{
isOpen = false;
GUI.ForceMouseOn(null);
textBox.Deselect();
}
if (isOpen)
{
+10 -3
View File
@@ -230,11 +230,18 @@ namespace Barotrauma
if (GameMain.ShowPerf)
{
int y = 10;
DrawString(spriteBatch, new Vector2(300, y), "Draw - Max val: " + GameMain.PerformanceCounter.DrawTimeGraph.LargestValue()+" ms", Color.Green, Color.Black * 0.8f, font: GUI.SmallFont);
DrawString(spriteBatch, new Vector2(300, y),
"Draw - Avg: " + GameMain.PerformanceCounter.DrawTimeGraph.Average().ToString("0.00") + " ms" +
" Max: " + GameMain.PerformanceCounter.DrawTimeGraph.LargestValue().ToString("0.00") + " ms",
Color.Green, Color.Black * 0.8f, font: SmallFont);
y += 15;
GameMain.PerformanceCounter.DrawTimeGraph.Draw(spriteBatch, new Rectangle(300, y, 170, 50), null, 0, Color.Green);
y += 50;
DrawString(spriteBatch, new Vector2(300, y), "Update - Max val: " + GameMain.PerformanceCounter.UpdateTimeGraph.LargestValue() + " ms", Color.LightBlue, Color.Black * 0.8f, font: GUI.SmallFont);
DrawString(spriteBatch, new Vector2(300, y),
"Update - Avg: " + GameMain.PerformanceCounter.UpdateTimeGraph.Average().ToString("0.00") + " ms" +
" Max: " + GameMain.PerformanceCounter.UpdateTimeGraph.LargestValue().ToString("0.00") + " ms",
Color.LightBlue, Color.Black * 0.8f, font: SmallFont);
y += 15;
GameMain.PerformanceCounter.UpdateTimeGraph.Draw(spriteBatch, new Rectangle(300, y, 170, 50), null, 0, Color.LightBlue);
GameMain.PerformanceCounter.UpdateIterationsGraph.Draw(spriteBatch, new Rectangle(300, y, 170, 50), 20, 0, Color.Red);
@@ -243,7 +250,7 @@ namespace Barotrauma
{
float elapsedMillisecs = GameMain.PerformanceCounter.GetAverageElapsedMillisecs(key);
DrawString(spriteBatch, new Vector2(300, y),
key + ": " + elapsedMillisecs,
key + ": " + elapsedMillisecs.ToString("0.00"),
Color.Lerp(Color.LightGreen, Color.Red, elapsedMillisecs / 10.0f), Color.Black * 0.5f, 0, SmallFont);
y += 15;
@@ -85,7 +85,9 @@ namespace Barotrauma
{
float totalSize = RectTransform.Children
.Where(c => !c.GUIComponent.IgnoreLayoutGroups)
.Sum(c => isHorizontal ? c.Rect.Width : c.Rect.Height);
.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));
totalSize +=
(RectTransform.Children.Count() - 1) *
@@ -117,7 +117,9 @@ namespace Barotrauma
{
LayoutGroup = new GUILayoutGroup(new RectTransform(Vector2.One, rectT), isHorizontal: true) { Stretch = true };
TextBox = new GUITextBox(new RectTransform(Vector2.One, LayoutGroup.RectTransform), textAlignment: textAlignment, style: style)
float 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)
{
ClampText = false,
// For some reason the caret in the number inputs is dimmer than it should.
@@ -126,7 +128,7 @@ namespace Barotrauma
CaretColor = Color.White
};
TextBox.OnTextChanged += TextChanged;
var buttonArea = new GUIFrame(new RectTransform(new Vector2(0.02f, 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) { MinSize = new Point(Rect.Height, 0) }, style: null);
PlusButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.5f), buttonArea.RectTransform), "+");
PlusButton.OnButtonDown += () =>
{
@@ -201,6 +203,8 @@ namespace Barotrauma
TextBox.textFilterFunction = text => new string(text.Where(c => char.IsDigit(c) || c == '.' || c == '-').ToArray());
break;
}
LayoutGroup.Recalculate();
}
private void ReduceValue()
@@ -35,8 +35,6 @@ namespace Barotrauma
this.graphicsDevice = graphicsDevice;
componentStyles = new Dictionary<string, GUIComponentStyle>();
GameMain.Instance.OnResolutionChanged += () => { RescaleFonts(); };
XDocument doc;
try
{
@@ -89,6 +87,8 @@ namespace Barotrauma
break;
}
}
GameMain.Instance.OnResolutionChanged += () => { RescaleFonts(); };
}
/// <summary>
@@ -20,6 +20,7 @@ namespace Barotrauma
protected Color textColor;
private string wrappedText;
private string censoredText;
public delegate string TextGetterHandler();
public TextGetterHandler TextGetter;
@@ -175,6 +176,17 @@ namespace Barotrauma
SetTextPos();
}
}
public bool Censor
{
get;
set;
}
public string CensoredText
{
get { return censoredText; }
}
/// <summary>
/// This is the new constructor.
@@ -204,6 +216,8 @@ namespace Barotrauma
RectTransform.ScaleChanged += SetTextPos;
RectTransform.SizeChanged += SetTextPos;
Censor = false;
}
public void CalculateHeightFromText()
@@ -225,13 +239,19 @@ namespace Barotrauma
{
if (text == null) return;
censoredText = "";
for (int i=0;i<text.Length;i++)
{
censoredText += "\u2022";
}
var rect = Rect;
overflowClipActive = false;
wrappedText = text;
TextSize = MeasureText(text);
TextSize = MeasureText(text);
if (Wrap && rect.Width > 0)
{
wrappedText = ToolBox.WrapText(text, rect.Width - padding.X - padding.Z, Font, textScale);
@@ -338,7 +358,7 @@ namespace Barotrauma
}
Font.DrawString(spriteBatch,
Wrap ? wrappedText : text,
Censor ? censoredText : (Wrap ? wrappedText : text),
pos,
textColor * (textColor.A / 255.0f),
0.0f, origin, TextScale,
@@ -142,6 +142,12 @@ namespace Barotrauma
}
}
public bool Censor
{
get { return textBlock.Censor; }
set { textBlock.Censor = value; }
}
public override string ToolTip
{
get
@@ -253,9 +259,12 @@ namespace Barotrauma
textBlock.Text = textBlock.Text.Substring(0, (int)maxTextLength);
}
}
else if (ClampText && Font.MeasureString(textBlock.Text).X > (int)(textBlock.Rect.Width - textBlock.Padding.X - textBlock.Padding.Z))
else
{
textBlock.Text = textBlock.Text.Substring(0, textBlock.Text.Length - 1);
while (ClampText && textBlock.Text.Length>0 && Font.MeasureString(textBlock.Text).X > (int)(textBlock.Rect.Width - textBlock.Padding.X - textBlock.Padding.Z))
{
textBlock.Text = textBlock.Text.Substring(0, textBlock.Text.Length - 1);
}
}
}
if (store)
@@ -267,9 +276,10 @@ namespace Barotrauma
private void CalculateCaretPos()
{
if (textBlock.WrappedText.Contains("\n"))
string textDrawn = Censor ? textBlock.CensoredText : textBlock.WrappedText;
if (textDrawn.Contains("\n"))
{
string[] lines = textBlock.WrappedText.Split('\n');
string[] lines = textDrawn.Split('\n');
int totalIndex = 0;
for (int i = 0; i < lines.Length; i++)
{
@@ -282,7 +292,7 @@ namespace Barotrauma
int index = currentLineLength - diff;
Vector2 lineTextSize = Font.MeasureString(lines[i].Substring(0, index));
Vector2 lastLineSize = Font.MeasureString(lines[i]);
float totalTextHeight = Font.MeasureString(textBlock.WrappedText.Substring(0, totalIndex)).Y;
float totalTextHeight = Font.MeasureString(textDrawn.Substring(0, totalIndex)).Y;
caretPos = new Vector2(lineTextSize.X, totalTextHeight - lastLineSize.Y) + textBlock.TextPos - textBlock.Origin;
break;
}
@@ -290,7 +300,8 @@ namespace Barotrauma
}
else
{
Vector2 textSize = Font.MeasureString(textBlock.Text.Substring(0, CaretIndex));
textDrawn = Censor ? textBlock.CensoredText : textBlock.Text;
Vector2 textSize = Font.MeasureString(textDrawn.Substring(0, CaretIndex));
caretPos = new Vector2(textSize.X, 0) + textBlock.TextPos - textBlock.Origin;
}
caretPosDirty = false;
@@ -298,17 +309,18 @@ namespace Barotrauma
protected List<Tuple<Vector2, int>> GetAllPositions()
{
string textDrawn = Censor ? textBlock.CensoredText : textBlock.WrappedText;
var positions = new List<Tuple<Vector2, int>>();
if (textBlock.WrappedText.Contains("\n"))
if (textDrawn.Contains("\n"))
{
string[] lines = textBlock.WrappedText.Split('\n');
string[] lines = textDrawn.Split('\n');
int index = 0;
int totalIndex = 0;
for (int i = 0; i < lines.Length; i++)
{
string line = lines[i];
totalIndex += line.Length;
float totalTextHeight = Font.MeasureString(textBlock.WrappedText.Substring(0, totalIndex)).Y;
float totalTextHeight = Font.MeasureString(textDrawn.Substring(0, totalIndex)).Y;
for (int j = 0; j <= line.Length; j++)
{
Vector2 lineTextSize = Font.MeasureString(line.Substring(0, j));
@@ -321,9 +333,10 @@ namespace Barotrauma
}
else
{
textDrawn = Censor ? textBlock.CensoredText : textBlock.Text;
for (int i = 0; i <= textBlock.Text.Length; i++)
{
Vector2 textSize = Font.MeasureString(textBlock.Text.Substring(0, i));
Vector2 textSize = Font.MeasureString(textDrawn.Substring(0, i));
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));
@@ -822,6 +835,7 @@ namespace Barotrauma
private void CalculateSelection()
{
string textDrawn = Censor ? textBlock.CensoredText : textBlock.WrappedText;
InitSelectionStart();
selectionEndIndex = CaretIndex;
selectionEndPos = caretPos;
@@ -829,12 +843,12 @@ namespace Barotrauma
if (IsLeftToRight)
{
selectedText = Text.Substring(selectionStartIndex, selectedCharacters);
selectionRectSize = Font.MeasureString(textBlock.WrappedText.Substring(selectionStartIndex, selectedCharacters));
selectionRectSize = Font.MeasureString(textDrawn.Substring(selectionStartIndex, selectedCharacters));
}
else
{
selectedText = Text.Substring(selectionEndIndex, selectedCharacters);
selectionRectSize = Font.MeasureString(textBlock.WrappedText.Substring(selectionEndIndex, selectedCharacters));
selectionRectSize = Font.MeasureString(textDrawn.Substring(selectionEndIndex, selectedCharacters));
}
}
}
@@ -21,6 +21,11 @@ namespace Barotrauma
BottomLeft, BottomCenter, BottomRight
}
public enum ScaleBasis
{
Normal, BothWidth, BothHeight
}
public class RectTransform
{
#region Fields and Properties
@@ -286,6 +291,8 @@ namespace Barotrauma
}
}
private ScaleBasis scaleBasis;
public bool IsLastChild
{
get
@@ -320,9 +327,10 @@ namespace Barotrauma
#endregion
#region Initialization
public RectTransform(Vector2 relativeSize, RectTransform parent, Anchor anchor = Anchor.TopLeft, Pivot? pivot = null, Point? minSize = null, Point? maxSize = null)
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;
this.relativeSize = relativeSize;
this.minSize = minSize;
this.maxSize = maxSize;
@@ -340,6 +348,7 @@ namespace Barotrauma
public RectTransform(Point absoluteSize, RectTransform parent = null, Anchor anchor = Anchor.TopLeft, Pivot? pivot = null)
{
Init(parent, anchor, pivot);
this.scaleBasis = ScaleBasis.Normal;
this.nonScaledSize = absoluteSize;
RecalculateScale();
RecalculateRelativeSize();
@@ -416,7 +425,16 @@ namespace Barotrauma
protected void RecalculateAbsoluteSize()
{
nonScaledSize = NonScaledParentRect.Size.Multiply(RelativeSize).Clamp(MinSize, MaxSize);
Point size = NonScaledParentRect.Size;
if (scaleBasis == ScaleBasis.BothWidth)
{
size.Y = size.X;
}
else if (scaleBasis == ScaleBasis.BothHeight)
{
size.X = size.Y;
}
nonScaledSize = size.Multiply(RelativeSize).Clamp(MinSize, MaxSize);
recalculateRect = true;
SizeChanged?.Invoke();
}
@@ -159,14 +159,7 @@ namespace Barotrauma
public GameMain()
{
/*#if !DEBUG && OSX
// Use a separate path for content that's editable due to macOS's .app bundles crashing when edited during runtime
string macPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Library/Barotrauma");
Directory.SetCurrentDirectory(macPath);
Content.RootDirectory = macPath + "/Content";
#else*/
Content.RootDirectory = "Content";
/*#endif*/
GraphicsDeviceManager = new GraphicsDeviceManager(this);
@@ -280,7 +273,7 @@ namespace Barotrauma
canLoadInSeparateThread = true;
#endif
loadingCoroutine = CoroutineManager.StartCoroutine(Load(canLoadInSeparateThread), "", canLoadInSeparateThread);
loadingCoroutine = CoroutineManager.StartCoroutine(Load(canLoadInSeparateThread), "Load", canLoadInSeparateThread);
}
private void InitUserStats()
@@ -541,7 +534,9 @@ namespace Barotrauma
/// </summary>
protected override void UnloadContent()
{
CoroutineManager.StopCoroutines("Load");
Video.Close();
VoipCapture.Instance?.Dispose();
SoundManager?.Dispose();
}
@@ -114,7 +114,11 @@ namespace Barotrauma
Character character = characterInfo.Character;
if (character == null || character.IsDead)
{
if (characterInfo.CauseOfDeath.Type == CauseOfDeathType.Affliction && characterInfo.CauseOfDeath.Affliction == null)
if (characterInfo.CauseOfDeath == null)
{
statusText = TextManager.Get("CauseOfDeathDescription.Unknown");
}
else if (characterInfo.CauseOfDeath.Type == CauseOfDeathType.Affliction && characterInfo.CauseOfDeath.Affliction == null)
{
string errorMsg = "Character \"" + character.Name + "\" had an invalid cause of death (the type of the cause of death was Affliction, but affliction was not specified).";
DebugConsole.ThrowError(errorMsg);
@@ -126,7 +130,7 @@ namespace Barotrauma
statusText = characterInfo.CauseOfDeath.Type == CauseOfDeathType.Affliction ?
characterInfo.CauseOfDeath.Affliction.CauseOfDeathDescription :
TextManager.Get("CauseOfDeathDescription." + characterInfo.CauseOfDeath.Type.ToString());
}
}
statusColor = Color.DarkRed;
}
else
@@ -3,7 +3,7 @@ using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using OpenTK.Audio.OpenAL;
using OpenAL;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -75,6 +75,8 @@ namespace Barotrauma
{
settingsFrame = new GUIFrame(new RectTransform(new Vector2(0.8f, 0.8f), GUI.Canvas, Anchor.Center));
Vector2 tickBoxScale = Vector2.One * 0.05f;
var settingsFramePadding = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.9f), settingsFrame.RectTransform, Anchor.TopCenter) { RelativeOffset = new Vector2(0.0f, 0.05f) }) { RelativeSpacing = 0.01f, IsHorizontal = true };
/// General tab --------------------------------------------------------------
@@ -96,7 +98,7 @@ namespace Barotrauma
foreach (ContentPackage contentPackage in ContentPackage.List)
{
var tickBox = new GUITickBox(new RectTransform(new Point(32, 32), contentPackageList.Content.RectTransform), contentPackage.Name)
var tickBox = new GUITickBox(new RectTransform(tickBoxScale, contentPackageList.Content.RectTransform, scaleBasis: ScaleBasis.BothHeight), contentPackage.Name)
{
UserData = contentPackage,
OnSelected = SelectContentPackage,
@@ -132,7 +134,7 @@ namespace Barotrauma
if (newLanguage == Language) return true;
Language = newLanguage;
ApplySettings();
UnsavedSettings = true;
var msgBox = new GUIMessageBox(TextManager.Get("RestartRequiredLabel"), TextManager.Get("RestartRequiredLanguage"));
//change fonts to the default font of the new language to make sure
@@ -250,7 +252,7 @@ namespace Barotrauma
return true;
};
GUITickBox vsyncTickBox = new GUITickBox(new RectTransform(new Point(32, 32), leftColumn.RectTransform), TextManager.Get("EnableVSync"))
GUITickBox vsyncTickBox = new GUITickBox(new RectTransform(tickBoxScale, leftColumn.RectTransform, scaleBasis: ScaleBasis.BothHeight), TextManager.Get("EnableVSync"))
{
ToolTip = TextManager.Get("EnableVSyncToolTip"),
OnSelected = (GUITickBox box) =>
@@ -266,7 +268,7 @@ namespace Barotrauma
};
//TODO: remove hardcoded texts after the texts have been added to localization
GUITickBox pauseOnFocusLostBox = new GUITickBox(new RectTransform(new Point(32, 32), leftColumn.RectTransform),
GUITickBox pauseOnFocusLostBox = new GUITickBox(new RectTransform(tickBoxScale, leftColumn.RectTransform, scaleBasis: ScaleBasis.BothHeight),
TextManager.Get("PauseOnFocusLost", returnNull: true) ?? "Pause on focus lost");
pauseOnFocusLostBox.Selected = PauseOnFocusLost;
pauseOnFocusLostBox.ToolTip = TextManager.Get("PauseOnFocusLostToolTip", returnNull: true) ?? "Pauses the game when its window is not in focus. Note that the game won't be paused when a multiplayer session is active.";
@@ -331,7 +333,7 @@ namespace Barotrauma
};
lightScrollBar.OnMoved(lightScrollBar, lightScrollBar.BarScroll);
new GUITickBox(new RectTransform(new Point(32, 32), rightColumn.RectTransform), TextManager.Get("SpecularLighting"))
new GUITickBox(new RectTransform(tickBoxScale, rightColumn.RectTransform, scaleBasis: ScaleBasis.BothHeight), TextManager.Get("SpecularLighting"))
{
ToolTip = TextManager.Get("SpecularLightingToolTip"),
Selected = SpecularityEnabled,
@@ -343,7 +345,7 @@ namespace Barotrauma
}
};
new GUITickBox(new RectTransform(new Point(32, 32), rightColumn.RectTransform), TextManager.Get("ChromaticAberration"))
new GUITickBox(new RectTransform(tickBoxScale, rightColumn.RectTransform, scaleBasis: ScaleBasis.BothHeight), TextManager.Get("ChromaticAberration"))
{
ToolTip = TextManager.Get("ChromaticAberrationToolTip"),
Selected = ChromaticAberrationEnabled,
@@ -443,7 +445,7 @@ namespace Barotrauma
};
voiceChatScrollBar.OnMoved(voiceChatScrollBar, voiceChatScrollBar.BarScroll);
GUITickBox muteOnFocusLostBox = new GUITickBox(new RectTransform(new Point(32, 32), audioSliders.RectTransform), TextManager.Get("MuteOnFocusLost"));
GUITickBox muteOnFocusLostBox = new GUITickBox(new RectTransform(tickBoxScale, audioSliders.RectTransform, scaleBasis: ScaleBasis.BothHeight), TextManager.Get("MuteOnFocusLost"));
muteOnFocusLostBox.Selected = MuteOnFocusLost;
muteOnFocusLostBox.ToolTip = TextManager.Get("MuteOnFocusLostToolTip");
muteOnFocusLostBox.OnSelected = (tickBox) =>
@@ -455,13 +457,13 @@ namespace Barotrauma
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform), TextManager.Get("VoiceChat"));
IList<string> deviceNames = Alc.GetString((IntPtr)null, AlcGetStringList.CaptureDeviceSpecifier);
IList<string> deviceNames = Alc.GetStringList((IntPtr)null, Alc.CaptureDeviceSpecifier);
foreach (string name in deviceNames)
{
DebugConsole.NewMessage(name + " " + name.Length.ToString(), Color.Lime);
}
GUITickBox directionalVoiceChat = new GUITickBox(new RectTransform(new Point(32, 32), audioSliders.RectTransform), TextManager.Get("DirectionalVoiceChat"));
GUITickBox directionalVoiceChat = new GUITickBox(new RectTransform(tickBoxScale, audioSliders.RectTransform, scaleBasis: ScaleBasis.BothHeight), TextManager.Get("DirectionalVoiceChat"));
directionalVoiceChat.Selected = UseDirectionalVoiceChat;
directionalVoiceChat.ToolTip = TextManager.Get("DirectionalVoiceChatToolTip");
directionalVoiceChat.OnSelected = (tickBox) =>
@@ -470,14 +472,13 @@ namespace Barotrauma
UnsavedSettings = true;
return true;
};
if (string.IsNullOrWhiteSpace(VoiceCaptureDevice)) VoiceCaptureDevice = deviceNames[0];
#if (!OSX)
var deviceList = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform), TextManager.EnsureUTF8(VoiceCaptureDevice), deviceNames.Count);
var deviceList = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform), TrimAudioDeviceName(VoiceCaptureDevice), deviceNames.Count);
foreach (string name in deviceNames)
{
deviceList.AddItem(TextManager.EnsureUTF8(name), name);
deviceList.AddItem(TrimAudioDeviceName(name), name);
}
deviceList.OnSelected = (GUIComponent selected, object obj) =>
{
@@ -488,28 +489,32 @@ namespace Barotrauma
return true;
};
#else
var suavemente = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform),
var defaultDeviceGroup = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.1f), audioSliders.RectTransform), true, Anchor.CenterLeft);
var suavemente = new GUITextBlock(new RectTransform(new Vector2(.7f, 0.75f), null),
TextManager.AddPunctuation(':', TextManager.Get("CurrentDevice"), TextManager.EnsureUTF8(VoiceCaptureDevice)))
{
ToolTip = TextManager.Get("CurrentDeviceToolTip.OSX"),
TextAlignment = Alignment.CenterX
TextAlignment = Alignment.CenterLeft
};
new GUIButton(new RectTransform(new Vector2(1.0f, 0.15f), audioSliders.RectTransform), TextManager.Get("RefreshDefaultDevice"))
string refreshText = ToolBox.WrapText(TextManager.Get("RefreshDefaultDevice"), defaultDeviceGroup.RectTransform.Rect.Width * 0.3f, GUI.Font);
new GUIButton(new RectTransform(new Vector2(.3f, 0.75f), defaultDeviceGroup.RectTransform), refreshText)
{
ToolTip = TextManager.Get("RefreshDefaultDeviceToolTip"),
OnClicked = (bt, userdata) =>
{
deviceNames = Alc.GetString((IntPtr)null, AlcGetStringList.CaptureDeviceSpecifier);
deviceNames = Alc.GetStringList((IntPtr)null, Alc.CaptureDeviceSpecifier);
if (VoiceCaptureDevice == deviceNames[0]) return true;
VoipCapture.ChangeCaptureDevice(deviceNames[0]);
suavemente.Text = TextManager.AddPunctuation(':', TextManager.Get("CurrentDevice"), TextManager.EnsureUTF8(VoiceCaptureDevice));
suavemente.Text = TextManager.AddPunctuation(':', TextManager.Get("CurrentDevice"), TrimAudioDeviceName(VoiceCaptureDevice));
suavemente.Flash(Color.Blue);
return true;
}
};
suavemente.RectTransform.Parent = defaultDeviceGroup.RectTransform;
#endif
//var radioButtonFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.12f), audioSliders.RectTransform));
@@ -517,7 +522,7 @@ namespace Barotrauma
for (int i = 0; i < 3; i++)
{
string langStr = "VoiceMode." + ((VoiceMode)i).ToString();
var tick = new GUITickBox(new RectTransform(new Point(32, 32), audioSliders.RectTransform), TextManager.Get(langStr))
var tick = new GUITickBox(new RectTransform(tickBoxScale, audioSliders.RectTransform, scaleBasis: ScaleBasis.BothHeight), TextManager.Get(langStr))
{
ToolTip = TextManager.Get(langStr + "ToolTip")
};
@@ -651,7 +656,7 @@ namespace Barotrauma
};
aimAssistSlider.OnMoved(aimAssistSlider, aimAssistSlider.BarScroll);
new GUITickBox(new RectTransform(new Point(32, 32), controlsLayoutGroup.RectTransform), TextManager.Get("EnableMouseLook"))
new GUITickBox(new RectTransform(tickBoxScale, controlsLayoutGroup.RectTransform, scaleBasis: ScaleBasis.BothHeight), TextManager.Get("EnableMouseLook"))
{
ToolTip = TextManager.Get("EnableMouseLookToolTip"),
Selected = EnableMouseLook,
@@ -776,6 +781,19 @@ namespace Barotrauma
SelectTab(selectedTab);
}
private string TrimAudioDeviceName(string name)
{
string[] prefixes = { "OpenAL Soft on " };
foreach (string prefix in prefixes)
{
if (name.StartsWith(prefix, StringComparison.InvariantCulture))
{
return name.Remove(0, prefix.Length);
}
}
return name;
}
private Tab currentTab;
private void SelectTab(Tab tab)
{
@@ -423,7 +423,14 @@ namespace Barotrauma
columns++;
}
int startX = slot.Rect.Center.X - (int)(subRect.Width * (columns / 2.0f) + spacing.X * ((columns - 1) / 2.0f));
int width = (int)(subRect.Width * columns + spacing.X * (columns - 1));
int startX = slot.Rect.Center.X - (int)(width / 2.0f);
//prevent the inventory from extending outside the left side of the screen
startX = Math.Max(startX, 10);
//same for the right side of the screen
startX -= Math.Max((startX + width) - GameMain.GraphicsWidth, 0);
subRect.X = startX;
int startY = dir < 0 ?
slot.EquipButtonRect.Y - subRect.Height - (int)(35 * UIScale) :
@@ -29,6 +29,10 @@ namespace Barotrauma
drawPos.Y = -drawPos.Y;
Color clr = currentHull == null ? Color.Blue : Color.White;
if (isObstructed)
{
clr = Color.Black;
}
if (IsSelected) clr = Color.Red;
if (IsHighlighted) clr = Color.DarkRed;
@@ -50,7 +54,7 @@ namespace Barotrauma
GUI.DrawLine(spriteBatch,
drawPos,
new Vector2(e.DrawPosition.X, -e.DrawPosition.Y),
Color.Green, width: 5);
isObstructed ? Color.Gray : Color.Green, width: 5);
}
GUI.SmallFont.DrawString(spriteBatch,
@@ -194,8 +194,7 @@ namespace Barotrauma.Networking
Hull.EditFire = false;
Hull.EditWater = false;
newName = newName.Replace(":", "").Replace(";", "");
name = newName;
Name = newName;
entityEventManager = new ClientEntityEventManager(this);
@@ -473,7 +472,8 @@ namespace Barotrauma.Networking
var passwordBox = new GUITextBox(new RectTransform(new Vector2(0.8f, 0.1f), msgBox.InnerFrame.RectTransform, Anchor.Center) { MinSize = new Point(0, 20) })
{
IgnoreLayoutGroups = true,
UserData = "password"
UserData = "password",
Censor = true
};
var okButton = msgBox.Buttons[0];
@@ -1303,6 +1303,11 @@ namespace Barotrauma.Networking
if (existingClient.ID == myID)
{
existingClient.SetPermissions(permissions, permittedConsoleCommands);
name = tc.Name;
if (GameMain.NetLobbyScreen.CharacterNameBox != null)
{
GameMain.NetLobbyScreen.CharacterNameBox.Text = name;
}
}
currentClients.Add(existingClient);
}
@@ -1562,6 +1567,7 @@ namespace Barotrauma.Networking
outmsg.Write(GameMain.NetLobbyScreen.LastUpdateID);
outmsg.Write(ChatMessage.LastID);
outmsg.Write(LastClientListUpdateID);
outmsg.Write(name);
var campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign;
if (campaign == null || campaign.LastSaveID == 0)
@@ -1581,8 +1587,8 @@ namespace Barotrauma.Networking
{
if (outmsg.LengthBytes + chatMsgQueue[i].EstimateLengthBytesClient() > client.Configuration.MaximumTransmissionUnit - 5)
{
//not enough room in this packet
return;
//no more room in this packet
break;
}
chatMsgQueue[i].ClientWrite(outmsg);
}
@@ -1617,7 +1623,7 @@ namespace Barotrauma.Networking
if (outmsg.LengthBytes + chatMsgQueue[i].EstimateLengthBytesClient() > client.Configuration.MaximumTransmissionUnit - 5)
{
//not enough room in this packet
return;
break;
}
chatMsgQueue[i].ClientWrite(outmsg);
}
@@ -11,5 +11,15 @@ namespace Barotrauma.Networking
respawnTimer = Math.Max(0.0f, respawnTimer - deltaTime);
}
}
partial void UpdateTransportingProjSpecific(float deltaTime)
{
if (shuttleTransportTimer + deltaTime > 15.0f && shuttleTransportTimer <= 15.0f &&
GameMain.Client?.Character != null &&
GameMain.Client.Character.Submarine == respawnShuttle)
{
GameMain.Client.AddChatMessage("ServerMessage.ShuttleLeaving", ChatMessageType.Server);
}
}
}
}
@@ -71,15 +71,16 @@ namespace Barotrauma.Networking
Stretch = true
};
var titleHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.97f, 0.07f), previewContainer.RectTransform))
var titleHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.07f), previewContainer.RectTransform))
{
IsHorizontal = true,
Stretch = true
};
var title = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), titleHolder.RectTransform), ServerName, font: GUI.LargeFont, wrap: true);
var title = new GUITextBlock(new RectTransform(new Vector2(0.7f, 1.0f), titleHolder.RectTransform), ServerName, font: GUI.LargeFont, wrap: true);
title.Text = ToolBox.LimitString(title.Text, title.Font, title.Rect.Width);
new GUITextBlock(new RectTransform(Vector2.One, title.RectTransform),
new GUITextBlock(new RectTransform(new Vector2(0.3f, 1.0f), titleHolder.RectTransform),
TextManager.AddPunctuation(':', TextManager.Get("ServerListVersion"), string.IsNullOrEmpty(GameVersion) ? TextManager.Get("Unknown") : GameVersion),
textAlignment: Alignment.Right);
@@ -63,6 +63,15 @@ namespace Barotrauma.Steam
return instance.client.SteamId;
}
public static string GetUsername()
{
if (instance == null || !instance.isInitialized)
{
return "";
}
return instance.client.Username;
}
public static ulong GetWorkshopItemIDFromUrl(string url)
{
try
@@ -1,6 +1,6 @@
using Lidgren.Network;
using Microsoft.Xna.Framework;
using OpenTK.Audio.OpenAL;
using OpenAL;
using System;
using System.Linq;
using System.Runtime.InteropServices;
@@ -69,7 +69,7 @@ namespace Barotrauma.Networking
VoipConfig.SetupEncoding();
//set up capture device
captureDevice = Alc.CaptureOpenDevice(deviceName, VoipConfig.FREQUENCY, ALFormat.Mono16, VoipConfig.BUFFER_SIZE * 5);
captureDevice = Alc.CaptureOpenDevice(deviceName, VoipConfig.FREQUENCY, Al.FormatMono16, VoipConfig.BUFFER_SIZE * 5);
if (captureDevice == IntPtr.Zero)
{
@@ -88,20 +88,20 @@ namespace Barotrauma.Networking
return;
}
ALError alError = AL.GetError();
AlcError alcError = Alc.GetError(captureDevice);
if (alcError != AlcError.NoError)
int alError = Al.GetError();
int alcError = Alc.GetError(captureDevice);
if (alcError != Alc.NoError)
{
throw new Exception("Failed to open capture device: " + alcError.ToString() + " (ALC)");
}
if (alError != ALError.NoError)
if (alError != Al.NoError)
{
throw new Exception("Failed to open capture device: " + alError.ToString() + " (AL)");
}
Alc.CaptureStart(captureDevice);
alcError = Alc.GetError(captureDevice);
if (alcError != AlcError.NoError)
if (alcError != Alc.NoError)
{
throw new Exception("Failed to start capturing: " + alcError.ToString());
}
@@ -132,11 +132,11 @@ namespace Barotrauma.Networking
short[] uncompressedBuffer = new short[VoipConfig.BUFFER_SIZE];
while (capturing)
{
AlcError alcError;
Alc.GetInteger(captureDevice, AlcGetInteger.CaptureSamples, 1, out int sampleCount);
int alcError;
Alc.GetInteger(captureDevice, Alc.EnumCaptureSamples, out int sampleCount);
alcError = Alc.GetError(captureDevice);
if (alcError != AlcError.NoError)
if (alcError != Alc.NoError)
{
throw new Exception("Failed to determine sample count: " + alcError.ToString());
}
@@ -160,7 +160,7 @@ namespace Barotrauma.Networking
}
alcError = Alc.GetError(captureDevice);
if (alcError != AlcError.NoError)
if (alcError != Alc.NoError)
{
throw new Exception("Failed to capture samples: " + alcError.ToString());
}
@@ -214,7 +214,7 @@ namespace Barotrauma.Networking
}
}
Thread.Sleep(VoipConfig.BUFFER_SIZE * 800 / VoipConfig.FREQUENCY);
Thread.Sleep(10);
}
}
@@ -335,12 +335,6 @@ namespace Barotrauma
}
subName = doc.Root.GetAttributeString("submarine", "");
saveTime = doc.Root.GetAttributeString("savetime", "");
if (long.TryParse(saveTime, out long unixTime))
{
DateTime time = ToolBox.Epoch.ToDateTime(unixTime);
saveTime = time.ToString();
}
}
else
{
@@ -350,6 +344,11 @@ namespace Barotrauma
if (splitSaveFile.Length > 1) { subName = splitSaveFile[1]; }
if (splitSaveFile.Length > 2) { saveTime = splitSaveFile[2]; }
}
if (!string.IsNullOrEmpty(saveTime) && long.TryParse(saveTime, out long unixTime))
{
DateTime time = ToolBox.Epoch.ToDateTime(unixTime);
saveTime = time.ToString();
}
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), saveFrame.RectTransform, Anchor.BottomLeft),
text: subName, font: GUI.SmallFont)
@@ -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;
@@ -231,7 +232,16 @@ namespace Barotrauma
"", style: "ItemCategory" + category.ToString())
{
UserData = category,
OnClicked = (btn, userdata) => { FilterStoreItems((MapEntityCategory)userdata, searchBox.Text); return true; }
OnClicked = (btn, userdata) =>
{
MapEntityCategory newCategory = (MapEntityCategory)userdata;
if (newCategory != selectedItemCategory)
{
searchBox.Text = "";
}
FilterStoreItems((MapEntityCategory)userdata, searchBox.Text);
return true;
}
};
itemCategoryButtons.Add(categoryButton);
@@ -487,10 +497,15 @@ namespace Barotrauma
{
//refresh store view
FillStoreItemList();
FilterStoreItems(MapEntityCategory.Equipment, searchBox.Text);
}
MapEntityCategory? category = null;
//only select a specific category if the search box is empty
//(items from all categories are shown when searching)
if (string.IsNullOrEmpty(searchBox.Text)) { category = selectedItemCategory; }
FilterStoreItems(category, searchBox.Text);
}
}
private void DrawMap(SpriteBatch spriteBatch, GUICustomComponent mapContainer)
{
GameMain.GameSession?.Map?.Draw(spriteBatch, mapContainer);
@@ -655,7 +670,7 @@ namespace Barotrauma
}
}
private void CreateItemFrame(PurchasedItem pi, PriceInfo priceInfo, GUIListBox listBox, int width)
private GUIComponent CreateItemFrame(PurchasedItem pi, PriceInfo priceInfo, GUIListBox listBox, int width)
{
GUIFrame frame = new GUIFrame(new RectTransform(new Point(listBox.Content.Rect.Width, (int)(GUI.Scale * 50)), listBox.Content.RectTransform), style: "ListBoxElement")
{
@@ -739,6 +754,10 @@ namespace Barotrauma
content.RectTransform.RecalculateChildren(true, true);
amountInput?.LayoutGroup.Recalculate();
textBlock.Text = ToolBox.LimitString(textBlock.Text, textBlock.Font, textBlock.Rect.Width);
content.RectTransform.IsFixedSize = true;
content.RectTransform.Children.ForEach(c => c.IsFixedSize = true);
return frame;
}
private bool BuyItem(GUIComponent component, object obj)
@@ -776,12 +795,24 @@ namespace Barotrauma
private void RefreshMyItems()
{
myItemList.Content.ClearChildren();
foreach (PurchasedItem ip in Campaign.CargoManager.PurchasedItems)
HashSet<GUIComponent> existingItemFrames = new HashSet<GUIComponent>();
foreach (PurchasedItem pi in Campaign.CargoManager.PurchasedItems)
{
CreateItemFrame(ip, ip.ItemPrefab.GetPrice(Campaign.Map.CurrentLocation), myItemList, myItemList.Rect.Width);
var itemFrame = myItemList.Content.GetChildByUserData(pi);
if (itemFrame == null)
{
itemFrame = CreateItemFrame(pi, pi.ItemPrefab.GetPrice(Campaign.Map.CurrentLocation), myItemList, myItemList.Rect.Width);
}
itemFrame.GetChild(0).GetChild<GUINumberInput>().IntValue = pi.Quantity;
existingItemFrames.Add(itemFrame);
}
var removedItemFrames = myItemList.Content.Children.Except(existingItemFrames).ToList();
foreach (GUIComponent removedItemFrame in removedItemFrames)
{
myItemList.Content.RemoveChild(removedItemFrame);
}
myItemList.Content.RectTransform.SortChildren((x, y) =>
(x.GUIComponent.UserData as PurchasedItem).ItemPrefab.Name.CompareTo((y.GUIComponent.UserData as PurchasedItem).ItemPrefab.Name));
myItemList.Content.RectTransform.SortChildren((x, y) =>
@@ -821,17 +852,28 @@ namespace Barotrauma
private void FillStoreItemList()
{
storeItemList.ClearChildren();
int width = storeItemList.Rect.Width;
HashSet<GUIComponent> existingItemFrames = new HashSet<GUIComponent>();
foreach (MapEntityPrefab mapEntityPrefab in MapEntityPrefab.List)
{
if (!(mapEntityPrefab is ItemPrefab itemPrefab)) { continue; }
PriceInfo priceInfo = itemPrefab.GetPrice(Campaign.Map.CurrentLocation);
if (priceInfo == null) continue;
if (priceInfo == null) { continue; }
CreateItemFrame(new PurchasedItem(itemPrefab, 0), priceInfo, storeItemList, width);
var itemFrame = myItemList.Content.GetChildByUserData(priceInfo);
if (itemFrame == null)
{
itemFrame = CreateItemFrame(new PurchasedItem(itemPrefab, 0), priceInfo, storeItemList, width);
}
existingItemFrames.Add(itemFrame);
}
var removedItemFrames = storeItemList.Content.Children.Except(existingItemFrames).ToList();
foreach (GUIComponent removedItemFrame in removedItemFrames)
{
storeItemList.Content.RemoveChild(removedItemFrame);
}
storeItemList.Content.RectTransform.SortChildren(
(x, y) => (x.GUIComponent.UserData as PurchasedItem).ItemPrefab.Name.CompareTo((y.GUIComponent.UserData as PurchasedItem).ItemPrefab.Name));
}
@@ -968,7 +968,10 @@ namespace Barotrauma
};
label = new GUITextBlock(new RectTransform(textLabelSize, parent.RectTransform), TextManager.Get("Password"), textAlignment: textAlignment);
passwordBox = new GUITextBox(new RectTransform(textFieldSize, label.RectTransform, Anchor.CenterRight), textAlignment: textAlignment);
passwordBox = new GUITextBox(new RectTransform(textFieldSize, label.RectTransform, Anchor.CenterRight), textAlignment: textAlignment)
{
Censor = true
};
isPublicBox = new GUITickBox(new RectTransform(tickBoxSize, parent.RectTransform), TextManager.Get("PublicServer"))
{
@@ -147,6 +147,12 @@ namespace Barotrauma
get { return playerList; }
}
public GUITextBox CharacterNameBox
{
get;
private set;
}
public GUIButton StartButton
{
get;
@@ -920,7 +926,26 @@ namespace Barotrauma
UserData = characterInfo
};
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), infoContainer.RectTransform), characterInfo.Name, font: GUI.LargeFont, textAlignment: Alignment.Center, wrap: true);
CharacterNameBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.1f), infoContainer.RectTransform), characterInfo.Name, font: GUI.LargeFont, textAlignment: Alignment.Center)
{
MaxTextLength = Client.MaxNameLength,
OverflowClip = true
};
CharacterNameBox.OnEnterPressed += (tb, text) => { CharacterNameBox.Deselect(); return true; };
CharacterNameBox.OnDeselected += (tb, key) =>
{
if (GameMain.Client == null) { return; }
string newName = Client.SanitizeName(tb.Text);
if (string.IsNullOrWhiteSpace(newName))
{
tb.Text = GameMain.Client.Name;
}
else
{
ReadyToStartBox.Selected = false;
GameMain.Client.Name = tb.Text;
};
};
GUIComponent headContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.6f, 0.2f), infoContainer.RectTransform, Anchor.TopCenter), isHorizontal: true)
{
@@ -1309,6 +1334,7 @@ namespace Barotrauma
{
Selected = true,
Enabled = false,
Visible = false,
ToolTip = TextManager.Get("ReadyToStartTickBox"),
UserData = "clientready"
};
@@ -70,8 +70,14 @@ namespace Barotrauma
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), infoHolder.RectTransform), TextManager.Get("YourName"));
clientNameBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.13f), infoHolder.RectTransform), "")
{
Text = GameMain.Config.DefaultPlayerName
Text = GameMain.Config.DefaultPlayerName,
MaxTextLength = Client.MaxNameLength,
OverflowClip = true
};
if (string.IsNullOrEmpty(clientNameBox.Text))
{
clientNameBox.Text = SteamManager.GetUsername();
}
clientNameBox.OnTextChanged += RefreshJoinButtonState;
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), infoHolder.RectTransform), TextManager.Get("ServerIP"));
@@ -236,7 +242,7 @@ namespace Barotrauma
{
serverInfo = (ServerInfo)obj;
ipBox.UserData = serverInfo;
ipBox.Text = serverInfo.ServerName;
ipBox.Text = ToolBox.LimitString(serverInfo.ServerName, ipBox.Font, ipBox.Rect.Width);
}
catch (InvalidCastException)
{
@@ -411,7 +417,6 @@ namespace Barotrauma
};
var serverName = new GUITextBlock(new RectTransform(new Vector2(columnRelativeWidth[3], 1.0f), serverContent.RectTransform), serverInfo.ServerName, style: "GUIServerListTextBox");
var gameStartedBox = new GUITickBox(new RectTransform(new Vector2(columnRelativeWidth[4], 0.4f), serverContent.RectTransform, Anchor.Center),
label: "", style: "GUIServerListRoundStartedTickBox") {
ToolTip = TextManager.Get((serverInfo.GameStarted) ? "ServerListRoundStarted" : "ServerListRoundNotStarted"),
@@ -1,5 +1,5 @@
using System;
using OpenTK.Audio.OpenAL;
using OpenAL;
using NVorbis;
using System.Collections.Generic;
@@ -21,7 +21,7 @@ namespace Barotrauma.Sounds
reader = new VorbisReader(filename);
ALFormat = reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16;
ALFormat = reader.Channels == 1 ? Al.FormatMono16 : Al.FormatStereo16;
SampleRate = reader.SampleRate;
if (!stream)
@@ -35,26 +35,26 @@ namespace Barotrauma.Sounds
CastBuffer(floatBuffer, shortBuffer, readSamples);
AL.BufferData((int)ALBuffer, ALFormat, shortBuffer,
Al.BufferData(ALBuffer, ALFormat, shortBuffer,
readSamples * sizeof(short), SampleRate);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set buffer data for non-streamed audio! "+AL.GetErrorString(alError));
throw new Exception("Failed to set buffer data for non-streamed audio! "+Al.GetErrorString(alError));
}
MuffleBuffer(floatBuffer, SampleRate, reader.Channels);
CastBuffer(floatBuffer, shortBuffer, readSamples);
AL.BufferData((int)ALMuffledBuffer, ALFormat, shortBuffer,
Al.BufferData(ALMuffledBuffer, ALFormat, shortBuffer,
readSamples * sizeof(short), SampleRate);
alError = AL.GetError();
if (alError != ALError.NoError)
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set buffer data for non-streamed audio! " + AL.GetErrorString(alError));
throw new Exception("Failed to set buffer data for non-streamed audio! " + Al.GetErrorString(alError));
}
reader.Dispose();
@@ -98,4 +98,4 @@ namespace Barotrauma.Sounds
base.Dispose();
}
}
}
}
@@ -1,5 +1,5 @@
using System;
using OpenTK.Audio.OpenAL;
using OpenAL;
using Microsoft.Xna.Framework;
using System.IO;
@@ -57,7 +57,7 @@ namespace Barotrauma.Sounds
get { return !Stream ? alMuffledBuffer : 0; }
}
public ALFormat ALFormat
public int ALFormat
{
get;
protected set;
@@ -91,26 +91,26 @@ namespace Barotrauma.Sounds
if (!stream)
{
AL.GenBuffer(out alBuffer);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.GenBuffer(out alBuffer);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to create OpenAL buffer for non-streamed sound: " + AL.GetErrorString(alError));
throw new Exception("Failed to create OpenAL buffer for non-streamed sound: " + Al.GetErrorString(alError));
}
if (!AL.IsBuffer(alBuffer))
if (!Al.IsBuffer(alBuffer))
{
throw new Exception("Generated OpenAL buffer is invalid!");
}
AL.GenBuffer(out alMuffledBuffer);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.GenBuffer(out alMuffledBuffer);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to create OpenAL buffer for non-streamed sound: " + AL.GetErrorString(alError));
throw new Exception("Failed to create OpenAL buffer for non-streamed sound: " + Al.GetErrorString(alError));
}
if (!AL.IsBuffer(alMuffledBuffer))
if (!Al.IsBuffer(alMuffledBuffer))
{
throw new Exception("Generated OpenAL buffer is invalid!");
}
@@ -186,32 +186,32 @@ namespace Barotrauma.Sounds
Owner.KillChannels(this);
if (alBuffer != 0)
{
if (!AL.IsBuffer(alBuffer))
if (!Al.IsBuffer(alBuffer))
{
throw new Exception("Buffer to delete is invalid!");
}
AL.DeleteBuffer(ref alBuffer); alBuffer = 0;
Al.DeleteBuffer(alBuffer); alBuffer = 0;
ALError alError = AL.GetError();
if (alError != ALError.NoError)
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to delete OpenAL buffer for non-streamed sound: " + AL.GetErrorString(alError));
throw new Exception("Failed to delete OpenAL buffer for non-streamed sound: " + Al.GetErrorString(alError));
}
}
if (alMuffledBuffer != 0)
{
if (!AL.IsBuffer(alMuffledBuffer))
if (!Al.IsBuffer(alMuffledBuffer))
{
throw new Exception("Buffer to delete is invalid!");
}
AL.DeleteBuffer(ref alMuffledBuffer); alMuffledBuffer = 0;
Al.DeleteBuffer(alMuffledBuffer); alMuffledBuffer = 0;
ALError alError = AL.GetError();
if (alError != ALError.NoError)
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to delete OpenAL buffer for non-streamed sound: " + AL.GetErrorString(alError));
throw new Exception("Failed to delete OpenAL buffer for non-streamed sound: " + Al.GetErrorString(alError));
}
}
@@ -1,5 +1,5 @@
using System;
using OpenTK.Audio.OpenAL;
using OpenAL;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
@@ -15,49 +15,49 @@ namespace Barotrauma.Sounds
public SoundSourcePool(int sourceCount = SoundManager.SOURCE_COUNT)
{
ALError alError = ALError.NoError;
int alError = Al.NoError;
ALSources = new uint[sourceCount];
for (int i = 0; i < sourceCount; i++)
{
AL.GenSource(out ALSources[i]);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.GenSource(out ALSources[i]);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Error generating alSource[" + i.ToString() + "]: " + AL.GetErrorString(alError));
throw new Exception("Error generating alSource[" + i.ToString() + "]: " + Al.GetErrorString(alError));
}
if (!AL.IsSource(ALSources[i]))
if (!Al.IsSource(ALSources[i]))
{
throw new Exception("Generated alSource[" + i.ToString() + "] is invalid!");
}
AL.SourceStop(ALSources[i]);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.SourceStop(ALSources[i]);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Error stopping newly generated alSource[" + i.ToString() + "]: " + AL.GetErrorString(alError));
throw new Exception("Error stopping newly generated alSource[" + i.ToString() + "]: " + Al.GetErrorString(alError));
}
AL.Source(ALSources[i], ALSourcef.MinGain, 0.0f);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcef(ALSources[i], Al.MinGain, 0.0f);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Error setting min gain: " + AL.GetErrorString(alError));
throw new Exception("Error setting min gain: " + Al.GetErrorString(alError));
}
AL.Source(ALSources[i], ALSourcef.MaxGain, 1.0f);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcef(ALSources[i], Al.MaxGain, 1.0f);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Error setting max gain: " + AL.GetErrorString(alError));
throw new Exception("Error setting max gain: " + Al.GetErrorString(alError));
}
AL.Source(ALSources[i], ALSourcef.RolloffFactor, 1.0f);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcef(ALSources[i], Al.RolloffFactor, 1.0f);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Error setting rolloff factor: " + AL.GetErrorString(alError));
throw new Exception("Error setting rolloff factor: " + Al.GetErrorString(alError));
}
}
}
@@ -66,11 +66,11 @@ namespace Barotrauma.Sounds
{
for (int i = 0; i < ALSources.Length; i++)
{
AL.DeleteSource(ref ALSources[i]);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.DeleteSource(ALSources[i]);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to delete ALSources[" + i.ToString() + "]: " + AL.GetErrorString(alError));
throw new Exception("Failed to delete ALSources[" + i.ToString() + "]: " + Al.GetErrorString(alError));
}
}
ALSources = null;
@@ -95,35 +95,35 @@ namespace Barotrauma.Sounds
if (position != null)
{
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
AL.Source(alSource, ALSourceb.SourceRelative, false);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(alSource, Al.SourceRelative, Al.False);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to enable source's relative flag: " + AL.GetErrorString(alError));
throw new Exception("Failed to enable source's relative flag: " + Al.GetErrorString(alError));
}
AL.Source(alSource, ALSource3f.Position, position.Value.X, position.Value.Y, position.Value.Z);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Source3f(alSource, Al.Position, position.Value.X, position.Value.Y, position.Value.Z);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set source's position: " + AL.GetErrorString(alError));
throw new Exception("Failed to set source's position: " + Al.GetErrorString(alError));
}
}
else
{
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
AL.Source(alSource, ALSourceb.SourceRelative, true);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(alSource, Al.SourceRelative, Al.True);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to disable source's relative flag: " + AL.GetErrorString(alError));
throw new Exception("Failed to disable source's relative flag: " + Al.GetErrorString(alError));
}
AL.Source(alSource, ALSource3f.Position, 0.0f, 0.0f, 0.0f);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Source3f(alSource, Al.Position, 0.0f, 0.0f, 0.0f);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to reset source's position: " + AL.GetErrorString(alError));
throw new Exception("Failed to reset source's position: " + Al.GetErrorString(alError));
}
}
}
@@ -140,12 +140,12 @@ namespace Barotrauma.Sounds
if (ALSourceIndex < 0) return;
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
AL.Source(alSource, ALSourcef.ReferenceDistance, near);
Al.Sourcef(alSource, Al.ReferenceDistance, near);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set source's reference distance: " + AL.GetErrorString(alError));
throw new Exception("Failed to set source's reference distance: " + Al.GetErrorString(alError));
}
}
}
@@ -161,11 +161,11 @@ namespace Barotrauma.Sounds
if (ALSourceIndex < 0) return;
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
AL.Source(alSource, ALSourcef.MaxDistance, far);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcef(alSource, Al.MaxDistance, far);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set source's max distance: " + AL.GetErrorString(alError));
throw new Exception("Failed to set source's max distance: " + Al.GetErrorString(alError));
}
}
}
@@ -185,11 +185,11 @@ namespace Barotrauma.Sounds
float effectiveGain = gain;
if (category != null) effectiveGain *= Sound.Owner.GetCategoryGainMultiplier(category);
AL.Source(alSource, ALSourcef.Gain, effectiveGain);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcef(alSource, Al.Gain, effectiveGain);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set source's gain: " + AL.GetErrorString(alError));
throw new Exception("Failed to set source's gain: " + Al.GetErrorString(alError));
}
}
}
@@ -207,11 +207,11 @@ namespace Barotrauma.Sounds
if (!IsStream)
{
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
AL.Source(alSource, ALSourceb.Looping, looping);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(alSource, Al.Looping, looping ? Al.True : Al.False);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set source's looping state: " + AL.GetErrorString(alError));
throw new Exception("Failed to set source's looping state: " + Al.GetErrorString(alError));
}
}
}
@@ -242,41 +242,41 @@ namespace Barotrauma.Sounds
if (!IsStream)
{
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
int playbackPos; AL.GetSource(alSource, ALGetSourcei.SampleOffset, out playbackPos);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
int playbackPos; Al.GetSourcei(alSource, Al.SampleOffset, out playbackPos);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to get source's playback position: " + AL.GetErrorString(alError));
throw new Exception("Failed to get source's playback position: " + Al.GetErrorString(alError));
}
AL.SourceStop(alSource);
Al.SourceStop(alSource);
alError = AL.GetError();
if (alError != ALError.NoError)
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to stop source: " + AL.GetErrorString(alError));
throw new Exception("Failed to stop source: " + Al.GetErrorString(alError));
}
AL.BindBufferToSource(alSource,(uint)(muffled ? Sound.ALMuffledBuffer : Sound.ALBuffer));
Al.Sourcei(alSource, Al.Buffer, muffled ? (int)Sound.ALMuffledBuffer : (int)Sound.ALBuffer);
alError = AL.GetError();
if (alError != ALError.NoError)
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to bind buffer to source: " + AL.GetErrorString(alError));
throw new Exception("Failed to bind buffer to source: " + Al.GetErrorString(alError));
}
AL.SourcePlay(alSource);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.SourcePlay(alSource);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to replay source: " + AL.GetErrorString(alError));
throw new Exception("Failed to replay source: " + Al.GetErrorString(alError));
}
AL.Source(alSource, ALSourcei.SampleOffset, playbackPos);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(alSource, Al.SampleOffset, playbackPos);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to reset playback position: " + AL.GetErrorString(alError));
throw new Exception("Failed to reset playback position: " + Al.GetErrorString(alError));
}
}
}
@@ -324,11 +324,13 @@ namespace Barotrauma.Sounds
{
if (ALSourceIndex < 0) return false;
if (IsStream && !reachedEndSample) return true;
bool playing = AL.GetSourceState(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex)) == ALSourceState.Playing;
ALError alError = AL.GetError();
if (alError != ALError.NoError)
int state;
Al.GetSourcei(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.SourceState, out state);
bool playing = state == Al.Playing;
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to determine playing state from source: " + AL.GetErrorString(alError));
throw new Exception("Failed to determine playing state from source: " + Al.GetErrorString(alError));
}
return playing;
}
@@ -357,47 +359,47 @@ namespace Barotrauma.Sounds
{
if (!IsStream)
{
AL.BindBufferToSource(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), 0);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.Buffer, 0);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to reset source buffer: " + AL.GetErrorString(alError));
throw new Exception("Failed to reset source buffer: " + Al.GetErrorString(alError));
}
if (!AL.IsBuffer(sound.ALBuffer))
if (!Al.IsBuffer(sound.ALBuffer))
{
throw new Exception(sound.Filename + " has an invalid buffer!");
}
uint alBuffer = sound.Owner.GetCategoryMuffle(category) || muffle ? sound.ALMuffledBuffer : sound.ALBuffer;
AL.BindBufferToSource(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), alBuffer);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.Buffer, (int)alBuffer);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to bind buffer to source (" + ALSourceIndex.ToString() + ":" + sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex) + "," + sound.ALBuffer.ToString() + "): " + AL.GetErrorString(alError));
throw new Exception("Failed to bind buffer to source (" + ALSourceIndex.ToString() + ":" + sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex) + "," + sound.ALBuffer.ToString() + "): " + Al.GetErrorString(alError));
}
AL.SourcePlay(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex));
alError = AL.GetError();
if (alError != ALError.NoError)
Al.SourcePlay(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex));
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to play source: " + AL.GetErrorString(alError));
throw new Exception("Failed to play source: " + Al.GetErrorString(alError));
}
}
else
{
AL.BindBufferToSource(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), (uint)sound.ALBuffer);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.Buffer, (int)sound.ALBuffer);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to reset source buffer: " + AL.GetErrorString(alError));
throw new Exception("Failed to reset source buffer: " + Al.GetErrorString(alError));
}
AL.Source(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), ALSourceb.Looping, false);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.Looping, Al.False);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set stream looping state: " + AL.GetErrorString(alError));
throw new Exception("Failed to set stream looping state: " + Al.GetErrorString(alError));
}
streamShortBuffer = new short[STREAM_BUFFER_SIZE];
@@ -406,15 +408,15 @@ namespace Barotrauma.Sounds
emptyBuffers = new List<uint>();
for (int i = 0; i < 4; i++)
{
AL.GenBuffer(out streamBuffers[i]);
Al.GenBuffer(out streamBuffers[i]);
alError = AL.GetError();
if (alError != ALError.NoError)
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to generate stream buffers: " + AL.GetErrorString(alError));
throw new Exception("Failed to generate stream buffers: " + Al.GetErrorString(alError));
}
if (!AL.IsBuffer(streamBuffers[i]))
if (!Al.IsBuffer(streamBuffers[i]))
{
throw new Exception("Generated streamBuffer[" + i.ToString() + "] is invalid!");
}
@@ -445,57 +447,57 @@ namespace Barotrauma.Sounds
{
if (ALSourceIndex >= 0)
{
AL.SourceStop(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex));
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.SourceStop(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex));
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to stop source: " + AL.GetErrorString(alError));
throw new Exception("Failed to stop source: " + Al.GetErrorString(alError));
}
if (IsStream)
{
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
AL.SourceStop(alSource);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.SourceStop(alSource);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to stop streamed source: " + AL.GetErrorString(alError));
throw new Exception("Failed to stop streamed source: " + Al.GetErrorString(alError));
}
int buffersToUnqueue = 0;
int[] unqueuedBuffers = null;
uint[] unqueuedBuffers = null;
buffersToUnqueue = 0;
AL.GetSource(alSource, ALGetSourcei.BuffersProcessed, out buffersToUnqueue);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.GetSourcei(alSource, Al.BuffersProcessed, out buffersToUnqueue);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to determine processed buffers from streamed source: " + AL.GetErrorString(alError));
throw new Exception("Failed to determine processed buffers from streamed source: " + Al.GetErrorString(alError));
}
unqueuedBuffers = new int[buffersToUnqueue];
AL.SourceUnqueueBuffers((int)alSource, buffersToUnqueue, unqueuedBuffers);
alError = AL.GetError();
if (alError != ALError.NoError)
unqueuedBuffers = new uint[buffersToUnqueue];
Al.SourceUnqueueBuffers(alSource, buffersToUnqueue, unqueuedBuffers);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to unqueue buffers from streamed source: " + AL.GetErrorString(alError));
throw new Exception("Failed to unqueue buffers from streamed source: " + Al.GetErrorString(alError));
}
AL.BindBufferToSource(alSource, 0);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(alSource, Al.Buffer, 0);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to reset buffer for streamed source: " + AL.GetErrorString(alError));
throw new Exception("Failed to reset buffer for streamed source: " + Al.GetErrorString(alError));
}
for (int i = 0; i < 4; i++)
{
AL.DeleteBuffer(ref streamBuffers[i]);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.DeleteBuffer(streamBuffers[i]);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to delete streamBuffers[" + i.ToString() + "] ("+streamBuffers[i].ToString()+"): " + AL.GetErrorString(alError));
throw new Exception("Failed to delete streamBuffers[" + i.ToString() + "] ("+streamBuffers[i].ToString()+"): " + Al.GetErrorString(alError));
}
}
@@ -503,11 +505,11 @@ namespace Barotrauma.Sounds
}
else
{
AL.BindBufferToSource(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), 0);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.Buffer, 0);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to unbind buffer to non-streamed source: " + AL.GetErrorString(alError));
throw new Exception("Failed to unbind buffer to non-streamed source: " + Al.GetErrorString(alError));
}
}
@@ -526,47 +528,49 @@ namespace Barotrauma.Sounds
{
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
bool playing = AL.GetSourceState(alSource) == ALSourceState.Playing;
ALError alError = AL.GetError();
if (alError != ALError.NoError)
int state;
Al.GetSourcei(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.SourceState, out state);
bool playing = state == Al.Playing;
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to determine playing state from streamed source: " + AL.GetErrorString(alError));
throw new Exception("Failed to determine playing state from streamed source: " + Al.GetErrorString(alError));
}
int buffersToUnqueue = 0;
int[] unqueuedBuffers = null;
uint[] unqueuedBuffers = null;
if (!startedPlaying)
{
buffersToUnqueue = 0;
AL.GetSource(alSource, ALGetSourcei.BuffersProcessed, out buffersToUnqueue);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.GetSourcei(alSource, Al.BuffersProcessed, out buffersToUnqueue);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to determine processed buffers from streamed source: " + AL.GetErrorString(alError));
throw new Exception("Failed to determine processed buffers from streamed source: " + Al.GetErrorString(alError));
}
unqueuedBuffers = new int[buffersToUnqueue+emptyBuffers.Count];
AL.SourceUnqueueBuffers((int)alSource, buffersToUnqueue, unqueuedBuffers);
unqueuedBuffers = new uint[buffersToUnqueue+emptyBuffers.Count];
Al.SourceUnqueueBuffers(alSource, buffersToUnqueue, unqueuedBuffers);
for (int i = 0; i < emptyBuffers.Count; i++)
{
unqueuedBuffers[buffersToUnqueue + i] = (int)emptyBuffers[i];
unqueuedBuffers[buffersToUnqueue + i] = emptyBuffers[i];
}
buffersToUnqueue += emptyBuffers.Count;
emptyBuffers.Clear();
alError = AL.GetError();
if (alError != ALError.NoError)
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to unqueue buffers from streamed source: " + AL.GetErrorString(alError));
throw new Exception("Failed to unqueue buffers from streamed source: " + Al.GetErrorString(alError));
}
}
else
{
startedPlaying = false;
buffersToUnqueue = 4;
unqueuedBuffers = new int[4];
unqueuedBuffers = new uint[4];
for (int i = 0; i < 4; i++)
{
unqueuedBuffers[i] = (int)streamBuffers[i];
unqueuedBuffers[i] = streamBuffers[i];
}
}
@@ -612,20 +616,20 @@ namespace Barotrauma.Sounds
if (readSamples > 0)
{
AL.BufferData<short>(unqueuedBuffers[i], Sound.ALFormat, buffer, readSamples, Sound.SampleRate);
Al.BufferData<short>(unqueuedBuffers[i], Sound.ALFormat, buffer, readSamples, Sound.SampleRate);
alError = AL.GetError();
if (alError != ALError.NoError)
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to assign data to stream buffer: " +
AL.GetErrorString(alError) + ": " + unqueuedBuffers[i].ToString() + "/" + unqueuedBuffers.Length + ", readSamples: " + readSamples);
Al.GetErrorString(alError) + ": " + unqueuedBuffers[i].ToString() + "/" + unqueuedBuffers.Length + ", readSamples: " + readSamples);
}
AL.SourceQueueBuffer((int)alSource, unqueuedBuffers[i]);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.SourceQueueBuffer(alSource, unqueuedBuffers[i]);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to queue buffer[" + i.ToString() + "] to stream: " + AL.GetErrorString(alError));
throw new Exception("Failed to queue buffer[" + i.ToString() + "] to stream: " + Al.GetErrorString(alError));
}
}
else if (readSamples < 0)
@@ -637,10 +641,11 @@ namespace Barotrauma.Sounds
emptyBuffers.Add((uint)unqueuedBuffers[i]);
}
}
if (AL.GetSourceState(alSource) != ALSourceState.Playing)
Al.GetSourcei(alSource, Al.SourceState, out state);
if (state != Al.Playing)
{
AL.SourcePlay(alSource);
Al.SourcePlay(alSource);
}
}
}
@@ -2,7 +2,7 @@
using System.Threading;
using System.Collections.Generic;
using System.Xml.Linq;
using OpenTK.Audio.OpenAL;
using OpenAL;
using Microsoft.Xna.Framework;
using System.Linq;
using System.IO;
@@ -20,7 +20,7 @@ namespace Barotrauma.Sounds
}
private IntPtr alcDevice;
private OpenTK.ContextHandle alcContext;
private IntPtr alcContext;
public enum SourcePoolIndex
{
@@ -42,11 +42,11 @@ namespace Barotrauma.Sounds
{
if (Disabled) { return; }
listenerPosition = value;
AL.Listener(ALListener3f.Position,value.X,value.Y,value.Z);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Listener3f(Al.Position,value.X,value.Y,value.Z);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set listener position: " + AL.GetErrorString(alError));
throw new Exception("Failed to set listener position: " + Al.GetErrorString(alError));
}
}
}
@@ -59,11 +59,11 @@ namespace Barotrauma.Sounds
{
if (Disabled) { return; }
listenerOrientation[0] = value.X; listenerOrientation[1] = value.Y; listenerOrientation[2] = value.Z;
AL.Listener(ALListenerfv.Orientation, ref listenerOrientation);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Listenerfv(Al.Orientation, listenerOrientation);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set listener target vector: " + AL.GetErrorString(alError));
throw new Exception("Failed to set listener target vector: " + Al.GetErrorString(alError));
}
}
}
@@ -74,11 +74,11 @@ namespace Barotrauma.Sounds
{
if (Disabled) { return; }
listenerOrientation[3] = value.X; listenerOrientation[4] = value.Y; listenerOrientation[5] = value.Z;
AL.Listener(ALListenerfv.Orientation, ref listenerOrientation);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Listenerfv(Al.Orientation, listenerOrientation);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set listener up vector: " + AL.GetErrorString(alError));
throw new Exception("Failed to set listener up vector: " + Al.GetErrorString(alError));
}
}
}
@@ -92,11 +92,11 @@ namespace Barotrauma.Sounds
if (Disabled) { return; }
if (Math.Abs(ListenerGain - value) < 0.001f) { return; }
listenerGain = value;
AL.Listener(ALListenerf.Gain, listenerGain);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Listenerf(Al.Gain, listenerGain);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set listener gain: " + AL.GetErrorString(alError));
throw new Exception("Failed to set listener gain: " + Al.GetErrorString(alError));
}
}
}
@@ -126,8 +126,8 @@ namespace Barotrauma.Sounds
return;
}
AlcError alcError = Alc.GetError(alcDevice);
if (alcError != AlcError.NoError)
int alcError = Alc.GetError(alcDevice);
if (alcError != Alc.NoError)
{
//The audio device probably wasn't ready, this happens quite often
//Just wait a while and try again
@@ -136,7 +136,7 @@ namespace Barotrauma.Sounds
alcDevice = Alc.OpenDevice(null);
alcError = Alc.GetError(alcDevice);
if (alcError != AlcError.NoError)
if (alcError != Alc.NoError)
{
DebugConsole.ThrowError("Error initializing ALC device: " + alcError.ToString() + ". Disabling audio playback...");
Disabled = true;
@@ -161,14 +161,14 @@ namespace Barotrauma.Sounds
}
alcError = Alc.GetError(alcDevice);
if (alcError != AlcError.NoError)
if (alcError != Alc.NoError)
{
DebugConsole.ThrowError("Error after assigning ALC context: " + alcError.ToString() + ". Disabling audio playback...");
Disabled = true;
return;
}
ALError alError = ALError.NoError;
int alError = Al.NoError;
sourcePools = new SoundSourcePool[2];
sourcePools[(int)SourcePoolIndex.Default] = new SoundSourcePool(SOURCE_COUNT);
@@ -177,12 +177,12 @@ namespace Barotrauma.Sounds
sourcePools[(int)SourcePoolIndex.Voice] = new SoundSourcePool(8);
playingChannels[(int)SourcePoolIndex.Voice] = new SoundChannel[8];
AL.DistanceModel(ALDistanceModel.LinearDistanceClamped);
Al.DistanceModel(Al.LinearDistanceClamped);
alError = AL.GetError();
if (alError != ALError.NoError)
alError = Al.GetError();
if (alError != Al.NoError)
{
DebugConsole.ThrowError("Error setting distance model: " + AL.GetErrorString(alError) + ". Disabling audio playback...");
DebugConsole.ThrowError("Error setting distance model: " + Al.GetErrorString(alError) + ". Disabling audio playback...");
Disabled = true;
return;
}
@@ -239,7 +239,7 @@ namespace Barotrauma.Sounds
{
if (Disabled || srcInd < 0 || srcInd >= sourcePools[(int)poolIndex].ALSources.Length) return 0;
if (!AL.IsSource(sourcePools[(int)poolIndex].ALSources[srcInd]))
if (!Al.IsSource(sourcePools[(int)poolIndex].ALSources[srcInd]))
{
throw new Exception("alSources[" + srcInd.ToString() + "] is invalid!");
}
@@ -276,8 +276,8 @@ namespace Barotrauma.Sounds
{
for (int i = 0; i < sourcePools[0].ALSources.Length; i++)
{
AL.Source(sourcePools[0].ALSources[i], ALSourcef.MaxGain, i == ind ? 1.0f : 0.0f);
AL.Source(sourcePools[0].ALSources[i], ALSourcef.MinGain, 0.0f);
Al.Sourcef(sourcePools[0].ALSources[i], Al.MaxGain, i == ind ? 1.0f : 0.0f);
Al.Sourcef(sourcePools[0].ALSources[i], Al.MinGain, 0.0f);
}
}
#endif
@@ -503,10 +503,7 @@ namespace Barotrauma.Sounds
}
}
}
if (streamingThread != null && !streamingThread.ThreadState.HasFlag(ThreadState.Stopped))
{
streamingThread.Join();
}
streamingThread?.Join();
for (int i = loadedSounds.Count - 1; i >= 0; i--)
{
loadedSounds[i].Dispose();
@@ -514,7 +511,7 @@ namespace Barotrauma.Sounds
sourcePools[(int)SourcePoolIndex.Default]?.Dispose();
sourcePools[(int)SourcePoolIndex.Voice]?.Dispose();
if (!Alc.MakeContextCurrent(OpenTK.ContextHandle.Zero))
if (!Alc.MakeContextCurrent(IntPtr.Zero))
{
throw new Exception("Failed to detach the current ALC context! (error code: " + Alc.GetError(alcDevice).ToString() + ")");
}
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK.Audio.OpenAL;
using OpenAL;
using Microsoft.Xna.Framework;
using System.Runtime.InteropServices;
using System.Threading;
@@ -21,7 +21,7 @@ namespace Barotrauma.Sounds
public VideoSound(SoundManager owner, string filename, int sampleRate, Video vid) : base(owner, filename, true, false)
{
ALFormat = ALFormat.Stereo16;
ALFormat = Al.FormatStereo16;
SampleRate = sampleRate;
sampleQueue = new Queue<short[]>();
@@ -110,4 +110,4 @@ namespace Barotrauma.Sounds
}
}
}
}
}
@@ -1,6 +1,6 @@
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using OpenTK.Audio.OpenAL;
using OpenAL;
using System;
using System.Collections.Generic;
@@ -58,7 +58,7 @@ namespace Barotrauma.Sounds
{
VoipConfig.SetupEncoding();
ALFormat = ALFormat.Mono16;
ALFormat = Al.FormatMono16;
SampleRate = VoipConfig.FREQUENCY;
queue = q;
@@ -40,6 +40,9 @@ namespace Barotrauma.SpriteDeformations
[Serialize(false, true)]
public bool UseMovementSine { get; set; }
[Serialize(false, true)]
public bool StopWhenHostIsDead { get; set; }
/// <summary>
/// Only used if UseMovementSine is enabled. Multiplier for Pi.
/// </summary>