Faction Test v1.0.1.0
This commit is contained in:
@@ -8,9 +8,7 @@ namespace Barotrauma
|
||||
{
|
||||
public class GUICanvas : RectTransform
|
||||
{
|
||||
private static readonly object mutex = new object();
|
||||
|
||||
protected GUICanvas() : base(size, parent: null) { }
|
||||
protected GUICanvas() : base(Size, parent: null) { }
|
||||
|
||||
private static GUICanvas _instance;
|
||||
public static GUICanvas Instance
|
||||
@@ -33,7 +31,7 @@ namespace Barotrauma
|
||||
//GUICanvas stores the children as weak references, to allow elements that we no longer need to get garbage collected
|
||||
private readonly List<WeakReference<RectTransform>> childrenWeakRef = new List<WeakReference<RectTransform>>();
|
||||
|
||||
private static Vector2 size => new Vector2(GameMain.GraphicsWidth / (float)GUI.UIWidth, 1f);
|
||||
private static Vector2 Size => new Vector2(GameMain.GraphicsWidth / (float)GUI.UIWidth, 1f);
|
||||
|
||||
protected override Rectangle NonScaledUIRect => UIRect;
|
||||
|
||||
@@ -41,25 +39,27 @@ namespace Barotrauma
|
||||
|
||||
private static void OnChildrenChanged(RectTransform _)
|
||||
{
|
||||
lock (mutex)
|
||||
CrossThread.RequestExecutionOnMainThread(RefreshChildren);
|
||||
}
|
||||
|
||||
private static void RefreshChildren()
|
||||
{
|
||||
//add weak reference if we don't have one yet
|
||||
foreach (var child in _instance.Children)
|
||||
{
|
||||
//add weak reference if we don't have one yet
|
||||
foreach (var child in _instance.Children)
|
||||
if (!_instance.childrenWeakRef.Any(c => c.TryGetTarget(out var existingChild) && existingChild == child))
|
||||
{
|
||||
if (!_instance.childrenWeakRef.Any(c => c.TryGetTarget(out var existingChild) && existingChild == child))
|
||||
{
|
||||
_instance.childrenWeakRef.Add(new WeakReference<RectTransform>(child));
|
||||
}
|
||||
_instance.childrenWeakRef.Add(new WeakReference<RectTransform>(child));
|
||||
}
|
||||
//get rid of strong references
|
||||
_instance.children.Clear();
|
||||
//remove dead children
|
||||
for (int i = _instance.childrenWeakRef.Count - 2; i >= 0; i--)
|
||||
}
|
||||
//get rid of strong references
|
||||
_instance.children.Clear();
|
||||
//remove dead children
|
||||
for (int i = _instance.childrenWeakRef.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (!_instance.childrenWeakRef[i].TryGetTarget(out var child) || child.Parent != _instance)
|
||||
{
|
||||
if (!_instance.childrenWeakRef[i].TryGetTarget(out var child) || child.Parent != _instance)
|
||||
{
|
||||
_instance.childrenWeakRef.RemoveAt(i);
|
||||
}
|
||||
_instance.childrenWeakRef.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace Barotrauma
|
||||
// Turn public, if there is a need to call this manually.
|
||||
private static void RecalculateSize()
|
||||
{
|
||||
Vector2 recalculatedSize = size;
|
||||
Vector2 recalculatedSize = Size;
|
||||
|
||||
// Scale children that are supposed to encompass the whole screen so that they are properly scaled on ultrawide as well
|
||||
for (int i = 0; i < Instance.childrenWeakRef.Count; i++)
|
||||
@@ -109,7 +109,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
Instance.Resize(size, resizeChildren: true);
|
||||
Instance.Resize(Size, resizeChildren: true);
|
||||
Instance.GetAllChildren().Select(c => c.GUIComponent as GUITextBlock).ForEach(t => t?.SetTextPos());
|
||||
_instance.children.Clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user