From 19915fc4e555b87689e4efd64cce09641369e20d Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 6 Jul 2016 18:08:26 +0300 Subject: [PATCH] - server log and item lists in editor can be filtered - changes to item highlighting logic (easier in cramped subs) - sub name/description boxes and selected items are reset when leaving the editor --- Subsurface/Content/Items/Ladder/ladder.xml | 2 +- Subsurface/Source/Characters/Character.cs | 11 +-- Subsurface/Source/GUI/GUIListBox.cs | 9 +-- Subsurface/Source/GUI/GUIScrollBar.cs | 5 -- .../Items/Components/Holdable/RepairTool.cs | 2 + .../Items/Components/Machines/Reactor.cs | 7 +- Subsurface/Source/Items/Item.cs | 70 +++++++++++-------- Subsurface/Source/Map/MapEntity.cs | 10 ++- Subsurface/Source/Map/Submarine.cs | 2 + Subsurface/Source/Networking/GameServer.cs | 2 +- Subsurface/Source/Networking/ServerLog.cs | 43 +++++++++++- Subsurface/Source/Screens/EditMapScreen.cs | 53 +++++++++++++- 12 files changed, 162 insertions(+), 54 deletions(-) diff --git a/Subsurface/Content/Items/Ladder/ladder.xml b/Subsurface/Content/Items/Ladder/ladder.xml index 44f701ed3..e33ff2387 100644 --- a/Subsurface/Content/Items/Ladder/ladder.xml +++ b/Subsurface/Content/Items/Ladder/ladder.xml @@ -7,5 +7,5 @@ - + \ No newline at end of file diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 995f9ecaa..7d5a5d2b2 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -752,8 +752,10 @@ namespace Barotrauma } } - private Item FindClosestItem(Vector2 mouseSimPos) + private Item FindClosestItem(Vector2 mouseSimPos, out float distance) { + distance = 0.0f; + Limb torso = AnimController.GetLimb(LimbType.Torso); if (torso == null) return null; @@ -769,7 +771,7 @@ namespace Barotrauma if (selectedConstruction != null) pickPos = ConvertUnits.ToSimUnits(selectedConstruction.WorldPosition); - return Item.FindPickable(pos, pickPos, AnimController.CurrentHull, selectedItems); + return Item.FindPickable(pos, pickPos, AnimController.CurrentHull, selectedItems, out distance); } private Character FindClosestCharacter(Vector2 mouseSimPos, float maxDist = 150.0f) @@ -890,11 +892,12 @@ namespace Barotrauma closestCharacter = null; } - closestItem = FindClosestItem(mouseSimPos); + float closestItemDist = 0.0f; + closestItem = FindClosestItem(mouseSimPos, out closestItemDist); if (closestCharacter != null && closestItem != null) { - if (Vector2.Distance(closestCharacter.SimPosition, mouseSimPos) < Vector2.Distance(closestItem.SimPosition, mouseSimPos)) + if (Vector2.Distance(closestCharacter.SimPosition, mouseSimPos) < ConvertUnits.ToSimUnits(closestItemDist)) { if (selectedConstruction != closestItem) closestItem = null; } diff --git a/Subsurface/Source/GUI/GUIListBox.cs b/Subsurface/Source/GUI/GUIListBox.cs index 8e466b1de..7943a2867 100644 --- a/Subsurface/Source/GUI/GUIListBox.cs +++ b/Subsurface/Source/GUI/GUIListBox.cs @@ -309,7 +309,7 @@ namespace Barotrauma for (int i = 0; i < children.Count; i++) { GUIComponent child = children[i]; - if (child == frame) continue; + if (child == frame || !child.Visible) continue; child.Rect = new Rectangle(x, y, child.Rect.Width, child.Rect.Height); if (scrollBar.IsHorizontal) @@ -321,7 +321,6 @@ namespace Barotrauma y += child.Rect.Height + spacing; } - child.Visible = false; if (scrollBar.IsHorizontal) { @@ -345,11 +344,7 @@ namespace Barotrauma continue; } } - - - - child.Visible = true; - + if (enabled && child.CanBeFocused && (MouseOn == this || (MouseOn != null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.MousePosition)) { diff --git a/Subsurface/Source/GUI/GUIScrollBar.cs b/Subsurface/Source/GUI/GUIScrollBar.cs index fc6f0a0eb..847be1243 100644 --- a/Subsurface/Source/GUI/GUIScrollBar.cs +++ b/Subsurface/Source/GUI/GUIScrollBar.cs @@ -191,11 +191,6 @@ namespace Barotrauma //barScroll = (float)newY / ((float)frame.Rect.Height - (float)bar.Rect.Height); } - if (moveAmount != 0) - { - int asdf = 1; - } - BarScroll = barScroll; if (moveAmount != 0 && OnMoved != null) OnMoved(this, BarScroll); diff --git a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs index 8b288773a..2f5532b08 100644 --- a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs +++ b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs @@ -169,6 +169,8 @@ namespace Barotrauma.Items.Components if (targetBody == null || targetBody.UserData == null) return; + pickedPosition = Submarine.LastPickedPosition; + Structure targetStructure; Limb targetLimb; Item targetItem; diff --git a/Subsurface/Source/Items/Components/Machines/Reactor.cs b/Subsurface/Source/Items/Components/Machines/Reactor.cs index 029727c75..20a304a6e 100644 --- a/Subsurface/Source/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Source/Items/Components/Machines/Reactor.cs @@ -589,8 +589,11 @@ namespace Barotrauma.Items.Components var sender = GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection); if (sender != null) { - Networking.GameServer.Log("Reactor settings adjusted by " + sender.name+": ", Color.Orange); - Networking.GameServer.Log("Autotemp: " +(autoTemp ? "ON " : "OFF") + " Shutdown temp: "+shutDownTemp+" Cooling rate: "+(int)coolingRate+" Fission rate: "+(int)fissionRate, Color.Orange); + Networking.GameServer.Log( + "Reactor settings adjusted by " + sender.name+": \n"+ + "Autotemp: " + (autoTemp ? "ON " : "OFF") + " Shutdown temp: " + shutDownTemp + + " Cooling rate: " + (int)coolingRate + " Fission rate: " + (int)fissionRate, + Color.Orange); } } diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 2f79d7a0a..dca27ec31 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -1116,10 +1116,16 @@ namespace Barotrauma yield return CoroutineStatus.Success; } + public static Item FindPickable(Vector2 position, Vector2 pickPosition, Hull hull = null, Item[] ignoredItems = null) + { + float dist; + return FindPickable(position, pickPosition, hull, ignoredItems, out dist); + } + /// Position of the Character doing the pick, only items that are close enough to this are checked /// the item closest to pickPosition is returned /// If a hull is specified, only items within that hull are checked - public static Item FindPickable(Vector2 position, Vector2 pickPosition, Hull hull = null, Item[] ignoredItems=null) + public static Item FindPickable(Vector2 position, Vector2 pickPosition, Hull hull, Item[] ignoredItems, out float distance) { float closestDist = 0.0f, dist; Item closest = null; @@ -1127,55 +1133,59 @@ namespace Barotrauma Vector2 displayPos = ConvertUnits.ToDisplayUnits(position); Vector2 displayPickPos = ConvertUnits.ToDisplayUnits(pickPosition); + distance = 1000.0f; + foreach (Item item in ItemList) { - if (ignoredItems!=null && ignoredItems.Contains(item)) continue; - //if (hull != item.CurrentHull && (hull==null || (item.Rect.Height(); if (pickableComponent != null && (pickableComponent.Picker != null && !pickableComponent.Picker.IsDead)) continue; + float pickDist = Vector2.Distance(item.WorldPosition, displayPickPos); + + bool outsideTrigger = false; foreach (Rectangle trigger in item.prefab.Triggers) { Rectangle transformedTrigger = item.TransformTrigger(trigger, true); - - if (!Submarine.RectContains(transformedTrigger, displayPos)) continue; - - Vector2 triggerCenter = - new Vector2( - transformedTrigger.X + transformedTrigger.Width / 2.0f, - transformedTrigger.Y - transformedTrigger.Height / 2.0f); - //dist = MathHelper.Min(Math.Abs(triggerCenter.X - displayPos.X), Math.Abs(triggerCenter.Y-displayPos.Y)); - //if (dist > closestDist && closest!=null) continue; - - dist = MathHelper.Min(Math.Abs(triggerCenter.X - displayPickPos.X), Math.Abs(triggerCenter.Y - displayPickPos.Y)); - if (closest == null || dist < closestDist) + if (!Submarine.RectContains(transformedTrigger, displayPos)) { - closest = item; - closestDist = dist; + outsideTrigger = true; + continue; } - } - - if (item.prefab.PickDistance == 0.0f) continue; - if (Vector2.Distance(displayPos, item.WorldPosition) > item.prefab.PickDistance) continue; - - if (!item.prefab.PickThroughWalls) - { - Body body = Submarine.CheckVisibility(item.Submarine == null ? position : position - item.Submarine.SimPosition, item.SimPosition, true); - if (body != null && body.UserData as Item != item) continue; + Vector2 triggerCenter = new Vector2(transformedTrigger.Center.X, transformedTrigger.Y - transformedTrigger.Height / 2); + pickDist = Math.Min(Math.Abs(triggerCenter.X - displayPickPos.X), Math.Abs(triggerCenter.Y - displayPickPos.Y)); } - dist = Vector2.Distance(displayPickPos, item.WorldPosition); - if (dist < item.prefab.PickDistance && (closest == null || dist < closestDist)) + if (outsideTrigger) continue; + + if (pickDist > item.PickDistance && item.PickDistance > 0.0f) continue; + + dist = item.Sprite.Depth * 10.0f + pickDist; + if (item.IsMouseOn(displayPickPos)) dist = dist * 0.1f; + + if (closest == null || dist < closestDist) { - closest = item; + if (item.PickDistance > 0.0f && Vector2.Distance(displayPos, item.WorldPosition) > item.prefab.PickDistance) continue; + + if (!item.prefab.PickThroughWalls) + { + Body body = Submarine.CheckVisibility(item.Submarine == null ? position : position - item.Submarine.SimPosition, item.SimPosition, true); + if (body != null && body.UserData as Item != item) continue; + } + closestDist = dist; + closest = item; + + distance = pickDist; } } - + return closest; } diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index f079fb7d9..1e22344a0 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -467,13 +467,19 @@ namespace Barotrauma } } - public static void SelectEntity(MapEntity entity) + public static void DeselectAll() { foreach (MapEntity e in selectedList) - { + { e.isSelected = false; } selectedList.Clear(); + } + + + public static void SelectEntity(MapEntity entity) + { + DeselectAll(); entity.isSelected = true; selectedList.Add(entity); diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index cc0d87b10..232560b76 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -927,6 +927,8 @@ namespace Barotrauma subBody = null; + if (MainSub == this) MainSub = null; + DockedTo.Clear(); } } diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index f29fad662..2be79e8bb 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -272,7 +272,6 @@ namespace Barotrauma.Networking { if (ShowNetStats) netStats.Update(deltaTime); if (settingsFrame != null) settingsFrame.Update(deltaTime); - if (log.LogFrame != null) log.LogFrame.Update(deltaTime); if (!started) return; @@ -1345,6 +1344,7 @@ namespace Barotrauma.Networking } else if (log.LogFrame!=null) { + log.LogFrame.Update(0.016f); log.LogFrame.Draw(spriteBatch); } diff --git a/Subsurface/Source/Networking/ServerLog.cs b/Subsurface/Source/Networking/ServerLog.cs index 5e2331dda..109af4624 100644 --- a/Subsurface/Source/Networking/ServerLog.cs +++ b/Subsurface/Source/Networking/ServerLog.cs @@ -62,7 +62,18 @@ namespace Barotrauma.Networking GUIFrame innerFrame = new GUIFrame(new Rectangle(0,0,400, 400), null, Alignment.Center, GUI.Style, LogFrame); innerFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); - listBox = new GUIListBox(new Rectangle(0,0,0,355), GUI.Style, innerFrame); + new GUITextBlock(new Rectangle(-200,0,100,15), "Filter", GUI.Style, Alignment.TopRight, Alignment.TopRight, innerFrame, false, GUI.SmallFont); + + GUITextBox searchBox = new GUITextBox(new Rectangle(-20,0,180,15), Alignment.TopRight, GUI.Style, innerFrame); + searchBox.Font = GUI.SmallFont; + searchBox.OnTextChanged = FilterMessages; + GUIComponent.KeyboardDispatcher.Subscriber = searchBox; + + var clearButton = new GUIButton(new Rectangle(0,0,15,15), "x", Alignment.TopRight, GUI.Style, innerFrame); + clearButton.OnClicked = ClearFilter; + clearButton.UserData = searchBox; + + listBox = new GUIListBox(new Rectangle(0,20,0,335), GUI.Style, innerFrame); var currLines = lines.ToList(); @@ -92,6 +103,36 @@ namespace Barotrauma.Networking textBlock.CanBeFocused = false; } + private bool FilterMessages(GUITextBox textBox, string text) + { + if (string.IsNullOrWhiteSpace(text)) + { + listBox.children.ForEach( c => c.Visible = true); + return true; + } + + text = text.ToLower(); + + foreach (GUITextBlock textBlock in listBox.children) + { + if (textBlock == null) continue; + + textBlock.Visible = textBlock.Text.ToLower().Contains(text); + } + + return true; + } + + public bool ClearFilter(GUIComponent button, object obj) + { + FilterMessages(null, ""); + + var searchBox = button.UserData as GUITextBox; + if (searchBox != null) searchBox.Text = ""; + + return true; + } + public void Save() { if (!Directory.Exists(SavePath)) diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index 3d84d432f..10ab83d1d 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -137,7 +137,18 @@ namespace Barotrauma GUItabs[i] = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style); GUItabs[i].Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); - GUIListBox itemList = new GUIListBox(new Rectangle(0, 0, 0, 0), Color.White * 0.7f, GUI.Style, GUItabs[i]); + new GUITextBlock(new Rectangle(-200, 0, 100, 15), "Filter", GUI.Style, Alignment.TopRight, Alignment.TopRight, GUItabs[i], false, GUI.SmallFont); + + GUITextBox searchBox = new GUITextBox(new Rectangle(-20, 0, 180, 15), Alignment.TopRight, GUI.Style, GUItabs[i]); + searchBox.Font = GUI.SmallFont; + searchBox.OnTextChanged = FilterMessages; + GUIComponent.KeyboardDispatcher.Subscriber = searchBox; + + var clearButton = new GUIButton(new Rectangle(0, 0, 15, 15), "x", Alignment.TopRight, GUI.Style, GUItabs[i]); + clearButton.OnClicked = ClearFilter; + clearButton.UserData = searchBox; + + GUIListBox itemList = new GUIListBox(new Rectangle(0, 20, 0, 0), Color.White * 0.7f, GUI.Style, GUItabs[i]); itemList.OnSelected = SelectPrefab; itemList.CheckSelected = MapEntityPrefab.GetSelected; @@ -269,6 +280,8 @@ namespace Barotrauma MapEntityPrefab.Selected = null; + MapEntity.DeselectAll(); + if (characterMode) ToggleCharacterMode(); if (wiringMode) ToggleWiringMode(); @@ -425,9 +438,47 @@ namespace Barotrauma private bool SelectTab(GUIButton button, object obj) { selectedTab = (int)obj; + + ClearFilter(GUItabs[selectedTab].GetChild(), null); + + GUIComponent.KeyboardDispatcher.Subscriber = GUItabs[selectedTab].GetChild(); + return true; } + private bool FilterMessages(GUITextBox textBox, string text) + { + if (selectedTab == -1) + { + GUIComponent.KeyboardDispatcher.Subscriber = null; + return false; + } + + if (string.IsNullOrWhiteSpace(text)) + { + GUItabs[selectedTab].GetChild().children.ForEach(c => c.Visible = true); + return true; + } + + text = text.ToLower(); + + foreach (GUIComponent child in GUItabs[selectedTab].GetChild().children) + { + child.Visible = child.GetChild().Text.ToLower().Contains(text); + } + + return true; + } + + public bool ClearFilter(GUIComponent button, object obj) + { + FilterMessages(null, ""); + + var searchBox = button.UserData as GUITextBox; + if (searchBox != null) searchBox.Text = ""; + + return true; + } public void ToggleCharacterMode() {