diff --git a/Subsurface/Source/GUI/GUIListBox.cs b/Subsurface/Source/GUI/GUIListBox.cs index 117d193f2..6c6cb3ee2 100644 --- a/Subsurface/Source/GUI/GUIListBox.cs +++ b/Subsurface/Source/GUI/GUIListBox.cs @@ -147,7 +147,8 @@ namespace Barotrauma scrollBar = new GUIScrollBar( new Rectangle(this.rect.Right - 20, this.rect.Y, 20, this.rect.Height), null, 1.0f, GUI.Style); } - + + scrollBar.IsHorizontal = isHorizontal; frame = new GUIFrame(Rectangle.Empty, style, this); if (style != null) style.Apply(frame, this); diff --git a/Subsurface/Source/GUI/GUIScrollBar.cs b/Subsurface/Source/GUI/GUIScrollBar.cs index 60bb9d1ed..4e21592df 100644 --- a/Subsurface/Source/GUI/GUIScrollBar.cs +++ b/Subsurface/Source/GUI/GUIScrollBar.cs @@ -25,6 +25,12 @@ namespace Barotrauma public bool IsHorizontal { get { return isHorizontal; } + set + { + if (isHorizontal == value) return; + isHorizontal = value; + UpdateRect(); + } } public bool Enabled diff --git a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs index edb85ccd6..a7e4516ad 100644 --- a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs +++ b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs @@ -177,7 +177,7 @@ namespace Barotrauma.Items.Components Item targetItem; if ((targetStructure = (targetBody.UserData as Structure)) != null) { - if (!fixableEntities.Contains(targetStructure.Name)) return; + if (!fixableEntities.Contains("structure") && !fixableEntities.Contains(targetStructure.Name)) return; if (targetStructure.IsPlatform) return; int sectionIndex = targetStructure.FindSectionIndex(ConvertUnits.ToDisplayUnits(pickedPosition)); diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 1b26fcc33..9bfea02aa 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -1145,23 +1145,32 @@ namespace Barotrauma public override void AddToGUIUpdateList() { - if (condition <= 0.0f) - { - FixRequirement.AddToGUIUpdateList(); - return; - } - - if (HasInGameEditableProperties) + if (Screen.Selected is EditMapScreen) { if (editingHUD != null) editingHUD.AddToGUIUpdateList(); } - - foreach (ItemComponent ic in components) + else { - ic.AddToGUIUpdateList(); + if (HasInGameEditableProperties) + { + if (editingHUD != null) editingHUD.AddToGUIUpdateList(); + } } - if (Screen.Selected is EditMapScreen && editingHUD != null) editingHUD.AddToGUIUpdateList(); + if (Character.Controlled!=null && Character.Controlled.SelectedConstruction == this) + { + + if (condition <= 0.0f) + { + FixRequirement.AddToGUIUpdateList(); + return; + } + + foreach (ItemComponent ic in components) + { + ic.AddToGUIUpdateList(); + } + } } public virtual void UpdateHUD(Camera cam, Character character) diff --git a/Subsurface/Source/Map/Gap.cs b/Subsurface/Source/Map/Gap.cs index b99a83ddf..7aa460dca 100644 --- a/Subsurface/Source/Map/Gap.cs +++ b/Subsurface/Source/Map/Gap.cs @@ -80,6 +80,14 @@ namespace Barotrauma } } + public override string Name + { + get + { + return "Gap"; + } + } + public override bool SelectableInEditor { get diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index 144f1851b..6d4389503 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -26,7 +26,18 @@ namespace Barotrauma } } private static List copiedList = new List(); - + + private static List highlightedList = new List(); + + 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) { } /// - /// Update the selection logic in editmap-screen + /// Update the selection logic in submarine editor /// 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 highlightedEntities = new List(); + 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 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; + }; + } + /// /// 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); } - - + /// /// copies a list of entities to the "clipboard" (copiedList) /// @@ -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) { } diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index a361a8189..747b3fae9 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -99,7 +99,7 @@ namespace Barotrauma public override string Name { - get { return "structure"; } + get { return prefab.Name; } } public bool HasBody diff --git a/Subsurface/Source/Map/WayPoint.cs b/Subsurface/Source/Map/WayPoint.cs index 769a655bd..6575a5ff0 100644 --- a/Subsurface/Source/Map/WayPoint.cs +++ b/Subsurface/Source/Map/WayPoint.cs @@ -54,13 +54,13 @@ namespace Barotrauma set { spawnType = value; } } - //public override string Name - //{ - // get - // { - // return spawnType == SpawnType.Path ? "WayPoint" : "SpawnPoint"; - // } - //} + public override string Name + { + get + { + return spawnType == SpawnType.Path ? "WayPoint" : "SpawnPoint"; + } + } public string[] IdCardTags { diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index 3c04b411b..025f050c4 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -858,6 +858,10 @@ namespace Barotrauma { MapEntity.SelectedList[0].AddToGUIUpdateList(); } + if (MapEntity.HighlightedListBox != null) + { + MapEntity.HighlightedListBox.AddToGUIUpdateList(); + } leftPanel.AddToGUIUpdateList(); topPanel.AddToGUIUpdateList(); @@ -899,10 +903,7 @@ namespace Barotrauma hullVolumeFrame.Visible = MapEntity.SelectedList.Any(s => s is Hull); - if (GUIComponent.MouseOn == null) - { - cam.MoveCamera((float)deltaTime); - } + cam.MoveCamera((float)deltaTime); if (characterMode || wiringMode) {