Merge branch 'dev' of https://github.com/Regalis11/Barotrauma.git into unstable-tests
This commit is contained in:
+75
-5
@@ -22,6 +22,12 @@ namespace Barotrauma.Transition
|
||||
public static class UgcTransition
|
||||
{
|
||||
private const string readmeName = "LOCALMODS_README.txt";
|
||||
|
||||
private enum ModsListChildType
|
||||
{
|
||||
Header,
|
||||
Entry
|
||||
}
|
||||
|
||||
public static void Prepare()
|
||||
{
|
||||
@@ -34,6 +40,17 @@ namespace Barotrauma.Transition
|
||||
var msgBox = new GUIMessageBox(TextManager.Get("Ugc.TransferTitle"), "", relativeSize: (0.5f, 0.8f),
|
||||
buttons: new LocalizedString[] { TextManager.Get("Ugc.TransferButton") });
|
||||
|
||||
var closeBtn = new GUIButton(
|
||||
new RectTransform(Vector2.One * 1.5f, msgBox.Header.RectTransform, anchor: Anchor.CenterRight, scaleBasis: ScaleBasis.BothHeight),
|
||||
style: "GUICancelButton")
|
||||
{
|
||||
OnClicked = (button, o) =>
|
||||
{
|
||||
msgBox.Close();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
var desc = new GUITextBlock(new RectTransform((1.0f, 0.24f), msgBox.Content.RectTransform),
|
||||
text: TextManager.Get("Ugc.TransferDesc"), wrap: true, textAlignment: Alignment.CenterLeft);
|
||||
|
||||
@@ -45,20 +62,73 @@ namespace Barotrauma.Transition
|
||||
|
||||
void addHeader(LocalizedString str)
|
||||
{
|
||||
var itemFrame = new GUITextBlock(new RectTransform((1.0f, 0.08f), modsList.Content.RectTransform),
|
||||
text: str, font: GUIStyle.SubHeadingFont)
|
||||
var itemFrame = new GUIFrame(new RectTransform((1.0f, 0.08f), modsList.Content.RectTransform),
|
||||
style: null)
|
||||
{
|
||||
CanBeFocused = false
|
||||
CanBeFocused = false,
|
||||
UserData = ModsListChildType.Header
|
||||
};
|
||||
if (str is RawLString { Value: "" }) { return; }
|
||||
|
||||
bool clicked = true;
|
||||
var tickBox = new GUITickBox(new RectTransform(Vector2.One, itemFrame.RectTransform),
|
||||
label: str, font: GUIStyle.SubHeadingFont)
|
||||
{
|
||||
Selected = false,
|
||||
OnSelected = box =>
|
||||
{
|
||||
if (!clicked) { return true; }
|
||||
bool toggleTickbox = false;
|
||||
foreach (var child in modsList.Content.Children)
|
||||
{
|
||||
if (child == itemFrame) { toggleTickbox = true; }
|
||||
else if (child.UserData is ModsListChildType.Header) { toggleTickbox = false; }
|
||||
else if (toggleTickbox)
|
||||
{
|
||||
var tb = child.GetAnyChild<GUITickBox>();
|
||||
if (tb is null) { continue; }
|
||||
|
||||
tb.Selected = box.Selected;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
new GUICustomComponent(new RectTransform(Vector2.Zero, itemFrame.RectTransform),
|
||||
onUpdate: (f, component) =>
|
||||
{
|
||||
clicked = false;
|
||||
bool shouldBeSelected = true;
|
||||
bool toggleTickbox = false;
|
||||
foreach (var child in modsList.Content.Children)
|
||||
{
|
||||
if (child == itemFrame) { toggleTickbox = true; }
|
||||
else if (child.UserData is ModsListChildType.Header) { toggleTickbox = false; }
|
||||
else if (toggleTickbox)
|
||||
{
|
||||
var tb = child.GetAnyChild<GUITickBox>();
|
||||
if (tb is null) { continue; }
|
||||
|
||||
if (!tb.Selected)
|
||||
{
|
||||
shouldBeSelected = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
tickBox.Selected = shouldBeSelected;
|
||||
clicked = true;
|
||||
});
|
||||
}
|
||||
void addTickbox(string dir, string name, bool ticked)
|
||||
{
|
||||
var itemFrame = new GUIFrame(new RectTransform((1.0f, 0.07f), modsList.Content.RectTransform),
|
||||
style: null)
|
||||
{
|
||||
CanBeFocused = false
|
||||
CanBeFocused = false,
|
||||
UserData = ModsListChildType.Entry
|
||||
};
|
||||
var tickbox = new GUITickBox(new RectTransform(Vector2.One, itemFrame.RectTransform), name)
|
||||
var tickbox = new GUITickBox(new RectTransform((0.97f, 1.0f), itemFrame.RectTransform, Anchor.CenterRight), name)
|
||||
{
|
||||
Selected = ticked
|
||||
};
|
||||
|
||||
@@ -501,8 +501,8 @@ namespace Barotrauma
|
||||
private string ApplyUpperCase(string text, ForceUpperCase forceUpperCase)
|
||||
=> forceUpperCase switch
|
||||
{
|
||||
Barotrauma.ForceUpperCase.Inherit => ForceUpperCase ? text.ToUpper() : text,
|
||||
Barotrauma.ForceUpperCase.Yes => text.ToUpper(),
|
||||
Barotrauma.ForceUpperCase.Inherit => ForceUpperCase ? text.ToUpperInvariant() : text,
|
||||
Barotrauma.ForceUpperCase.Yes => text.ToUpperInvariant(),
|
||||
Barotrauma.ForceUpperCase.No => text
|
||||
};
|
||||
|
||||
|
||||
@@ -151,8 +151,13 @@ namespace Barotrauma
|
||||
loadingTextures = true;
|
||||
loading = true;
|
||||
TaskPool.Add("LoadTextureAsync",
|
||||
LoadTextureAsync(), (Task) =>
|
||||
LoadTextureAsync(), task =>
|
||||
{
|
||||
if (task.Exception != null)
|
||||
{
|
||||
var innerMost = task.Exception.GetInnermost();
|
||||
DebugConsole.ThrowError($"Failed to load \"{Sprite.FilePath}\"", innerMost);
|
||||
}
|
||||
loading = false;
|
||||
lazyLoaded = true;
|
||||
RectTransform.SizeChanged += RecalculateScale;
|
||||
@@ -232,7 +237,7 @@ namespace Barotrauma
|
||||
{
|
||||
wait = activeTextureLoads.Contains(Sprite.FullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
@@ -981,17 +981,19 @@ namespace Barotrauma
|
||||
BarSize = 0.1f,
|
||||
OnMoved = (bar, scroll) =>
|
||||
{
|
||||
SetRewardText((int)(scroll * 100), rewardBlock);
|
||||
int rewardDistribution = RoundRewardDistribution(scroll, bar.Step);
|
||||
SetRewardText(rewardDistribution, rewardBlock);
|
||||
return true;
|
||||
},
|
||||
OnReleased = (bar, scroll) =>
|
||||
{
|
||||
int newRewardDistribution = (int)(scroll * 100);
|
||||
int newRewardDistribution = RoundRewardDistribution(scroll, bar.Step);
|
||||
if (newRewardDistribution == targetWallet.RewardDistribution) { return false; }
|
||||
SetRewardDistribution(character, newRewardDistribution);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
int RoundRewardDistribution(float scroll, float step) => (int)MathUtils.RoundTowardsClosest(scroll * 100, step * 100);
|
||||
|
||||
SetRewardText(targetWallet.RewardDistribution, rewardBlock);
|
||||
|
||||
|
||||
@@ -182,7 +182,10 @@ namespace Barotrauma
|
||||
}
|
||||
// Exchange money
|
||||
store.Balance -= itemValue;
|
||||
campaign.Bank.Give(itemValue);
|
||||
if (GameMain.IsSingleplayer)
|
||||
{
|
||||
campaign.Bank.Give(itemValue);
|
||||
}
|
||||
GameAnalyticsManager.AddMoneyGainedEvent(itemValue, GameAnalyticsManager.MoneySource.Store, item.ItemPrefab.Identifier.Value);
|
||||
|
||||
// Remove from the sell crate
|
||||
|
||||
@@ -703,7 +703,7 @@ namespace Barotrauma
|
||||
AbsoluteSpacing = GUI.IntScale(10),
|
||||
Stretch = true
|
||||
};
|
||||
var factionIcon = new GUIImage(new RectTransform(new Point((int)(factionInfoHorizontal.Rect.Height * 0.7f)), factionInfoHorizontal.RectTransform, scaleBasis: ScaleBasis.Smallest), icon, scaleToFit: true)
|
||||
var factionIcon = new GUIImage(new RectTransform(Vector2.One * 0.7f, factionInfoHorizontal.RectTransform, scaleBasis: ScaleBasis.Smallest), icon, scaleToFit: true)
|
||||
{
|
||||
Color = iconColor
|
||||
};
|
||||
|
||||
@@ -208,7 +208,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private void DrawConnection(SpriteBatch spriteBatch, ConnectionPanel panel, Vector2 position, Vector2 labelPos, Vector2 scale)
|
||||
{
|
||||
string text = DisplayName.Value.ToUpper();
|
||||
string text = DisplayName.Value.ToUpperInvariant();
|
||||
|
||||
//nasty
|
||||
if (GUIStyle.GetComponentStyle("ConnectionPanelLabel")?.Sprites.Values.First().First() is UISprite labelSprite)
|
||||
@@ -401,13 +401,13 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (c.IsOutput)
|
||||
{
|
||||
var labelArea = GetLabelArea(GetOutputLabelPosition(rightPos, panel, c), c.DisplayName.Value.ToUpper(), scale);
|
||||
var labelArea = GetLabelArea(GetOutputLabelPosition(rightPos, panel, c), c.DisplayName.Value.ToUpperInvariant(), scale);
|
||||
labelAreas.Add(labelArea);
|
||||
rightPos.Y += connectorIntervalLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
var labelArea = GetLabelArea(GetInputLabelPosition(leftPos, panel, c), c.DisplayName.Value.ToUpper(), scale);
|
||||
var labelArea = GetLabelArea(GetInputLabelPosition(leftPos, panel, c), c.DisplayName.Value.ToUpperInvariant(), scale);
|
||||
labelAreas.Add(labelArea);
|
||||
leftPos.Y += connectorIntervalRight;
|
||||
}
|
||||
|
||||
@@ -415,7 +415,7 @@ namespace Barotrauma.Networking
|
||||
GameMain.ServerListScreen.Select();
|
||||
}
|
||||
|
||||
GUIMessageBox.MessageBoxes.RemoveAll(m => true);
|
||||
GUIMessageBox.MessageBoxes.Clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -722,7 +722,10 @@ namespace Barotrauma.Networking
|
||||
//allow interpreting this packet
|
||||
break;
|
||||
case ServerPacketHeader.STARTGAME:
|
||||
GameMain.NetLobbyScreen.ShowSpectateButton();
|
||||
gameStarted = true;
|
||||
return;
|
||||
case ServerPacketHeader.ENDGAME:
|
||||
gameStarted = false;
|
||||
return;
|
||||
default:
|
||||
return; //ignore any other packets
|
||||
@@ -2112,11 +2115,11 @@ namespace Barotrauma.Networking
|
||||
|
||||
serverSettings.ServerLog.ServerName = serverSettings.ServerName;
|
||||
|
||||
if (!GameMain.NetLobbyScreen.ServerName.Selected) GameMain.NetLobbyScreen.ServerName.Text = serverSettings.ServerName;
|
||||
if (!GameMain.NetLobbyScreen.ServerMessage.Selected) GameMain.NetLobbyScreen.ServerMessage.Text = serverSettings.ServerMessageText;
|
||||
if (!GameMain.NetLobbyScreen.ServerName.Selected) { GameMain.NetLobbyScreen.ServerName.Text = serverSettings.ServerName; }
|
||||
if (!GameMain.NetLobbyScreen.ServerMessage.Selected) { GameMain.NetLobbyScreen.ServerMessage.Text = serverSettings.ServerMessageText; }
|
||||
GameMain.NetLobbyScreen.UsingShuttle = usingShuttle;
|
||||
|
||||
if (!allowSubVoting) GameMain.NetLobbyScreen.TrySelectSub(selectSubName, selectSubHash, GameMain.NetLobbyScreen.SubList);
|
||||
if (!allowSubVoting) { GameMain.NetLobbyScreen.TrySelectSub(selectSubName, selectSubHash, GameMain.NetLobbyScreen.SubList); }
|
||||
GameMain.NetLobbyScreen.TrySelectSub(selectShuttleName, selectShuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox);
|
||||
|
||||
GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace Barotrauma
|
||||
{
|
||||
OnClicked = (guiButton, o) =>
|
||||
{
|
||||
GameMain.Client.Disconnect();
|
||||
GameMain.Client?.Disconnect();
|
||||
GameMain.MainMenuScreen.Select();
|
||||
return false;
|
||||
}
|
||||
@@ -153,7 +153,7 @@ namespace Barotrauma
|
||||
buttonContainerSpacing(0.2f);
|
||||
button(TextManager.Get("No"), () =>
|
||||
{
|
||||
GameMain.Client.Disconnect();
|
||||
GameMain.Client?.Disconnect();
|
||||
GameMain.MainMenuScreen.Select();
|
||||
});
|
||||
buttonContainerSpacing(0.1f);
|
||||
@@ -170,11 +170,14 @@ namespace Barotrauma
|
||||
buttonContainerSpacing(0.15f);
|
||||
button(TextManager.Get("SubscribeToAllOnWorkshop"), () =>
|
||||
{
|
||||
BulkDownloader.SubscribeToServerMods(missingIds,
|
||||
rejoinEndpoint: GameMain.Client.ClientPeer.ServerConnection.EndPointString,
|
||||
rejoinLobby: SteamManager.CurrentLobbyID,
|
||||
rejoinServerName: GameMain.NetLobbyScreen.ServerName.Text);
|
||||
GameMain.Client.Disconnect();
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
BulkDownloader.SubscribeToServerMods(missingIds,
|
||||
rejoinEndpoint: GameMain.Client.ClientPeer.ServerConnection.EndPointString,
|
||||
rejoinLobby: SteamManager.CurrentLobbyID,
|
||||
rejoinServerName: GameMain.NetLobbyScreen.ServerName.Text);
|
||||
GameMain.Client.Disconnect();
|
||||
}
|
||||
GameMain.MainMenuScreen.Select();
|
||||
}, width: 0.7f);
|
||||
buttonContainerSpacing(0.15f);
|
||||
|
||||
@@ -3796,20 +3796,27 @@ namespace Barotrauma
|
||||
OnSelected = SelectWire
|
||||
};
|
||||
|
||||
List<ItemPrefab> wirePrefabs = new List<ItemPrefab>();
|
||||
|
||||
foreach (ItemPrefab itemPrefab in ItemPrefab.Prefabs)
|
||||
{
|
||||
if (itemPrefab.Name.IsNullOrEmpty()) { continue; }
|
||||
if (itemPrefab.Name.IsNullOrEmpty() || itemPrefab.HideInMenus) { continue; }
|
||||
if (!itemPrefab.Tags.Contains("wire")) { continue; }
|
||||
wirePrefabs.Add(itemPrefab);
|
||||
}
|
||||
|
||||
foreach (ItemPrefab itemPrefab in wirePrefabs.OrderBy(w => !w.CanBeBought).ThenBy(w => w.UintIdentifier))
|
||||
{
|
||||
GUIFrame imgFrame = new GUIFrame(new RectTransform(new Point(listBox.Content.Rect.Width, listBox.Rect.Width / 2), listBox.Content.RectTransform), style: "ListBoxElement")
|
||||
{
|
||||
UserData = itemPrefab
|
||||
};
|
||||
|
||||
var img = new GUIImage(new RectTransform(new Vector2(0.9f), imgFrame.RectTransform, Anchor.Center), itemPrefab.Sprite, scaleToFit: true)
|
||||
{
|
||||
UserData = itemPrefab,
|
||||
Color = itemPrefab.SpriteColor
|
||||
Color = itemPrefab.SpriteColor,
|
||||
HoverColor = Color.Lerp(itemPrefab.SpriteColor, Color.White, 0.3f),
|
||||
SelectedColor = Color.Lerp(itemPrefab.SpriteColor, Color.White, 0.6f)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -167,7 +167,13 @@ namespace Barotrauma
|
||||
Texture2D newTexture = TextureLoader.FromFile(file, compress);
|
||||
lock (list)
|
||||
{
|
||||
textureRefCounts.Add(fullPath, new TextureRefCounter { RefCount = 1, Texture = newTexture });
|
||||
if (!textureRefCounts.TryAdd(fullPath,
|
||||
new TextureRefCounter { RefCount = 1, Texture = newTexture }))
|
||||
{
|
||||
CrossThread.RequestExecutionOnMainThread(() => newTexture.Dispose());
|
||||
textureRefCounts[fullPath].RefCount++;
|
||||
return textureRefCounts[fullPath].Texture;
|
||||
}
|
||||
}
|
||||
return newTexture;
|
||||
}
|
||||
|
||||
@@ -11,8 +11,18 @@ namespace Barotrauma.Steam
|
||||
{
|
||||
public static class BulkDownloader
|
||||
{
|
||||
private static void CloseAllMessageBoxes()
|
||||
{
|
||||
GUIMessageBox.MessageBoxes.ForEachMod(b =>
|
||||
{
|
||||
if (b is GUIMessageBox m) { m.Close(); }
|
||||
else { GUIMessageBox.MessageBoxes.Remove(b); }
|
||||
});
|
||||
}
|
||||
|
||||
public static void PrepareUpdates()
|
||||
{
|
||||
CloseAllMessageBoxes();
|
||||
GUIMessageBox msgBox = new GUIMessageBox(headerText: "", text: TextManager.Get("DeterminingRequiredModUpdates"),
|
||||
buttons: Array.Empty<LocalizedString>());
|
||||
TaskPool.Add(
|
||||
@@ -29,6 +39,7 @@ namespace Barotrauma.Steam
|
||||
|
||||
internal static void SubscribeToServerMods(IEnumerable<UInt64> missingIds, string rejoinEndpoint, ulong rejoinLobby, string rejoinServerName)
|
||||
{
|
||||
CloseAllMessageBoxes();
|
||||
GUIMessageBox msgBox = new GUIMessageBox(headerText: "", text: TextManager.Get("PreparingWorkshopDownloads"),
|
||||
buttons: Array.Empty<LocalizedString>());
|
||||
TaskPool.Add(
|
||||
|
||||
@@ -202,7 +202,22 @@ namespace Barotrauma.Steam
|
||||
}
|
||||
|
||||
DateTime getEditTime(ContentPackage p)
|
||||
=> File.GetLastWriteTime(Path.GetDirectoryName(p.Path)!);
|
||||
{
|
||||
DateTime writeTime = File.GetLastWriteTime(p.Dir);
|
||||
|
||||
//File.GetLastWriteTime on the directory is not good enough;
|
||||
//it's possible to update a file in a directory without
|
||||
//updating its parent directories' write time, so let's
|
||||
//look at all of those files
|
||||
var files = Directory.GetFiles(p.Dir, "*", System.IO.SearchOption.AllDirectories);
|
||||
foreach (var file in files)
|
||||
{
|
||||
DateTime newTime = File.GetLastWriteTime(file);
|
||||
if (newTime > writeTime) { writeTime = newTime; }
|
||||
}
|
||||
|
||||
return writeTime;
|
||||
}
|
||||
|
||||
//Find local packages associated with the Workshop items if available
|
||||
(Steamworks.Ugc.Item WorkshopItem, ContentPackage? LocalPackage)[] publishedItems = workshopItems
|
||||
|
||||
Reference in New Issue
Block a user