Unstable 1.1.14.0

This commit is contained in:
Markus Isberg
2023-10-02 16:43:54 +03:00
parent 94f5a93a0c
commit cf8f0de659
606 changed files with 21906 additions and 11456 deletions
@@ -693,5 +693,52 @@ namespace Barotrauma
rectT.Parent = RectTransform;
Buttons.Add(new GUIButton(rectT, text) { OnClicked = onClick });
}
public static GUIMessageBox CreateLoadingBox(LocalizedString text, (LocalizedString Label, Action<GUIMessageBox> Action)[] buttons = null, Vector2? relativeSize = null)
{
buttons ??= Array.Empty<(LocalizedString Label, Action<GUIMessageBox> Action)>();
var relativeSizeFallback = relativeSize ?? (0.7f, 0.5f);
var newMessageBox = new GUIMessageBox(
headerText: "",
text: "",
relativeSize: relativeSizeFallback,
buttons: buttons.Select(b => b.Label).ToArray());
newMessageBox.InnerFrame.RectTransform.ScaleBasis = ScaleBasis.BothHeight;
for (int i = 0; i < buttons.Length; i++)
{
var capturedIndex = i;
newMessageBox.Buttons[i].OnClicked = (_, _) =>
{
buttons[capturedIndex].Action(newMessageBox);
return false;
};
}
const float throbberSize = 0.25f;
new GUITextBlock(
new RectTransform((0.9f, 0f), newMessageBox.InnerFrame.RectTransform, Anchor.Center, Pivot.BottomCenter) { RelativeOffset = (0f, -throbberSize * 0.5f) },
text: text, textAlignment: Alignment.Center, wrap: true);
// Throbber
new GUICustomComponent(
new RectTransform(Vector2.One * throbberSize, newMessageBox.InnerFrame.RectTransform, Anchor.Center, scaleBasis: ScaleBasis.BothHeight),
onDraw: static (sb, component) =>
{
GUIStyle.GenericThrobber.Draw(
sb,
spriteIndex: (int)(Timing.TotalTime * 20f) % GUIStyle.GenericThrobber.FrameCount,
pos: component.Rect.Center.ToVector2(),
color: Color.White,
origin: GUIStyle.GenericThrobber.FrameSize.ToVector2() * 0.5f,
rotate: 0f,
scale: component.Rect.Size.ToVector2() / GUIStyle.GenericThrobber.FrameSize.ToVector2());
});
MessageBoxes.Remove(newMessageBox);
MessageBoxes.Insert(0, newMessageBox);
return newMessageBox;
}
}
}