(df244251c) Fixed: Electric devices that are underwater and are broken by flooding being repairable forever, due to condition never staying at full condition for long enough for the repairing to stop

This commit is contained in:
Joonas Rikkonen
2019-06-11 21:46:02 +03:00
parent 20d88b3769
commit dd1ce8bf2f
10 changed files with 79 additions and 155 deletions
@@ -148,7 +148,7 @@ namespace Barotrauma
//find the parent GUIListBox highest in the hierarchy //find the parent GUIListBox highest in the hierarchy
for (int i = parentHierarchy.Count - 1; i >= 0; i--) 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 //or just go with the direct parent if there are no listboxes in the hierarchy
parentHierarchy.Clear(); parentHierarchy.Clear();
@@ -82,7 +82,7 @@ namespace Barotrauma
center.Y -= center.Y % Submarine.GridSize.Y; center.Y -= center.Y % Submarine.GridSize.Y;
MapEntity.SelectedList.Clear(); MapEntity.SelectedList.Clear();
assemblyEntities.ForEach(e => MapEntity.AddSelection(e)); MapEntity.SelectedList.AddRange(assemblyEntities);
foreach (MapEntity mapEntity in assemblyEntities) foreach (MapEntity mapEntity in assemblyEntities)
{ {
@@ -478,45 +478,6 @@ namespace Barotrauma
return true; 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<Door>();
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<Door>();
if (door != null)
{
var gap = door.LinkedGap;
if (gap != null)
{
selectedList.Remove(gap);
}
}
}
}
static partial void UpdateAllProjSpecific(float deltaTime) static partial void UpdateAllProjSpecific(float deltaTime)
{ {
@@ -585,7 +546,6 @@ namespace Barotrauma
public static void UpdateEditor(Camera cam) public static void UpdateEditor(Camera cam)
{ {
FilteredSelectedList.Clear();
if (highlightedListBox != null) highlightedListBox.UpdateManually((float)Timing.Step); if (highlightedListBox != null) highlightedListBox.UpdateManually((float)Timing.Step);
if (editingHUD != null) if (editingHUD != null)
@@ -603,16 +563,11 @@ namespace Barotrauma
} }
if (selectedList.Count == 0) return; if (selectedList.Count == 0) return;
foreach (var e in selectedList)
if (editingHUD != null)
{ {
if (e is Gap) { continue; } selectedList[0].UpdateEditing(cam);
FilteredSelectedList.Add(e); if (selectedList[0].ResizeHorizontal || selectedList[0].ResizeVertical)
}
var first = FilteredSelectedList.FirstOrDefault();
if (first != null)
{
first.UpdateEditing(cam);
if (first.ResizeHorizontal || first.ResizeVertical)
{ {
first.UpdateResizing(cam); first.UpdateResizing(cam);
} }
@@ -594,15 +594,8 @@ namespace Barotrauma.Steam
} }
SaveUtil.ClearFolder(WorkshopItemStagingFolder); SaveUtil.ClearFolder(WorkshopItemStagingFolder);
Directory.Delete(WorkshopItemStagingFolder);
File.Delete(PreviewImageName); File.Delete(PreviewImageName);
try
{
Directory.Delete(WorkshopItemStagingFolder);
}
catch (Exception e)
{
DebugConsole.ThrowError("Failed to delete Workshop item staging folder.", e);
}
yield return CoroutineStatus.Success; yield return CoroutineStatus.Success;
} }
@@ -934,50 +927,28 @@ namespace Barotrauma.Steam
{ {
if (instance == null || !instance.isInitialized) { return false; } if (instance == null || !instance.isInitialized) { return false; }
bool? itemsUpdated = null; bool itemsUpdated = false;
bool timedOut = false; foreach (ulong subscribedItemId in instance.client.Workshop.GetSubscribedItemIds())
var query = instance.client.Workshop.CreateQuery();
query.FileId = new List<ulong>(instance.client.Workshop.GetSubscribedItemIds());
query.UploaderAppId = AppID;
query.Run();
query.OnResult = (Workshop.Query q) =>
{ {
if (timedOut) { return; } //TODO: fix this, GetItem doesn't query item.Modified
itemsUpdated = false; var item = instance.client.Workshop.GetItem(subscribedItemId);
foreach (var item in q.Items) 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(
DebugConsole.ThrowError(errorMsg); TextManager.Get("Error"),
new GUIMessageBox( TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { item.Title, errorMsg }));
TextManager.Get("Error"), }
TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { item.Title, errorMsg })); else
} {
else new GUIMessageBox("", TextManager.GetWithVariable("WorkshopItemUpdated", "[itemname]", item.Title));
{ itemsUpdated = true;
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;
return itemsUpdated.Value;
} }
public static bool UpdateWorkshopItem(Workshop.Item item, out string errorMsg) public static bool UpdateWorkshopItem(Workshop.Item item, out string errorMsg)
@@ -49,7 +49,7 @@ namespace Barotrauma
{ {
tabs = new GUIFrame[Enum.GetValues(typeof(Tab)).Length]; 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 }; 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, IsHorizontal = true,
Stretch = true, Stretch = true,
RelativeSpacing = 0.05f,
CanBeFocused = false CanBeFocused = false
}; };
@@ -406,6 +405,32 @@ namespace Barotrauma
if (item.Installed) 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; GUITickBox enabledTickBox = null;
try 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) 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")); 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 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) => descriptionBox.OnTextChanged += (textBox, text) =>
{ {
Vector2 textSize = textBox.Font.MeasureString(descriptionBox.WrappedText); Vector2 textSize = textBox.Font.MeasureString(descriptionBox.WrappedText);
@@ -1083,7 +1081,6 @@ namespace Barotrauma
{ {
InitialDirectory = Path.GetFullPath(SteamManager.WorkshopItemStagingFolder), InitialDirectory = Path.GetFullPath(SteamManager.WorkshopItemStagingFolder),
Title = TextManager.Get("workshopitemaddfiles"), Title = TextManager.Get("workshopitemaddfiles"),
Multiselect = true
}; };
if (ofd.ShowDialog() == DialogResult.OK) if (ofd.ShowDialog() == DialogResult.OK)
{ {
@@ -1231,7 +1228,7 @@ namespace Barotrauma
private void OnAddFilesSelected(string[] fileNames) private void OnAddFilesSelected(string[] fileNames)
{ {
if (fileNames == null) { return; } if (fileNames == null) { return; }
for (int i = 0; i < fileNames.Length; i++) for(int i = 0; i < fileNames.Length; i++)
{ {
string file = fileNames[i]; string file = fileNames[i];
if (string.IsNullOrEmpty(file)) { continue; } if (string.IsNullOrEmpty(file)) { continue; }
@@ -1261,7 +1258,6 @@ namespace Barotrauma
itemContentPackage.AddFile(filePathRelativeToStagingFolder, ContentType.None); itemContentPackage.AddFile(filePathRelativeToStagingFolder, ContentType.None);
} }
} }
itemContentPackage.Save(itemContentPackage.Path);
RefreshCreateItemFileList(); RefreshCreateItemFileList();
} }
@@ -1335,7 +1331,6 @@ namespace Barotrauma
OnClicked = (btn, userdata) => OnClicked = (btn, userdata) =>
{ {
itemContentPackage.RemoveFile(contentFile); itemContentPackage.RemoveFile(contentFile);
itemContentPackage.Save(itemContentPackage.Path);
RefreshCreateItemFileList(); RefreshCreateItemFileList();
return true; return true;
} }
@@ -1351,7 +1346,7 @@ namespace Barotrauma
{ {
if (itemContentPackage == null || itemEditor == null) return; if (itemContentPackage == null || itemEditor == null) return;
SteamManager.StartPublishItem(itemContentPackage, itemEditor); SteamManager.StartPublishItem(itemContentPackage, itemEditor);
CoroutineManager.StartCoroutine(WaitForPublish(itemEditor), "WaitForPublish"); CoroutineManager.StartCoroutine(WaitForPublish(itemEditor), "WaitForPublish");
} }
@@ -2109,7 +2109,10 @@ namespace Barotrauma
public override void AddToGUIUpdateList() public override void AddToGUIUpdateList()
{ {
MapEntity.FilteredSelectedList.FirstOrDefault()?.AddToGUIUpdateList(); if (MapEntity.SelectedList.Count == 1)
{
MapEntity.SelectedList[0].AddToGUIUpdateList();
}
if (MapEntity.HighlightedListBox != null) if (MapEntity.HighlightedListBox != null)
{ {
MapEntity.HighlightedListBox.AddToGUIUpdateList(); MapEntity.HighlightedListBox.AddToGUIUpdateList();
@@ -2290,9 +2293,9 @@ namespace Barotrauma
dummyCharacter.SelectedConstruction = null; 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); CharacterHUD.Update((float)deltaTime, dummyCharacter, cam);
@@ -22,6 +22,7 @@ namespace Barotrauma.Items.Components
private float openState; private float openState;
private Sprite doorSprite, weldedSprite, brokenSprite; private Sprite doorSprite, weldedSprite, brokenSprite;
private bool scaleBrokenSprite, fadeBrokenSprite; private bool scaleBrokenSprite, fadeBrokenSprite;
private bool createdNewGap;
private bool autoOrientGap; private bool autoOrientGap;
private bool isStuck; private bool isStuck;
@@ -88,7 +89,12 @@ namespace Barotrauma.Items.Components
{ {
if (linkedGap == null) if (linkedGap == null)
{ {
GetLinkedGap(); linkedGap = e as Gap;
if (linkedGap != null)
{
linkedGap.PassAmbientLight = Window != Rectangle.Empty;
return linkedGap;
}
} }
return linkedGap; return linkedGap;
} }
@@ -110,11 +116,16 @@ namespace Barotrauma.Items.Components
rect.X -= 5; rect.X -= 5;
rect.Width += 10; rect.Width += 10;
} }
linkedGap = new Gap(rect, !IsHorizontal, Item.Submarine) linkedGap = new Gap(rect, !IsHorizontal, Item.Submarine)
{ {
Submarine = item.Submarine Submarine = item.Submarine,
PassAmbientLight = Window != Rectangle.Empty,
Open = openState
}; };
item.linkedTo.Add(linkedGap); item.linkedTo.Add(linkedGap);
createdNewGap = true;
return linkedGap;
} }
RefreshLinkedGap(); RefreshLinkedGap();
} }
@@ -375,8 +386,7 @@ namespace Barotrauma.Items.Components
LinkedGap.AutoOrient(); LinkedGap.AutoOrient();
} }
LinkedGap.Open = openState; LinkedGap.Open = openState;
LinkedGap.PassAmbientLight = Window != Rectangle.Empty; if (createdNewGap && autoOrientGap) linkedGap.AutoOrient();
}
public override void OnMapLoaded() public override void OnMapLoaded()
{ {
@@ -285,7 +285,7 @@ namespace Barotrauma
get { return spriteColor; } get { return spriteColor; }
} }
public bool IsFullCondition => Condition >= MaxCondition; public bool IsFullCondition => MathUtils.NearlyEqual(Condition, MaxCondition);
public float MaxCondition => Prefab.Health; public float MaxCondition => Prefab.Health;
public float ConditionPercentage => MathUtils.Percentage(Condition, MaxCondition); public float ConditionPercentage => MathUtils.Percentage(Condition, MaxCondition);
@@ -304,6 +304,7 @@ namespace Barotrauma
if (Indestructible) return; if (Indestructible) return;
float prev = condition; float prev = condition;
condition = MathHelper.Clamp(value, 0.0f, Prefab.Health); condition = MathHelper.Clamp(value, 0.0f, Prefab.Health);
if (condition == 0.0f && prev > 0.0f) if (condition == 0.0f && prev > 0.0f)
{ {
@@ -107,7 +107,7 @@ namespace Barotrauma
if (Screen.Selected == GameMain.SubEditorScreen) if (Screen.Selected == GameMain.SubEditorScreen)
{ {
MapEntity.SelectedList.Clear(); MapEntity.SelectedList.Clear();
entities.ForEach(e => MapEntity.AddSelection(e)); MapEntity.SelectedList.AddRange(entities);
} }
#endif #endif
return entities; return entities;
@@ -378,6 +378,8 @@ namespace Barotrauma
Thread.Sleep(250); Thread.Sleep(250);
} }
} }
return true; return true;
} }
@@ -468,20 +470,7 @@ namespace Barotrauma
foreach (DirectoryInfo di in dir.GetDirectories()) foreach (DirectoryInfo di in dir.GetDirectories())
{ {
ClearFolder(di.FullName, ignoredFileNames); ClearFolder(di.FullName, ignoredFileNames);
int maxRetries = 4; di.Delete();
for (int i = 0; i <= maxRetries; i++)
{
try
{
di.Delete();
break;
}
catch (IOException)
{
if (i >= maxRetries) { throw; }
Thread.Sleep(250);
}
}
} }
} }
} }