Unstable 0.1400.2.0 (a mimir edition)

This commit is contained in:
Markus Isberg
2021-05-28 19:04:09 +03:00
parent 5bc850cddb
commit 0b3fb5e440
126 changed files with 1623 additions and 787 deletions

View File

@@ -29,20 +29,14 @@ namespace Barotrauma
public static bool SelectionChanged;
//which entities have been selected for editing
private static List<MapEntity> selectedList = new List<MapEntity>();
public static List<MapEntity> SelectedList
{
get
{
return selectedList;
}
}
private static List<MapEntity> copiedList = new List<MapEntity>();
public static HashSet<MapEntity> SelectedList { get; private set; } = new HashSet<MapEntity>();
public static List<MapEntity> CopiedList = new List<MapEntity>();
private static List<MapEntity> highlightedList = new List<MapEntity>();
// Test feature. Not yet saved.
public static Dictionary<MapEntity, List<MapEntity>> SelectionGroups { get; private set; } = new Dictionary<MapEntity, List<MapEntity>>();
public static Dictionary<MapEntity, HashSet<MapEntity>> SelectionGroups { get; private set; } = new Dictionary<MapEntity, HashSet<MapEntity>>();
private static float highlightTimer;
@@ -78,26 +72,12 @@ namespace Barotrauma
}
}
public virtual bool SelectableInEditor
{
get { return true; }
}
public virtual bool SelectableInEditor => true;
public static bool SelectedAny
{
get { return selectedList.Count > 0; }
}
public static bool SelectedAny => SelectedList.Count > 0;
public static IEnumerable<MapEntity> CopiedList
{
get { return copiedList; }
}
public bool IsSelected => SelectedList.Contains(this);
public bool IsSelected
{
get { return selectedList.Contains(this); }
}
public bool IsIncludedInSelection { get; set; }
public virtual bool IsVisible(Rectangle worldView)
@@ -131,7 +111,10 @@ namespace Barotrauma
{
if (resizing)
{
if (selectedList.Count == 0) resizing = false;
if (!SelectedAny)
{
resizing = false;
}
return;
}
@@ -159,19 +142,19 @@ namespace Barotrauma
if (MapEntityPrefab.Selected != null)
{
selectionPos = Vector2.Zero;
selectedList.Clear();
SelectedList.Clear();
return;
}
if (GUI.KeyboardDispatcher.Subscriber == null)
{
if (PlayerInput.KeyHit(Keys.Delete))
{
if (selectedList.Any())
if (SelectedAny)
{
SubEditorScreen.StoreCommand(new AddOrDeleteCommand(selectedList, true));
SubEditorScreen.StoreCommand(new AddOrDeleteCommand(new List<MapEntity>(SelectedList), true));
}
selectedList.ForEach(e => { if (!e.Removed) { e.Remove(); } });
selectedList.Clear();
SelectedList.ForEach(e => { if (!e.Removed) { e.Remove(); } });
SelectedList.Clear();
}
if (PlayerInput.IsCtrlDown())
@@ -180,7 +163,7 @@ namespace Barotrauma
if (PlayerInput.KeyHit(Keys.D))
{
bool terminate = false;
foreach (MapEntity entity in selectedList)
foreach (MapEntity entity in SelectedList)
{
if (entity is Item item && item.GetComponent<Planter>() is { } planter)
{
@@ -203,11 +186,11 @@ namespace Barotrauma
#endif
if (PlayerInput.KeyHit(Keys.C))
{
Copy(selectedList);
Copy(SelectedList.ToList());
}
else if (PlayerInput.KeyHit(Keys.X))
{
Cut(selectedList);
Cut(SelectedList.ToList());
}
else if (PlayerInput.KeyHit(Keys.V))
{
@@ -215,21 +198,21 @@ namespace Barotrauma
}
else if (PlayerInput.KeyHit(Keys.G))
{
if (selectedList.Any())
if (SelectedList.Any())
{
if (SelectionGroups.ContainsKey(selectedList.Last()))
if (SelectionGroups.ContainsKey(SelectedList.Last()))
{
// Ungroup all selected
selectedList.ForEach(e => SelectionGroups.Remove(e));
SelectedList.ForEach(e => SelectionGroups.Remove(e));
}
else
{
foreach (var entity in selectedList)
foreach (var entity in SelectedList)
{
// Remove the old group, if any
SelectionGroups.Remove(entity);
// Create a group that can be accessed with any member
SelectionGroups.Add(entity, selectedList);
SelectionGroups.Add(entity, SelectedList);
}
}
}
@@ -279,7 +262,7 @@ namespace Barotrauma
Vector2 nudge = GetNudgeAmount();
if (nudge != Vector2.Zero)
{
foreach (MapEntity entityToNudge in selectedList) { entityToNudge.Move(nudge); }
foreach (MapEntity entityToNudge in SelectedList) { entityToNudge.Move(nudge); }
}
}
else
@@ -292,7 +275,7 @@ namespace Barotrauma
//started moving selected entities
if (startMovingPos != Vector2.Zero)
{
Item targetContainer = GetPotentialContainer(position, selectedList);
Item targetContainer = GetPotentialContainer(position, SelectedList);
if (targetContainer != null) { targetContainer.IsHighlighted = true; }
@@ -315,16 +298,16 @@ namespace Barotrauma
//clone
if (PlayerInput.IsCtrlDown())
{
var clones = Clone(selectedList).Where(c => c != null).ToList();
selectedList = clones;
selectedList.ForEach(c => c.Move(moveAmount));
SubEditorScreen.StoreCommand(new AddOrDeleteCommand(clones, false));
HashSet<MapEntity> clones = Clone(SelectedList.ToList()).Where(c => c != null).ToHashSet();
SelectedList = clones;
SelectedList.ForEach(c => c.Move(moveAmount));
SubEditorScreen.StoreCommand(new AddOrDeleteCommand(new List<MapEntity>(clones), false));
}
else // move
{
var oldRects = selectedList.Select(e => e.Rect).ToList();
var oldRects = SelectedList.Select(e => e.Rect).ToList();
List<MapEntity> deposited = new List<MapEntity>();
foreach (MapEntity e in selectedList)
foreach (MapEntity e in SelectedList)
{
e.Move(moveAmount);
@@ -342,14 +325,14 @@ namespace Barotrauma
}
}
SubEditorScreen.StoreCommand(new TransformCommand(new List<MapEntity>(selectedList),selectedList.Select(entity => entity.Rect).ToList(), oldRects, false));
SubEditorScreen.StoreCommand(new TransformCommand(new List<MapEntity>(SelectedList),SelectedList.Select(entity => entity.Rect).ToList(), oldRects, false));
if (deposited.Any() && deposited.Any(entity => entity is Item))
{
var depositedItems = deposited.Where(entity => entity is Item).Cast<Item>().ToList();
SubEditorScreen.StoreCommand(new InventoryPlaceCommand(targetContainer.OwnInventory, depositedItems, false));
}
deposited.ForEach(entity => { selectedList.Remove(entity); });
deposited.ForEach(entity => { SelectedList.Remove(entity); });
}
}
startMovingPos = Vector2.Zero;
@@ -367,7 +350,7 @@ namespace Barotrauma
entity.IsIncludedInSelection = false;
}
List<MapEntity> newSelection = new List<MapEntity>();// FindSelectedEntities(selectionPos, selectionSize);
HashSet<MapEntity> newSelection = new HashSet<MapEntity>();// FindSelectedEntities(selectionPos, selectionSize);
if (Math.Abs(selectionSize.X) > Submarine.GridSize.X || Math.Abs(selectionSize.Y) > Submarine.GridSize.Y)
{
newSelection = FindSelectedEntities(selectionPos, selectionSize);
@@ -376,9 +359,13 @@ namespace Barotrauma
{
if (highLightedEntity != null)
{
if (SelectionGroups.TryGetValue(highLightedEntity, out List<MapEntity> group))
if (SelectionGroups.TryGetValue(highLightedEntity, out HashSet<MapEntity> group))
{
newSelection.AddRange(group);
foreach (MapEntity entity in group.Where(e => !newSelection.Contains(e)))
{
newSelection.Add(entity);
}
foreach (MapEntity entity in group)
{
entity.IsIncludedInSelection = true;
@@ -398,7 +385,7 @@ namespace Barotrauma
{
foreach (MapEntity e in newSelection)
{
if (selectedList.Contains(e))
if (SelectedList.Contains(e))
{
RemoveSelection(e);
}
@@ -410,7 +397,7 @@ namespace Barotrauma
}
else
{
selectedList = new List<MapEntity>(newSelection);
SelectedList = new HashSet<MapEntity>(newSelection);
//selectedList.Clear();
//newSelection.ForEach(e => AddSelection(e));
foreach (var entity in newSelection)
@@ -419,23 +406,23 @@ namespace Barotrauma
onGapFound: (door, gap) =>
{
door.RefreshLinkedGap();
if (!selectedList.Contains(gap))
if (!SelectedList.Contains(gap))
{
selectedList.Add(gap);
SelectedList.Add(gap);
}
},
onDoorFound: (door, gap) =>
{
if (!selectedList.Contains(door.Item))
if (!SelectedList.Contains(door.Item))
{
selectedList.Add(door.Item);
SelectedList.Add(door.Item);
}
});
}
}
//select wire if both items it's connected to are selected
var selectedItems = selectedList.Where(e => e is Item).Cast<Item>().ToList();
var selectedItems = SelectedList.Where(e => e is Item).Cast<Item>().ToList();
foreach (Item item in selectedItems)
{
if (item.Connections == null) continue;
@@ -443,11 +430,11 @@ namespace Barotrauma
{
foreach (Wire w in c.Wires)
{
if (w == null || selectedList.Contains(w.Item)) continue;
if (w == null || SelectedList.Contains(w.Item)) continue;
if (w.OtherConnection(c) != null && selectedList.Contains(w.OtherConnection(c).Item))
if (w.OtherConnection(c) != null && SelectedList.Contains(w.OtherConnection(c).Item))
{
selectedList.Add(w.Item);
SelectedList.Add(w.Item);
}
}
}
@@ -471,7 +458,7 @@ namespace Barotrauma
(highlightedListBox == null || (GUI.MouseOn != highlightedListBox && !highlightedListBox.IsParentOf(GUI.MouseOn))))
{
//if clicking a selected entity, start moving it
foreach (MapEntity e in selectedList)
foreach (MapEntity e in SelectedList)
{
if (e.IsMouseOn(position)) startMovingPos = position;
}
@@ -519,7 +506,7 @@ namespace Barotrauma
return ReplacedBy?.GetReplacementOrThis() ?? this;
}
public static Item GetPotentialContainer(Vector2 position, List<MapEntity> entities = null)
public static Item GetPotentialContainer(Vector2 position, HashSet<MapEntity> entities = null)
{
Item targetContainer = null;
bool isShiftDown = PlayerInput.IsShiftDown();
@@ -654,7 +641,7 @@ namespace Barotrauma
if (PlayerInput.IsCtrlDown() && !wiringMode)
{
if (selectedList.Contains(entity))
if (SelectedList.Contains(entity))
{
RemoveSelection(entity);
}
@@ -673,56 +660,60 @@ namespace Barotrauma
public static void AddSelection(MapEntity entity)
{
if (selectedList.Contains(entity)) { return; }
selectedList.Add(entity);
if (SelectedList.Contains(entity)) { return; }
SelectedList.Add(entity);
HandleDoorGapLinks(entity,
onGapFound: (door, gap) =>
{
door.RefreshLinkedGap();
if (!selectedList.Contains(gap))
if (!SelectedList.Contains(gap))
{
selectedList.Add(gap);
SelectedList.Add(gap);
}
},
onDoorFound: (door, gap) =>
{
if (!selectedList.Contains(door.Item))
if (!SelectedList.Contains(door.Item))
{
selectedList.Add(door.Item);
SelectedList.Add(door.Item);
}
});
}
private static void HandleDoorGapLinks(MapEntity entity, Action<Door, Gap> onGapFound, Action<Door, Gap> onDoorFound)
{
if (entity is Item i)
switch (entity)
{
var door = i.GetComponent<Door>();
if (door != null)
case Item i:
{
var gap = door.LinkedGap;
var door = i.GetComponent<Door>();
var gap = door?.LinkedGap;
if (gap != null)
{
onGapFound(door, gap);
}
break;
}
}
else if (entity is Gap gap)
{
var door = gap.ConnectedDoor;
if (door != null)
case Gap gap:
{
onDoorFound(door, gap);
var door = gap.ConnectedDoor;
if (door != null)
{
onDoorFound(door, gap);
}
break;
}
}
}
public static void RemoveSelection(MapEntity entity)
{
selectedList.Remove(entity);
SelectedList.Remove(entity);
HandleDoorGapLinks(entity,
onGapFound: (door, gap) => selectedList.Remove(gap),
onDoorFound: (door, gap) => selectedList.Remove(door.Item));
onGapFound: (door, gap) => SelectedList.Remove(gap),
onDoorFound: (door, gap) => SelectedList.Remove(door.Item));
}
static partial void UpdateAllProjSpecific(float deltaTime)
@@ -767,7 +758,7 @@ namespace Barotrauma
//started moving the selected entities
if (Math.Abs(moveAmount.X) >= Submarine.GridSize.X || Math.Abs(moveAmount.Y) >= Submarine.GridSize.Y || isShiftDown)
{
foreach (MapEntity e in selectedList)
foreach (MapEntity e in SelectedList)
{
SpriteEffects spriteEffects = SpriteEffects.None;
switch (e)
@@ -865,8 +856,8 @@ namespace Barotrauma
}
}
FilteredSelectedList.Clear();
if (selectedList.Count == 0) return;
foreach (var e in selectedList)
if (SelectedList.Count == 0) return;
foreach (var e in SelectedList)
{
if (e is Gap gap && gap.ConnectedDoor != null) { continue; }
FilteredSelectedList.Add(e);
@@ -885,15 +876,19 @@ namespace Barotrauma
{
if (PlayerInput.KeyHit(Keys.N))
{
float minX = selectedList[0].WorldRect.X, maxX = selectedList[0].WorldRect.Right;
for (int i = 0; i < selectedList.Count; i++)
MapEntity firstSelected = SelectedList.First();
float minX = firstSelected.WorldRect.X,
maxX = firstSelected.WorldRect.Right;
foreach (MapEntity entity in SelectedList)
{
minX = Math.Min(minX, selectedList[i].WorldRect.X);
maxX = Math.Max(maxX, selectedList[i].WorldRect.Right);
minX = Math.Min(minX, entity.WorldRect.X);
maxX = Math.Max(maxX, entity.WorldRect.Right);
}
float centerX = (minX + maxX) / 2.0f;
foreach (MapEntity me in selectedList)
foreach (MapEntity me in SelectedList)
{
me.FlipX(false);
me.Move(new Vector2((centerX - me.WorldPosition.X) * 2.0f, 0.0f));
@@ -901,15 +896,20 @@ namespace Barotrauma
}
else if (PlayerInput.KeyHit(Keys.M))
{
float minY = selectedList[0].WorldRect.Y - selectedList[0].WorldRect.Height, maxY = selectedList[0].WorldRect.Y;
for (int i = 0; i < selectedList.Count; i++)
MapEntity firstSelected = SelectedList.First();
float minY = firstSelected.WorldRect.Y - firstSelected.WorldRect.Height,
maxY = firstSelected.WorldRect.Y;
foreach (MapEntity entity in SelectedList)
{
minY = Math.Min(minY, selectedList[i].WorldRect.Y - selectedList[i].WorldRect.Height);
maxY = Math.Max(maxY, selectedList[i].WorldRect.Y);
minY = Math.Min(minY, entity.WorldRect.Y - entity.WorldRect.Height);
maxY = Math.Max(maxY, entity.WorldRect.Y);
}
float centerY = (minY + maxY) / 2.0f;
foreach (MapEntity me in selectedList)
foreach (MapEntity me in SelectedList)
{
me.FlipY(false);
me.Move(new Vector2(0.0f, (centerY - me.WorldPosition.Y) * 2.0f));
@@ -920,19 +920,20 @@ namespace Barotrauma
public static void DrawEditor(SpriteBatch spriteBatch, Camera cam)
{
if (selectedList.Count == 1)
if (SelectedList.Count == 1)
{
selectedList[0].DrawEditing(spriteBatch, cam);
if (selectedList[0].ResizeHorizontal || selectedList[0].ResizeVertical)
MapEntity firstSelected = SelectedList.First();
firstSelected.DrawEditing(spriteBatch, cam);
if (firstSelected.ResizeHorizontal || firstSelected.ResizeVertical)
{
selectedList[0].DrawResizing(spriteBatch, cam);
firstSelected.DrawResizing(spriteBatch, cam);
}
}
}
public static void DeselectAll()
{
selectedList.Clear();
SelectedList.Clear();
}
public static void SelectEntity(MapEntity entity)
@@ -967,10 +968,10 @@ namespace Barotrauma
public static void Paste(Vector2 position)
{
if (copiedList.Count == 0) { return; }
if (CopiedList.Count == 0) { return; }
List<MapEntity> prevEntities = new List<MapEntity>(mapEntityList);
Clone(copiedList);
Clone(CopiedList);
var clones = mapEntityList.Except(prevEntities).ToList();
var nonWireClones = clones.Where(c => !(c is Item item) || item.GetComponent<Wire>() == null);
@@ -982,8 +983,8 @@ namespace Barotrauma
Vector2 moveAmount = Submarine.VectorToWorldGrid(position - center);
selectedList = new List<MapEntity>(clones);
foreach (MapEntity clone in selectedList)
SelectedList = new HashSet<MapEntity>(clones);
foreach (MapEntity clone in SelectedList)
{
clone.Move(moveAmount);
clone.Submarine = Submarine.MainSub;
@@ -999,7 +1000,7 @@ namespace Barotrauma
{
List<MapEntity> prevEntities = new List<MapEntity>(mapEntityList);
copiedList = Clone(entities);
CopiedList = Clone(entities);
//find all new entities created during cloning
var newEntities = mapEntityList.Except(prevEntities).ToList();
@@ -1172,9 +1173,9 @@ namespace Barotrauma
/// <summary>
/// Find entities whose rect intersects with the "selection rect"
/// </summary>
public static List<MapEntity> FindSelectedEntities(Vector2 pos, Vector2 size)
public static HashSet<MapEntity> FindSelectedEntities(Vector2 pos, Vector2 size)
{
List<MapEntity> foundEntities = new List<MapEntity>();
HashSet<MapEntity> foundEntities = new HashSet<MapEntity>();
Rectangle selectionRect = Submarine.AbsRect(pos, size);