Unstable 0.17.7.0

This commit is contained in:
Markus Isberg
2022-04-08 00:34:17 +09:00
parent 95764d1fa8
commit 164d72ae3a
82 changed files with 852 additions and 385 deletions
@@ -484,7 +484,9 @@ namespace Barotrauma
(int)(HUDLayoutSettings.BottomRightInfoArea.Y + HUDLayoutSettings.BottomRightInfoArea.Height * 0.1f),
(int)(HUDLayoutSettings.BottomRightInfoArea.Width / 2),
(int)(HUDLayoutSettings.BottomRightInfoArea.Height * 0.7f)), character.Info.IsDisguisedAsAnother);
character.Info.DrawPortrait(spriteBatch, HUDLayoutSettings.PortraitArea.Location.ToVector2(), new Vector2(-12 * GUI.Scale, 4 * GUI.Scale), targetWidth: HUDLayoutSettings.PortraitArea.Width, true, character.Info.IsDisguisedAsAnother);
float yOffset = (GameMain.GameSession?.Campaign is MultiPlayerCampaign ? -10 : 4) * GUI.Scale;
character.Info.DrawPortrait(spriteBatch, HUDLayoutSettings.PortraitArea.Location.ToVector2(), new Vector2(-12 * GUI.Scale, yOffset), targetWidth: HUDLayoutSettings.PortraitArea.Width, true, character.Info.IsDisguisedAsAnother);
character.Info.DrawForeground(spriteBatch);
}
mouseOnPortrait = HUDLayoutSettings.BottomRightInfoArea.Contains(PlayerInput.MousePosition) && !character.ShouldLockHud();
if (mouseOnPortrait)
@@ -309,6 +309,32 @@ namespace Barotrauma
HUDLayoutSettings.BottomRightInfoArea.Height / (float)infoAreaPortraitBG.SourceRect.Height));
}
public void DrawForeground(SpriteBatch spriteBatch)
{
if (Character is null || GameMain.IsSingleplayer) { return; }
const int million = 1000000;
int xfraction = (int)(HUDLayoutSettings.BottomRightInfoArea.Width * 0.2f);
int yoffset = GUI.IntScale(6);
int walletAmount = Character.Wallet.Balance;
LocalizedString str = walletAmount >= million ? TextManager.Get("crewwallet.balance.toomuchtoshow") : TextManager.FormatCurrency(walletAmount);
Vector2 size = GUIStyle.Font.MeasureString(str);
int barHeight = GUI.IntScale(18);
Rectangle barRect = new Rectangle((int)(HUDLayoutSettings.BottomRightInfoArea.X + xfraction / 2.5f), HUDLayoutSettings.BottomRightInfoArea.Bottom - barHeight - yoffset, HUDLayoutSettings.BottomRightInfoArea.Width - xfraction, barHeight);
float textScale = Math.Max(0.1f, Math.Min(barRect.Width / size.X, barRect.Height / size.Y)) - 0.01f;
GUIStyle.WalletPortraitBG.Draw(spriteBatch, barRect, Color.White);
int iconSize = GUI.IntScale(28);
int iconXOffset = iconSize / 2;
Rectangle iconRect = new Rectangle(barRect.Right - iconXOffset, barRect.Top - iconSize / 4, iconSize, iconSize);
GUIStyle.CrewWalletIconSmall.Draw(spriteBatch, iconRect, Color.White);
var (scaledTextSizeX, scaledTextSizeY) = size * textScale;
GUIStyle.Font.DrawString(spriteBatch, str, new Vector2(barRect.Right - iconXOffset - scaledTextSizeX - GUI.IntScale(4), barRect.Center.Y - scaledTextSizeY / 2), GUIStyle.TextColorNormal, 0f, Vector2.Zero, textScale, SpriteEffects.None, 0f);
}
public void DrawPortrait(SpriteBatch spriteBatch, Vector2 screenPos, Vector2 offset, float targetWidth, bool flip = false, bool evaluateDisguise = false)
{
if (evaluateDisguise && IsDisguised) { return; }
@@ -512,23 +512,36 @@ namespace Barotrauma
}
/// <summary>
/// Scrolls the list to the specific element, currently only works when smooth scrolling and PadBottom are enabled.
/// Scrolls the list to the specific element.
/// </summary>
/// <param name="component"></param>
public void ScrollToElement(GUIComponent component)
public void ScrollToElement(GUIComponent component, bool playSound = true)
{
SoundPlayer.PlayUISound(GUISoundType.Click);
if (playSound) { SoundPlayer.PlayUISound(GUISoundType.Click); }
List<GUIComponent> children = Content.Children.ToList();
int index = children.IndexOf(component);
if (index < 0) { return; }
void performScroll(GUIComponent c)
{
if (SmoothScroll && PadBottom)
{
scrollToElement = c;
}
else
{
float diff = isHorizontal ? c.Rect.X - Content.Rect.X : c.Rect.Y - Content.Rect.Y;
ScrollBar.BarScroll += diff / TotalSize;
}
}
if (!Content.Children.Contains(component) || !component.Visible)
{
scrollToElement = null;
performScroll(null);
}
else
{
scrollToElement = component;
performScroll(component);
}
}
@@ -64,6 +64,8 @@ namespace Barotrauma
public readonly static GUISprite UIGlowSolidCircular = new GUISprite("UIGlowSolidCircular");
public readonly static GUISprite UIThermalGlow = new GUISprite("UIGlowSolidCircular");
public readonly static GUISprite ButtonPulse = new GUISprite("ButtonPulse");
public readonly static GUISprite WalletPortraitBG = new GUISprite("WalletPortraitBG");
public readonly static GUISprite CrewWalletIconSmall = new GUISprite("CrewWalletIconSmall");
public readonly static GUISprite EndRoundButtonPulse = new GUISprite("EndRoundButtonPulse");
@@ -96,6 +98,11 @@ namespace Barotrauma
/// </summary>
public readonly static GUIColor Yellow = new GUIColor("Yellow");
/// <summary>
/// Color to display the name of modded servers in the server list.
/// </summary>
public readonly static GUIColor ModdedServerColor = new GUIColor("ModdedServerColor");
public readonly static GUIColor ColorInventoryEmpty = new GUIColor("ColorInventoryEmpty");
public readonly static GUIColor ColorInventoryHalf = new GUIColor("ColorInventoryHalf");
public readonly static GUIColor ColorInventoryFull = new GUIColor("ColorInventoryFull");
@@ -50,6 +50,7 @@ namespace Barotrauma
private GUIImage sellValueChangeArrow;
private GUIDropDown sortingDropDown;
private GUITextBox searchBox;
private GUILayoutGroup categoryButtonContainer;
private GUIListBox storeBuyList, storeSellList, storeSellFromSubList;
/// <summary>
/// Can be null when there are no deals at the current location
@@ -482,7 +483,7 @@ namespace Barotrauma
};
// Item category buttons ------------------------------------------------
var categoryButtonContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.08f, 1.0f), storeInventoryContainer.RectTransform))
categoryButtonContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.08f, 1.0f), storeInventoryContainer.RectTransform))
{
RelativeSpacing = 0.02f
};
@@ -765,6 +766,34 @@ namespace Barotrauma
}
}
private void UpdateCategoryButtons()
{
var tabItems = activeTab switch
{
StoreTab.Buy => ActiveStore?.Stock,
StoreTab.Sell => itemsToSell,
StoreTab.SellSub => itemsToSellFromSub,
_ => null
} ?? Enumerable.Empty<PurchasedItem>();
foreach (var button in itemCategoryButtons)
{
if (!(button.UserData is MapEntityCategory category))
{
continue;
}
bool isButtonEnabled = false;
foreach (var item in tabItems)
{
if (item.ItemPrefab.Category.HasFlag(category))
{
isButtonEnabled = true;
break;
}
}
button.Enabled = isButtonEnabled;
}
}
private void ChangeStoreTab(StoreTab tab)
{
activeTab = tab;
@@ -774,6 +803,7 @@ namespace Barotrauma
}
sortingDropDown.SelectItem(tabSortingMethods[tab]);
relevantBalanceName.Text = IsBuying ? TextManager.Get("campaignstore.balance") : TextManager.Get("campaignstore.storebalance");
UpdateCategoryButtons();
SetShoppingCrateTotalText();
SetClearAllButtonStatus();
SetConfirmButtonBehavior();
@@ -879,7 +909,7 @@ namespace Barotrauma
prevDailySpecialCount = dailySpecialCount;
}
bool hasPermissions = HasTabPermissions(StoreTab.Sell);
bool hasPermissions = HasTabPermissions(StoreTab.Buy);
var existingItemFrames = new HashSet<GUIComponent>();
foreach (PurchasedItem item in ActiveStore.Stock)
{
@@ -931,7 +961,11 @@ namespace Barotrauma
removedItemFrames.AddRange(storeDailySpecialsGroup.Children.Where(c => c.UserData is PurchasedItem).Except(existingItemFrames).ToList());
}
removedItemFrames.ForEach(f => f.RectTransform.Parent = null);
if (activeTab == StoreTab.Buy) { FilterStoreItems(); }
if (activeTab == StoreTab.Buy)
{
UpdateCategoryButtons();
FilterStoreItems();
}
SortItems(StoreTab.Buy);
storeBuyList.BarScroll = prevBuyListScroll;
@@ -1011,7 +1045,11 @@ namespace Barotrauma
}
removedItemFrames.ForEach(f => f.RectTransform.Parent = null);
if (activeTab == StoreTab.Sell) { FilterStoreItems(); }
if (activeTab == StoreTab.Sell)
{
UpdateCategoryButtons();
FilterStoreItems();
}
SortItems(StoreTab.Sell);
storeSellList.BarScroll = prevSellListScroll;
@@ -1091,7 +1129,11 @@ namespace Barotrauma
}
removedItemFrames.ForEach(f => f.RectTransform.Parent = null);
if (activeTab == StoreTab.SellSub) { FilterStoreItems(); }
if (activeTab == StoreTab.SellSub)
{
UpdateCategoryButtons();
FilterStoreItems();
}
SortItems(StoreTab.SellSub);
storeSellFromSubList.BarScroll = prevSellListScroll;
@@ -50,19 +50,23 @@ namespace Barotrauma
private const ushort lowPingThreshold = 100;
private const ushort mediumPingThreshold = 200;
public readonly Client Client;
private ushort currentPing;
private readonly Client client;
private readonly Character character;
private readonly bool hasCharacter;
private readonly GUITextBlock textBlock;
private readonly GUIFrame frame;
public LinkedGUI(Client client, GUIFrame frame, bool hasCharacter, GUITextBlock textBlock)
private readonly GUIImage permissionIcon;
public LinkedGUI(Client client, GUIFrame frame, bool hasCharacter, GUITextBlock textBlock, GUIImage permissionIcon)
{
this.client = client;
this.Client = client;
this.textBlock = textBlock;
this.frame = frame;
this.hasCharacter = hasCharacter;
this.permissionIcon = permissionIcon;
}
public LinkedGUI(Character character, GUIFrame frame, bool hasCharacter, GUITextBlock textBlock)
@@ -75,33 +79,39 @@ namespace Barotrauma
public bool HasMultiplayerCharacterChanged()
{
if (client == null) return false;
bool characterState = client.Character != null;
if (characterState && client.Character.IsDead) characterState = false;
if (Client == null) { return false; }
bool characterState = Client.Character != null;
if (characterState && Client.Character.IsDead) characterState = false;
return hasCharacter != characterState;
}
public bool HasMultiplayerCharacterDied()
{
if (client == null || !hasCharacter || client.Character == null) return false;
return client.Character.IsDead;
if (Client == null || !hasCharacter || Client.Character == null) { return false; }
return Client.Character.IsDead;
}
public bool HasAICharacterDied()
{
if (character == null) return false;
if (character == null) { return false; }
return character.IsDead;
}
public void TryPingRefresh()
{
if (client == null) return;
if (currentPing == client.Ping) return;
currentPing = client.Ping;
if (Client == null) { return; }
if (currentPing == Client.Ping) { return; }
currentPing = Client.Ping;
textBlock.Text = currentPing.ToString();
textBlock.TextColor = GetPingColor();
}
public void TryPermissionIconRefresh(Sprite icon)
{
if (Client == null || permissionIcon == null) { return; }
permissionIcon.Sprite = icon;
}
private Color GetPingColor()
{
if (currentPing < lowPingThreshold)
@@ -196,6 +206,7 @@ namespace Barotrauma
for (int i = 0; i < linkedGUIList.Count; i++)
{
linkedGUIList[i].TryPingRefresh();
linkedGUIList[i].TryPermissionIconRefresh(GetPermissionIcon(linkedGUIList[i].Client));
if (linkedGUIList[i].HasMultiplayerCharacterChanged() || linkedGUIList[i].HasMultiplayerCharacterDied() || linkedGUIList[i].HasAICharacterDied())
{
RemoveCurrentElements();
@@ -549,31 +560,42 @@ namespace Barotrauma
GUITextBlock characterNameBlock = new GUITextBlock(new RectTransform(new Point(characterColumnWidth, paddedFrame.Rect.Height), paddedFrame.RectTransform),
ToolBox.LimitString(character.Info.Name, GUIStyle.Font, characterColumnWidth), textAlignment: Alignment.Center, textColor: character.Info.Job.Prefab.UIColor);
linkedGUIList.Add(new LinkedGUI(character, frame, !character.IsDead, null));
linkedGUIList.Add(new LinkedGUI(character, frame, !character.IsDead, textBlock: null));
}
private void CreateMultiPlayerListContentHolder(GUILayoutGroup headerFrame)
{
bool isCampaign = GameMain.GameSession?.Campaign is MultiPlayerCampaign;
GUIButton jobButton = new GUIButton(new RectTransform(new Vector2(0f, 1f), headerFrame.RectTransform), TextManager.Get("tabmenu.job"), style: "GUIButtonSmallFreeScale");
GUIButton characterButton = new GUIButton(new RectTransform(new Vector2(0f, 1f), headerFrame.RectTransform), TextManager.Get("name"), style: "GUIButtonSmallFreeScale");
GUIButton pingButton = new GUIButton(new RectTransform(new Vector2(0f, 1f), headerFrame.RectTransform), TextManager.Get("serverlistping"), style: "GUIButtonSmallFreeScale");
GUIButton walletButton = new GUIButton(new RectTransform(new Vector2(0f, 1f), headerFrame.RectTransform), TextManager.Get("crewwallet.wallet"), style: "GUIButtonSmallFreeScale");
if (isCampaign)
{
GUIButton walletButton = new GUIButton(new RectTransform(new Vector2(0f, 1f), headerFrame.RectTransform)
{
RelativeSize = new Vector2(walletColumnWidthPercentage * sizeMultiplier, 1f)
}, TextManager.Get("crewwallet.wallet"), style: "GUIButtonSmallFreeScale")
{
TextBlock = { Font = GUIStyle.HotkeyFont },
CanBeFocused = false,
ForceUpperCase = ForceUpperCase.Yes
};
walletColumnWidth = walletButton.Rect.Width;
}
sizeMultiplier = (headerFrame.Rect.Width - headerFrame.AbsoluteSpacing * (headerFrame.CountChildren - 1)) / (float)headerFrame.Rect.Width;
jobButton.RectTransform.RelativeSize = new Vector2(jobColumnWidthPercentage * sizeMultiplier, 1f);
characterButton.RectTransform.RelativeSize = new Vector2(characterColumnWidthPercentage * sizeMultiplier, 1f);
characterButton.RectTransform.RelativeSize = new Vector2((characterColumnWidthPercentage + (isCampaign ? 0 : walletColumnWidthPercentage)) * sizeMultiplier, 1f);
pingButton.RectTransform.RelativeSize = new Vector2(pingColumnWidthPercentage * sizeMultiplier, 1f);
walletButton.RectTransform.RelativeSize = new Vector2(walletColumnWidthPercentage * sizeMultiplier, 1f);
jobButton.TextBlock.Font = characterButton.TextBlock.Font = pingButton.TextBlock.Font = walletButton.TextBlock.Font = GUIStyle.HotkeyFont;
jobButton.CanBeFocused = characterButton.CanBeFocused = pingButton.CanBeFocused = walletButton.CanBeFocused = false;
jobButton.TextBlock.ForceUpperCase = characterButton.TextBlock.ForceUpperCase = pingButton.ForceUpperCase = walletButton.ForceUpperCase = ForceUpperCase.Yes;
jobButton.TextBlock.Font = characterButton.TextBlock.Font = pingButton.TextBlock.Font = GUIStyle.HotkeyFont;
jobButton.CanBeFocused = characterButton.CanBeFocused = pingButton.CanBeFocused = false;
jobButton.TextBlock.ForceUpperCase = characterButton.TextBlock.ForceUpperCase = pingButton.ForceUpperCase = ForceUpperCase.Yes;
jobColumnWidth = jobButton.Rect.Width;
characterColumnWidth = characterButton.Rect.Width;
pingColumnWidth = pingButton.Rect.Width;
walletColumnWidth = walletButton.Rect.Width;
}
private void CreateMultiPlayerList(bool refresh)
@@ -634,8 +656,10 @@ namespace Barotrauma
if (client != null)
{
CreateNameWithPermissionIcon(client, paddedFrame);
linkedGUIList.Add(new LinkedGUI(client, frame, true, new GUITextBlock(new RectTransform(new Point(pingColumnWidth, paddedFrame.Rect.Height), paddedFrame.RectTransform), client.Ping.ToString(), textAlignment: Alignment.Center)));
CreateNameWithPermissionIcon(client, paddedFrame, out GUIImage permissionIcon);
linkedGUIList.Add(new LinkedGUI(client, frame, true,
new GUITextBlock(new RectTransform(new Point(pingColumnWidth, paddedFrame.Rect.Height), paddedFrame.RectTransform), client.Ping.ToString(), textAlignment: Alignment.Center),
permissionIcon));
}
else
{
@@ -644,11 +668,12 @@ namespace Barotrauma
if (character is AICharacter)
{
linkedGUIList.Add(new LinkedGUI(character, frame, !character.IsDead, new GUITextBlock(new RectTransform(new Point(pingColumnWidth, paddedFrame.Rect.Height), paddedFrame.RectTransform), TextManager.Get("tabmenu.bot"), textAlignment: Alignment.Center) { ForceUpperCase = ForceUpperCase.Yes }));
linkedGUIList.Add(new LinkedGUI(character, frame, !character.IsDead,
new GUITextBlock(new RectTransform(new Point(pingColumnWidth, paddedFrame.Rect.Height), paddedFrame.RectTransform), TextManager.Get("tabmenu.bot"), textAlignment: Alignment.Center) { ForceUpperCase = ForceUpperCase.Yes }));
}
else
{
linkedGUIList.Add(new LinkedGUI(client: null, frame, true, null));
linkedGUIList.Add(new LinkedGUI(client: null, frame, true, textBlock: null, permissionIcon: null));
new GUICustomComponent(new RectTransform(new Point(pingColumnWidth, paddedFrame.Rect.Height), paddedFrame.RectTransform, Anchor.Center), onDraw: (sb, component) => DrawDisconnectedIcon(sb, component.Rect))
{
@@ -686,12 +711,15 @@ namespace Barotrauma
SelectedColor = Color.White
};
CreateNameWithPermissionIcon(client, paddedFrame);
CreateNameWithPermissionIcon(client, paddedFrame, out GUIImage permissionIcon);
linkedGUIList.Add(new LinkedGUI(client, frame, false,
new GUITextBlock(new RectTransform(new Point(pingColumnWidth, paddedFrame.Rect.Height), paddedFrame.RectTransform), client.Ping.ToString(), textAlignment: Alignment.Center),
permissionIcon));
if (client.Character is { } character)
{
CreateWalletCrewFrame(character, paddedFrame);
}
linkedGUIList.Add(new LinkedGUI(client, frame, false, new GUITextBlock(new RectTransform(new Point(pingColumnWidth, paddedFrame.Rect.Height), paddedFrame.RectTransform), client.Ping.ToString(), textAlignment: Alignment.Center)));
}
private int GetTeamIndex(Client client)
@@ -729,21 +757,47 @@ namespace Barotrauma
private void CreateWalletCrewFrame(Character character, GUILayoutGroup paddedFrame)
{
if (!(GameMain.GameSession?.Campaign is MultiPlayerCampaign)) { return; }
GUILayoutGroup walletLayout = new GUILayoutGroup(new RectTransform(new Point(walletColumnWidth, paddedFrame.Rect.Height), paddedFrame.RectTransform, Anchor.Center), childAnchor: Anchor.Center)
{
CanBeFocused = false
};
if (character.IsBot) { return; }
GUILayoutGroup paddedLayoutGroup = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 1f), walletLayout.RectTransform, Anchor.Center), isHorizontal: true)
{
Stretch = true
};
GUIImage icon = new GUIImage(new RectTransform(Vector2.One, paddedLayoutGroup.RectTransform, scaleBasis: ScaleBasis.BothHeight), style: "StoreTradingIcon", scaleToFit: true);
GUITextBlock walletBlock = new GUITextBlock(new RectTransform(Vector2.One, paddedLayoutGroup.RectTransform), string.Empty, textAlignment: Alignment.Right, font: GUIStyle.SubHeadingFont);
SetWalletText(walletBlock, character.Wallet);
if (character.IsBot) { return; }
Sprite walletSprite = GUIStyle.CrewWalletIconSmall.Value.Sprite;
GUIImage icon = new GUIImage(new RectTransform(Vector2.One, paddedLayoutGroup.RectTransform, scaleBasis: ScaleBasis.BothHeight), walletSprite, scaleToFit: true);
GUITextBlock walletBlock = new GUITextBlock(new RectTransform(Vector2.One, paddedLayoutGroup.RectTransform), string.Empty, textAlignment: Alignment.Right, font: GUIStyle.Font)
{
AutoScaleHorizontal = true,
Padding = Vector4.Zero
};
GUIImage largeIcon = new GUIImage(new RectTransform(Vector2.One, paddedLayoutGroup.RectTransform), walletSprite, scaleToFit: true)
{
IgnoreLayoutGroups = true,
Visible = false
};
if (character.IsBot)
{
largeIcon.Visible = true;
icon.Visible = false;
walletBlock.Visible = false;
largeIcon.Enabled = false;
return;
}
walletLayout.Recalculate();
paddedLayoutGroup.Recalculate();
SetWalletText(walletBlock, character.Wallet, icon, largeIcon);
if (GameMain.GameSession?.Campaign is MultiPlayerCampaign campaign)
{
@@ -751,47 +805,56 @@ namespace Barotrauma
campaign.OnMoneyChanged.RegisterOverwriteExisting(eventIdentifier, e =>
{
if (!(e.Owner is Some<Character> { Value: var owner }) || owner != character) { return; }
SetWalletText(walletBlock, e.Wallet);
SetWalletText(walletBlock, e.Wallet, icon, largeIcon);
});
registeredEvents.Add(eventIdentifier);
}
static void SetWalletText(GUITextBlock block, Wallet wallet)
static void SetWalletText(GUITextBlock block, Wallet wallet, GUIImage icon, GUIImage largeIcon)
{
const int million = 1000000,
tooSmallPixelTreshold = 50; // 50 pixels is just not enough to see any meaningful info
block.Text = TextManager.FormatCurrency(wallet.Balance);
block.ToolTip = string.Empty;
if (block.TextSize.X + block.Padding.X + block.Padding.Z > block.Rect.Width)
if (wallet.Balance >= million)
{
block.ToolTip = block.Text;
block.Text = TextManager.Get("crewwallet.balance.toomuchtoshow");
block.ToolTip = block.Text;
}
largeIcon.Visible = false;
icon.Visible = true;
block.Visible = true;
if (tooSmallPixelTreshold > block.Rect.Width)
{
largeIcon.Visible = true;
icon.Visible = false;
block.Visible = false;
largeIcon.ToolTip = block.Text;
}
}
}
private void CreateNameWithPermissionIcon(Client client, GUILayoutGroup paddedFrame)
private void CreateNameWithPermissionIcon(Client client, GUILayoutGroup paddedFrame, out GUIImage permissionIcon)
{
GUITextBlock characterNameBlock;
Sprite permissionIcon = GetPermissionIcon(client);
Sprite permissionIconSprite = GetPermissionIcon(client);
JobPrefab prefab = client.Character?.Info?.Job?.Prefab;
Color nameColor = prefab != null ? prefab.UIColor : Color.White;
if (permissionIcon != null)
{
Point iconSize = permissionIcon.SourceRect.Size;
float characterNameWidthAdjustment = (iconSize.X + paddedFrame.AbsoluteSpacing) / characterColumnWidth;
Point iconSize = new Point((int)(paddedFrame.Rect.Height * 0.8f));
float characterNameWidthAdjustment = (iconSize.X + paddedFrame.AbsoluteSpacing) / characterColumnWidth;
characterNameBlock = new GUITextBlock(new RectTransform(new Point(characterColumnWidth, paddedFrame.Rect.Height), paddedFrame.RectTransform),
ToolBox.LimitString(client.Name, GUIStyle.Font, (int)(characterColumnWidth - paddedFrame.Rect.Width * characterNameWidthAdjustment)), textAlignment: Alignment.Center, textColor: nameColor);
characterNameBlock = new GUITextBlock(new RectTransform(new Point(characterColumnWidth, paddedFrame.Rect.Height), paddedFrame.RectTransform),
ToolBox.LimitString(client.Name, GUIStyle.Font, (int)(characterColumnWidth - paddedFrame.Rect.Width * characterNameWidthAdjustment)), textAlignment: Alignment.Center, textColor: nameColor);
float iconWidth = iconSize.X / (float)characterColumnWidth;
int xOffset = (int)(jobColumnWidth + characterNameBlock.TextPos.X - GUIStyle.Font.MeasureString(characterNameBlock.Text).X / 2f - paddedFrame.AbsoluteSpacing - iconWidth * paddedFrame.Rect.Width);
new GUIImage(new RectTransform(new Vector2(iconWidth, 1f), paddedFrame.RectTransform) { AbsoluteOffset = new Point(xOffset + 2, 0) }, permissionIcon) { IgnoreLayoutGroups = true };
}
else
{
characterNameBlock = new GUITextBlock(new RectTransform(new Point(characterColumnWidth, paddedFrame.Rect.Height), paddedFrame.RectTransform),
ToolBox.LimitString(client.Name, GUIStyle.Font, characterColumnWidth), textAlignment: Alignment.Center, textColor: nameColor);
}
float iconWidth = iconSize.X / (float)characterColumnWidth;
int xOffset = (int)(jobColumnWidth + characterNameBlock.TextPos.X - GUIStyle.Font.MeasureString(characterNameBlock.Text).X / 2f - paddedFrame.AbsoluteSpacing - iconWidth * paddedFrame.Rect.Width);
permissionIcon = new GUIImage(new RectTransform(new Vector2(iconWidth, 1f), paddedFrame.RectTransform) { AbsoluteOffset = new Point(xOffset + 2, 0) }, permissionIconSprite) { IgnoreLayoutGroups = true };
if (client.Character != null && client.Character.IsDead)
{
@@ -801,7 +864,7 @@ namespace Barotrauma
private Sprite GetPermissionIcon(Client client)
{
if (GameMain.NetworkMember == null || client == null || !client.HasPermissions) return null;
if (GameMain.NetworkMember == null || client == null || !client.HasPermissions) { return null; }
if (client.IsOwner) // Owner cannot be kicked
{
@@ -898,7 +961,7 @@ namespace Barotrauma
GUILayoutGroup walletLayout = new GUILayoutGroup(new RectTransform(ToolBox.PaddingSizeParentRelative(walletFrame.RectTransform, 0.9f), walletFrame.RectTransform, anchor: Anchor.Center));
GUILayoutGroup headerLayout = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.33f), walletLayout.RectTransform), isHorizontal: true);
GUIImage icon = new GUIImage(new RectTransform(Vector2.One, headerLayout.RectTransform, scaleBasis: ScaleBasis.BothHeight), style: "StoreTradingIcon", scaleToFit: true);
GUIImage icon = new GUIImage(new RectTransform(Vector2.One, headerLayout.RectTransform, scaleBasis: ScaleBasis.BothHeight), style: "CrewWalletIconLarge", scaleToFit: true);
float relativeX = icon.RectTransform.NonScaledSize.X / (float)icon.Parent.RectTransform.NonScaledSize.X;
GUILayoutGroup headerTextLayout = new GUILayoutGroup(new RectTransform(new Vector2(1.0f - relativeX, 1f), headerLayout.RectTransform), isHorizontal: true) { Stretch = true };
new GUITextBlock(new RectTransform(new Vector2(0.5f, 1f), headerTextLayout.RectTransform), TextManager.Get("crewwallet.wallet"), font: GUIStyle.LargeFont);
@@ -950,7 +1013,7 @@ namespace Barotrauma
GUITextBlock rightBalance = new GUITextBlock(new RectTransform(new Vector2(1f, 0.5f), rightLayout.RectTransform), string.Empty, textAlignment: Alignment.Right) { TextColor = GUIStyle.Red };
GUILayoutGroup centerLayout = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.9f), mainLayout.RectTransform, Anchor.Center), childAnchor: Anchor.Center) { IgnoreLayoutGroups = true };
new GUIFrame(new RectTransform(new Vector2(0f, 1f), centerLayout.RectTransform, Anchor.Center), style: "VerticalLine") { IgnoreLayoutGroups = true };
GUIButton centerButton = new GUIButton(new RectTransform(new Vector2(0.6f), centerLayout.RectTransform, scaleBasis: ScaleBasis.BothHeight, anchor: Anchor.Center), style: "GUIButtonTransferArrow");
GUIButton centerButton = new GUIButton(new RectTransform(new Vector2(1f), centerLayout.RectTransform, scaleBasis: ScaleBasis.BothHeight, anchor: Anchor.Center), style: "GUIButtonTransferArrow");
GUILayoutGroup inputLayout = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.25f), paddedTransferMenuLayout.RectTransform), childAnchor: Anchor.Center);
GUINumberInput transferAmountInput = new GUINumberInput(new RectTransform(new Vector2(0.5f, 1f), inputLayout.RectTransform), GUINumberInput.NumberType.Int, hidePlusMinusButtons: true)
@@ -477,6 +477,8 @@ namespace Barotrauma
DebugConsole.Init();
ContentPackageManager.LogEnabledRegularPackageErrors();
#if !DEBUG && !OSX
GameAnalyticsManager.InitIfConsented();
#endif
@@ -59,6 +59,7 @@ namespace Barotrauma.Items.Components
public override bool ShouldDrawHUD(Character character)
{
if (item.HiddenInGame) { return false; }
if (!HasRequiredItems(character, false) || character.SelectedConstruction != item) { return false; }
if (character.IsTraitor && item.ConditionPercentage > MinSabotageCondition) { return true; }
@@ -222,6 +223,7 @@ namespace Barotrauma.Items.Components
partial void UpdateProjSpecific(float deltaTime)
{
if (item.HiddenInGame) { return; }
if (FakeBrokenTimer > 0.0f)
{
item.FakeBroken = true;
@@ -358,9 +358,9 @@ namespace Barotrauma
WorldRect.Width, WorldRect.Height);
GUI.DrawLine(spriteBatch,
new Vector2(currentHullRect.X, -currentHullRect.Y),
new Vector2(connectedHullRect.X, -connectedHullRect.Y),
GUIStyle.Green, width: 2);
new Vector2(currentHullRect.X, -currentHullRect.Y),
new Vector2(connectedHullRect.X, -connectedHullRect.Y),
GUIStyle.Green, width: 2);
}
}
}
@@ -378,7 +378,7 @@ namespace Barotrauma
if (section.ColorStrength < 0.01f || section.Color.A < 1) { continue; }
if (DecalManager.GrimeSprites.None())
if (section.GrimeSprite == null)
{
GUI.DrawRectangle(spriteBatch,
new Vector2(drawOffset.X + rect.X + section.Rect.X, -(drawOffset.Y + rect.Y + section.Rect.Y)),
@@ -389,8 +389,7 @@ namespace Barotrauma
{
Vector2 sectionPos = new Vector2(drawPos.X + section.Rect.Location.X, -(drawPos.Y + section.Rect.Location.Y));
Vector2 randomOffset = new Vector2(section.Noise.X - 0.5f, section.Noise.Y - 0.5f) * 15.0f;
var sprite = DecalManager.GrimeSprites[$"{nameof(GrimeSprite)}{i % DecalManager.GrimeSpriteCount}"].Sprite;
sprite.Draw(spriteBatch, sectionPos + randomOffset, section.GetStrengthAdjustedColor(), scale: 1.25f);
section.GrimeSprite.Draw(spriteBatch, sectionPos + randomOffset, section.GetStrengthAdjustedColor(), scale: 1.25f);
}
}
}
@@ -81,8 +81,8 @@ namespace Barotrauma
}
Vector2 center = new Vector2((minX + maxX) / 2.0f, (minY + maxY) / 2.0f);
if (Submarine.MainSub != null) { center -= Submarine.MainSub.HiddenSubPosition; }
center.X -= center.X % Submarine.GridSize.X;
center.Y -= center.Y % Submarine.GridSize.Y;
center.X -= MathUtils.RoundTowardsClosest(center.X, Submarine.GridSize.X);
center.Y -= MathUtils.RoundTowardsClosest(center.Y, Submarine.GridSize.Y);
MapEntity.SelectedList.Clear();
assemblyEntities.ForEach(e => MapEntity.AddSelection(e));
@@ -143,7 +143,7 @@ namespace Barotrauma
Stretch = true,
RelativeSpacing = 0.01f
};
new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("MirrorEntityX"))
new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("MirrorEntityX"), style: "GUIButtonSmall")
{
ToolTip = TextManager.Get("MirrorEntityXToolTip"),
OnClicked = (button, data) =>
@@ -156,7 +156,7 @@ namespace Barotrauma
return true;
}
};
new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("MirrorEntityY"))
new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("MirrorEntityY"), style: "GUIButtonSmall")
{
ToolTip = TextManager.Get("MirrorEntityYToolTip"),
OnClicked = (button, data) =>
@@ -169,7 +169,7 @@ namespace Barotrauma
return true;
}
};
new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("ReloadSprite"))
new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("ReloadSprite"), style: "GUIButtonSmall")
{
OnClicked = (button, data) =>
{
@@ -178,7 +178,7 @@ namespace Barotrauma
return true;
}
};
new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("ResetToPrefab"))
new GUIButton(new RectTransform(new Vector2(0.23f, 1.0f), buttonContainer.RectTransform), TextManager.Get("ResetToPrefab"), style: "GUIButtonSmall")
{
OnClicked = (button, data) =>
{
@@ -186,9 +186,8 @@ namespace Barotrauma
{
if (predicate != null)
{
if (!predicate(e)) continue;
if (!predicate(e)) { continue; }
}
hull.DrawSectionColors(spriteBatch);
}
}
@@ -299,7 +299,7 @@ namespace Barotrauma
};
new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), spawnTypeContainer.RectTransform), TextManager.Get("SpawnType"));
var button = new GUIButton(new RectTransform(new Vector2(0.1f, 1.0f), spawnTypeContainer.RectTransform, scaleBasis: ScaleBasis.BothHeight), style: "GUIMinusButton")
var button = new GUIButton(new RectTransform(Vector2.One, spawnTypeContainer.RectTransform, scaleBasis: ScaleBasis.BothHeight), style: "GUIMinusButton")
{
UserData = -1,
OnClicked = ChangeSpawnType
@@ -308,7 +308,7 @@ namespace Barotrauma
{
UserData = "spawntypetext"
};
button = new GUIButton(new RectTransform(new Vector2(0.1f, 1.0f), spawnTypeContainer.RectTransform, scaleBasis: ScaleBasis.BothHeight), style: "GUIPlusButton")
button = new GUIButton(new RectTransform(Vector2.One, spawnTypeContainer.RectTransform, scaleBasis: ScaleBasis.BothHeight), style: "GUIPlusButton")
{
UserData = 1,
OnClicked = ChangeSpawnType
@@ -108,7 +108,7 @@ namespace Barotrauma.Networking
{
return;
}
if (!Permissions.HasFlag(permission)) Permissions |= permission;
if (!Permissions.HasFlag(permission)) { Permissions |= permission; }
}
public void RemovePermission(ClientPermissions permission)
@@ -117,7 +117,7 @@ namespace Barotrauma.Networking
{
return;
}
if (Permissions.HasFlag(permission)) Permissions &= ~permission;
if (Permissions.HasFlag(permission)) { Permissions &= ~permission; }
}
public bool HasPermission(ClientPermissions permission)
@@ -51,6 +51,17 @@ namespace Barotrauma.Networking
set;
}
public DateTime LastOffsetAckTime
{
get;
private set;
}
public void RecordOffsetAckTime()
{
LastOffsetAckTime = DateTime.Now;
}
public float BytesPerSecond
{
get;
@@ -91,6 +102,8 @@ namespace Barotrauma.Networking
Connection = connection;
Status = FileTransferStatus.NotStarted;
LastOffsetAckTime = DateTime.Now - new TimeSpan(days: 0, hours: 0, minutes: 5, seconds: 0);
}
public void OpenStream()
@@ -214,11 +227,11 @@ namespace Barotrauma.Networking
fileName != existingTransfer.FileName)
{
GameMain.Client.CancelFileTransfer(transferId);
DebugConsole.ThrowError("File transfer error: file transfer initiated with an ID that's already in use");
DebugConsole.AddWarning("File transfer error: file transfer initiated with an ID that's already in use");
}
else //resend acknowledgement packet
{
GameMain.Client.UpdateFileTransfer(transferId, existingTransfer.Received, existingTransfer.LastSeen);
GameMain.Client.UpdateFileTransfer(existingTransfer, existingTransfer.Received, existingTransfer.LastSeen);
}
return;
}
@@ -285,7 +298,7 @@ namespace Barotrauma.Networking
}
activeTransfers.Add(newTransfer);
GameMain.Client.UpdateFileTransfer(transferId, 0, 0); //send acknowledgement packet
GameMain.Client.UpdateFileTransfer(newTransfer, 0, 0); //send acknowledgement packet
}
break;
case (byte)FileTransferMessageType.TransferOnSameMachine:
@@ -333,7 +346,7 @@ namespace Barotrauma.Networking
if (!finishedTransfers.Any(t => t.transferId == transferId))
{
GameMain.Client.CancelFileTransfer(transferId);
DebugConsole.ThrowError("File transfer error: received data without a transfer initiation message");
DebugConsole.AddWarning("File transfer error: received data without a transfer initiation message");
}
return;
}
@@ -344,7 +357,7 @@ namespace Barotrauma.Networking
{
activeTransfer.LastSeen = Math.Max(offset, activeTransfer.LastSeen);
DebugConsole.Log($"Received {bytesToRead} bytes of the file {activeTransfer.FileName} (ignoring: offset {offset}, waiting for {activeTransfer.Received})");
GameMain.Client.UpdateFileTransfer(activeTransfer.ID, activeTransfer.Received, activeTransfer.LastSeen);
GameMain.Client.UpdateFileTransfer(activeTransfer, activeTransfer.Received, activeTransfer.LastSeen);
return;
}
activeTransfer.LastSeen = offset;
@@ -375,7 +388,7 @@ namespace Barotrauma.Networking
return;
}
GameMain.Client.UpdateFileTransfer(activeTransfer.ID, activeTransfer.Received, activeTransfer.LastSeen, reliable: activeTransfer.Status == FileTransferStatus.Finished);
GameMain.Client.UpdateFileTransfer(activeTransfer, activeTransfer.Received, activeTransfer.LastSeen, reliable: activeTransfer.Status == FileTransferStatus.Finished);
if (activeTransfer.Status == FileTransferStatus.Finished)
{
activeTransfer.Dispose();
@@ -1947,7 +1947,6 @@ namespace Barotrauma.Networking
existingClient.Character = null;
existingClient.Karma = tc.Karma;
existingClient.Muted = tc.Muted;
existingClient.HasPermissions = tc.HasPermissions;
existingClient.InGame = tc.InGame;
existingClient.IsOwner = tc.IsOwner;
existingClient.AllowKicking = tc.AllowKicking;
@@ -2493,12 +2492,18 @@ namespace Barotrauma.Networking
CancelFileTransfer(transfer.ID);
}
public void UpdateFileTransfer(int id, int expecting, int lastSeen, bool reliable = false)
public void UpdateFileTransfer(FileReceiver.FileTransferIn transfer, int expecting, int lastSeen, bool reliable = false)
{
if (!reliable && (DateTime.Now - transfer.LastOffsetAckTime).TotalSeconds < 1)
{
return;
}
transfer.RecordOffsetAckTime();
IWriteMessage msg = new WriteOnlyMessage();
msg.Write((byte)ClientPacketHeader.FILE_REQUEST);
msg.Write((byte)FileTransferMessageType.Data);
msg.Write((byte)id);
msg.Write((byte)transfer.ID);
msg.Write(expecting);
msg.Write(lastSeen);
clientPeer.Send(msg, reliable ? DeliveryMethod.Reliable : DeliveryMethod.Unreliable);
@@ -2784,7 +2789,9 @@ namespace Barotrauma.Networking
public void ShowSubmarineChangeVoteInterface(Client starter, SubmarineInfo info, VoteType type, float timeOut)
{
if (info == null || votingInterface != null) { return; }
if (info == null) { return; }
if (votingInterface != null && votingInterface.VoteRunning) { return; }
votingInterface?.Remove();
votingInterface = VotingInterface.CreateSubmarineVotingInterface(starter, info, type, timeOut);
}
#endregion
@@ -2792,12 +2799,13 @@ namespace Barotrauma.Networking
#region Money Transfer Voting
public void ShowMoneyTransferVoteInterface(Client starter, Client from, int amount, Client to, float timeOut)
{
if (votingInterface != null) { return; }
if (votingInterface != null && votingInterface.VoteRunning) { return; }
if (from == null && to == null)
{
DebugConsole.ThrowError("Tried to initiate a vote for transferring from null to null!");
return;
}
votingInterface?.Remove();
votingInterface = VotingInterface.CreateMoneyTransferVotingInterface(starter, from, to, amount, timeOut);
}
#endregion
@@ -78,24 +78,6 @@ namespace Barotrauma.Networking
get;
private set;
} = new List<ulong>();
public bool ContentPackagesMatch()
{
//make sure we have all the packages the server requires
if (ContentPackageHashes.Count != ContentPackageWorkshopIds.Count) { return false; }
for (int i = 0; i < ContentPackageWorkshopIds.Count; i++)
{
string hash = ContentPackageHashes[i];
UInt64 id = ContentPackageWorkshopIds[i];
if (!GameMain.ServerListScreen.ContentPackagesByHash.ContainsKey(hash))
{
if (GameMain.ServerListScreen.ContentPackagesByWorkshopId.ContainsKey(id)) { return false; }
if (id == 0) { return false; }
}
}
return true;
}
public void CreatePreviewWindow(GUIFrame frame)
{
@@ -105,7 +87,8 @@ namespace Barotrauma.Networking
var title = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), frame.RectTransform), ServerName, font: GUIStyle.LargeFont)
{
ToolTip = ServerName
ToolTip = ServerName,
CanBeFocused = false
};
title.Text = ToolBox.LimitString(title.Text, title.Font, (int)(title.Rect.Width * 0.85f));
@@ -130,7 +113,11 @@ namespace Barotrauma.Networking
};
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), frame.RectTransform),
TextManager.AddPunctuation(':', TextManager.Get("ServerListVersion"), string.IsNullOrEmpty(GameVersion) ? TextManager.Get("Unknown") : GameVersion));
TextManager.AddPunctuation(':', TextManager.Get("ServerListVersion"),
string.IsNullOrEmpty(GameVersion) ? TextManager.Get("Unknown") : GameVersion))
{
CanBeFocused = false
};
bool hidePlaystyleBanner = !PlayStyle.HasValue;
if (!hidePlaystyleBanner)
@@ -141,15 +128,23 @@ namespace Barotrauma.Networking
var playStyleBanner = new GUIImage(new RectTransform(new Point(frame.Rect.Width, (int)(frame.Rect.Width / playStyleBannerAspectRatio)), frame.RectTransform),
playStyleBannerSprite, null, true);
var playStyleName = new GUITextBlock(new RectTransform(new Vector2(0.15f, 0.0f), playStyleBanner.RectTransform) { RelativeOffset = new Vector2(0.0f, 0.06f) },
TextManager.AddPunctuation(':', TextManager.Get("serverplaystyle"), TextManager.Get("servertag."+ playStyle)), textColor: Color.White,
font: GUIStyle.SmallFont, textAlignment: Alignment.Center,
var playStyleName = new GUITextBlock(
new RectTransform(new Vector2(0.15f, 0.0f), playStyleBanner.RectTransform)
{ RelativeOffset = new Vector2(0.0f, 0.06f) },
TextManager.AddPunctuation(':', TextManager.Get("serverplaystyle"),
TextManager.Get("servertag." + playStyle)), textColor: Color.White,
font: GUIStyle.SmallFont, textAlignment: Alignment.Center,
color: ServerListScreen.PlayStyleColors[(int)playStyle], style: "GUISlopedHeader");
playStyleName.RectTransform.NonScaledSize = (playStyleName.Font.MeasureString(playStyleName.Text) + new Vector2(20, 5) * GUI.Scale).ToPoint();
playStyleName.RectTransform.IsFixedSize = true;
}
var serverType = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), frame.RectTransform),
TextManager.Get((OwnerID != 0 || LobbyID != 0) ? "SteamP2PServer" : "DedicatedServer"), textAlignment: Alignment.TopLeft);
TextManager.Get((OwnerID != 0 || LobbyID != 0) ? "SteamP2PServer" : "DedicatedServer"),
textAlignment: Alignment.TopLeft)
{
CanBeFocused = false
};
serverType.RectTransform.MinSize = new Point(0, (int)(serverType.Rect.Height * 1.5f));
var content = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.6f), frame.RectTransform))
@@ -270,7 +265,11 @@ namespace Barotrauma.Networking
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), content.RectTransform),
TextManager.Get("ServerListContentPackages"), textAlignment: Alignment.Center, font: GUIStyle.SubHeadingFont);
var contentPackageList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.3f), frame.RectTransform)) { ScrollBarVisible = true };
var contentPackageList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.3f), frame.RectTransform))
{
ScrollBarVisible = true,
OnSelected = (component, o) => false
};
if (ContentPackageNames.Count == 0)
{
new GUITextBlock(new RectTransform(Vector2.One, contentPackageList.Content.RectTransform), TextManager.Get("Unknown"), textAlignment: Alignment.Center)
@@ -282,28 +281,30 @@ namespace Barotrauma.Networking
{
for (int i = 0; i < ContentPackageNames.Count; i++)
{
var packageText = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.15f), contentPackageList.Content.RectTransform) { MinSize = new Point(0, 15) },
var packageText = new GUITickBox(
new RectTransform(new Vector2(1.0f, 0.15f), contentPackageList.Content.RectTransform)
{ MinSize = new Point(0, 15) },
ContentPackageNames[i])
{
CanBeFocused = false
Enabled = false
};
packageText.Box.Enabled = true;
packageText.TextBlock.Enabled = true;
if (i < ContentPackageHashes.Count)
{
if (ContentPackageManager.AllPackages.Any(contentPackage => contentPackage.Hash.StringRepresentation == ContentPackageHashes[i]))
{
packageText.TextColor = GUIStyle.Green;
packageText.Selected = true;
continue;
}
//workshop download link found
if (i < ContentPackageWorkshopIds.Count && ContentPackageWorkshopIds[i] != 0)
else if (i < ContentPackageWorkshopIds.Count && ContentPackageWorkshopIds[i] != 0)
{
packageText.TextColor = GUIStyle.Yellow;
packageText.ToolTip = TextManager.GetWithVariable("ServerListIncompatibleContentPackageWorkshopAvailable", "[contentpackage]", ContentPackageNames[i]);
}
else //no package or workshop download link found, tough luck
else //no package or workshop download link found (TODO: update text to say that they could be downloaded through the server)
{
packageText.TextColor = GUIStyle.Red;
packageText.TextColor = GameMain.VanillaContent.NameMatches(ContentPackageNames[i]) ? GUIStyle.Red : GUIStyle.Yellow;
packageText.ToolTip = TextManager.GetWithVariables("ServerListIncompatibleContentPackage",
("[contentpackage]", ContentPackageNames[i]), ("[hash]", ContentPackageHashes[i]));
}
@@ -342,7 +343,7 @@ namespace Barotrauma.Networking
}
if (ContentPackageNames.Count > 0)
{
tags.Add(ContentPackageNames.Count > 1 || ContentPackageNames[0] != GameMain.VanillaContent?.Name ? "modded.true" : "modded.false");
tags.Add(ContentPackageNames.Count > 1 || !GameMain.VanillaContent.NameMatches(ContentPackageNames[0]) ? "modded.true" : "modded.false");
}
return tags;
}
@@ -336,7 +336,7 @@ namespace Barotrauma.Particles
Hull collidedHull = Hull.FindHull(position);
if (collidedHull != null)
{
if (prefab.DeleteOnCollision) return UpdateResult.Delete;
if (prefab.DeleteOnCollision) { return UpdateResult.Delete; }
OnWallCollisionOutside(collidedHull);
}
}
@@ -346,20 +346,10 @@ namespace Barotrauma.Particles
Vector2 collisionNormal = Vector2.Zero;
if (velocity.Y < 0.0f && position.Y - prefab.CollisionRadius * size.Y < hullRect.Y - hullRect.Height)
{
if (prefab.DeleteOnCollision)
{
OnCollision?.Invoke(position, currentHull);
return UpdateResult.Delete;
}
collisionNormal = new Vector2(0.0f, 1.0f);
}
else if (velocity.Y > 0.0f && position.Y + prefab.CollisionRadius * size.Y > hullRect.Y)
{
if (prefab.DeleteOnCollision)
{
OnCollision?.Invoke(position, currentHull);
return UpdateResult.Delete;
}
collisionNormal = new Vector2(0.0f, -1.0f);
}
@@ -379,18 +369,21 @@ namespace Barotrauma.Particles
break;
}
if (prefab.DeleteOnCollision && !gapFound)
{
OnCollision?.Invoke(position, currentHull);
return UpdateResult.Delete;
}
handleCollision(gapFound, collisionNormal);
}
collisionNormal = Vector2.Zero;
if (velocity.X < 0.0f && position.X - prefab.CollisionRadius * size.X < hullRect.X)
{
if (prefab.DeleteOnCollision) { return UpdateResult.Delete; }
collisionNormal = new Vector2(1.0f, 0.0f);
}
else if (velocity.X > 0.0f && position.X + prefab.CollisionRadius * size.X > hullRect.Right)
{
if (prefab.DeleteOnCollision) { return UpdateResult.Delete; }
collisionNormal = new Vector2(-1.0f, 0.0f);
}
@@ -408,7 +401,11 @@ namespace Barotrauma.Particles
gapFound = true;
break;
}
if (prefab.DeleteOnCollision && !gapFound)
{
OnCollision?.Invoke(position, currentHull);
return UpdateResult.Delete;
}
handleCollision(gapFound, collisionNormal);
}
@@ -512,7 +509,7 @@ namespace Barotrauma.Particles
{
Rectangle hullRect = collisionHull.WorldRect;
Vector2 center = new Vector2(hullRect.X + hullRect.Width /2, hullRect.Y - hullRect.Height / 2);
Vector2 center = new Vector2(hullRect.X + hullRect.Width / 2, hullRect.Y - hullRect.Height / 2);
if (position.Y < center.Y)
{
@@ -17,6 +17,7 @@ namespace Barotrauma
Hull.EditFire = false;
Hull.EditWater = false;
#endif
HumanAIController.DisableCrewAI = false;
}
protected virtual void DeselectEditorSpecific() { }
@@ -131,7 +131,7 @@ namespace Barotrauma
}
else
{
connection.OverrideValue = Convert.ChangeType(overrideValue, type);
connection.OverrideValue = EventEditorScreen.ChangeType(overrideValue, type);
}
}
}
@@ -513,7 +513,7 @@ namespace Barotrauma
}
else
{
newNode.Value = Convert.ChangeType(value, type);
newNode.Value = EventEditorScreen.ChangeType(value, type);
}
}
@@ -440,7 +440,7 @@ namespace Barotrauma
}
else
{
connection.OverrideValue = Convert.ChangeType(attribute.Value, connection.ValueType);
connection.OverrideValue = ChangeType(attribute.Value, connection.ValueType);
}
}
}
@@ -524,6 +524,18 @@ namespace Barotrauma
GuiFrame.AddToGUIUpdateList();
}
public static object? ChangeType(string value, Type type)
{
if (type == typeof(Identifier))
{
return value.ToIdentifier();
}
else
{
return Convert.ChangeType(value, type);
}
}
private XElement? ExportXML()
{
XElement mainElement = new XElement("ScriptedEvent", new XAttribute("identifier", projectName.RemoveWhitespace().ToLowerInvariant()));
@@ -883,12 +883,17 @@ namespace Barotrauma
private void SerializeAll()
{
IEnumerable<ContentPackage> packages = ContentPackageManager.LocalPackages;
#if DEBUG
packages = packages.Union(ContentPackageManager.VanillaCorePackage.ToEnumerable());
#endif
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings
{
Indent = true,
NewLineOnAttributes = true
};
foreach (var configFile in ContentPackageManager.AllPackages.SelectMany(p => p.GetFiles<LevelGenerationParametersFile>()))
foreach (var configFile in packages.SelectMany(p => p.GetFiles<LevelGenerationParametersFile>()))
{
XDocument doc = XMLExtensions.TryLoadXml(configFile.Path);
if (doc == null) { continue; }
@@ -922,7 +927,7 @@ namespace Barotrauma
}
}
foreach (var configFile in ContentPackageManager.AllPackages.SelectMany(p => p.GetFiles<CaveGenerationParametersFile>()))
foreach (var configFile in packages.SelectMany(p => p.GetFiles<CaveGenerationParametersFile>()))
{
XDocument doc = XMLExtensions.TryLoadXml(configFile.Path);
if (doc == null) { continue; }
@@ -957,7 +962,7 @@ namespace Barotrauma
}
settings.NewLineOnAttributes = false;
foreach (var configFile in ContentPackageManager.AllPackages.SelectMany(p => p.GetFiles<LevelObjectPrefabsFile>()))
foreach (var configFile in packages.SelectMany(p => p.GetFiles<LevelObjectPrefabsFile>()))
{
XDocument doc = XMLExtensions.TryLoadXml(configFile.Path);
if (doc == null) { continue; }
@@ -8,7 +8,6 @@ using Barotrauma.Networking;
using Barotrauma.Steam;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Steamworks.Data;
using Color = Microsoft.Xna.Framework.Color;
using ServerContentPackage = Barotrauma.Networking.ClientPeer.ServerContentPackage;
@@ -164,7 +163,7 @@ namespace Barotrauma
=> wp.SteamWorkshopId != mp.WorkshopId))
.Select(mp => mp.WorkshopId)
.ToArray();
if (missingIds.Any())
if (missingIds.Any() && SteamManager.IsInitialized)
{
buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), innerLayout.RectTransform), isHorizontal: true);
buttonContainerSpacing(0.15f);
@@ -208,7 +207,7 @@ namespace Barotrauma
{
if (currentDownload == p)
{
FileReceiver.FileTransferIn? getTransfer() => GameMain.Client.FileReceiver.ActiveTransfers.FirstOrDefault(t => t.FileType == FileTransferType.Mod);
FileReceiver.FileTransferIn? getTransfer() => GameMain.Client?.FileReceiver.ActiveTransfers.FirstOrDefault(t => t.FileType == FileTransferType.Mod);
if (downloadProgress.GetAnyChild<GUITextBlock>() is null)
{
@@ -2298,7 +2298,7 @@ namespace Barotrauma
text: selectedClient.Name, font: GUIStyle.LargeFont);
nameText.Text = ToolBox.LimitString(nameText.Text, nameText.Font, (int)(nameText.Rect.Width * 0.95f));
if (hasManagePermissions)
if (hasManagePermissions && !selectedClient.IsOwner)
{
PlayerFrame.UserData = selectedClient;
@@ -557,7 +557,9 @@ namespace Barotrauma
};
serverPreview = new GUIListBox(new RectTransform(Vector2.One, serverPreviewContainer.RectTransform, Anchor.Center))
{
Padding = Vector4.One * 10 * GUI.Scale
Padding = Vector4.One * 10 * GUI.Scale,
HoverCursor = CursorState.Default,
OnSelected = (component, o) => false
};
// Spacing
@@ -915,12 +917,7 @@ namespace Barotrauma
{
case "ServerListCompatible":
bool? s1Compatible = NetworkMember.IsCompatible(GameMain.Version.ToString(), s1.GameVersion);
if (!s1.ContentPackageHashes.Any()) { s1Compatible = null; }
if (s1Compatible.HasValue) { s1Compatible = s1Compatible.Value && s1.ContentPackagesMatch(); };
bool? s2Compatible = NetworkMember.IsCompatible(GameMain.Version.ToString(), s2.GameVersion);
if (!s2.ContentPackageHashes.Any()) { s2Compatible = null; }
if (s2Compatible.HasValue) { s2Compatible = s2Compatible.Value && s2.ContentPackagesMatch(); };
//convert to int to make sorting easier
//1 Compatible
@@ -1028,8 +1025,7 @@ namespace Barotrauma
foreach (GUIComponent child in serverList.Content.Children)
{
if (!(child.UserData is ServerInfo)) continue;
ServerInfo serverInfo = (ServerInfo)child.UserData;
if (!(child.UserData is ServerInfo serverInfo)) { continue; }
Version remoteVersion = null;
if (!string.IsNullOrEmpty(serverInfo.GameVersion))
@@ -1047,8 +1043,7 @@ namespace Barotrauma
else
{
bool incompatible =
(serverInfo.ContentPackageHashes.Any() && !serverInfo.ContentPackagesMatch()) ||
(remoteVersion != null && !NetworkMember.IsCompatible(GameMain.Version, remoteVersion));
remoteVersion != null && !NetworkMember.IsCompatible(GameMain.Version, remoteVersion);
var karmaFilterPassed = filterKarmaValue == TernaryOption.Any|| (filterKarmaValue == TernaryOption.Enabled) == serverInfo.KarmaEnabled;
var friendlyFireFilterPassed = filterFriendlyFireValue == TernaryOption.Any || (filterFriendlyFireValue == TernaryOption.Enabled) == serverInfo.FriendlyFireEnabled;
@@ -1798,8 +1793,7 @@ namespace Barotrauma
{
CanBeFocused = false,
Selected =
(NetworkMember.IsCompatible(GameMain.Version.ToString(), serverInfo.GameVersion) ?? true) &&
serverInfo.ContentPackagesMatch(),
(NetworkMember.IsCompatible(GameMain.Version.ToString(), serverInfo.GameVersion) ?? true),
UserData = "compatible"
};
@@ -1826,9 +1820,9 @@ namespace Barotrauma
if (serverInfo.ContentPackageNames.Any())
{
if (serverInfo.ContentPackageNames.Any(cp => !cp.Equals(GameMain.VanillaContent.Name, StringComparison.OrdinalIgnoreCase)))
if (serverInfo.ContentPackageNames.Any(p => !GameMain.VanillaContent.NameMatches(p)))
{
serverName.TextColor = new Color(219, 125, 217);
serverName.TextColor = GUIStyle.ModdedServerColor;
}
}
@@ -2841,6 +2841,7 @@ namespace Barotrauma
private void CreateLoadScreen()
{
CloseItem();
SubmarineInfo.RefreshSavedSubs();
SetMode(Mode.Default);
loadFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas, Anchor.Center), style: null)
@@ -3162,7 +3163,6 @@ namespace Barotrauma
}
sub.Dispose();
SubmarineInfo.RefreshSavedSubs();
CreateLoadScreen();
}
catch (Exception e)
@@ -168,7 +168,10 @@ namespace Barotrauma
{
var dropdown = new GUIDropDown(NewItemRectT(parent));
values.ForEach(v => dropdown.AddItem(text: textFunc(v), userData: v, toolTip: tooltipFunc?.Invoke(v) ?? null));
dropdown.Select(values.IndexOf(currentValue));
int childIndex = values.IndexOf(currentValue);
dropdown.Select(childIndex);
dropdown.ListBox.ForceLayoutRecalculation();
dropdown.ListBox.ScrollToElement(dropdown.ListBox.Content.GetChild(childIndex), playSound: false);
dropdown.OnSelected = (dd, obj) =>
{
setter((T)obj);
@@ -231,6 +234,8 @@ namespace Barotrauma
GameMain.GraphicsDeviceManager.GraphicsDevice.Adapter.SupportedDisplayModes
.Where(m => m.Format == SurfaceFormat.Color)
.Select(m => (m.Width, m.Height))
.Where(m => m.Width >= GameSettings.Config.GraphicsSettings.MinSupportedResolution.X
&& m.Height >= GameSettings.Config.GraphicsSettings.MinSupportedResolution.Y)
.ToList();
var currentResolution = (unsavedConfig.Graphics.Width, unsavedConfig.Graphics.Height);
if (!supportedResolutions.Contains(currentResolution))
@@ -372,13 +372,10 @@ namespace Barotrauma.Sounds
}
var newSound = new OggSound(this, filePath, stream, xElement: element);
if (newSound != null)
{
newSound.BaseGain = element.GetAttributeFloat("volume", 1.0f);
float range = element.GetAttributeFloat("range", 1000.0f);
newSound.BaseNear = range * 0.4f;
newSound.BaseFar = range;
}
newSound.BaseGain = element.GetAttributeFloat("volume", 1.0f);
float range = element.GetAttributeFloat("range", 1000.0f);
newSound.BaseNear = range * 0.4f;
newSound.BaseFar = range;
lock (loadedSounds)
{
@@ -178,6 +178,7 @@ namespace Barotrauma
SoundChannel chn = waterAmbienceChannels.FirstOrDefault(c => c.Sound == sound);
if (chn is null || !chn.IsPlaying)
{
if (volume < 0.01f) { return; }
if (!(chn is null)) { waterAmbienceChannels.Remove(chn); }
chn = sound.Play(volume, "waterambience");
chn.Looping = true;
@@ -202,6 +202,11 @@ namespace Barotrauma
{
Sound?.Dispose(); Sound = null;
}
~SoundPrefab()
{
Dispose();
}
}
[TagNames("damagesound")]
@@ -270,8 +270,9 @@ namespace Barotrauma.Steam
.ToHashSet();
toUninstall.Select(p => p.Dir).ForEach(d => Directory.Delete(d));
CrossThread.RequestExecutionOnMainThread(() => ContentPackageManager.WorkshopPackages.Refresh());
var installWaiter = WaitForInstall(workshopItem);
DownloadModThenEnqueueInstall(workshopItem);
await WaitForInstall(workshopItem);
await installWaiter;
}
public static async Task WaitForInstall(Steamworks.Ugc.Item item)
@@ -1,5 +1,6 @@
#nullable enable
using System;
using System.Linq;
using Barotrauma.Extensions;
using Microsoft.Xna.Framework;
@@ -39,6 +40,11 @@ namespace Barotrauma.Steam
CanBeFocused = false,
UserData = p
};
if (p.Errors.Any())
{
CreateModErrorInfo(p, regularBox, regularBox);
regularBox.CanBeFocused = true;
}
}
filterBox = CreateSearchBox(mainLayout, width: 1.0f);
@@ -20,10 +20,10 @@ namespace Barotrauma.Steam
Publish
}
protected readonly GUILayoutGroup tabber;
protected readonly Dictionary<Tab, (GUIButton Button, GUIFrame Content)> tabContents;
private readonly GUILayoutGroup tabber;
private readonly Dictionary<Tab, (GUIButton Button, GUIFrame Content)> tabContents;
protected readonly GUIFrame contentFrame;
private readonly GUIFrame contentFrame;
private CorePackage EnabledCorePackage => enabledCoreDropdown.SelectedData as CorePackage ?? throw new Exception("Valid core package not selected");
@@ -40,6 +40,8 @@ namespace Barotrauma.Steam
private readonly GUIListBox popularModsList;
private readonly GUIListBox selfModsList;
private uint memSubscribedModCount = 0;
public MutableWorkshopMenu(GUIFrame parent) : base(parent)
{
var mainLayout
@@ -50,6 +52,9 @@ namespace Barotrauma.Steam
tabContents = new Dictionary<Tab, (GUIButton Button, GUIFrame Content)>();
contentFrame = new GUIFrame(new RectTransform((1.0f, 0.95f), mainLayout.RectTransform), style: null);
new GUICustomComponent(new RectTransform(Vector2.Zero, mainLayout.RectTransform),
onUpdate: (f, component) => UpdateSubscribedModInstalls());
CreateInstalledModsTab(
out enabledCoreDropdown,
@@ -64,6 +69,38 @@ namespace Barotrauma.Steam
SelectTab(Tab.InstalledMods);
}
private void UpdateSubscribedModInstalls()
{
if (!SteamManager.IsInitialized) { return; }
uint numSubscribedMods = Steamworks.SteamUGC.NumSubscribedItems;
if (numSubscribedMods == memSubscribedModCount) { return; }
memSubscribedModCount = numSubscribedMods;
var subscribedIds = Steamworks.SteamUGC.GetSubscribedItems().ToHashSet();
var installedIds = ContentPackageManager.WorkshopPackages.Select(p => p.SteamWorkshopId).ToHashSet();
foreach (var id in subscribedIds.Where(id2 => !installedIds.Contains(id2)))
{
Steamworks.Ugc.Item item = new Steamworks.Ugc.Item(id);
if (!item.IsDownloading && !SteamManager.Workshop.IsInstalling(item))
{
SteamManager.Workshop.DownloadModThenEnqueueInstall(item);
}
}
TaskPool.Add("RemoveUnsubscribedItems", SteamManager.Workshop.GetPublishedItems(), t =>
{
if (!t.TryGetResult(out ISet<Steamworks.Ugc.Item> publishedItems)) { return; }
var allRequiredInstalled = subscribedIds.Union(publishedItems.Select(it => it.Id)).ToHashSet();
foreach (var id in installedIds.Where(id2 => !allRequiredInstalled.Contains(id2)))
{
Steamworks.Ugc.Item item = new Steamworks.Ugc.Item(id);
SteamManager.Workshop.Uninstall(item);
}
});
}
private void SwitchContent(GUIFrame newContent)
{
contentFrame.Children.ForEach(c => c.Visible = false);
@@ -462,6 +499,10 @@ namespace Barotrauma.Steam
{
CanBeFocused = false
};
if (mod.Errors.Any())
{
CreateModErrorInfo(mod, modFrame, modName);
}
if (ContentPackageManager.LocalPackages.Contains(mod))
{
var editButton = new GUIButton(new RectTransform(Vector2.One, frameContent.RectTransform, scaleBasis: ScaleBasis.Smallest), "",
@@ -593,6 +634,7 @@ namespace Barotrauma.Steam
ContentPackageManager.EnabledPackages.SetRegular(enabledRegularModsList.Content.Children
.Select(c => c.UserData as RegularPackage).OfType<RegularPackage>().ToArray());
PopulateInstalledModLists(forceRefreshEnabled: true, refreshDisabled: true);
ContentPackageManager.LogEnabledRegularPackageErrors();
}
}
}
@@ -129,5 +129,20 @@ namespace Barotrauma.Steam
};
return searchBox;
}
protected void CreateModErrorInfo(ContentPackage mod, GUIComponent uiElement, GUITextBlock nameText)
{
if (mod.Errors.Any())
{
const int maxErrorsToShow = 5;
nameText.TextColor = GUIStyle.Red;
uiElement.ToolTip =
TextManager.GetWithVariable("contentpackagehaserrors", "[packagename]", mod.Name) + '\n' + string.Join('\n', mod.Errors.Take(maxErrorsToShow).Select(e => e.error));
if (mod.Errors.Count() > maxErrorsToShow)
{
uiElement.ToolTip += '\n' + TextManager.GetWithVariable("workshopitemdownloadprompttruncated", "[number]", (mod.Errors.Count() - maxErrorsToShow).ToString());
}
}
}
}
}