(1986bc0d3) Merge branch 'dev' of https://github.com/Regalis11/Barotrauma-development into dev

This commit is contained in:
Joonas Rikkonen
2019-06-11 21:46:21 +03:00
parent dd1ce8bf2f
commit 5f497543a4
9 changed files with 154 additions and 77 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]; if (parentHierarchy[i].GUIComponent is GUIListBox) return parentHierarchy[i]?.Parent ?? 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();
MapEntity.SelectedList.AddRange(assemblyEntities); assemblyEntities.ForEach(e => MapEntity.AddSelection(e));
foreach (MapEntity mapEntity in assemblyEntities) foreach (MapEntity mapEntity in assemblyEntities)
{ {
@@ -478,6 +478,45 @@ 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)
{ {
@@ -546,6 +585,7 @@ 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)
@@ -563,11 +603,16 @@ namespace Barotrauma
} }
if (selectedList.Count == 0) return; if (selectedList.Count == 0) return;
foreach (var e in selectedList)
if (editingHUD != null)
{ {
selectedList[0].UpdateEditing(cam); if (e is Gap) { continue; }
if (selectedList[0].ResizeHorizontal || selectedList[0].ResizeVertical) FilteredSelectedList.Add(e);
}
var first = FilteredSelectedList.FirstOrDefault();
if (first != null)
{
first.UpdateEditing(cam);
if (first.ResizeHorizontal || first.ResizeVertical)
{ {
first.UpdateResizing(cam); first.UpdateResizing(cam);
} }
@@ -594,8 +594,15 @@ 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;
} }
@@ -927,28 +934,50 @@ namespace Barotrauma.Steam
{ {
if (instance == null || !instance.isInitialized) { return false; } if (instance == null || !instance.isInitialized) { return false; }
bool itemsUpdated = false; bool? itemsUpdated = null;
foreach (ulong subscribedItemId in instance.client.Workshop.GetSubscribedItemIds()) bool timedOut = false;
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) =>
{ {
//TODO: fix this, GetItem doesn't query item.Modified if (timedOut) { return; }
var item = instance.client.Workshop.GetItem(subscribedItemId); itemsUpdated = false;
if (item.Installed && CheckWorkshopItemEnabled(item) && !CheckWorkshopItemUpToDate(item)) foreach (var item in q.Items)
{ {
if (!UpdateWorkshopItem(item, out string errorMsg)) if (item.Installed && CheckWorkshopItemEnabled(item) && !CheckWorkshopItemUpToDate(item))
{ {
DebugConsole.ThrowError(errorMsg); if (!UpdateWorkshopItem(item, out string errorMsg))
new GUIMessageBox( {
TextManager.Get("Error"), DebugConsole.ThrowError(errorMsg);
TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { item.Title, errorMsg })); new GUIMessageBox(
} TextManager.Get("Error"),
else TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { item.Title, errorMsg }));
{ }
new GUIMessageBox("", TextManager.GetWithVariable("WorkshopItemUpdated", "[itemname]", item.Title)); else
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.6f, 0.8f), GUI.Canvas, Anchor.Center) { MinSize = new Point(GameMain.GraphicsHeight, 0) }); menu = new GUIFrame(new RectTransform(new Vector2(0.85f, 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,6 +394,7 @@ namespace Barotrauma
{ {
IsHorizontal = true, IsHorizontal = true,
Stretch = true, Stretch = true,
RelativeSpacing = 0.05f,
CanBeFocused = false CanBeFocused = false
}; };
@@ -405,32 +406,6 @@ 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
{ {
@@ -476,6 +451,33 @@ 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)
{ {
@@ -900,7 +902,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, wrap: true); var descriptionBox = new GUITextBox(new RectTransform(Vector2.One, descriptionContainer.Content.RectTransform), itemEditor.Description, textAlignment: Alignment.TopLeft, font: GUI.SmallFont, wrap: true);
descriptionBox.OnTextChanged += (textBox, text) => descriptionBox.OnTextChanged += (textBox, text) =>
{ {
Vector2 textSize = textBox.Font.MeasureString(descriptionBox.WrappedText); Vector2 textSize = textBox.Font.MeasureString(descriptionBox.WrappedText);
@@ -1081,6 +1083,7 @@ 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)
{ {
@@ -1228,7 +1231,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; }
@@ -1258,6 +1261,7 @@ namespace Barotrauma
itemContentPackage.AddFile(filePathRelativeToStagingFolder, ContentType.None); itemContentPackage.AddFile(filePathRelativeToStagingFolder, ContentType.None);
} }
} }
itemContentPackage.Save(itemContentPackage.Path);
RefreshCreateItemFileList(); RefreshCreateItemFileList();
} }
@@ -1331,6 +1335,7 @@ namespace Barotrauma
OnClicked = (btn, userdata) => OnClicked = (btn, userdata) =>
{ {
itemContentPackage.RemoveFile(contentFile); itemContentPackage.RemoveFile(contentFile);
itemContentPackage.Save(itemContentPackage.Path);
RefreshCreateItemFileList(); RefreshCreateItemFileList();
return true; return true;
} }
@@ -1346,7 +1351,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,10 +2109,7 @@ namespace Barotrauma
public override void AddToGUIUpdateList() public override void AddToGUIUpdateList()
{ {
if (MapEntity.SelectedList.Count == 1) MapEntity.FilteredSelectedList.FirstOrDefault()?.AddToGUIUpdateList();
{
MapEntity.SelectedList[0].AddToGUIUpdateList();
}
if (MapEntity.HighlightedListBox != null) if (MapEntity.HighlightedListBox != null)
{ {
MapEntity.HighlightedListBox.AddToGUIUpdateList(); MapEntity.HighlightedListBox.AddToGUIUpdateList();
@@ -2293,9 +2290,9 @@ namespace Barotrauma
dummyCharacter.SelectedConstruction = null; dummyCharacter.SelectedConstruction = null;
}*/ }*/
} }
else if (MapEntity.SelectedList.Count == 1) else if (MapEntity.FilteredSelectedList.Count == 1)
{ {
(MapEntity.SelectedList[0] as Item)?.UpdateHUD(cam, dummyCharacter, (float)deltaTime); (MapEntity.FilteredSelectedList[0] as Item)?.UpdateHUD(cam, dummyCharacter, (float)deltaTime);
} }
CharacterHUD.Update((float)deltaTime, dummyCharacter, cam); CharacterHUD.Update((float)deltaTime, dummyCharacter, cam);
@@ -22,7 +22,6 @@ 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;
@@ -89,12 +88,7 @@ namespace Barotrauma.Items.Components
{ {
if (linkedGap == null) if (linkedGap == null)
{ {
linkedGap = e as Gap; GetLinkedGap();
if (linkedGap != null)
{
linkedGap.PassAmbientLight = Window != Rectangle.Empty;
return linkedGap;
}
} }
return linkedGap; return linkedGap;
} }
@@ -116,16 +110,11 @@ 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();
} }
@@ -386,7 +375,8 @@ namespace Barotrauma.Items.Components
LinkedGap.AutoOrient(); LinkedGap.AutoOrient();
} }
LinkedGap.Open = openState; LinkedGap.Open = openState;
if (createdNewGap && autoOrientGap) linkedGap.AutoOrient(); LinkedGap.PassAmbientLight = Window != Rectangle.Empty;
}
public override void OnMapLoaded() public override void OnMapLoaded()
{ {
@@ -107,7 +107,7 @@ namespace Barotrauma
if (Screen.Selected == GameMain.SubEditorScreen) if (Screen.Selected == GameMain.SubEditorScreen)
{ {
MapEntity.SelectedList.Clear(); MapEntity.SelectedList.Clear();
MapEntity.SelectedList.AddRange(entities); entities.ForEach(e => MapEntity.AddSelection(e));
} }
#endif #endif
return entities; return entities;
@@ -378,8 +378,6 @@ namespace Barotrauma
Thread.Sleep(250); Thread.Sleep(250);
} }
} }
return true; return true;
} }
@@ -470,7 +468,20 @@ namespace Barotrauma
foreach (DirectoryInfo di in dir.GetDirectories()) foreach (DirectoryInfo di in dir.GetDirectories())
{ {
ClearFolder(di.FullName, ignoredFileNames); ClearFolder(di.FullName, ignoredFileNames);
di.Delete(); int maxRetries = 4;
for (int i = 0; i <= maxRetries; i++)
{
try
{
di.Delete();
break;
}
catch (IOException)
{
if (i >= maxRetries) { throw; }
Thread.Sleep(250);
}
}
} }
} }
} }