diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUIDropDown.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUIDropDown.cs index f92554433..6cdba8652 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUIDropDown.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUIDropDown.cs @@ -148,7 +148,7 @@ namespace Barotrauma //find the parent GUIListBox highest in the hierarchy for (int i = parentHierarchy.Count - 1; i >= 0; i--) { - if (parentHierarchy[i].GUIComponent is GUIListBox) return parentHierarchy[i]?.Parent ?? parentHierarchy[i]; + if (parentHierarchy[i].GUIComponent is GUIListBox) return parentHierarchy[i]; } //or just go with the direct parent if there are no listboxes in the hierarchy parentHierarchy.Clear(); diff --git a/Barotrauma/BarotraumaClient/Source/Map/ItemAssemblyPrefab.cs b/Barotrauma/BarotraumaClient/Source/Map/ItemAssemblyPrefab.cs index 0fcff3a6d..00eb633c9 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/ItemAssemblyPrefab.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/ItemAssemblyPrefab.cs @@ -82,7 +82,7 @@ namespace Barotrauma center.Y -= center.Y % Submarine.GridSize.Y; MapEntity.SelectedList.Clear(); - assemblyEntities.ForEach(e => MapEntity.AddSelection(e)); + MapEntity.SelectedList.AddRange(assemblyEntities); foreach (MapEntity mapEntity in assemblyEntities) { diff --git a/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs b/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs index 91dd8e015..638d8f4ed 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs @@ -478,45 +478,6 @@ namespace Barotrauma return true; }; } - - public static void AddSelection(MapEntity entity) - { - if (selectedList.Contains(entity)) { return; } - selectedList.Add(entity); - if (entity is Item i) - { - var door = i.GetComponent(); - if (door != null) - { - var gap = door.LinkedGap; - if (gap != null) - { - door.RefreshLinkedGap(); - if (!selectedList.Contains(gap)) - { - selectedList.Add(gap); - } - } - } - } - } - - public static void RemoveSelection(MapEntity entity) - { - selectedList.Remove(entity); - if (entity is Item i) - { - var door = i.GetComponent(); - if (door != null) - { - var gap = door.LinkedGap; - if (gap != null) - { - selectedList.Remove(gap); - } - } - } - } static partial void UpdateAllProjSpecific(float deltaTime) { @@ -585,7 +546,6 @@ namespace Barotrauma public static void UpdateEditor(Camera cam) { - FilteredSelectedList.Clear(); if (highlightedListBox != null) highlightedListBox.UpdateManually((float)Timing.Step); if (editingHUD != null) @@ -603,16 +563,11 @@ namespace Barotrauma } if (selectedList.Count == 0) return; - foreach (var e in selectedList) + + if (editingHUD != null) { - if (e is Gap) { continue; } - FilteredSelectedList.Add(e); - } - var first = FilteredSelectedList.FirstOrDefault(); - if (first != null) - { - first.UpdateEditing(cam); - if (first.ResizeHorizontal || first.ResizeVertical) + selectedList[0].UpdateEditing(cam); + if (selectedList[0].ResizeHorizontal || selectedList[0].ResizeVertical) { first.UpdateResizing(cam); } diff --git a/Barotrauma/BarotraumaClient/Source/Networking/SteamManager.cs b/Barotrauma/BarotraumaClient/Source/Networking/SteamManager.cs index a7e1a484b..4b27e024c 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/SteamManager.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/SteamManager.cs @@ -594,15 +594,8 @@ namespace Barotrauma.Steam } SaveUtil.ClearFolder(WorkshopItemStagingFolder); + Directory.Delete(WorkshopItemStagingFolder); File.Delete(PreviewImageName); - try - { - Directory.Delete(WorkshopItemStagingFolder); - } - catch (Exception e) - { - DebugConsole.ThrowError("Failed to delete Workshop item staging folder.", e); - } yield return CoroutineStatus.Success; } @@ -934,50 +927,28 @@ namespace Barotrauma.Steam { if (instance == null || !instance.isInitialized) { return false; } - bool? itemsUpdated = null; - bool timedOut = false; - var query = instance.client.Workshop.CreateQuery(); - query.FileId = new List(instance.client.Workshop.GetSubscribedItemIds()); - query.UploaderAppId = AppID; - query.Run(); - query.OnResult = (Workshop.Query q) => + bool itemsUpdated = false; + foreach (ulong subscribedItemId in instance.client.Workshop.GetSubscribedItemIds()) { - if (timedOut) { return; } - itemsUpdated = false; - foreach (var item in q.Items) + //TODO: fix this, GetItem doesn't query item.Modified + var item = instance.client.Workshop.GetItem(subscribedItemId); + if (item.Installed && CheckWorkshopItemEnabled(item) && !CheckWorkshopItemUpToDate(item)) { - if (item.Installed && CheckWorkshopItemEnabled(item) && !CheckWorkshopItemUpToDate(item)) + if (!UpdateWorkshopItem(item, out string errorMsg)) { - if (!UpdateWorkshopItem(item, out string errorMsg)) - { - DebugConsole.ThrowError(errorMsg); - new GUIMessageBox( - TextManager.Get("Error"), - TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { item.Title, errorMsg })); - } - else - { - new GUIMessageBox("", TextManager.GetWithVariable("WorkshopItemUpdated", "[itemname]", item.Title)); - itemsUpdated = true; - } + DebugConsole.ThrowError(errorMsg); + new GUIMessageBox( + TextManager.Get("Error"), + TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { item.Title, errorMsg })); + } + else + { + new GUIMessageBox("", TextManager.GetWithVariable("WorkshopItemUpdated", "[itemname]", item.Title)); + itemsUpdated = true; } } - }; - - DateTime timeOut = DateTime.Now + new TimeSpan(0, 0, 10); - while (!itemsUpdated.HasValue) - { - if (DateTime.Now > timeOut) - { - itemsUpdated = false; - timedOut = true; - break; - } - instance.client.Update(); - System.Threading.Thread.Sleep(10); } - - return itemsUpdated.Value; + return itemsUpdated; } public static bool UpdateWorkshopItem(Workshop.Item item, out string errorMsg) diff --git a/Barotrauma/BarotraumaClient/Source/Screens/SteamWorkshopScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/SteamWorkshopScreen.cs index f249d921c..ce5b54c2d 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/SteamWorkshopScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/SteamWorkshopScreen.cs @@ -49,7 +49,7 @@ namespace Barotrauma { tabs = new GUIFrame[Enum.GetValues(typeof(Tab)).Length]; - menu = new GUIFrame(new RectTransform(new Vector2(0.85f, 0.8f), GUI.Canvas, Anchor.Center) { MinSize = new Point(GameMain.GraphicsHeight, 0) }); + menu = new GUIFrame(new RectTransform(new Vector2(0.6f, 0.8f), GUI.Canvas, Anchor.Center) { MinSize = new Point(GameMain.GraphicsHeight, 0) }); var container = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.85f), menu.RectTransform, Anchor.Center) { RelativeOffset = new Vector2(0.0f, 0.05f) }) { Stretch = true }; @@ -394,7 +394,6 @@ namespace Barotrauma { IsHorizontal = true, Stretch = true, - RelativeSpacing = 0.05f, CanBeFocused = false }; @@ -406,6 +405,32 @@ namespace Barotrauma if (item.Installed) { + if (listBox != publishedItemList && SteamManager.CheckWorkshopItemEnabled(item) && !SteamManager.CheckWorkshopItemUpToDate(item)) + { + new GUIButton(new RectTransform(new Vector2(0.4f, 0.5f), rightColumn.RectTransform, Anchor.BottomLeft), text: "Update") + { + UserData = "updatebutton", + IgnoreLayoutGroups = true, + OnClicked = (btn, userdata) => + { + if (SteamManager.UpdateWorkshopItem(item, out string errorMsg)) + { + new GUIMessageBox("", TextManager.GetWithVariable("WorkshopItemUpdated", "[itemname]", TextManager.EnsureUTF8(item.Title))); + } + else + { + DebugConsole.ThrowError(errorMsg); + new GUIMessageBox( + TextManager.Get("Error"), + TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { TextManager.EnsureUTF8(item.Title), errorMsg })); + } + btn.Enabled = false; + btn.Visible = false; + return true; + } + }; + } + GUITickBox enabledTickBox = null; try { @@ -451,33 +476,6 @@ namespace Barotrauma }; } } - - if (Rand.Range(0.0f, 1.0f) < 0.5f)//listBox != publishedItemList && SteamManager.CheckWorkshopItemEnabled(item) && !SteamManager.CheckWorkshopItemUpToDate(item)) - { - new GUIButton(new RectTransform(new Vector2(0.4f, 0.5f), rightColumn.RectTransform, Anchor.BottomLeft), text: TextManager.Get("WorkshopItemUpdate")) - { - UserData = "updatebutton", - Font = GUI.SmallFont, - OnClicked = (btn, userdata) => - { - if (SteamManager.UpdateWorkshopItem(item, out string errorMsg)) - { - new GUIMessageBox("", TextManager.GetWithVariable("WorkshopItemUpdated", "[itemname]", TextManager.EnsureUTF8(item.Title))); - } - else - { - DebugConsole.ThrowError(errorMsg); - new GUIMessageBox( - TextManager.Get("Error"), - TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { TextManager.EnsureUTF8(item.Title), errorMsg })); - } - btn.Enabled = false; - btn.Visible = false; - return true; - } - }; - } - } else if (item.Downloading) { @@ -902,7 +900,7 @@ namespace Barotrauma new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), topRightColumn.RectTransform), TextManager.Get("WorkshopItemDescription")); var descriptionContainer = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.4f), topRightColumn.RectTransform)); - var descriptionBox = new GUITextBox(new RectTransform(Vector2.One, descriptionContainer.Content.RectTransform), itemEditor.Description, textAlignment: Alignment.TopLeft, font: GUI.SmallFont, wrap: true); + var descriptionBox = new GUITextBox(new RectTransform(Vector2.One, descriptionContainer.Content.RectTransform), itemEditor.Description, textAlignment: Alignment.TopLeft, wrap: true); descriptionBox.OnTextChanged += (textBox, text) => { Vector2 textSize = textBox.Font.MeasureString(descriptionBox.WrappedText); @@ -1083,7 +1081,6 @@ namespace Barotrauma { InitialDirectory = Path.GetFullPath(SteamManager.WorkshopItemStagingFolder), Title = TextManager.Get("workshopitemaddfiles"), - Multiselect = true }; if (ofd.ShowDialog() == DialogResult.OK) { @@ -1231,7 +1228,7 @@ namespace Barotrauma private void OnAddFilesSelected(string[] fileNames) { if (fileNames == null) { return; } - for (int i = 0; i < fileNames.Length; i++) + for(int i = 0; i < fileNames.Length; i++) { string file = fileNames[i]; if (string.IsNullOrEmpty(file)) { continue; } @@ -1261,7 +1258,6 @@ namespace Barotrauma itemContentPackage.AddFile(filePathRelativeToStagingFolder, ContentType.None); } } - itemContentPackage.Save(itemContentPackage.Path); RefreshCreateItemFileList(); } @@ -1335,7 +1331,6 @@ namespace Barotrauma OnClicked = (btn, userdata) => { itemContentPackage.RemoveFile(contentFile); - itemContentPackage.Save(itemContentPackage.Path); RefreshCreateItemFileList(); return true; } @@ -1351,7 +1346,7 @@ namespace Barotrauma { if (itemContentPackage == null || itemEditor == null) return; - SteamManager.StartPublishItem(itemContentPackage, itemEditor); + SteamManager.StartPublishItem(itemContentPackage, itemEditor); CoroutineManager.StartCoroutine(WaitForPublish(itemEditor), "WaitForPublish"); } diff --git a/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs index e69d4a663..a45f872e6 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs @@ -2109,7 +2109,10 @@ namespace Barotrauma public override void AddToGUIUpdateList() { - MapEntity.FilteredSelectedList.FirstOrDefault()?.AddToGUIUpdateList(); + if (MapEntity.SelectedList.Count == 1) + { + MapEntity.SelectedList[0].AddToGUIUpdateList(); + } if (MapEntity.HighlightedListBox != null) { MapEntity.HighlightedListBox.AddToGUIUpdateList(); @@ -2290,9 +2293,9 @@ namespace Barotrauma dummyCharacter.SelectedConstruction = null; }*/ } - else if (MapEntity.FilteredSelectedList.Count == 1) + else if (MapEntity.SelectedList.Count == 1) { - (MapEntity.FilteredSelectedList[0] as Item)?.UpdateHUD(cam, dummyCharacter, (float)deltaTime); + (MapEntity.SelectedList[0] as Item)?.UpdateHUD(cam, dummyCharacter, (float)deltaTime); } CharacterHUD.Update((float)deltaTime, dummyCharacter, cam); diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs index 7ac15962c..50de362ac 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs @@ -22,6 +22,7 @@ namespace Barotrauma.Items.Components private float openState; private Sprite doorSprite, weldedSprite, brokenSprite; private bool scaleBrokenSprite, fadeBrokenSprite; + private bool createdNewGap; private bool autoOrientGap; private bool isStuck; @@ -88,7 +89,12 @@ namespace Barotrauma.Items.Components { if (linkedGap == null) { - GetLinkedGap(); + linkedGap = e as Gap; + if (linkedGap != null) + { + linkedGap.PassAmbientLight = Window != Rectangle.Empty; + return linkedGap; + } } return linkedGap; } @@ -110,11 +116,16 @@ namespace Barotrauma.Items.Components rect.X -= 5; rect.Width += 10; } + linkedGap = new Gap(rect, !IsHorizontal, Item.Submarine) { - Submarine = item.Submarine + Submarine = item.Submarine, + PassAmbientLight = Window != Rectangle.Empty, + Open = openState }; item.linkedTo.Add(linkedGap); + createdNewGap = true; + return linkedGap; } RefreshLinkedGap(); } @@ -375,8 +386,7 @@ namespace Barotrauma.Items.Components LinkedGap.AutoOrient(); } LinkedGap.Open = openState; - LinkedGap.PassAmbientLight = Window != Rectangle.Empty; - } + if (createdNewGap && autoOrientGap) linkedGap.AutoOrient(); public override void OnMapLoaded() { diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 964e2651c..d62ab48bb 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -285,7 +285,7 @@ namespace Barotrauma get { return spriteColor; } } - public bool IsFullCondition => Condition >= MaxCondition; + public bool IsFullCondition => MathUtils.NearlyEqual(Condition, MaxCondition); public float MaxCondition => Prefab.Health; public float ConditionPercentage => MathUtils.Percentage(Condition, MaxCondition); @@ -304,6 +304,7 @@ namespace Barotrauma if (Indestructible) return; float prev = condition; + condition = MathHelper.Clamp(value, 0.0f, Prefab.Health); if (condition == 0.0f && prev > 0.0f) { diff --git a/Barotrauma/BarotraumaShared/Source/Map/ItemAssemblyPrefab.cs b/Barotrauma/BarotraumaShared/Source/Map/ItemAssemblyPrefab.cs index 3e1024dfa..736acb775 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/ItemAssemblyPrefab.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/ItemAssemblyPrefab.cs @@ -107,7 +107,7 @@ namespace Barotrauma if (Screen.Selected == GameMain.SubEditorScreen) { MapEntity.SelectedList.Clear(); - entities.ForEach(e => MapEntity.AddSelection(e)); + MapEntity.SelectedList.AddRange(entities); } #endif return entities; diff --git a/Barotrauma/BarotraumaShared/Source/Utils/SaveUtil.cs b/Barotrauma/BarotraumaShared/Source/Utils/SaveUtil.cs index 23c9465fa..acbe640cb 100644 --- a/Barotrauma/BarotraumaShared/Source/Utils/SaveUtil.cs +++ b/Barotrauma/BarotraumaShared/Source/Utils/SaveUtil.cs @@ -378,6 +378,8 @@ namespace Barotrauma Thread.Sleep(250); } } + + return true; } @@ -468,20 +470,7 @@ namespace Barotrauma foreach (DirectoryInfo di in dir.GetDirectories()) { ClearFolder(di.FullName, ignoredFileNames); - int maxRetries = 4; - for (int i = 0; i <= maxRetries; i++) - { - try - { - di.Delete(); - break; - } - catch (IOException) - { - if (i >= maxRetries) { throw; } - Thread.Sleep(250); - } - } + di.Delete(); } } }