Entities that are behind other entities can be selected using a listbox that appears when hovering the cursor over them, itemcomponent GUIFrames aren't added to GUIUpdateList in sub editor (unless in character mode)

This commit is contained in:
Regalis
2016-11-28 21:27:36 +02:00
parent d035d3bfb2
commit 0b03b78606
9 changed files with 196 additions and 61 deletions
+146 -36
View File
@@ -26,7 +26,18 @@ namespace Barotrauma
}
}
private static List<MapEntity> copiedList = new List<MapEntity>();
private static List<MapEntity> highlightedList = new List<MapEntity>();
private static float highlightTimer;
private static GUIListBox highlightedListBox;
public static GUIListBox HighlightedListBox
{
get { return highlightedListBox; }
}
protected static GUIComponent editingHUD;
public static GUIComponent EditingHUD
{
@@ -371,7 +382,7 @@ namespace Barotrauma
public virtual void Update(Camera cam, float deltaTime) { }
/// <summary>
/// Update the selection logic in editmap-screen
/// Update the selection logic in submarine editor
/// </summary>
public static void UpdateSelecting(Camera cam)
{
@@ -392,7 +403,15 @@ namespace Barotrauma
return;
}
if (GUIComponent.MouseOn != null || !PlayerInput.MouseInsideWindow) return;
if (GUIComponent.MouseOn != null || !PlayerInput.MouseInsideWindow)
{
if (highlightedListBox == null ||
(GUIComponent.MouseOn != highlightedListBox && !highlightedListBox.IsParentOf(GUIComponent.MouseOn)))
{
UpdateHighlightedListBox(null);
return;
}
}
if (MapEntityPrefab.Selected != null)
{
@@ -445,19 +464,62 @@ namespace Barotrauma
if (startMovingPos == Vector2.Zero)
{
foreach (MapEntity e in mapEntityList)
List<MapEntity> highlightedEntities = new List<MapEntity>();
if (highlightedListBox != null && highlightedListBox.IsParentOf(GUIComponent.MouseOn))
{
if (!e.SelectableInEditor) continue;
if (highLightedEntity == null || e.Sprite == null ||
(highLightedEntity.Sprite != null && e.Sprite.Depth < highLightedEntity.Sprite.Depth))
highLightedEntity = GUIComponent.MouseOn.UserData as MapEntity;
}
else
{
foreach (MapEntity e in mapEntityList)
{
if (e.IsMouseOn(position)) highLightedEntity = e;
if (!e.SelectableInEditor) continue;
if (e.IsMouseOn(position))
{
int i = 0;
while (i < highlightedEntities.Count &&
e.Sprite != null &&
(highlightedEntities[i].Sprite == null || highlightedEntities[i].Sprite.Depth < e.Sprite.Depth))
{
i++;
}
highlightedEntities.Insert(i, e);
if (i == 0) highLightedEntity = e;
}
}
if (PlayerInput.MouseSpeed.LengthSquared() > 10)
{
highlightTimer = 0.0f;
}
else
{
bool mouseNearHighlightBox = false;
if (highlightedListBox != null)
{
Rectangle expandedRect = highlightedListBox.Rect;
expandedRect.Inflate(20, 20);
mouseNearHighlightBox = expandedRect.Contains(PlayerInput.MousePosition);
if (!mouseNearHighlightBox) highlightedListBox = null;
}
highlightTimer += (float)Timing.Step;
if (highlightTimer > 1.0f)
{
if (!mouseNearHighlightBox)
{
UpdateHighlightedListBox(highlightedEntities);
highlightTimer = 0.0f;
}
}
}
}
if (highLightedEntity != null) highLightedEntity.isHighlighted = true;
}
//started moving selected entities
@@ -505,11 +567,6 @@ namespace Barotrauma
if (highLightedEntity != null) newSelection.Add(highLightedEntity);
}
foreach (MapEntity e in newSelection)
{
e.isHighlighted = true;
}
if (PlayerInput.LeftButtonReleased())
{
if (PlayerInput.KeyDown(Keys.LeftControl) ||
@@ -517,14 +574,7 @@ namespace Barotrauma
{
foreach (MapEntity e in newSelection)
{
bool alreadySelected = false;
foreach (MapEntity e2 in selectedList)
{
if (e.ID == e2.ID) alreadySelected = true;
}
if (alreadySelected)
if (selectedList.Contains(e))
selectedList.Remove(e);
else
selectedList.Add(e);
@@ -562,7 +612,8 @@ namespace Barotrauma
else
{
if (PlayerInput.LeftButtonHeld() &&
PlayerInput.KeyUp(Keys.Space))
PlayerInput.KeyUp(Keys.Space) &&
(highlightedListBox == null || (GUIComponent.MouseOn != highlightedListBox && !highlightedListBox.IsParentOf(GUIComponent.MouseOn))))
{
//if clicking a selected entity, start moving it
foreach (MapEntity e in selectedList)
@@ -575,6 +626,57 @@ namespace Barotrauma
}
}
private static void UpdateHighlightedListBox(List<MapEntity> highlightedEntities)
{
if (highlightedEntities == null || highlightedEntities.Count < 2)
{
highlightedListBox = null;
return;
}
if (highlightedListBox != null)
{
if (GUIComponent.MouseOn == highlightedListBox || highlightedListBox.IsParentOf(GUIComponent.MouseOn)) return;
if (highlightedEntities.SequenceEqual(highlightedList)) return;
}
highlightedList = highlightedEntities;
highlightedListBox = new GUIListBox(
new Rectangle((int)PlayerInput.MousePosition.X+15, (int)PlayerInput.MousePosition.Y+15, 150, highlightedEntities.Count * 15),
null, Alignment.TopLeft, GUI.Style, null, false);
highlightedListBox.Color = Color.Black * 0.6f;
foreach (MapEntity entity in highlightedEntities)
{
var textBlock = new GUITextBlock(
new Rectangle(0,0,0,15),
ToolBox.LimitString(entity.Name, GUI.SmallFont, 140), GUI.Style, highlightedListBox, GUI.SmallFont);
textBlock.UserData = entity;
}
highlightedListBox.OnSelected = (GUIComponent component, object obj) =>
{
MapEntity entity = obj as MapEntity;
if (PlayerInput.KeyDown(Keys.LeftControl) ||
PlayerInput.KeyDown(Keys.RightControl))
{
if (selectedList.Contains(entity))
selectedList.Remove(entity);
else
selectedList.Add(entity);
}
else
{
SelectEntity(entity);
}
return true;
};
}
/// <summary>
/// Draw the "selection rectangle" and outlines of entities that are being dragged (if any)
@@ -612,6 +714,8 @@ namespace Barotrauma
public static void UpdateEditor(Camera cam)
{
if (highlightedListBox != null) highlightedListBox.Update((float)Timing.Step);
if (selectedList.Count == 1)
{
selectedList[0].UpdateEditing(cam);
@@ -621,19 +725,21 @@ namespace Barotrauma
selectedList[0].UpdateResizing(cam);
}
}
else
if (editingHUD != null)
{
if (editingHUD == null) return;
foreach (GUIComponent component in editingHUD.children)
if (selectedList.Count == 0 || editingHUD.UserData != selectedList[0])
{
var textBox = component as GUITextBox;
if (textBox == null) continue;
foreach (GUIComponent component in editingHUD.children)
{
var textBox = component as GUITextBox;
if (textBox == null) continue;
textBox.Deselect();
textBox.Deselect();
}
editingHUD = null;
}
editingHUD = null;
}
}
@@ -648,6 +754,11 @@ namespace Barotrauma
selectedList[0].DrawResizing(spriteBatch, cam);
}
}
if (highlightedListBox != null)
{
highlightedListBox.Draw(spriteBatch);
}
}
public static void DeselectAll()
@@ -662,8 +773,7 @@ namespace Barotrauma
selectedList.Add(entity);
}
/// <summary>
/// copies a list of entities to the "clipboard" (copiedList)
/// </summary>
@@ -697,7 +807,7 @@ namespace Barotrauma
public virtual void AddToGUIUpdateList()
{
if (editingHUD != null) editingHUD.AddToGUIUpdateList();
if (editingHUD != null && editingHUD.UserData == this) editingHUD.AddToGUIUpdateList();
}
public virtual void UpdateEditing(Camera cam) { }