From 2290645bc9451e913e463861d3b5a7e179a78d9b Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 3 Apr 2019 16:29:47 +0300 Subject: [PATCH] (caa04a08a) Added a search bar to fabricators, made the interface larger and item previews smaller to fit more items in the view, take chatbox into account when preventing item interface overlap. Closes #1305 + merge fix --- .../BarotraumaClient/Source/GameSettings.cs | 53 ------------------ .../Items/Components/Machines/Fabricator.cs | 55 +++++++++++++++++-- .../BarotraumaClient/Source/Items/Item.cs | 3 + .../BarotraumaClient/Source/Sprite/Sprite.cs | 2 - .../Items/Components/Signal/LightComponent.cs | 6 -- .../Source/Physics/PhysicsBody.cs | 1 - 6 files changed, 53 insertions(+), 67 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GameSettings.cs b/Barotrauma/BarotraumaClient/Source/GameSettings.cs index b55758962..4f8d0a992 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSettings.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSettings.cs @@ -648,59 +648,6 @@ namespace Barotrauma //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), inputFrame.RectTransform), style: null); } - GUITextBlock aimAssistText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), controlsLayoutGroup.RectTransform), TextManager.Get("AimAssist")); - GUIScrollBar aimAssistSlider = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), controlsLayoutGroup.RectTransform), - barSize: 0.05f) - { - UserData = aimAssistText, - BarScroll = MathUtils.InverseLerp(0.0f, 5.0f, AimAssistAmount), - OnMoved = (scrollBar, scroll) => - { - ChangeSliderText(scrollBar, scroll); - AimAssistAmount = MathHelper.Lerp(0.0f, 5.0f, scroll); - return true; - }, - Step = 0.1f - }; - aimAssistSlider.OnMoved(aimAssistSlider, aimAssistSlider.BarScroll); - - //spacing - new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), generalLayoutGroup.RectTransform), style: null); - - new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonArea.RectTransform, Anchor.BottomLeft), - TextManager.Get("Cancel"), style: "GUIButtonLarge") - { - IgnoreLayoutGroups = true, - OnClicked = (x, y) => - { - if (UnsavedSettings) - { - LoadPlayerConfig(); - } - if (Screen.Selected == GameMain.MainMenuScreen) GameMain.MainMenuScreen.ReturnToMainMenu(null, null); - GUI.SettingsMenuOpen = false; - return true; - } - }; - - //spacing - new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), generalLayoutGroup.RectTransform), style: null); - - new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonArea.RectTransform, Anchor.BottomLeft), - TextManager.Get("Cancel"), style: "GUIButtonLarge") - { - IgnoreLayoutGroups = true, - OnClicked = (x, y) => - { - if (UnsavedSettings) - { - LoadPlayerConfig(); - } - if (Screen.Selected == GameMain.MainMenuScreen) GameMain.MainMenuScreen.ReturnToMainMenu(null, null); - GUI.SettingsMenuOpen = false; - return true; - } - }; //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), generalLayoutGroup.RectTransform), style: null); diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs index e074796e4..4dc0b89a1 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs @@ -17,6 +17,8 @@ namespace Barotrauma.Items.Components private GUIButton activateButton; + private GUITextBox itemFilterBox; + private GUIComponent inputInventoryHolder, outputInventoryHolder; private GUICustomComponent inputInventoryOverlay, outputInventoryOverlay; @@ -28,12 +30,25 @@ namespace Barotrauma.Items.Components partial void InitProjSpecific() { - var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.9f), GuiFrame.RectTransform, Anchor.Center), childAnchor: Anchor.TopCenter) + var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), GuiFrame.RectTransform, Anchor.Center), childAnchor: Anchor.TopCenter) { Stretch = true, RelativeSpacing = 0.02f }; + var filterArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.06f), paddedFrame.RectTransform), isHorizontal: true) + { + Stretch = true, + UserData = "filterarea" + }; + new GUITextBlock(new RectTransform(new Vector2(0.25f, 1.0f), filterArea.RectTransform), TextManager.Get("FilterMapEntities"), font: GUI.Font); + itemFilterBox = new GUITextBox(new RectTransform(new Vector2(0.8f, 1.0f), filterArea.RectTransform), font: GUI.Font); + itemFilterBox.OnTextChanged += (textBox, text) => { FilterEntities(text); return true; }; + var clearButton = new GUIButton(new RectTransform(new Vector2(0.1f, 1.0f), filterArea.RectTransform), "x") + { + OnClicked = (btn, userdata) => { ClearFilter(); itemFilterBox.Flash(Color.White); return true; } + }; + itemList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.5f), paddedFrame.RectTransform)) { OnSelected = (GUIComponent component, object userdata) => @@ -50,7 +65,7 @@ namespace Barotrauma.Items.Components CanBeFocused = false }; - var outputArea = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.3f), paddedFrame.RectTransform), isHorizontal: true); + var outputArea = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.25f), paddedFrame.RectTransform), isHorizontal: true); selectedItemFrame = new GUIFrame(new RectTransform(new Vector2(0.75f, 1.0f), outputArea.RectTransform), style: "InnerFrame"); outputInventoryHolder = new GUIFrame(new RectTransform(new Vector2(0.25f, 1.0f), outputArea.RectTransform), style: null); @@ -61,7 +76,7 @@ namespace Barotrauma.Items.Components foreach (FabricationRecipe fi in fabricationRecipes) { - GUIFrame frame = new GUIFrame(new RectTransform(new Point(itemList.Rect.Width, 50), itemList.Content.RectTransform), style: null) + GUIFrame frame = new GUIFrame(new RectTransform(new Point(itemList.Rect.Width, 30), itemList.Content.RectTransform), style: null) { UserData = fi, HoverColor = Color.Gold * 0.2f, @@ -78,7 +93,7 @@ namespace Barotrauma.Items.Components var itemIcon = fi.TargetItem.InventoryIcon ?? fi.TargetItem.sprite; if (itemIcon != null) { - GUIImage img = new GUIImage(new RectTransform(new Point(40, 40), frame.RectTransform, Anchor.CenterLeft) { AbsoluteOffset = new Point(3, 0) }, + GUIImage img = new GUIImage(new RectTransform(new Point(30, 30), frame.RectTransform, Anchor.CenterLeft) { AbsoluteOffset = new Point(3, 0) }, itemIcon, scaleToFit: true) { Color = fi.TargetItem.InventoryIconColor, @@ -88,7 +103,7 @@ namespace Barotrauma.Items.Components } activateButton = new GUIButton(new RectTransform(new Vector2(0.8f, 0.07f), paddedFrame.RectTransform), - TextManager.Get("FabricatorCreate")) + TextManager.Get("FabricatorCreate"), style: "GUIButtonLarge") { OnClicked = StartButtonClicked, UserData = selectedItem, @@ -257,6 +272,36 @@ namespace Barotrauma.Items.Components } } + private bool FilterEntities(string filter) + { + if (string.IsNullOrWhiteSpace(filter)) + { + itemList.Content.Children.ForEach(c => c.Visible = true); + return true; + } + + filter = filter.ToLower(); + foreach (GUIComponent child in itemList.Content.Children) + { + FabricationRecipe recipe = child.UserData as FabricationRecipe; + if (recipe?.DisplayName == null) { continue; } + child.Visible = recipe.DisplayName.ToLower().Contains(filter); + } + itemList.UpdateScrollBarSize(); + itemList.BarScroll = 0.0f; + + return true; + } + + public bool ClearFilter() + { + FilterEntities(""); + itemList.UpdateScrollBarSize(); + itemList.BarScroll = 0.0f; + itemFilterBox.Text = ""; + return true; + } + private bool SelectItem(Character user, FabricationRecipe selectedItem) { selectedItemFrame.ClearChildren(); diff --git a/Barotrauma/BarotraumaClient/Source/Items/Item.cs b/Barotrauma/BarotraumaClient/Source/Items/Item.cs index 574b97e2e..03f723062 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Item.cs @@ -607,6 +607,9 @@ namespace Barotrauma if (GameMain.GameSession?.CrewManager != null) { disallowedAreas.Add(GameMain.GameSession.CrewManager.GetCharacterListArea()); + disallowedAreas.Add(new Rectangle( + HUDLayoutSettings.ChatBoxArea.X - 150, HUDLayoutSettings.ChatBoxArea.Y, + HUDLayoutSettings.ChatBoxArea.Width + 150, HUDLayoutSettings.ChatBoxArea.Height)); } GUI.PreventElementOverlap(elementsToMove, disallowedAreas, diff --git a/Barotrauma/BarotraumaClient/Source/Sprite/Sprite.cs b/Barotrauma/BarotraumaClient/Source/Sprite/Sprite.cs index 50640ffbf..324b091aa 100644 --- a/Barotrauma/BarotraumaClient/Source/Sprite/Sprite.cs +++ b/Barotrauma/BarotraumaClient/Source/Sprite/Sprite.cs @@ -10,8 +10,6 @@ namespace Barotrauma { protected Texture2D texture; - private bool preMultipliedAlpha; - public Texture2D Texture { get diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs index eebf1146a..4f140dd39 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs @@ -24,12 +24,6 @@ namespace Barotrauma.Items.Components private bool itemLoaded; - private float blinkTimer; - - private bool itemLoaded; - - private float blinkTimer; - public PhysicsBody ParentBody; [Editable(MinValueFloat = 0.0f, MaxValueFloat = 2048.0f), Serialize(100.0f, true)] diff --git a/Barotrauma/BarotraumaShared/Source/Physics/PhysicsBody.cs b/Barotrauma/BarotraumaShared/Source/Physics/PhysicsBody.cs index b8823bf70..4113750c9 100644 --- a/Barotrauma/BarotraumaShared/Source/Physics/PhysicsBody.cs +++ b/Barotrauma/BarotraumaShared/Source/Physics/PhysicsBody.cs @@ -584,7 +584,6 @@ namespace Barotrauma /// public void ApplyLinearImpulse(Vector2 impulse, float maxVelocity) { - if (!IsValidValue(impulse / body.Mass, "new velocity")) return; if (!IsValidValue(impulse, "impulse", -1e10f, 1e10f)) return; if (!IsValidValue(maxVelocity, "max velocity")) return;